Added support for AES-ECB to the PSA Crypto implementation
PSA_ALG_ECB_NO_PADDING came in to the PSA Crypto API spec v1.0.0, but
was not implemented yet in the mbed TLS implementation.
Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index 4c3966c..9362ef0 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -2518,6 +2518,9 @@
case PSA_ALG_OFB:
mode = MBEDTLS_MODE_OFB;
break;
+ case PSA_ALG_ECB_NO_PADDING:
+ mode = MBEDTLS_MODE_ECB;
+ break;
case PSA_ALG_CBC_NO_PADDING:
mode = MBEDTLS_MODE_CBC;
break;
@@ -3746,7 +3749,11 @@
operation->alg = alg;
operation->key_set = 0;
operation->iv_set = 0;
- operation->iv_required = 1;
+ if( alg == PSA_ALG_ECB_NO_PADDING ) {
+ operation->iv_required = 0;
+ } else {
+ operation->iv_required = 1;
+ }
operation->iv_size = 0;
operation->block_size = 0;
mbedtls_cipher_init( &operation->ctx.cipher );
@@ -3837,7 +3844,7 @@
operation->key_set = 1;
operation->block_size = ( PSA_ALG_IS_STREAM_CIPHER( alg ) ? 1 :
PSA_BLOCK_CIPHER_BLOCK_SIZE( slot->attr.type ) );
- if( alg & PSA_ALG_CIPHER_FROM_BLOCK_FLAG )
+ if( alg & PSA_ALG_CIPHER_FROM_BLOCK_FLAG && alg != PSA_ALG_ECB_NO_PADDING )
{
operation->iv_size = PSA_BLOCK_CIPHER_BLOCK_SIZE( slot->attr.type );
}
@@ -3991,12 +3998,14 @@
return( PSA_ERROR_BAD_STATE );
}
- if( operation->ctx.cipher.operation == MBEDTLS_ENCRYPT &&
- operation->alg == PSA_ALG_CBC_NO_PADDING &&
- operation->ctx.cipher.unprocessed_len != 0 )
+ if( operation->ctx.cipher.unprocessed_len != 0 )
{
+ if( operation->alg == PSA_ALG_ECB_NO_PADDING ||
+ ( operation->alg == PSA_ALG_CBC_NO_PADDING &&
+ operation->ctx.cipher.operation == MBEDTLS_ENCRYPT ) ) {
status = PSA_ERROR_INVALID_ARGUMENT;
goto error;
+ }
}
cipher_ret = mbedtls_cipher_finish( &operation->ctx.cipher,