Skip to content

Commit

Permalink
Fixed sign tool SHA384 alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
danielinux committed Oct 28, 2024
1 parent 9d9e4f9 commit 34c9f67
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions tools/keytools/sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
{
#ifndef NO_SHA384
wc_Sha384 sha;
digest_sz = HDR_SHA384_LEN;
digest_sz = SHA384_DIGEST_SIZE;
ALIGN_8(header_idx);
printf("Calculating SHA384 digest...\n");
/* pubkey hash calculation */
Expand All @@ -1259,16 +1259,17 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
if (ret == 0) {
wc_Sha384Final(&sha, buf);
/* Add Pubkey Hash to header */
ALIGN_8(header_idx);
header_append_tag(header, &header_idx, HDR_PUBKEY, digest_sz, buf);
#ifdef DEBUG_SIGNTOOL
printf("Pubkey hash %d\n", digest_sz);
WOLFSSL_BUFFER(buf, digest_sz);
#endif
ALIGN_8(header_idx);
}
wc_Sha384Free(&sha);
}
if (ret == 0 && CMD.hybrid && secondary_key_sz > 0) {
ALIGN_8(header_idx);
ret = wc_InitSha384_ex(&sha, NULL, INVALID_DEVID);
if (ret == 0) {
ret = wc_Sha384Update(&sha, secondary_key, secondary_key_sz);
Expand All @@ -1282,6 +1283,7 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
printf("Secondary pubkey hash %d\n", digest_sz);
WOLFSSL_BUFFER(second_buf, digest_sz);
#endif
ALIGN_8(header_idx);
}
wc_Sha384Free(&sha);
}
Expand All @@ -1308,8 +1310,10 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
pos += read_sz;
}
fclose(f);
if (ret == 0)
if (ret == 0) {
wc_Sha384Final(&sha, digest);
digest_sz = HDR_SHA384_LEN;
}
wc_Sha384Free(&sha);
}
#endif
Expand All @@ -1329,6 +1333,7 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
printf("Pubkey hash %d\n", digest_sz);
WOLFSSL_BUFFER(buf, digest_sz);
#endif
ALIGN_8(header_idx);
}
wc_Sha3_384_Free(&sha);
}
Expand All @@ -1346,6 +1351,7 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
printf("Secondary pubkey hash %d\n", digest_sz);
WOLFSSL_BUFFER(second_buf, digest_sz);
#endif
ALIGN_8(header_idx);
}
wc_Sha3_384_Free(&sha);
}
Expand Down Expand Up @@ -1375,8 +1381,10 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
pos += read_sz;
}
fclose(f);
if (ret == 0)
if (ret == 0) {
ret = wc_Sha3_384_Final(&sha, digest);
digest_sz = HDR_SHA3_384_LEN;
}
wc_Sha3_384_Free(&sha);
}

Expand All @@ -1392,7 +1400,6 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
#endif

/* Add image hash to header */
ALIGN_8(header_idx);
header_append_tag(header, &header_idx, CMD.hash_algo, digest_sz, digest);
if (CMD.sign != NO_SIGN) {
/* If hash only, then save digest and exit */
Expand Down

0 comments on commit 34c9f67

Please sign in to comment.