blob: f3175796b6eb20b35c9d099a59c5cbd3af6d6d57 [file] [log] [blame]
Philippe Antoine72333522018-05-03 16:40:24 +02001#include <stdint.h>
2#include "mbedtls/x509_crt.h"
3
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01004int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
5{
Philippe Antoine72333522018-05-03 16:40:24 +02006#ifdef MBEDTLS_X509_CRT_PARSE_C
7 int ret;
8 mbedtls_x509_crt crt;
9 unsigned char buf[4096];
10
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010011 mbedtls_x509_crt_init(&crt);
Przemek Stekiel8fa17b62023-04-19 11:47:01 +020012#if defined(MBEDTLS_USE_PSA_CRYPTO)
13 psa_status_t status = psa_crypto_init();
14 if (status != PSA_SUCCESS) {
15 goto exit;
16 }
17#endif /* MBEDTLS_USE_PSA_CRYPTO */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010018 ret = mbedtls_x509_crt_parse(&crt, Data, Size);
Philippe Antoine72333522018-05-03 16:40:24 +020019 if (ret == 0) {
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010020 ret = mbedtls_x509_crt_info((char *) buf, sizeof(buf) - 1, " ", &crt);
Philippe Antoine72333522018-05-03 16:40:24 +020021 }
Przemek Stekiel8fa17b62023-04-19 11:47:01 +020022exit:
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010023 mbedtls_x509_crt_free(&crt);
Przemek Stekiel8fa17b62023-04-19 11:47:01 +020024 mbedtls_psa_crypto_free();
Philippe Antoine72333522018-05-03 16:40:24 +020025#else
26 (void) Data;
27 (void) Size;
28#endif
29
30 return 0;
31}