Skip to content

Commit

Permalink
PSA RSA PSS: pass pre-hash algorithm to Mbed TLS
Browse files Browse the repository at this point in the history
PSA Crypto always passed MBEDTLS_MD_NONE to Mbed TLS, which worked well
as Mbed TLS does not use this parameter for anything beyond determining
the input lengths.

Some alternative implementations however check the consistency of the
algorithm used for pre-hash and for other uses in verification (verify
operation and mask generation) and fail if they don't match. This makes
all such verifications fail.

Furthermore, the PSA Crypto API mandates that the pre-hash and internal
uses are aligned as well.

Fixes Mbed-TLS#3990.

Signed-off-by: Janos Follath <janos.follath@arm.com>
  • Loading branch information
yanesca committed Jun 17, 2021
1 parent 86ae88e commit bf179e5
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions library/psa_crypto_rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,27 +360,19 @@ static psa_status_t psa_rsa_decode_md_type( psa_algorithm_t alg,
return( PSA_ERROR_INVALID_ARGUMENT );
#endif

#if defined(BUILTIN_ALG_RSA_PKCS1V15_SIGN)
/* For PKCS#1 v1.5 signature, if using a hash, the hash length
* must be correct. */
if( PSA_ALG_IS_RSA_PKCS1V15_SIGN( alg ) &&
alg != PSA_ALG_RSA_PKCS1V15_SIGN_RAW )
/* For signatures using a hash, the hash length must be correct. */
if( alg != PSA_ALG_RSA_PKCS1V15_SIGN_RAW )
{
if( md_info == NULL )
return( PSA_ERROR_NOT_SUPPORTED );
if( mbedtls_md_get_size( md_info ) != hash_length )
return( PSA_ERROR_INVALID_ARGUMENT );
}
#endif /* BUILTIN_ALG_RSA_PKCS1V15_SIGN */

#if defined(BUILTIN_ALG_RSA_PSS)
/* PSS requires a hash internally. */
if( PSA_ALG_IS_RSA_PSS( alg ) )
else
{
if( md_info == NULL )
return( PSA_ERROR_NOT_SUPPORTED );
if( hash_alg != 0 )
return( PSA_ERROR_INVALID_ARGUMENT );
}
#endif /* BUILTIN_ALG_RSA_PSS */

return( PSA_SUCCESS );
}
Expand Down Expand Up @@ -516,7 +508,7 @@ static psa_status_t rsa_verify_hash(
if( ret == 0 )
{
ret = mbedtls_rsa_rsassa_pss_verify( rsa,
MBEDTLS_MD_NONE,
md_alg,
(unsigned int) hash_length,
hash,
signature );
Expand Down

0 comments on commit bf179e5

Please sign in to comment.