Commit aa89efd4 authored by Marek Vasut's avatar Marek Vasut

mxssb: Wrap image key into image context

The image key is part of the image context, don't make it into a
self-standing variable. Instead, wrap it into the image context
structure.
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent 39a8d5c4
......@@ -73,6 +73,7 @@ struct sb_image_ctx {
char *input_filename;
char *output_filename;
char *cfg_filename;
uint8_t image_key[16];
/* Number of section in the image */
unsigned int sect_count;
......@@ -107,9 +108,6 @@ struct sb_image_ctx {
* JTAG/SPI2_EEPROM/SD_SSP0/SD_SSP1
*/
/* Blank image key. */
static uint8_t image_key[16] = {0};
/*
* AES libcrypto
*/
......@@ -120,10 +118,10 @@ static int sb_aes_init(struct sb_image_ctx *ictx, uint8_t *iv, int enc)
/* If there is no init vector, init vector is all zeroes. */
if (!iv)
iv = image_key;
iv = ictx->image_key;
EVP_CIPHER_CTX_init(ctx);
ret = EVP_CipherInit(ctx, EVP_aes_128_cbc(), image_key, iv, enc);
ret = EVP_CipherInit(ctx, EVP_aes_128_cbc(), ictx->image_key, iv, enc);
if (ret == 1)
EVP_CIPHER_CTX_set_padding(ctx, 0);
return ret;
......@@ -259,7 +257,7 @@ static void sb_encrypt_key_dictionary_key(struct sb_image_ctx *ictx)
{
EVP_MD_CTX *md_ctx = &ictx->md_ctx;
sb_aes_crypt(ictx, image_key, ictx->sb_dict_key.key,
sb_aes_crypt(ictx, ictx->image_key, ictx->sb_dict_key.key,
sizeof(ictx->sb_dict_key.key));
EVP_DigestUpdate(md_ctx, &ictx->sb_dict_key, sizeof(ictx->sb_dict_key));
}
......@@ -269,7 +267,7 @@ static void sb_decrypt_key_dictionary_key(struct sb_image_ctx *ictx)
EVP_MD_CTX *md_ctx = &ictx->md_ctx;
EVP_DigestUpdate(md_ctx, &ictx->sb_dict_key, sizeof(ictx->sb_dict_key));
sb_aes_crypt(ictx, ictx->sb_dict_key.key, image_key,
sb_aes_crypt(ictx, ictx->sb_dict_key.key, ictx->image_key,
sizeof(ictx->sb_dict_key.key));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment