psa: aead: Remove from operation ctx members only used in setup
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
parent
ea7ab13991
commit
ecbc068252
1 changed files with 11 additions and 11 deletions
|
@ -32,7 +32,6 @@
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
const mbedtls_cipher_info_t *cipher_info;
|
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
unsigned dummy; /* Make the union non-empty even with no supported algorithms. */
|
unsigned dummy; /* Make the union non-empty even with no supported algorithms. */
|
||||||
|
@ -47,11 +46,10 @@ typedef struct
|
||||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
||||||
} ctx;
|
} ctx;
|
||||||
psa_algorithm_t core_alg;
|
psa_algorithm_t core_alg;
|
||||||
uint8_t full_tag_length;
|
|
||||||
uint8_t tag_length;
|
uint8_t tag_length;
|
||||||
} aead_operation_t;
|
} aead_operation_t;
|
||||||
|
|
||||||
#define AEAD_OPERATION_INIT {0, {0}, 0, 0, 0}
|
#define AEAD_OPERATION_INIT {{0}, 0, 0}
|
||||||
|
|
||||||
static void psa_aead_abort_internal( aead_operation_t *operation )
|
static void psa_aead_abort_internal( aead_operation_t *operation )
|
||||||
{
|
{
|
||||||
|
@ -78,14 +76,16 @@ static psa_status_t psa_aead_setup(
|
||||||
{
|
{
|
||||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
size_t key_bits;
|
size_t key_bits;
|
||||||
|
const mbedtls_cipher_info_t *cipher_info;
|
||||||
mbedtls_cipher_id_t cipher_id;
|
mbedtls_cipher_id_t cipher_id;
|
||||||
|
size_t full_tag_length = 0;
|
||||||
|
|
||||||
key_bits = attributes->core.bits;
|
key_bits = attributes->core.bits;
|
||||||
|
|
||||||
operation->cipher_info =
|
cipher_info = mbedtls_cipher_info_from_psa( alg,
|
||||||
mbedtls_cipher_info_from_psa( alg, attributes->core.type, key_bits,
|
attributes->core.type, key_bits,
|
||||||
&cipher_id );
|
&cipher_id );
|
||||||
if( operation->cipher_info == NULL )
|
if( cipher_info == NULL )
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
return( PSA_ERROR_NOT_SUPPORTED );
|
||||||
|
|
||||||
switch( PSA_ALG_AEAD_WITH_SHORTENED_TAG( alg, 0 ) )
|
switch( PSA_ALG_AEAD_WITH_SHORTENED_TAG( alg, 0 ) )
|
||||||
|
@ -93,7 +93,7 @@ static psa_status_t psa_aead_setup(
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
|
||||||
case PSA_ALG_AEAD_WITH_SHORTENED_TAG( PSA_ALG_CCM, 0 ):
|
case PSA_ALG_AEAD_WITH_SHORTENED_TAG( PSA_ALG_CCM, 0 ):
|
||||||
operation->core_alg = PSA_ALG_CCM;
|
operation->core_alg = PSA_ALG_CCM;
|
||||||
operation->full_tag_length = 16;
|
full_tag_length = 16;
|
||||||
/* CCM allows the following tag lengths: 4, 6, 8, 10, 12, 14, 16.
|
/* CCM allows the following tag lengths: 4, 6, 8, 10, 12, 14, 16.
|
||||||
* The call to mbedtls_ccm_encrypt_and_tag or
|
* The call to mbedtls_ccm_encrypt_and_tag or
|
||||||
* mbedtls_ccm_auth_decrypt will validate the tag length. */
|
* mbedtls_ccm_auth_decrypt will validate the tag length. */
|
||||||
|
@ -112,7 +112,7 @@ static psa_status_t psa_aead_setup(
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
|
||||||
case PSA_ALG_AEAD_WITH_SHORTENED_TAG( PSA_ALG_GCM, 0 ):
|
case PSA_ALG_AEAD_WITH_SHORTENED_TAG( PSA_ALG_GCM, 0 ):
|
||||||
operation->core_alg = PSA_ALG_GCM;
|
operation->core_alg = PSA_ALG_GCM;
|
||||||
operation->full_tag_length = 16;
|
full_tag_length = 16;
|
||||||
/* GCM allows the following tag lengths: 4, 8, 12, 13, 14, 15, 16.
|
/* GCM allows the following tag lengths: 4, 8, 12, 13, 14, 15, 16.
|
||||||
* The call to mbedtls_gcm_crypt_and_tag or
|
* The call to mbedtls_gcm_crypt_and_tag or
|
||||||
* mbedtls_gcm_auth_decrypt will validate the tag length. */
|
* mbedtls_gcm_auth_decrypt will validate the tag length. */
|
||||||
|
@ -131,7 +131,7 @@ static psa_status_t psa_aead_setup(
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
|
||||||
case PSA_ALG_AEAD_WITH_SHORTENED_TAG( PSA_ALG_CHACHA20_POLY1305, 0 ):
|
case PSA_ALG_AEAD_WITH_SHORTENED_TAG( PSA_ALG_CHACHA20_POLY1305, 0 ):
|
||||||
operation->core_alg = PSA_ALG_CHACHA20_POLY1305;
|
operation->core_alg = PSA_ALG_CHACHA20_POLY1305;
|
||||||
operation->full_tag_length = 16;
|
full_tag_length = 16;
|
||||||
/* We only support the default tag length. */
|
/* We only support the default tag length. */
|
||||||
if( alg != PSA_ALG_CHACHA20_POLY1305 )
|
if( alg != PSA_ALG_CHACHA20_POLY1305 )
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
return( PSA_ERROR_NOT_SUPPORTED );
|
||||||
|
@ -149,7 +149,7 @@ static psa_status_t psa_aead_setup(
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
return( PSA_ERROR_NOT_SUPPORTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( PSA_AEAD_TAG_LENGTH( alg ) > operation->full_tag_length )
|
if( PSA_AEAD_TAG_LENGTH( alg ) > full_tag_length )
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
|
||||||
operation->tag_length = PSA_AEAD_TAG_LENGTH( alg );
|
operation->tag_length = PSA_AEAD_TAG_LENGTH( alg );
|
||||||
|
|
Loading…
Reference in a new issue