From c45b4afc63fb6fb9116d80658b9823f7eee500cf Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Tue, 29 Sep 2020 16:18:05 +0200 Subject: [PATCH] Fix PSA SE driver tests Fix PSA SE driver tests in configuration full + MBEDTLS_PSA_CRYPTO_DRIVERS. Signed-off-by: Ronald Cron --- library/psa_crypto.c | 12 ++++++++++++ library/psa_crypto_driver_wrappers.c | 14 +++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index 37389f8d01..b9369feaba 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -3558,6 +3558,12 @@ psa_status_t psa_cipher_generate_iv( psa_cipher_operation_t *operation, { psa_status_t status; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + + if( operation->alg == 0 ) + { + return( PSA_ERROR_BAD_STATE ); + } + if( operation->iv_set || ! operation->iv_required ) { return( PSA_ERROR_BAD_STATE ); @@ -3602,6 +3608,12 @@ psa_status_t psa_cipher_set_iv( psa_cipher_operation_t *operation, { psa_status_t status; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + + if( operation->alg == 0 ) + { + return( PSA_ERROR_BAD_STATE ); + } + if( operation->iv_set || ! operation->iv_required ) { return( PSA_ERROR_BAD_STATE ); diff --git a/library/psa_crypto_driver_wrappers.c b/library/psa_crypto_driver_wrappers.c index 6c94472f86..9fbc610233 100644 --- a/library/psa_crypto_driver_wrappers.c +++ b/library/psa_crypto_driver_wrappers.c @@ -779,7 +779,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup( #endif /* PSA_CRYPTO_DRIVER_TEST */ default: /* Key is declared with a lifetime not known to us */ - return( PSA_ERROR_NOT_SUPPORTED ); + return( PSA_ERROR_INVALID_ARGUMENT ); } #else /* PSA_CRYPTO_DRIVER_PRESENT */ (void)slot; @@ -860,7 +860,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup( #endif /* PSA_CRYPTO_DRIVER_TEST */ default: /* Key is declared with a lifetime not known to us */ - return( PSA_ERROR_NOT_SUPPORTED ); + return( PSA_ERROR_INVALID_ARGUMENT ); } #else /* PSA_CRYPTO_DRIVER_PRESENT */ (void)slot; @@ -896,7 +896,7 @@ psa_status_t psa_driver_wrapper_cipher_generate_iv( #endif /* PSA_CRYPTO_DRIVER_TEST */ default: /* Key is attached to a driver not known to us */ - return( PSA_ERROR_BAD_STATE ); + return( PSA_ERROR_INVALID_ARGUMENT ); } #else /* PSA_CRYPTO_DRIVER_PRESENT */ (void) operation; @@ -930,7 +930,7 @@ psa_status_t psa_driver_wrapper_cipher_set_iv( #endif /* PSA_CRYPTO_DRIVER_TEST */ default: /* Key is attached to a driver not known to us */ - return( PSA_ERROR_BAD_STATE ); + return( PSA_ERROR_INVALID_ARGUMENT ); } #else /* PSA_CRYPTO_DRIVER_PRESENT */ (void) operation; @@ -972,7 +972,7 @@ psa_status_t psa_driver_wrapper_cipher_update( #endif /* PSA_CRYPTO_DRIVER_TEST */ default: /* Key is attached to a driver not known to us */ - return( PSA_ERROR_BAD_STATE ); + return( PSA_ERROR_INVALID_ARGUMENT ); } #else /* PSA_CRYPTO_DRIVER_PRESENT */ (void) operation; @@ -1011,7 +1011,7 @@ psa_status_t psa_driver_wrapper_cipher_finish( #endif /* PSA_CRYPTO_DRIVER_TEST */ default: /* Key is attached to a driver not known to us */ - return( PSA_ERROR_BAD_STATE ); + return( PSA_ERROR_INVALID_ARGUMENT ); } #else /* PSA_CRYPTO_DRIVER_PRESENT */ (void) operation; @@ -1062,7 +1062,7 @@ psa_status_t psa_driver_wrapper_cipher_abort( #endif /* PSA_CRYPTO_DRIVER_TEST */ default: /* Operation is attached to a driver not known to us */ - return( PSA_ERROR_BAD_STATE ); + return( PSA_ERROR_INVALID_ARGUMENT ); } #else /* PSA_CRYPTO_DRIVER_PRESENT */ (void)operation;