Commit c2d36932 authored by Marek Vasut's avatar Marek Vasut

mxssb: Add separate field into command context for encrypted data

The encryption of command data corrupted the contents of the
structure. To prevent that, store the encrypted command data
in a separate entry in the command context structure.
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent 9a2ba915
......@@ -50,6 +50,7 @@ struct sb_cmd_ctx {
uint32_t length;
struct sb_command payload;
struct sb_command c_payload;
};
struct sb_section_ctx {
......@@ -346,14 +347,16 @@ static uint8_t sb_command_checksum(struct sb_command *inst)
}
static void sb_encrypt_tag(struct sb_image_ctx *ictx,
struct sb_command *cmd,
uint8_t result[sizeof(struct sb_command)])
struct sb_cmd_ctx *cctx)
{
EVP_MD_CTX *md_ctx = &ictx->md_ctx;
struct sb_command *cmd = &cctx->payload;
cmd->header.checksum = sb_command_checksum(cmd);
sb_aes_encrypt(ictx, (uint8_t *)cmd, result, sizeof(*cmd));
EVP_DigestUpdate(md_ctx, result, sizeof(*cmd));
sb_aes_encrypt(ictx, (uint8_t *)cmd,
(uint8_t *)&cctx->c_payload, sizeof(*cmd));
EVP_DigestUpdate(md_ctx, &cctx->c_payload, sizeof(*cmd));
}
static void sb_emit_data(uint8_t *image, size_t *offset, void *data, size_t len)
......@@ -415,7 +418,6 @@ static int sb_create_image(struct sb_image_ctx *ictx, uint8_t **image)
/*
* Section tags.
*/
uint8_t encrypted_tag[sizeof(struct sb_command)];
struct sb_cmd_ctx *cctx;
struct sb_command *ccmd;
sctx = ictx->sect;
......@@ -428,9 +430,9 @@ static int sb_create_image(struct sb_image_ctx *ictx, uint8_t **image)
while (cctx) {
ccmd = &cctx->payload;
sb_encrypt_tag(ictx, ccmd, encrypted_tag);
sb_emit_data(*image, &image_offset, encrypted_tag,
sizeof(struct sb_command));
sb_encrypt_tag(ictx, cctx);
sb_emit_data(*image, &image_offset, &cctx->c_payload,
sizeof(cctx->payload));
if (ccmd->header.tag == ROM_TAG_CMD) {
sb_aes_reinit(ictx, sb_header->iv);
......
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