Skip to content

Commit

Permalink
Merge pull request #861 from ronald-cron-arm/fix-aead-nonce
Browse files Browse the repository at this point in the history
psa: aead: Fix invalid output buffer usage in generate_nonce()
  • Loading branch information
mpg authored Dec 8, 2021
2 parents 39c2aba + 0b4d123 commit 5d9f422
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.d/fix-aead-nonce.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Security
* In psa_aead_generate_nonce(), do not read back from the output buffer.
This fixes a potential policy bypass or decryption oracle vulnerability
if the output buffer is in memory that is shared with an untrusted
application.
8 changes: 6 additions & 2 deletions library/psa_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -3901,6 +3901,7 @@ psa_status_t psa_aead_generate_nonce( psa_aead_operation_t *operation,
size_t *nonce_length )
{
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
uint8_t local_nonce[PSA_AEAD_NONCE_MAX_SIZE];
size_t required_nonce_size;

*nonce_length = 0;
Expand All @@ -3925,15 +3926,18 @@ psa_status_t psa_aead_generate_nonce( psa_aead_operation_t *operation,
goto exit;
}

status = psa_generate_random( nonce, required_nonce_size );
status = psa_generate_random( local_nonce, required_nonce_size );
if( status != PSA_SUCCESS )
goto exit;

status = psa_aead_set_nonce( operation, nonce, required_nonce_size );
status = psa_aead_set_nonce( operation, local_nonce, required_nonce_size );

exit:
if( status == PSA_SUCCESS )
{
memcpy( nonce, local_nonce, required_nonce_size );
*nonce_length = required_nonce_size;
}
else
psa_aead_abort( operation );

Expand Down

0 comments on commit 5d9f422

Please sign in to comment.