Skip to content

Commit 01e22ed

Browse files
dgarskedanielinux
authored andcommitted
Fix sign tool TLV alignment padding.
1 parent 2826f70 commit 01e22ed

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

tools/keytools/sign.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ static inline int fp_truncate(FILE *f, size_t len)
6969

7070
#define MAX_SRC_SIZE (1 << 24)
7171

72+
#ifndef MAX_CUSTOM_TLVS
7273
#define MAX_CUSTOM_TLVS (16)
74+
#endif
7375

7476
#include <wolfssl/wolfcrypt/settings.h>
7577
#include <wolfssl/wolfcrypt/asn.h>
@@ -1082,11 +1084,10 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
10821084
if (CMD.custom_tlvs > 0) {
10831085
uint32_t i;
10841086
for (i = 0; i < CMD.custom_tlvs; i++) {
1085-
if (CMD.custom_tlv[i].len == 8) {
1086-
/* This field requires 8-byte alignment */
1087-
while((header_idx % 8) != 4)
1088-
header_idx++;
1089-
}
1087+
/* require 8-byte alignment */
1088+
while ((header_idx % 8) != 0)
1089+
header_idx++;
1090+
10901091
if (CMD.custom_tlv[i].buffer == NULL) {
10911092
header_append_tag(header, &header_idx, CMD.custom_tlv[i].tag,
10921093
CMD.custom_tlv[i].len, &CMD.custom_tlv[i].val);
@@ -1095,13 +1096,10 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
10951096
CMD.custom_tlv[i].len, CMD.custom_tlv[i].buffer);
10961097
}
10971098
}
1098-
/* Align for next field */
1099-
while ((header_idx % 4) != 0)
1100-
header_idx++;
11011099
}
11021100

11031101
/* Add padding bytes. Sha-3 val field requires 8-byte alignment */
1104-
while ((header_idx % 8) != 4)
1102+
while ((header_idx % 8) != 0)
11051103
header_idx++;
11061104

11071105
/* Calculate hashes */

0 commit comments

Comments
 (0)