1 #define MBEDTLS_ALLOW_PRIVATE_ACCESS 2 3 #include <stdint.h> 4 #include "mbedtls/x509_csr.h" 5 LLVMFuzzerTestOneInput(const uint8_t * Data,size_t Size)6int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) 7 { 8 #ifdef MBEDTLS_X509_CSR_PARSE_C 9 int ret; 10 mbedtls_x509_csr csr; 11 unsigned char buf[4096]; 12 13 mbedtls_x509_csr_init(&csr); 14 #if defined(MBEDTLS_USE_PSA_CRYPTO) 15 psa_status_t status = psa_crypto_init(); 16 if (status != PSA_SUCCESS) { 17 goto exit; 18 } 19 #endif /* MBEDTLS_USE_PSA_CRYPTO */ 20 ret = mbedtls_x509_csr_parse(&csr, Data, Size); 21 #if !defined(MBEDTLS_X509_REMOVE_INFO) 22 if (ret == 0) { 23 ret = mbedtls_x509_csr_info((char *) buf, sizeof(buf) - 1, " ", &csr); 24 } 25 #else 26 ((void) ret); 27 ((void) buf); 28 #endif /* !MBEDTLS_X509_REMOVE_INFO */ 29 30 #if defined(MBEDTLS_USE_PSA_CRYPTO) 31 exit: 32 mbedtls_psa_crypto_free(); 33 #endif /* MBEDTLS_USE_PSA_CRYPTO */ 34 mbedtls_x509_csr_free(&csr); 35 #else 36 (void) Data; 37 (void) Size; 38 #endif 39 40 return 0; 41 } 42