Skip to content

Commit ca3e7af

Browse files
magnevrlubos
authored andcommitted
nrf_security: drivers: cracen: Fix HKDF-EXTRACT PRK len
Fixes issue where HKDF-EXTRACT uses the hardcoded value 32 instead of the length of the given SHA variant when doing memcpy of the generated PRK. Signed-off-by: Magne Værnes <[email protected]>
1 parent c82b2b0 commit ca3e7af

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

subsys/nrf_security/src/drivers/cracen/cracenpsa/src/key_derivation.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,14 @@ psa_status_t cracen_key_derivation_output_bytes(cracen_key_derivation_operation_
11421142
}
11431143

11441144
operation->state = CRACEN_KD_STATE_HKDF_OUTPUT;
1145-
memcpy(output, operation->hkdf.prk, 32);
1145+
1146+
size_t prk_length = PSA_HASH_LENGTH(PSA_ALG_HKDF_GET_HASH(operation->alg));
1147+
1148+
if (output_length < prk_length) {
1149+
return PSA_ERROR_BUFFER_TOO_SMALL;
1150+
}
1151+
1152+
memcpy(output, operation->hkdf.prk, prk_length);
11461153
return PSA_SUCCESS;
11471154
}
11481155

0 commit comments

Comments
 (0)