mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Add tls12_prf_read for the new API
Technically we could have reused the old one for the new API, but then we had to set an extra field during setup. The new version works when all the fields that haven't been set explicitely are zero-initialised.
This commit is contained in:
@ -4144,7 +4144,7 @@ static psa_status_t psa_key_derivation_tls12_prf_generate_next_block(
|
||||
|
||||
/* We need a new block */
|
||||
++tls12_prf->block_number;
|
||||
tls12_prf->offset_in_block = 0;
|
||||
tls12_prf->left_in_block = hash_length;
|
||||
|
||||
/* Recall the definition of the TLS-1.2-PRF from RFC 5246:
|
||||
*
|
||||
@ -4211,6 +4211,45 @@ static psa_status_t psa_key_derivation_tls12_prf_read(
|
||||
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
#else
|
||||
static psa_status_t psa_key_derivation_tls12_prf_read(
|
||||
psa_tls12_prf_key_derivation_t *tls12_prf,
|
||||
psa_algorithm_t alg,
|
||||
uint8_t *output,
|
||||
size_t output_length )
|
||||
{
|
||||
psa_algorithm_t hash_alg = PSA_ALG_TLS12_PRF_GET_HASH( alg );
|
||||
uint8_t hash_length = PSA_HASH_SIZE( hash_alg );
|
||||
psa_status_t status;
|
||||
uint8_t offset, length;
|
||||
|
||||
while( output_length != 0 )
|
||||
{
|
||||
/* Check if we have fully processed the current block. */
|
||||
if( tls12_prf->left_in_block == 0 )
|
||||
{
|
||||
status = psa_key_derivation_tls12_prf_generate_next_block( tls12_prf,
|
||||
alg );
|
||||
if( status != PSA_SUCCESS )
|
||||
return( status );
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if( tls12_prf->left_in_block > output_length )
|
||||
length = (uint8_t) output_length;
|
||||
else
|
||||
length = tls12_prf->left_in_block;
|
||||
|
||||
offset = hash_length - tls12_prf->left_in_block;
|
||||
memcpy( output, tls12_prf->output_block + offset, length );
|
||||
output += length;
|
||||
output_length -= length;
|
||||
tls12_prf->left_in_block -= length;
|
||||
}
|
||||
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
#endif /* PSA_PRE_1_0_KEY_DERIVATION */
|
||||
#endif /* MBEDTLS_MD_C */
|
||||
|
||||
|
Reference in New Issue
Block a user