derive_output test: Adapt for HKDF-Extract/Expand algs

Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
This commit is contained in:
Przemek Stekiel 2022-05-11 12:22:57 +02:00
parent 17520fe2c5
commit ead1bb9987

View file

@ -7087,9 +7087,12 @@ void derive_output( int alg_arg,
goto exit; goto exit;
break; break;
default: default:
PSA_ASSERT( psa_key_derivation_input_bytes( TEST_EQUAL( psa_key_derivation_input_bytes(
&operation, steps[i], &operation, steps[i],
inputs[i]->x, inputs[i]->len ) ); inputs[i]->x, inputs[i]->len ), statuses[i] );
if( statuses[i] != PSA_SUCCESS )
goto exit;
break; break;
} }
} }
@ -7102,6 +7105,10 @@ void derive_output( int alg_arg,
if( derive_type == 1 ) // output key if( derive_type == 1 ) // output key
{ {
psa_status_t expected_status = PSA_ERROR_NOT_PERMITTED; psa_status_t expected_status = PSA_ERROR_NOT_PERMITTED;
size_t bits = 48; // default for Mix-PSK-to-MS
if( PSA_ALG_IS_HKDF_EXTRACT( alg ) || PSA_ALG_IS_HKDF_EXPAND( alg ))
bits = PSA_HASH_LENGTH( alg );
/* For output key derivation secret must be provided using /* For output key derivation secret must be provided using
input key, otherwise operation is not permitted. */ input key, otherwise operation is not permitted. */
@ -7111,7 +7118,7 @@ void derive_output( int alg_arg,
psa_set_key_usage_flags( &attributes4, PSA_KEY_USAGE_EXPORT ); psa_set_key_usage_flags( &attributes4, PSA_KEY_USAGE_EXPORT );
psa_set_key_algorithm( &attributes4, alg ); psa_set_key_algorithm( &attributes4, alg );
psa_set_key_type( &attributes4, PSA_KEY_TYPE_DERIVE ); psa_set_key_type( &attributes4, PSA_KEY_TYPE_DERIVE );
psa_set_key_bits( &attributes4, 48 ); psa_set_key_bits( &attributes4, bits );
TEST_EQUAL( psa_key_derivation_output_key( &attributes4, &operation, TEST_EQUAL( psa_key_derivation_output_key( &attributes4, &operation,
&derived_key ), expected_status ); &derived_key ), expected_status );