blob: 29331b94d4313df6038c2706bbcda3ab218293d8 [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_crt.h"
Michael Schustere708e862024-06-01 21:08:45 +02005#include "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_CRT_PARSE_C
10 int ret;
11 mbedtls_x509_crt crt;
12 unsigned char buf[4096];
13
Gilles Peskine449bd832023-01-11 14:50:10 +010014 mbedtls_x509_crt_init(&crt);
Przemek Stekiel774f9de2023-04-19 11:47:01 +020015#if defined(MBEDTLS_USE_PSA_CRYPTO)
16 psa_status_t status = psa_crypto_init();
17 if (status != PSA_SUCCESS) {
18 goto exit;
19 }
20#endif /* MBEDTLS_USE_PSA_CRYPTO */
Gilles Peskine449bd832023-01-11 14:50:10 +010021 ret = mbedtls_x509_crt_parse(&crt, Data, Size);
Hanno Becker54ac1852020-10-09 09:45:29 +010022#if !defined(MBEDTLS_X509_REMOVE_INFO)
Philippe Antoine72333522018-05-03 16:40:24 +020023 if (ret == 0) {
Gilles Peskine449bd832023-01-11 14:50:10 +010024 ret = mbedtls_x509_crt_info((char *) buf, sizeof(buf) - 1, " ", &crt);
Philippe Antoine72333522018-05-03 16:40:24 +020025 }
Hanno Becker54ac1852020-10-09 09:45:29 +010026#else
27 ((void) ret);
Hanno Beckereb2efb02020-10-16 06:54:39 +010028 ((void) buf);
Hanno Becker54ac1852020-10-09 09:45:29 +010029#endif /* !MBEDTLS_X509_REMOVE_INFO */
Przemek Stekiel758aef62023-04-19 13:47:43 +020030
31#if defined(MBEDTLS_USE_PSA_CRYPTO)
Przemek Stekiel774f9de2023-04-19 11:47:01 +020032exit:
Przemek Stekiel774f9de2023-04-19 11:47:01 +020033 mbedtls_psa_crypto_free();
Przemek Stekiel758aef62023-04-19 13:47:43 +020034#endif /* MBEDTLS_USE_PSA_CRYPTO */
35 mbedtls_x509_crt_free(&crt);
Philippe Antoine72333522018-05-03 16:40:24 +020036#else
37 (void) Data;
38 (void) Size;
39#endif
40
41 return 0;
42}