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