fuzz_pubkey, fuzz_privkey: no real need to access private fields

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine 2024-02-22 12:05:35 +01:00
parent 7a3059ac92
commit d5f68976e8
2 changed files with 9 additions and 7 deletions

View file

@ -1,5 +1,3 @@
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@ -73,7 +71,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
if (mbedtls_pk_get_type(&pk) == MBEDTLS_PK_ECKEY ||
mbedtls_pk_get_type(&pk) == MBEDTLS_PK_ECKEY_DH) {
mbedtls_ecp_keypair *ecp = mbedtls_pk_ec(pk);
mbedtls_ecp_group_id grp_id = ecp->grp.id;
mbedtls_ecp_group_id grp_id = mbedtls_ecp_keypair_get_group_id(ecp);
const mbedtls_ecp_curve_info *curve_info =
mbedtls_ecp_curve_info_from_grp_id(grp_id);

View file

@ -1,5 +1,3 @@
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
#include <stdint.h>
#include <stdlib.h>
#include "mbedtls/pk.h"
@ -49,7 +47,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
if (mbedtls_pk_get_type(&pk) == MBEDTLS_PK_ECKEY ||
mbedtls_pk_get_type(&pk) == MBEDTLS_PK_ECKEY_DH) {
mbedtls_ecp_keypair *ecp = mbedtls_pk_ec(pk);
mbedtls_ecp_group_id grp_id = ecp->grp.id;
mbedtls_ecp_group_id grp_id = mbedtls_ecp_keypair_get_group_id(ecp);
const mbedtls_ecp_curve_info *curve_info =
mbedtls_ecp_curve_info_from_grp_id(grp_id);
@ -61,9 +59,15 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
/* It's a public key, so the private value should not have
* been changed from its initialization to 0. */
if (mbedtls_mpi_cmp_int(&ecp->d, 0) != 0) {
mbedtls_mpi d;
mbedtls_mpi_init(&d);
if (mbedtls_ecp_export(ecp, NULL, &d, NULL) != 0) {
abort();
}
if (mbedtls_mpi_cmp_int(&d, 0) != 0) {
abort();
}
mbedtls_mpi_free(&d);
} else
#endif
{