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