Skip to content

Commit

Permalink
Handle value_len == 0
Browse files Browse the repository at this point in the history
  • Loading branch information
qpernil committed Mar 21, 2024
1 parent 89006ae commit 108c11a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkcs11/util_pkcs11.c
Original file line number Diff line number Diff line change
Expand Up @@ -5331,7 +5331,7 @@ CK_RV ecdh_kdf(ecdh_session_key *shared_secret, uint8_t *fixed_info, size_t fixe
uint8_t res[ECDH_KEY_BUF_SIZE] = {0};
size_t res_len = 0;

while (res_len < value_len) {
do {
increment_ctr(ctr, sizeof(ctr));
hash_init(hash);
hash_update(hash, ctr, sizeof(ctr));
Expand All @@ -5340,6 +5340,10 @@ CK_RV ecdh_kdf(ecdh_session_key *shared_secret, uint8_t *fixed_info, size_t fixe
size_t len = sizeof(res) - res_len;
hash_final(hash, res + res_len, &len);
res_len += len;
} while(res_len < value_len);

if(value_len == 0) {
value_len = res_len;
}

memcpy(shared_secret->ecdh_key, res, value_len);
Expand Down

0 comments on commit 108c11a

Please sign in to comment.