Move mbedtls_ssl_cipher_to_psa() and psa_status_to_mbedtls() defs out of MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED build flag

Signed-off-by: Przemyslaw Stekiel <przemyslaw.stekiel@mobica.com>
This commit is contained in:
Przemyslaw Stekiel 2022-01-25 00:56:34 +01:00
parent 4a36dd3da6
commit e5c2238a99

View File

@ -1282,56 +1282,6 @@ static inline mbedtls_svc_key_id_t mbedtls_ssl_get_opaque_psk(
return( MBEDTLS_SVC_KEY_ID_INIT );
}
/* Corresponding PSA algorithm for MBEDTLS_CIPHER_NULL.
* Same value is used fo PSA_ALG_CATEGORY_CIPHER, hence it is
* guaranteed to not be a valid PSA algorithm identifier.
*/
#define MBEDTLS_SSL_NULL_CIPHER 0x04000000
/**
* \brief Translate mbedtls cipher type/taglen pair to psa:
* algorithm, key type and key size.
*
* \param mbedtls_cipher_type [in] given mbedtls cipher type
* \param taglen [in] given tag length
* 0 - default tag length
* \param alg [out] corresponding PSA alg
* There is no corresponding PSA
* alg for MBEDTLS_SSL_NULL_CIPHER, so
* MBEDTLS_SSL_NULL_CIPHER is returned
* \param key_type [out] corresponding PSA key type
* \param key_size [out] corresponding PSA key size
*
* \return PSA_SUCCESS on success or PSA_ERROR_NOT_SUPPORTED if
* conversion is not supported.
*/
psa_status_t mbedtls_ssl_cipher_to_psa( mbedtls_cipher_type_t mbedtls_cipher_type,
size_t taglen,
psa_algorithm_t *alg,
psa_key_type_t *key_type,
size_t *key_size );
/**
* \brief Convert given PSA status to mbedtls error code.
*
* \param status [in] given PSA status
*
* \return corresponding mbedtls error code
*/
static inline int psa_status_to_mbedtls( psa_status_t status )
{
switch( status )
{
case PSA_SUCCESS:
return( 0 );
case PSA_ERROR_INSUFFICIENT_MEMORY:
return( MBEDTLS_ERR_CIPHER_ALLOC_FAILED );
case PSA_ERROR_NOT_SUPPORTED:
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
default:
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
}
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
#endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */
@ -2069,5 +2019,57 @@ static inline int mbedtls_ssl_sig_alg_is_supported(
#define MBEDTLS_SSL_SIG_ALG( hash )
#endif /* MBEDTLS_ECDSA_C && MBEDTLS_RSA_C */
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 && MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */
#if defined(MBEDTLS_USE_PSA_CRYPTO)
/* Corresponding PSA algorithm for MBEDTLS_CIPHER_NULL.
* Same value is used fo PSA_ALG_CATEGORY_CIPHER, hence it is
* guaranteed to not be a valid PSA algorithm identifier.
*/
#define MBEDTLS_SSL_NULL_CIPHER 0x04000000
/**
* \brief Translate mbedtls cipher type/taglen pair to psa:
* algorithm, key type and key size.
*
* \param mbedtls_cipher_type [in] given mbedtls cipher type
* \param taglen [in] given tag length
* 0 - default tag length
* \param alg [out] corresponding PSA alg
* There is no corresponding PSA
* alg for MBEDTLS_SSL_NULL_CIPHER, so
* MBEDTLS_SSL_NULL_CIPHER is returned
* \param key_type [out] corresponding PSA key type
* \param key_size [out] corresponding PSA key size
*
* \return PSA_SUCCESS on success or PSA_ERROR_NOT_SUPPORTED if
* conversion is not supported.
*/
psa_status_t mbedtls_ssl_cipher_to_psa( mbedtls_cipher_type_t mbedtls_cipher_type,
size_t taglen,
psa_algorithm_t *alg,
psa_key_type_t *key_type,
size_t *key_size );
/**
* \brief Convert given PSA status to mbedtls error code.
*
* \param status [in] given PSA status
*
* \return corresponding mbedtls error code
*/
static inline int psa_status_to_mbedtls( psa_status_t status )
{
switch( status )
{
case PSA_SUCCESS:
return( 0 );
case PSA_ERROR_INSUFFICIENT_MEMORY:
return( MBEDTLS_ERR_CIPHER_ALLOC_FAILED );
case PSA_ERROR_NOT_SUPPORTED:
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
default:
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
}
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
#endif /* ssl_misc.h */