Optimize code by adding PSA_ALG_IS_ANY_HKDF macro
Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
This commit is contained in:
parent
459ee35062
commit
a29b488296
@ -1853,6 +1853,21 @@
|
||||
#define PSA_ALG_IS_HKDF_EXPAND(alg) \
|
||||
(((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_HKDF_EXPAND_BASE)
|
||||
|
||||
/** Whether the specified algorithm is an HKDF or HKDF-Extract or
|
||||
* HKDF-Expand algorithm.
|
||||
*
|
||||
*
|
||||
* \param alg An algorithm identifier (value of type #psa_algorithm_t).
|
||||
*
|
||||
* \return 1 if \c alg is any HKDF type algorithm, 0 otherwise.
|
||||
* This macro may return either 0 or 1 if \c alg is not a supported
|
||||
* key derivation algorithm identifier.
|
||||
*/
|
||||
#define PSA_ALG_IS_ANY_HKDF(alg) \
|
||||
(((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_HKDF_BASE || \
|
||||
((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_HKDF_EXTRACT_BASE || \
|
||||
((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_HKDF_EXPAND_BASE)
|
||||
|
||||
#define PSA_ALG_TLS12_PRF_BASE ((psa_algorithm_t)0x08000200)
|
||||
/** Macro to build a TLS-1.2 PRF algorithm.
|
||||
*
|
||||
|
@ -4295,8 +4295,7 @@ psa_status_t psa_key_derivation_abort( psa_key_derivation_operation_t *operation
|
||||
}
|
||||
else
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_HKDF)
|
||||
if( PSA_ALG_IS_HKDF( kdf_alg ) || PSA_ALG_IS_HKDF_EXTRACT( kdf_alg ) ||
|
||||
PSA_ALG_IS_HKDF_EXPAND( kdf_alg ) )
|
||||
if( PSA_ALG_IS_ANY_HKDF( kdf_alg ) )
|
||||
{
|
||||
mbedtls_free( operation->ctx.hkdf.info );
|
||||
status = psa_mac_abort( &operation->ctx.hkdf.hmac );
|
||||
@ -4653,8 +4652,7 @@ psa_status_t psa_key_derivation_output_bytes(
|
||||
operation->capacity -= output_length;
|
||||
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_HKDF)
|
||||
if( PSA_ALG_IS_HKDF( kdf_alg ) || PSA_ALG_IS_HKDF_EXPAND( kdf_alg ) ||
|
||||
PSA_ALG_IS_HKDF_EXTRACT( kdf_alg ) )
|
||||
if( PSA_ALG_IS_ANY_HKDF( kdf_alg ) )
|
||||
{
|
||||
status = psa_key_derivation_hkdf_read( &operation->ctx.hkdf, kdf_alg,
|
||||
output, output_length );
|
||||
@ -5046,8 +5044,7 @@ psa_status_t psa_key_derivation_output_key( const psa_key_attributes_t *attribut
|
||||
static int is_kdf_alg_supported( psa_algorithm_t kdf_alg )
|
||||
{
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_HKDF)
|
||||
if( PSA_ALG_IS_HKDF( kdf_alg ) || PSA_ALG_IS_HKDF_EXTRACT( kdf_alg ) ||
|
||||
PSA_ALG_IS_HKDF_EXPAND( kdf_alg ) )
|
||||
if( PSA_ALG_IS_ANY_HKDF( kdf_alg ) )
|
||||
return( 1 );
|
||||
#endif
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_TLS12_PRF)
|
||||
@ -5530,8 +5527,7 @@ static psa_status_t psa_key_derivation_input_internal(
|
||||
goto exit;
|
||||
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_HKDF)
|
||||
if( PSA_ALG_IS_HKDF( kdf_alg ) || PSA_ALG_IS_HKDF_EXTRACT( kdf_alg ) ||
|
||||
PSA_ALG_IS_HKDF_EXPAND( kdf_alg ) )
|
||||
if( PSA_ALG_IS_ANY_HKDF( kdf_alg ) )
|
||||
{
|
||||
status = psa_hkdf_input( &operation->ctx.hkdf, kdf_alg,
|
||||
step, data, data_length );
|
||||
|
Loading…
Reference in New Issue
Block a user