| Philippe Antoine | 7233352 | 2018-05-03 16:40:24 +0200 | [diff] [blame] | 1 | #include <stdint.h> | 
|  | 2 | #include "mbedtls/x509_crt.h" | 
| Michael Schuster | 41a686b | 2024-06-01 21:08:45 +0200 | [diff] [blame] | 3 | #include "common.h" | 
| Philippe Antoine | 7233352 | 2018-05-03 16:40:24 +0200 | [diff] [blame] | 4 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 5 | int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) | 
|  | 6 | { | 
| Philippe Antoine | 7233352 | 2018-05-03 16:40:24 +0200 | [diff] [blame] | 7 | #ifdef MBEDTLS_X509_CRT_PARSE_C | 
|  | 8 | int ret; | 
|  | 9 | mbedtls_x509_crt crt; | 
|  | 10 | unsigned char buf[4096]; | 
|  | 11 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 12 | mbedtls_x509_crt_init(&crt); | 
| Przemek Stekiel | 774f9de | 2023-04-19 11:47:01 +0200 | [diff] [blame] | 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 */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 19 | ret = mbedtls_x509_crt_parse(&crt, Data, Size); | 
| Hanno Becker | 54ac185 | 2020-10-09 09:45:29 +0100 | [diff] [blame] | 20 | #if !defined(MBEDTLS_X509_REMOVE_INFO) | 
| Philippe Antoine | 7233352 | 2018-05-03 16:40:24 +0200 | [diff] [blame] | 21 | if (ret == 0) { | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 22 | ret = mbedtls_x509_crt_info((char *) buf, sizeof(buf) - 1, " ", &crt); | 
| Philippe Antoine | 7233352 | 2018-05-03 16:40:24 +0200 | [diff] [blame] | 23 | } | 
| Hanno Becker | 54ac185 | 2020-10-09 09:45:29 +0100 | [diff] [blame] | 24 | #else | 
|  | 25 | ((void) ret); | 
| Hanno Becker | eb2efb0 | 2020-10-16 06:54:39 +0100 | [diff] [blame] | 26 | ((void) buf); | 
| Hanno Becker | 54ac185 | 2020-10-09 09:45:29 +0100 | [diff] [blame] | 27 | #endif /* !MBEDTLS_X509_REMOVE_INFO */ | 
| Przemek Stekiel | 758aef6 | 2023-04-19 13:47:43 +0200 | [diff] [blame] | 28 |  | 
|  | 29 | #if defined(MBEDTLS_USE_PSA_CRYPTO) | 
| Przemek Stekiel | 774f9de | 2023-04-19 11:47:01 +0200 | [diff] [blame] | 30 | exit: | 
| Przemek Stekiel | 774f9de | 2023-04-19 11:47:01 +0200 | [diff] [blame] | 31 | mbedtls_psa_crypto_free(); | 
| Przemek Stekiel | 758aef6 | 2023-04-19 13:47:43 +0200 | [diff] [blame] | 32 | #endif /* MBEDTLS_USE_PSA_CRYPTO */ | 
|  | 33 | mbedtls_x509_crt_free(&crt); | 
| Philippe Antoine | 7233352 | 2018-05-03 16:40:24 +0200 | [diff] [blame] | 34 | #else | 
|  | 35 | (void) Data; | 
|  | 36 | (void) Size; | 
|  | 37 | #endif | 
|  | 38 |  | 
|  | 39 | return 0; | 
|  | 40 | } |