mirror of
https://github.com/espressif/mbedtls.git
synced 2026-09-15 23:09:54 +00:00
FFDH: clean up size check
Signed-off-by: Manuel Pégourié-Gonnard <[email protected]>
This commit is contained in:
@@ -7923,10 +7923,8 @@ psa_status_t psa_raw_key_agreement(psa_algorithm_t alg,
|
||||
* for the output size. The PSA specification only guarantees that this
|
||||
* function works if output_size >= PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE(...),
|
||||
* but it might be nice to allow smaller buffers if the output fits.
|
||||
* At the time of writing this comment, with only ECDH implemented,
|
||||
* PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE() is exact so the point is moot.
|
||||
* If FFDH is implemented, PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE() can easily
|
||||
* be exact for it as well. */
|
||||
* At the time of writing this comment, for both FFDH and ECDH,
|
||||
* PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE() is exact so the point is moot. */
|
||||
expected_length =
|
||||
PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE(slot->attr.type, slot->attr.bits);
|
||||
if (output_size < expected_length) {
|
||||
|
||||
@@ -267,14 +267,15 @@ psa_status_t mbedtls_psa_ffdh_key_agreement(
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
mbedtls_mpi P, X, GY, K;
|
||||
const size_t calculated_shared_secret_size = peer_key_length;
|
||||
const size_t calculated_shared_secret_size = key_buffer_size;
|
||||
|
||||
if (peer_key_length != key_buffer_size ||
|
||||
calculated_shared_secret_size > shared_secret_size) {
|
||||
return PSA_ERROR_INVALID_ARGUMENT;
|
||||
/* This has been checked by the library, but keep a local check too. */
|
||||
if (calculated_shared_secret_size > shared_secret_size) {
|
||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
if (!PSA_KEY_TYPE_IS_DH_KEY_PAIR(psa_get_key_type(attributes))) {
|
||||
if (peer_key_length != key_buffer_size ||
|
||||
!PSA_KEY_TYPE_IS_DH_KEY_PAIR(psa_get_key_type(attributes))) {
|
||||
return PSA_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user