Fix fuzz_pubkey failure on valid RSA keys

On a valid RSA public key, mbedtls_rsa_export should succeed if you
ask for the public fields, but fail if you ask for private fields. The
code was expecting to succeed when asking for private fields, so
failed on every valid RSA public key.
This commit is contained in:
Gilles Peskine 2020-02-25 19:51:07 +01:00
parent a08e699afc
commit 8d36696e1f

View file

@ -21,7 +21,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
mbedtls_mpi_init( &DQ ); mbedtls_mpi_init( &QP ); mbedtls_mpi_init( &DQ ); mbedtls_mpi_init( &QP );
rsa = mbedtls_pk_rsa( pk ); rsa = mbedtls_pk_rsa( pk );
if ( mbedtls_rsa_export( rsa, &N, &P, &Q, &D, &E ) != 0 ) { if ( mbedtls_rsa_export( rsa, &N, NULL, NULL, NULL, &E ) != 0 ) {
abort();
}
if ( mbedtls_rsa_export( rsa, &N, &P, &Q, &D, &E ) != MBEDTLS_ERR_RSA_BAD_INPUT_DATA ) {
abort(); abort();
} }
if ( mbedtls_rsa_export_crt( rsa, &DP, &DQ, &QP ) != MBEDTLS_ERR_RSA_BAD_INPUT_DATA ) { if ( mbedtls_rsa_export_crt( rsa, &DP, &DQ, &QP ) != MBEDTLS_ERR_RSA_BAD_INPUT_DATA ) {