| Philippe Antoine | 7233352 | 2018-05-03 16:40:24 +0200 | [diff] [blame] | 1 | #include <stdint.h> | 
|  | 2 | #include "mbedtls/x509_crt.h" | 
|  | 3 |  | 
| Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 4 | int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) | 
|  | 5 | { | 
| Philippe Antoine | 7233352 | 2018-05-03 16:40:24 +0200 | [diff] [blame] | 6 | #ifdef MBEDTLS_X509_CRT_PARSE_C | 
|  | 7 | int ret; | 
|  | 8 | mbedtls_x509_crt crt; | 
|  | 9 | unsigned char buf[4096]; | 
|  | 10 |  | 
| Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 11 | mbedtls_x509_crt_init(&crt); | 
| Przemek Stekiel | 8fa17b6 | 2023-04-19 11:47:01 +0200 | [diff] [blame] | 12 | #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 Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 18 | ret = mbedtls_x509_crt_parse(&crt, Data, Size); | 
| Philippe Antoine | 7233352 | 2018-05-03 16:40:24 +0200 | [diff] [blame] | 19 | if (ret == 0) { | 
| Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 20 | ret = mbedtls_x509_crt_info((char *) buf, sizeof(buf) - 1, " ", &crt); | 
| Philippe Antoine | 7233352 | 2018-05-03 16:40:24 +0200 | [diff] [blame] | 21 | } | 
| Przemek Stekiel | d4d049b | 2023-04-19 13:47:43 +0200 | [diff] [blame] | 22 | #if defined(MBEDTLS_USE_PSA_CRYPTO) | 
| Przemek Stekiel | 8fa17b6 | 2023-04-19 11:47:01 +0200 | [diff] [blame] | 23 | exit: | 
| Przemek Stekiel | 8fa17b6 | 2023-04-19 11:47:01 +0200 | [diff] [blame] | 24 | mbedtls_psa_crypto_free(); | 
| Przemek Stekiel | d4d049b | 2023-04-19 13:47:43 +0200 | [diff] [blame] | 25 | #endif /* MBEDTLS_USE_PSA_CRYPTO */ | 
|  | 26 | mbedtls_x509_crt_free(&crt); | 
| Philippe Antoine | 7233352 | 2018-05-03 16:40:24 +0200 | [diff] [blame] | 27 | #else | 
|  | 28 | (void) Data; | 
|  | 29 | (void) Size; | 
|  | 30 | #endif | 
|  | 31 |  | 
|  | 32 | return 0; | 
|  | 33 | } |