mirror of
https://github.com/cuberite/polarssl.git
synced 2025-09-21 11:24:37 -04:00
Merge pull request #10115 from bjwtaylor/move-fuzz-progs
remove fuzz_privkey.c and fuzz_pubkey.c
This commit is contained in:
commit
d2c293bd0a
2
programs/fuzz/.gitignore
vendored
2
programs/fuzz/.gitignore
vendored
@ -2,8 +2,6 @@ fuzz_client
|
||||
fuzz_dtlsclient
|
||||
fuzz_dtlsserver
|
||||
fuzz_pkcs7
|
||||
fuzz_privkey
|
||||
fuzz_pubkey
|
||||
fuzz_server
|
||||
fuzz_x509crl
|
||||
fuzz_x509crt
|
||||
|
@ -9,7 +9,6 @@ if(FUZZINGENGINE_LIB)
|
||||
endif()
|
||||
|
||||
set(executables_no_common_c
|
||||
fuzz_pubkey
|
||||
fuzz_x509crl
|
||||
fuzz_x509crt
|
||||
fuzz_x509csr
|
||||
@ -18,7 +17,6 @@ set(executables_no_common_c
|
||||
add_dependencies(${programs_target} ${executables_no_common_c})
|
||||
|
||||
set(executables_with_common_c
|
||||
fuzz_privkey
|
||||
fuzz_client
|
||||
fuzz_dtlsclient
|
||||
fuzz_dtlsserver
|
||||
|
@ -3,12 +3,16 @@ MBEDTLS_TEST_PATH:=../../tests
|
||||
MBEDTLS_PATH := ../..
|
||||
include ../../scripts/common.make
|
||||
|
||||
PROGRAM_FUZZ_PATH:=$(MBEDTLS_PATH)/programs/fuzz
|
||||
|
||||
DEP=${MBEDLIBS}
|
||||
|
||||
ifdef FUZZINGENGINE
|
||||
LOCAL_LDFLAGS += -lFuzzingEngine
|
||||
endif
|
||||
|
||||
LOCAL_CFLAGS += -I$(PROGRAM_FUZZ_PATH)
|
||||
|
||||
# A test application is built for each fuzz_*.c file.
|
||||
APPS = $(basename $(wildcard fuzz_*.c))
|
||||
|
||||
@ -28,19 +32,21 @@ C_FILES := $(addsuffix .c,$(APPS))
|
||||
|
||||
|
||||
ifdef FUZZINGENGINE
|
||||
$(BINARIES): %$(EXEXT): %.o common.o $(DEP)
|
||||
echo " $(CC) common.o $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@"
|
||||
$(CXX) common.o $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
|
||||
$(BINARIES): %$(EXEXT): %.o $(PROGRAM_FUZZ_PATH)/common.o $(DEP)
|
||||
echo " $(PROGRAM_FUZZ_PATH)/common.o $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@"
|
||||
$(CXX) $(PROGRAM_FUZZ_PATH)/common.o $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
|
||||
else
|
||||
$(BINARIES): %$(EXEXT): %.o common.o onefile.o $(DEP)
|
||||
echo " $(CC) common.o onefile.o $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@"
|
||||
$(CC) common.o onefile.o $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
|
||||
$(BINARIES): %$(EXEXT): %.o $(PROGRAM_FUZZ_PATH)/common.o $(PROGRAM_FUZZ_PATH)/onefile.o $(DEP)
|
||||
echo " $(CC) $(PROGRAM_FUZZ_PATH)/common.o $(PROGRAM_FUZZ_PATH)/onefile.o $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@"
|
||||
$(CC) $(PROGRAM_FUZZ_PATH)/common.o $(PROGRAM_FUZZ_PATH)/onefile.o $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
|
||||
endif
|
||||
|
||||
clean:
|
||||
ifndef WINDOWS
|
||||
rm -rf $(BINARIES) *.o
|
||||
rm -rf $(MBEDTLS_PATH)/tf-psa-crypto/programs/fuzz/*.o
|
||||
else
|
||||
if exist *.o del /Q /F *.o
|
||||
if exist *.exe del /Q /F *.exe
|
||||
if exist $(MBEDTLS_PATH)\tf-psa-crypto\programs\fuzz\*.o del /Q /F $(MBEDTLS_PATH)\tf-psa-crypto\programs\fuzz\*.o
|
||||
endif
|
||||
|
@ -1,105 +0,0 @@
|
||||
#define MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "mbedtls/pk.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "common.h"
|
||||
|
||||
//4 Kb should be enough for every bug ;-)
|
||||
#define MAX_LEN 0x1000
|
||||
|
||||
#if defined(MBEDTLS_PK_PARSE_C) && defined(MBEDTLS_CTR_DRBG_C) && defined(MBEDTLS_ENTROPY_C)
|
||||
const char *pers = "fuzz_privkey";
|
||||
#endif // MBEDTLS_PK_PARSE_C && MBEDTLS_CTR_DRBG_C && MBEDTLS_ENTROPY_C
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
||||
{
|
||||
#if defined(MBEDTLS_PK_PARSE_C) && defined(MBEDTLS_CTR_DRBG_C) && defined(MBEDTLS_ENTROPY_C)
|
||||
int ret;
|
||||
mbedtls_pk_context pk;
|
||||
mbedtls_ctr_drbg_context ctr_drbg;
|
||||
mbedtls_entropy_context entropy;
|
||||
|
||||
if (Size > MAX_LEN) {
|
||||
//only work on small inputs
|
||||
Size = MAX_LEN;
|
||||
}
|
||||
|
||||
mbedtls_ctr_drbg_init(&ctr_drbg);
|
||||
mbedtls_entropy_init(&entropy);
|
||||
mbedtls_pk_init(&pk);
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
if (mbedtls_ctr_drbg_seed(&ctr_drbg, dummy_entropy, &entropy,
|
||||
(const unsigned char *) pers, strlen(pers)) != 0) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ret = mbedtls_pk_parse_key(&pk, Data, Size, NULL, 0);
|
||||
if (ret == 0) {
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
if (mbedtls_pk_get_type(&pk) == MBEDTLS_PK_RSA) {
|
||||
mbedtls_mpi N, P, Q, D, E, DP, DQ, QP;
|
||||
mbedtls_rsa_context *rsa;
|
||||
|
||||
mbedtls_mpi_init(&N); mbedtls_mpi_init(&P); mbedtls_mpi_init(&Q);
|
||||
mbedtls_mpi_init(&D); mbedtls_mpi_init(&E); mbedtls_mpi_init(&DP);
|
||||
mbedtls_mpi_init(&DQ); mbedtls_mpi_init(&QP);
|
||||
|
||||
rsa = mbedtls_pk_rsa(pk);
|
||||
if (mbedtls_rsa_export(rsa, &N, &P, &Q, &D, &E) != 0) {
|
||||
abort();
|
||||
}
|
||||
if (mbedtls_rsa_export_crt(rsa, &DP, &DQ, &QP) != 0) {
|
||||
abort();
|
||||
}
|
||||
|
||||
mbedtls_mpi_free(&N); mbedtls_mpi_free(&P); mbedtls_mpi_free(&Q);
|
||||
mbedtls_mpi_free(&D); mbedtls_mpi_free(&E); mbedtls_mpi_free(&DP);
|
||||
mbedtls_mpi_free(&DQ); mbedtls_mpi_free(&QP);
|
||||
} else
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
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 = mbedtls_ecp_keypair_get_group_id(ecp);
|
||||
const mbedtls_ecp_curve_info *curve_info =
|
||||
mbedtls_ecp_curve_info_from_grp_id(grp_id);
|
||||
|
||||
/* If the curve is not supported, the key should not have been
|
||||
* accepted. */
|
||||
if (curve_info == NULL) {
|
||||
abort();
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/* The key is valid but is not of a supported type.
|
||||
* This should not happen. */
|
||||
abort();
|
||||
}
|
||||
}
|
||||
exit:
|
||||
mbedtls_entropy_free(&entropy);
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
mbedtls_pk_free(&pk);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
#else
|
||||
(void) Data;
|
||||
(void) Size;
|
||||
#endif // MBEDTLS_PK_PARSE_C && MBEDTLS_CTR_DRBG_C && MBEDTLS_ENTROPY_C
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
#define MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include "mbedtls/pk.h"
|
||||
#include "common.h"
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
||||
{
|
||||
#ifdef MBEDTLS_PK_PARSE_C
|
||||
int ret;
|
||||
mbedtls_pk_context pk;
|
||||
|
||||
mbedtls_pk_init(&pk);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
ret = mbedtls_pk_parse_public_key(&pk, Data, Size);
|
||||
if (ret == 0) {
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
if (mbedtls_pk_get_type(&pk) == MBEDTLS_PK_RSA) {
|
||||
mbedtls_mpi N, P, Q, D, E, DP, DQ, QP;
|
||||
mbedtls_rsa_context *rsa;
|
||||
|
||||
mbedtls_mpi_init(&N); mbedtls_mpi_init(&P); mbedtls_mpi_init(&Q);
|
||||
mbedtls_mpi_init(&D); mbedtls_mpi_init(&E); mbedtls_mpi_init(&DP);
|
||||
mbedtls_mpi_init(&DQ); mbedtls_mpi_init(&QP);
|
||||
|
||||
rsa = mbedtls_pk_rsa(pk);
|
||||
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) {
|
||||
abort();
|
||||
}
|
||||
|
||||
mbedtls_mpi_free(&N); mbedtls_mpi_free(&P); mbedtls_mpi_free(&Q);
|
||||
mbedtls_mpi_free(&D); mbedtls_mpi_free(&E); mbedtls_mpi_free(&DP);
|
||||
mbedtls_mpi_free(&DQ); mbedtls_mpi_free(&QP);
|
||||
|
||||
} else
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
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 = mbedtls_ecp_keypair_get_group_id(ecp);
|
||||
const mbedtls_ecp_curve_info *curve_info =
|
||||
mbedtls_ecp_curve_info_from_grp_id(grp_id);
|
||||
|
||||
/* If the curve is not supported, the key should not have been
|
||||
* accepted. */
|
||||
if (curve_info == NULL) {
|
||||
abort();
|
||||
}
|
||||
|
||||
/* It's a public key, so the private value should not have
|
||||
* been changed from its initialization to 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
|
||||
{
|
||||
/* The key is valid but is not of a supported type.
|
||||
* This should not happen. */
|
||||
abort();
|
||||
}
|
||||
}
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
exit:
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
mbedtls_pk_free(&pk);
|
||||
#else
|
||||
(void) Data;
|
||||
(void) Size;
|
||||
#endif //MBEDTLS_PK_PARSE_C
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user