Commit 391834c4 authored by Marek Vasut's avatar Marek Vasut
Browse files

mxssb: Split image encryption and wrtiting function



Split the code that encrypts portions of the image and the code
that assembles the resulting image in memory.
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent 3cc85a72
......@@ -368,13 +368,10 @@ static void sb_emit_data(uint8_t *image, size_t *offset, void *data, size_t len)
*offset += len;
}
static int sb_create_image(struct sb_image_ctx *ictx, uint8_t **image)
static int sb_create_image(struct sb_image_ctx *ictx)
{
struct sb_boot_image_header *sb_header = &ictx->payload;
/* The currect offset in the SB image. */
size_t image_offset = 0;
/* Start image-wide crypto. */
EVP_MD_CTX_init(&ictx->md_ctx);
EVP_DigestInit(&ictx->md_ctx, EVP_sha1());
......@@ -442,11 +439,20 @@ static int sb_create_image(struct sb_image_ctx *ictx, uint8_t **image)
/* Stop the encryption session. */
sb_aes_deinit(&ictx->cipher_ctx);
/*
* Export the image
*/
return 0;
}
static int sb_assemble_image(struct sb_image_ctx *ictx, uint8_t **image)
{
struct sb_boot_image_header *sb_header = &ictx->payload;
struct sb_section_ctx *sctx;
struct sb_cmd_ctx *cctx;
struct sb_command *ccmd;
struct sb_key_dictionary_key *sb_dict_key = &ictx->sb_dict_key;
/* The currect offset in the SB image. */
size_t image_offset = 0;
/* Allocate the resulting SB image. */
*image = malloc(sb_header->image_blocks * SB_BLOCK_SIZE);
if (!*image)
......@@ -984,7 +990,11 @@ int main(int argc, char **argv)
if (ret)
goto fail;
ret = sb_create_image(&ctx, &image);
ret = sb_create_image(&ctx);
if (ret)
return ret;
ret = sb_assemble_image(&ctx, &image);
if (ret)
return ret;
......
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