blob: 1c26e6f0823945d184daf51d3ad95e2497163042 [file] [log] [blame]
Felix Conway998760a2025-03-24 11:37:33 +00001#define MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS
2
Philippe Antoine72333522018-05-03 16:40:24 +02003#include <stdint.h>
4#include "mbedtls/x509_csr.h"
Ben Taylor52510b22025-06-04 09:35:35 +01005#include "fuzz_common.h"
Philippe Antoine72333522018-05-03 16:40:24 +02006
Gilles Peskine449bd832023-01-11 14:50:10 +01007int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
8{
Philippe Antoine72333522018-05-03 16:40:24 +02009#ifdef MBEDTLS_X509_CSR_PARSE_C
10 int ret;
11 mbedtls_x509_csr csr;
12 unsigned char buf[4096];
13
Gilles Peskine449bd832023-01-11 14:50:10 +010014 mbedtls_x509_csr_init(&csr);
Przemek Stekiel774f9de2023-04-19 11:47:01 +020015 psa_status_t status = psa_crypto_init();
16 if (status != PSA_SUCCESS) {
17 goto exit;
18 }
Gilles Peskine449bd832023-01-11 14:50:10 +010019 ret = mbedtls_x509_csr_parse(&csr, Data, Size);
Hanno Becker54ac1852020-10-09 09:45:29 +010020#if !defined(MBEDTLS_X509_REMOVE_INFO)
Philippe Antoine72333522018-05-03 16:40:24 +020021 if (ret == 0) {
Gilles Peskine449bd832023-01-11 14:50:10 +010022 ret = mbedtls_x509_csr_info((char *) buf, sizeof(buf) - 1, " ", &csr);
Philippe Antoine72333522018-05-03 16:40:24 +020023 }
Ben Taylor4bb98be2025-05-07 14:21:20 +010024#else /* !MBEDTLS_X509_REMOVE_INFO */
Hanno Becker54ac1852020-10-09 09:45:29 +010025 ((void) ret);
Hanno Beckereb2efb02020-10-16 06:54:39 +010026 ((void) buf);
Hanno Becker54ac1852020-10-09 09:45:29 +010027#endif /* !MBEDTLS_X509_REMOVE_INFO */
Przemek Stekiel758aef62023-04-19 13:47:43 +020028
Przemek Stekiel774f9de2023-04-19 11:47:01 +020029exit:
Przemek Stekiel774f9de2023-04-19 11:47:01 +020030 mbedtls_psa_crypto_free();
Przemek Stekiel53463962023-04-24 09:00:14 +020031 mbedtls_x509_csr_free(&csr);
Ben Taylor4bb98be2025-05-07 14:21:20 +010032#else /* MBEDTLS_X509_CSR_PARSE_C */
Philippe Antoine72333522018-05-03 16:40:24 +020033 (void) Data;
34 (void) Size;
Ben Taylor4bb98be2025-05-07 14:21:20 +010035#endif /* MBEDTLS_X509_CSR_PARSE_C */
Philippe Antoine72333522018-05-03 16:40:24 +020036
37 return 0;
38}