Skip to content

Commit

Permalink
Indicate nonce sizes invalid for ChaCha20-Poly1305
Browse files Browse the repository at this point in the history
Signed-off-by: Bence Szépkúti <[email protected]>
  • Loading branch information
bensze01 committed Nov 17, 2021
1 parent 357b78e commit 6d48e20
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.d/chacha20-poly1305-invalid-nonce.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Changes
* Indicate in the error returned if the nonce length used with
ChaCha20-Poly1305 is invalid, and not just unsupported.
4 changes: 3 additions & 1 deletion library/psa_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -3658,7 +3658,9 @@ static psa_status_t psa_aead_check_nonce_length( psa_algorithm_t alg,
case PSA_ALG_CHACHA20_POLY1305:
if( nonce_length == 12 )
return( PSA_SUCCESS );
return( PSA_ERROR_NOT_SUPPORTED );
else if( nonce_length == 8 )
return( PSA_ERROR_NOT_SUPPORTED );
break;
#endif /* PSA_WANT_ALG_CHACHA20_POLY1305 */
default:
return( PSA_ERROR_NOT_SUPPORTED );
Expand Down
4 changes: 2 additions & 2 deletions tests/suites/test_suite_psa_crypto.data
Original file line number Diff line number Diff line change
Expand Up @@ -2821,11 +2821,11 @@ aead_decrypt:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495

PSA AEAD decrypt: ChaCha20-Poly1305 (nonce=11, too short)
depends_on:PSA_WANT_ALG_CHACHA20_POLY1305:PSA_WANT_KEY_TYPE_CHACHA20
aead_decrypt:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_CHACHA20_POLY1305:"0700000040414243444546":"":"a0784d7a4716f3feb4f64e7f4b39bf04":"":PSA_ERROR_NOT_SUPPORTED
aead_decrypt:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_CHACHA20_POLY1305:"0700000040414243444546":"":"a0784d7a4716f3feb4f64e7f4b39bf04":"":PSA_ERROR_INVALID_ARGUMENT

PSA AEAD decrypt: ChaCha20-Poly1305 (nonce=13, too long)
depends_on:PSA_WANT_ALG_CHACHA20_POLY1305:PSA_WANT_KEY_TYPE_CHACHA20
aead_decrypt:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_CHACHA20_POLY1305:"07000000404142434445464700":"":"a0784d7a4716f3feb4f64e7f4b39bf04":"":PSA_ERROR_NOT_SUPPORTED
aead_decrypt:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_CHACHA20_POLY1305:"07000000404142434445464700":"":"a0784d7a4716f3feb4f64e7f4b39bf04":"":PSA_ERROR_INVALID_ARGUMENT

PSA AEAD encrypt/decrypt: invalid algorithm (CTR)
depends_on:MBEDTLS_AES_C:MBEDTLS_GCM_C
Expand Down

0 comments on commit 6d48e20

Please sign in to comment.