From 8d36696e1fdb5228938a6cfe9c60ad3772a769dc Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 25 Feb 2020 19:51:07 +0100 Subject: [PATCH] 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. --- programs/fuzz/fuzz_pubkey.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/programs/fuzz/fuzz_pubkey.c b/programs/fuzz/fuzz_pubkey.c index 38eacfb61..c0571c47d 100644 --- a/programs/fuzz/fuzz_pubkey.c +++ b/programs/fuzz/fuzz_pubkey.c @@ -21,7 +21,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { mbedtls_mpi_init( &DQ ); mbedtls_mpi_init( &QP ); 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(); } if ( mbedtls_rsa_export_crt( rsa, &DP, &DQ, &QP ) != MBEDTLS_ERR_RSA_BAD_INPUT_DATA ) {