This support has been deprecated since v2017.09 due to security issues.
We now remove this support.
Signed-off-by: Tom Rini <trini@konsulko.com>
endchoice
-config ENV_AES
- bool "AES-128 encryption for stored environment (DEPRECATED)"
- help
- Enable this to have the on-device stored environment be encrypted
- with AES-128. The implementation here however has security
- complications and is not recommended for use. Please see
- CVE-2017-3225 and CVE-2017-3226 for more details.
-
config ENV_FAT_INTERFACE
string "Name of the block device for the environment"
depends on ENV_IS_IN_FAT
H_NOCLEAR | H_INTERACTIVE, 0, nvars, vars);
}
-#ifdef CONFIG_ENV_AES
-#include <uboot_aes.h>
-/**
- * env_aes_cbc_get_key() - Get AES-128-CBC key for the environment
- *
- * This function shall return 16-byte array containing AES-128 key used
- * to encrypt and decrypt the environment. This function must be overridden
- * by the implementer as otherwise the environment encryption will not
- * work.
- */
-__weak uint8_t *env_aes_cbc_get_key(void)
-{
- return NULL;
-}
-
-static int env_aes_cbc_crypt(env_t *env, const int enc)
-{
- unsigned char *data = env->data;
- uint8_t *key;
- uint8_t key_exp[AES_EXPAND_KEY_LENGTH];
- uint32_t aes_blocks;
-
- key = env_aes_cbc_get_key();
- if (!key)
- return -EINVAL;
-
- /* First we expand the key. */
- aes_expand_key(key, key_exp);
-
- /* Calculate the number of AES blocks to encrypt. */
- aes_blocks = ENV_SIZE / AES_KEY_LENGTH;
-
- if (enc)
- aes_cbc_encrypt_blocks(key_exp, data, data, aes_blocks);
- else
- aes_cbc_decrypt_blocks(key_exp, data, data, aes_blocks);
-
- return 0;
-}
-#else
-static inline int env_aes_cbc_crypt(env_t *env, const int enc)
-{
- return 0;
-}
-#endif
-
/*
* Check if CRC is valid and (if yes) import the environment.
* Note that "buf" may or may not be aligned.
int env_import(const char *buf, int check)
{
env_t *ep = (env_t *)buf;
- int ret;
if (check) {
uint32_t crc;
}
}
- /* Decrypt the env if desired. */
- ret = env_aes_cbc_crypt(ep, 0);
- if (ret) {
- pr_err("Failed to decrypt env!\n");
- set_default_env("!import failed");
- return ret;
- }
-
if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0, 0,
0, NULL)) {
gd->flags |= GD_FLG_ENV_READY;
{
char *res;
ssize_t len;
- int ret;
res = (char *)env_out->data;
len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL);
return 1;
}
- /* Encrypt the env if desired. */
- ret = env_aes_cbc_crypt(env_out, 1);
- if (ret)
- return ret;
-
env_out->crc = crc32(0, env_out->data, ENV_SIZE);
#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
# define ENV_HEADER_SIZE (sizeof(uint32_t))
#endif
-#ifdef CONFIG_ENV_AES
-/* Make sure the payload is multiple of AES block size */
-#define ENV_SIZE ((CONFIG_ENV_SIZE - ENV_HEADER_SIZE) & ~(16 - 1))
-#else
#define ENV_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE)
-#endif
typedef struct environment_s {
uint32_t crc; /* CRC32 over data bytes */
unsigned char flags; /* active/obsolete flags */
#endif
unsigned char data[ENV_SIZE]; /* Environment data */
-} env_t
-#ifdef CONFIG_ENV_AES
-/* Make sure the env is aligned to block size. */
-__attribute__((aligned(16)))
-#endif
-;
+} env_t;
#ifdef ENV_IS_EMBEDDED
extern env_t environment;
lib-y += fw_env.o \
crc32.o ctype.o linux_string.o \
- env_attr.o env_flags.o aes.o
+ env_attr.o env_flags.o
fw_printenv-objs := fw_env_main.o $(lib-y)
+++ /dev/null
-#include "../../lib/aes.c"
.flag_scheme = FLAG_NONE,
};
-static int env_aes_cbc_crypt(char *data, const int enc, uint8_t *key);
-
static int HaveRedundEnv = 0;
static unsigned char active_flag = 1;
return NULL;
}
-int parse_aes_key(char *key, uint8_t *bin_key)
-{
- char tmp[5] = { '0', 'x', 0, 0, 0 };
- unsigned long ul;
- int i;
-
- if (strnlen(key, 64) != 32) {
- fprintf(stderr,
- "## Error: '-a' option requires 16-byte AES key\n");
- return -1;
- }
-
- for (i = 0; i < 16; i++) {
- tmp[2] = key[0];
- tmp[3] = key[1];
- errno = 0;
- ul = strtoul(tmp, NULL, 16);
- if (errno) {
- fprintf(stderr,
- "## Error: '-a' option requires valid AES key\n");
- return -1;
- }
- bin_key[i] = ul & 0xff;
- key += 2;
- }
- return 0;
-}
-
/*
* Print the current definition of one, or more, or all
* environment variables
if (!opts)
opts = &default_opts;
- if (opts->aes_flag) {
- ret = env_aes_cbc_crypt(environment.data, 1,
- opts->aes_key);
- if (ret) {
- fprintf(stderr,
- "Error: can't encrypt env for flash\n");
- return ret;
- }
- }
-
/*
* Update CRC
*/
return rc;
}
-/* Encrypt or decrypt the environment before writing or reading it. */
-static int env_aes_cbc_crypt(char *payload, const int enc, uint8_t *key)
-{
- uint8_t *data = (uint8_t *)payload;
- const int len = usable_envsize;
- uint8_t key_exp[AES_EXPAND_KEY_LENGTH];
- uint32_t aes_blocks;
-
- /* First we expand the key. */
- aes_expand_key(key, key_exp);
-
- /* Calculate the number of AES blocks to encrypt. */
- aes_blocks = DIV_ROUND_UP(len, AES_KEY_LENGTH);
-
- if (enc)
- aes_cbc_encrypt_blocks(key_exp, data, data, aes_blocks);
- else
- aes_cbc_decrypt_blocks(key_exp, data, data, aes_blocks);
-
- return 0;
-}
-
static int flash_write (int fd_current, int fd_target, int dev_target)
{
int rc;
crc0 = crc32 (0, (uint8_t *) environment.data, ENV_SIZE);
- if (opts->aes_flag) {
- ret = env_aes_cbc_crypt(environment.data, 0,
- opts->aes_key);
- if (ret)
- goto open_cleanup;
- }
-
crc0_ok = (crc0 == *environment.crc);
if (!HaveRedundEnv) {
if (!crc0_ok) {
crc1 = crc32 (0, (uint8_t *) redundant->data, ENV_SIZE);
- if (opts->aes_flag) {
- ret = env_aes_cbc_crypt(redundant->data, 0,
- opts->aes_key);
- if (ret)
- goto open_cleanup;
- }
-
crc1_ok = (crc1 == redundant->crc);
flag1 = redundant->flags;
if (HaveRedundEnv)
usable_envsize -= sizeof(char);
- if (opts->aes_flag)
- usable_envsize &= ~(AES_KEY_LENGTH - 1);
-
return 0;
}
*/
#include <stdint.h>
-#include <uboot_aes.h>
/*
* Programs using the library must check which API is available,
#ifdef CONFIG_FILE
char *config_file;
#endif
- int aes_flag; /* Is AES encryption used? */
- uint8_t aes_key[AES_KEY_LENGTH];
char *lockname;
};
-int parse_aes_key(char *key, uint8_t *bin_key);
-
/**
* fw_printenv() - print one or several environment variables
*
static int do_printenv;
static struct option long_options[] = {
- {"aes", required_argument, NULL, 'a'},
{"config", required_argument, NULL, 'c'},
{"help", no_argument, NULL, 'h'},
{"script", required_argument, NULL, 's'},
"\n"
" -h, --help print this help.\n"
" -v, --version display version\n"
-#ifdef CONFIG_ENV_AES
- " -a, --aes aes key to access environment\n"
-#endif
#ifdef CONFIG_FILE
" -c, --config configuration file, default:" CONFIG_FILE "\n"
#endif
"\n"
" -h, --help print this help.\n"
" -v, --version display version\n"
-#ifdef CONFIG_ENV_AES
- " -a, --aes aes key to access environment\n"
-#endif
#ifdef CONFIG_FILE
" -c, --config configuration file, default:" CONFIG_FILE "\n"
#endif
while ((c = getopt_long(argc, argv, ":a:c:l:h:v", long_options, NULL)) !=
EOF) {
switch (c) {
- case 'a':
- if (parse_aes_key(optarg, env_opts.aes_key)) {
- fprintf(stderr, "AES key parse error\n");
- exit(EXIT_FAILURE);
- }
- env_opts.aes_flag = 1;
- break;
#ifdef CONFIG_FILE
case 'c':
env_opts.config_file = optarg;