From 49a7276c497b466d4eea7dd283ba940dbb297c2a Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Fri, 3 Nov 2023 19:51:40 +0000 Subject: [PATCH] Switch error code to more appropriate value Since we are internal rather than user-facing, PSA_ERROR_CORRUPTION_DETECTED makes more sense than PSA_ERROR_BUFFER_TOO_SMALL. Whilst it really is a buffer that is too small, this error code is intended to indicate that a user-supplied buffer is too small, not an internal one. Signed-off-by: David Horstmann --- library/psa_crypto.c | 4 ++-- library/psa_crypto_core.h | 6 +++--- tests/suites/test_suite_psa_crypto.data | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index 33068af385..09180b3c3a 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -8446,7 +8446,7 @@ psa_status_t psa_crypto_copy_input(const uint8_t *input, size_t input_len, uint8_t *input_copy, size_t input_copy_len) { if (input_len > input_copy_len) { - return PSA_ERROR_BUFFER_TOO_SMALL; + return PSA_ERROR_CORRUPTION_DETECTED; } memcpy(input_copy, input, input_len); @@ -8458,7 +8458,7 @@ psa_status_t psa_crypto_copy_output(const uint8_t *output_copy, size_t output_co uint8_t *output, size_t output_len) { if (output_len < output_copy_len) { - return PSA_ERROR_BUFFER_TOO_SMALL; + return PSA_ERROR_CORRUPTION_DETECTED; } memcpy(output, output_copy, output_copy_len); return PSA_SUCCESS; diff --git a/library/psa_crypto_core.h b/library/psa_crypto_core.h index 78550f8ee5..00d9e9eedd 100644 --- a/library/psa_crypto_core.h +++ b/library/psa_crypto_core.h @@ -862,8 +862,8 @@ psa_status_t mbedtls_psa_verify_hash_abort( * \param[out] input_copy_len Length of the local copy buffer. * \return #PSA_SUCCESS, if the buffer was successfully * copied. - * \return #PSA_ERROR_BUFFER_TOO_SMALL, if the local copy - * is too small to hold contents of the + * \return #PSA_ERROR_CORRUPTION_DETECTED, if the local + * copy is too small to hold contents of the * input buffer. */ psa_status_t psa_crypto_copy_input(const uint8_t *input, size_t input_len, @@ -877,7 +877,7 @@ psa_status_t psa_crypto_copy_input(const uint8_t *input, size_t input_len, * \param[out] output_len Length of the user-supplied output buffer. * \return #PSA_SUCCESS, if the buffer was successfully * copied. - * \return #PSA_ERROR_BUFFER_TOO_SMALL, if the + * \return #PSA_ERROR_CORRUPTION_DETECTED, if the * user-supplied output buffer is too small to * hold the contents of the local buffer. */ diff --git a/tests/suites/test_suite_psa_crypto.data b/tests/suites/test_suite_psa_crypto.data index 6b112462b4..594c609e3c 100644 --- a/tests/suites/test_suite_psa_crypto.data +++ b/tests/suites/test_suite_psa_crypto.data @@ -7414,7 +7414,7 @@ PSA input buffer copy: copy buffer larger than required copy_input:10:20:PSA_SUCCESS PSA input buffer copy: copy buffer too small -copy_input:20:10:PSA_ERROR_BUFFER_TOO_SMALL +copy_input:20:10:PSA_ERROR_CORRUPTION_DETECTED PSA input buffer copy: zero-length source buffer copy_input:0:10:PSA_SUCCESS @@ -7429,7 +7429,7 @@ PSA output buffer copy: output buffer larger than required copy_output:10:20:PSA_SUCCESS PSA output buffer copy: output buffer too small -copy_output:20:10:PSA_ERROR_BUFFER_TOO_SMALL +copy_output:20:10:PSA_ERROR_CORRUPTION_DETECTED PSA output buffer copy: zero-length source buffer copy_output:0:10:PSA_SUCCESS