Skip to content

Commit 9210dd1

Browse files
authored
Fix for issue #356 HKDF infinite loop bug for n = 255 (#361)
* Fix for issue #356 HKDF infinite loop bug for n = 255 * Changed pointer casting to integer cast and unsigned int to uint32_t to account for big endian architecture * Naming is hard. Updated variable names from PR suggestion
1 parent a7ef51e commit 9210dd1

File tree

2 files changed

+454
-6
lines changed

2 files changed

+454
-6
lines changed

source/hkdf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ static int aws_cryptosdk_hkdf_expand(
7777
if (!prk || !okm->len || !prk_len) goto err;
7878
n = (okm->len + hash_len - 1) / hash_len;
7979
if (n > 255) goto err;
80-
81-
for (uint8_t idx = 1; idx <= n; idx++) {
80+
for (uint32_t idx = 1; idx <= n; idx++) {
81+
uint8_t idx_byte = idx;
8282
if (!HMAC_Init_ex(&ctx, prk, prk_len, evp_md, NULL)) goto err;
8383
if (idx != 1) {
8484
if (!HMAC_Update(&ctx, t, hash_len)) goto err;
8585
}
8686
if (!HMAC_Update(&ctx, info->buffer, info->len)) goto err;
87-
if (!HMAC_Update(&ctx, &idx, 1)) goto err;
87+
if (!HMAC_Update(&ctx, &idx_byte, 1)) goto err;
8888
if (!HMAC_Final(&ctx, t, &t_len)) goto err;
8989

9090
assert(t_len == hash_len);

0 commit comments

Comments
 (0)