mbedtls_ssl_get_record_expansion: rework switch statement for psa
As PSA_ALG_IS_AEAD( transform->psa_alg ) can't be used as switch labels (switch labels must be constant expressions, they have to be evaluated at compile time) refactor switch to "if else" statement.
@@ -5096,15 +5096,13 @@ int mbedtls_ssl_get_record_expansion( const mbedtls_ssl_context *ssl )
#if defined(MBEDTLS_USE_PSA_CRYPTO)
- switch( transform->psa_alg )
+ if ( transform->psa_alg == PSA_ALG_IS_AEAD( transform->psa_alg ) ||
+ transform->psa_alg == MBEDTLS_SSL_NULL_CIPHER )
{
- case PSA_ALG_GCM:
- case PSA_ALG_CHACHA20_POLY1305:
- case MBEDTLS_SSL_NULL_CIPHER:
transform_expansion = transform->minlen;
- break;
-
- case PSA_ALG_CBC_NO_PADDING:
+ }
+ else if ( transform->psa_alg )
+ {
(void) psa_get_key_attributes( transform->psa_key_enc, &attr );
key_type = psa_get_key_type( &attr );
@@ -5123,19 +5121,9 @@ int mbedtls_ssl_get_record_expansion( const mbedtls_ssl_context *ssl )
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
transform_expansion += block_size;
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
- break;
-
- default:
- /* Handle CCM case in default:
- PSA_ALG_IS_AEAD( transform->psa_alg ) corresponds to
- psa_alg == PSA_ALG_CCM || psa_alg == PSA_ALG_AEAD_WITH_SHORTENED_TAG( PSA_ALG_CCM, 8 )
- in tls context (TLS only uses the default taglen or 8) */
- if ( PSA_ALG_IS_AEAD( transform->psa_alg ) )
- {
- transform_expansion = transform->minlen;
- break;
}
-
+ else
+ {
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
}
