Simplify psa_generator_tls12_prf_generate_next_block()
This commit is contained in:
parent
580fba1431
commit
3b339e2342
1 changed files with 26 additions and 40 deletions
|
@ -3372,6 +3372,9 @@ static psa_status_t psa_generator_tls12_prf_generate_next_block(
|
||||||
psa_hmac_internal_data hmac;
|
psa_hmac_internal_data hmac;
|
||||||
psa_status_t status, cleanup_status;
|
psa_status_t status, cleanup_status;
|
||||||
|
|
||||||
|
unsigned char *Ai;
|
||||||
|
size_t Ai_len;
|
||||||
|
|
||||||
/* We can't be wanting more output after block 0xff, otherwise
|
/* We can't be wanting more output after block 0xff, otherwise
|
||||||
* the capacity check in psa_generator_read() would have
|
* the capacity check in psa_generator_read() would have
|
||||||
* prevented this call. It could happen only if the generator
|
* prevented this call. It could happen only if the generator
|
||||||
|
@ -3415,51 +3418,34 @@ static psa_status_t psa_generator_tls12_prf_generate_next_block(
|
||||||
* length than the other A(i). */
|
* length than the other A(i). */
|
||||||
if( tls12_prf->block_number == 1 )
|
if( tls12_prf->block_number == 1 )
|
||||||
{
|
{
|
||||||
/* Compute A(1) = HMAC_hash(secret, label + seed) */
|
Ai = tls12_prf->Ai_with_seed + hash_length;
|
||||||
status = psa_hmac_setup_internal( &hmac,
|
Ai_len = tls12_prf->Ai_with_seed_len - hash_length;
|
||||||
tls12_prf->key,
|
|
||||||
tls12_prf->key_len,
|
|
||||||
hash_alg );
|
|
||||||
if( status != PSA_SUCCESS )
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
status = psa_hash_update( &hmac.hash_ctx,
|
|
||||||
/* This omits the (so far undefined)
|
|
||||||
* first hash_length bytes. */
|
|
||||||
tls12_prf->Ai_with_seed + hash_length,
|
|
||||||
tls12_prf->Ai_with_seed_len - hash_length );
|
|
||||||
if( status != PSA_SUCCESS )
|
|
||||||
goto cleanup;
|
|
||||||
status = psa_hmac_finish_internal( &hmac,
|
|
||||||
tls12_prf->Ai_with_seed,
|
|
||||||
hash_length );
|
|
||||||
if( status != PSA_SUCCESS )
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Compute A(i+1) = HMAC_hash(secret, A(i)) */
|
Ai = tls12_prf->Ai_with_seed;
|
||||||
status = psa_hmac_setup_internal( &hmac,
|
Ai_len = hash_length;
|
||||||
tls12_prf->key,
|
|
||||||
tls12_prf->key_len,
|
|
||||||
hash_alg );
|
|
||||||
if( status != PSA_SUCCESS )
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
status = psa_hash_update( &hmac.hash_ctx,
|
|
||||||
tls12_prf->Ai_with_seed,
|
|
||||||
/* This omits the seed part of A(i) */
|
|
||||||
hash_length );
|
|
||||||
if( status != PSA_SUCCESS )
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
status = psa_hmac_finish_internal( &hmac,
|
|
||||||
tls12_prf->Ai_with_seed,
|
|
||||||
hash_length );
|
|
||||||
if( status != PSA_SUCCESS )
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Compute A(i+1) = HMAC_hash(secret, A(i)) */
|
||||||
|
status = psa_hmac_setup_internal( &hmac,
|
||||||
|
tls12_prf->key,
|
||||||
|
tls12_prf->key_len,
|
||||||
|
hash_alg );
|
||||||
|
if( status != PSA_SUCCESS )
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
status = psa_hash_update( &hmac.hash_ctx,
|
||||||
|
Ai, Ai_len );
|
||||||
|
if( status != PSA_SUCCESS )
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
status = psa_hmac_finish_internal( &hmac,
|
||||||
|
tls12_prf->Ai_with_seed,
|
||||||
|
hash_length );
|
||||||
|
if( status != PSA_SUCCESS )
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
/* Compute the next block `HMAC_hash(secret, A(i+1) + seed)`. */
|
/* Compute the next block `HMAC_hash(secret, A(i+1) + seed)`. */
|
||||||
status = psa_hmac_setup_internal( &hmac,
|
status = psa_hmac_setup_internal( &hmac,
|
||||||
tls12_prf->key,
|
tls12_prf->key,
|
||||||
|
|
Loading…
Reference in a new issue