mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-24 18:31:08 +00:00
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:
parent
f2381aaa43
commit
6ad554cb83
|
@ -39,8 +39,8 @@
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* Context structure for the Mbed TLS cipher implementation. */
|
/* Context structure for the Mbed TLS cipher implementation. */
|
||||||
psa_algorithm_t alg;
|
psa_algorithm_t alg;
|
||||||
uint8_t iv_size;
|
uint8_t iv_length;
|
||||||
uint8_t block_size;
|
uint8_t block_length;
|
||||||
mbedtls_cipher_context_t cipher;
|
mbedtls_cipher_context_t cipher;
|
||||||
} mbedtls_psa_cipher_operation_t;
|
} mbedtls_psa_cipher_operation_t;
|
||||||
|
|
||||||
|
|
|
@ -219,18 +219,18 @@ static psa_status_t cipher_setup(
|
||||||
goto exit;
|
goto exit;
|
||||||
#endif /* BUILTIN_ALG_CBC_NO_PADDING || BUILTIN_ALG_CBC_PKCS7 */
|
#endif /* BUILTIN_ALG_CBC_NO_PADDING || BUILTIN_ALG_CBC_PKCS7 */
|
||||||
|
|
||||||
operation->block_size = ( PSA_ALG_IS_STREAM_CIPHER( alg ) ? 1 :
|
operation->block_length = ( PSA_ALG_IS_STREAM_CIPHER( alg ) ? 1 :
|
||||||
PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type ) );
|
PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type ) );
|
||||||
if( ( alg & PSA_ALG_CIPHER_FROM_BLOCK_FLAG ) != 0 &&
|
if( ( alg & PSA_ALG_CIPHER_FROM_BLOCK_FLAG ) != 0 &&
|
||||||
alg != PSA_ALG_ECB_NO_PADDING )
|
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)
|
#if defined(BUILTIN_KEY_TYPE_CHACHA20)
|
||||||
else
|
else
|
||||||
if( ( alg == PSA_ALG_STREAM_CIPHER ) &&
|
if( ( alg == PSA_ALG_STREAM_CIPHER ) &&
|
||||||
( key_type == PSA_KEY_TYPE_CHACHA20 ) )
|
( key_type == PSA_KEY_TYPE_CHACHA20 ) )
|
||||||
operation->iv_size = 12;
|
operation->iv_length = 12;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
exit:
|
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,
|
static psa_status_t cipher_set_iv( mbedtls_psa_cipher_operation_t *operation,
|
||||||
const uint8_t *iv, size_t iv_length )
|
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( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
|
||||||
return( mbedtls_to_psa_error(
|
return( mbedtls_to_psa_error(
|
||||||
|
@ -276,14 +276,14 @@ static psa_status_t cipher_generate_iv(
|
||||||
{
|
{
|
||||||
int status = PSA_ERROR_CORRUPTION_DETECTED;
|
int status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
|
|
||||||
if( iv_size < operation->iv_size )
|
if( iv_size < operation->iv_length )
|
||||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
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 )
|
if( status != PSA_SUCCESS )
|
||||||
return( status );
|
return( status );
|
||||||
|
|
||||||
*iv_length = operation->iv_size;
|
*iv_length = operation->iv_length;
|
||||||
|
|
||||||
return( cipher_set_iv( operation, iv, *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. */
|
* output in this call. */
|
||||||
expected_output_size =
|
expected_output_size =
|
||||||
( operation->cipher.unprocessed_len + input_length )
|
( operation->cipher.unprocessed_len + input_length )
|
||||||
/ operation->block_size * operation->block_size;
|
/ operation->block_length * operation->block_length;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue