psa: cipher: Prefer length rather than size for IV/block length

Prefer length rather than size for IV/block length as
per the PSA specification.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
Ronald Cron 2021-03-26 09:29:09 +01:00
parent f2381aaa43
commit 6ad554cb83
2 changed files with 11 additions and 11 deletions

View File

@ -39,8 +39,8 @@
typedef struct {
/* Context structure for the Mbed TLS cipher implementation. */
psa_algorithm_t alg;
uint8_t iv_size;
uint8_t block_size;
uint8_t iv_length;
uint8_t block_length;
mbedtls_cipher_context_t cipher;
} mbedtls_psa_cipher_operation_t;

View File

@ -219,18 +219,18 @@ static psa_status_t cipher_setup(
goto exit;
#endif /* BUILTIN_ALG_CBC_NO_PADDING || BUILTIN_ALG_CBC_PKCS7 */
operation->block_size = ( PSA_ALG_IS_STREAM_CIPHER( alg ) ? 1 :
PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type ) );
operation->block_length = ( PSA_ALG_IS_STREAM_CIPHER( alg ) ? 1 :
PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type ) );
if( ( alg & PSA_ALG_CIPHER_FROM_BLOCK_FLAG ) != 0 &&
alg != PSA_ALG_ECB_NO_PADDING )
{
operation->iv_size = PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type );
operation->iv_length = PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type );
}
#if defined(BUILTIN_KEY_TYPE_CHACHA20)
else
if( ( alg == PSA_ALG_STREAM_CIPHER ) &&
( key_type == PSA_KEY_TYPE_CHACHA20 ) )
operation->iv_size = 12;
operation->iv_length = 12;
#endif
exit:
@ -262,7 +262,7 @@ static psa_status_t cipher_decrypt_setup(
static psa_status_t cipher_set_iv( mbedtls_psa_cipher_operation_t *operation,
const uint8_t *iv, size_t iv_length )
{
if( iv_length != operation->iv_size )
if( iv_length != operation->iv_length )
return( PSA_ERROR_INVALID_ARGUMENT );
return( mbedtls_to_psa_error(
@ -276,14 +276,14 @@ static psa_status_t cipher_generate_iv(
{
int status = PSA_ERROR_CORRUPTION_DETECTED;
if( iv_size < operation->iv_size )
if( iv_size < operation->iv_length )
return( PSA_ERROR_BUFFER_TOO_SMALL );
status = psa_generate_random( iv, operation->iv_size );
status = psa_generate_random( iv, operation->iv_length );
if( status != PSA_SUCCESS )
return( status );
*iv_length = operation->iv_size;
*iv_length = operation->iv_length;
return( cipher_set_iv( operation, iv, *iv_length ) );
}
@ -394,7 +394,7 @@ static psa_status_t cipher_update( mbedtls_psa_cipher_operation_t *operation,
* output in this call. */
expected_output_size =
( operation->cipher.unprocessed_len + input_length )
/ operation->block_size * operation->block_size;
/ operation->block_length * operation->block_length;
}
else
{