Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file entropy_poll.h |
| 3 | * |
| 4 | * \brief Platform-specific and custom entropy polling functions |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 5 | */ |
| 6 | /* |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 7 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 7ff7965 | 2023-11-03 12:04:52 +0000 | [diff] [blame] | 8 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame] | 9 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 10 | #ifndef MBEDTLS_ENTROPY_POLL_H |
| 11 | #define MBEDTLS_ENTROPY_POLL_H |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame] | 12 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 13 | #if !defined(MBEDTLS_CONFIG_FILE) |
Jaeden Amero | c49fbbf | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 14 | #include "mbedtls/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 15 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 16 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 17 | #endif |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame] | 18 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 19 | #include <stddef.h> |
| 20 | |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame] | 21 | #ifdef __cplusplus |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
Paul Bakker | bd4a9d0 | 2011-12-10 17:02:19 +0000 | [diff] [blame] | 25 | /* |
Manuel Pégourié-Gonnard | bf82ff0 | 2015-06-19 09:40:51 +0200 | [diff] [blame] | 26 | * Default thresholds for built-in sources, in bytes |
Paul Bakker | bd4a9d0 | 2011-12-10 17:02:19 +0000 | [diff] [blame] | 27 | */ |
Manuel Pégourié-Gonnard | bf82ff0 | 2015-06-19 09:40:51 +0200 | [diff] [blame] | 28 | #define MBEDTLS_ENTROPY_MIN_PLATFORM 32 /**< Minimum for platform source */ |
| 29 | #define MBEDTLS_ENTROPY_MIN_HAVEGE 32 /**< Minimum for HAVEGE */ |
| 30 | #define MBEDTLS_ENTROPY_MIN_HARDCLOCK 4 /**< Minimum for mbedtls_timing_hardclock() */ |
Andres AG | 7abc974 | 2016-09-23 17:58:49 +0100 | [diff] [blame] | 31 | #if !defined(MBEDTLS_ENTROPY_MIN_HARDWARE) |
Manuel Pégourié-Gonnard | 3f77dfb | 2015-06-19 10:06:21 +0200 | [diff] [blame] | 32 | #define MBEDTLS_ENTROPY_MIN_HARDWARE 32 /**< Minimum for the hardware source */ |
Andres AG | 7abc974 | 2016-09-23 17:58:49 +0100 | [diff] [blame] | 33 | #endif |
Paul Bakker | bd4a9d0 | 2011-12-10 17:02:19 +0000 | [diff] [blame] | 34 | |
Janos Follath | 53de784 | 2016-06-08 15:29:18 +0100 | [diff] [blame] | 35 | /** |
| 36 | * \brief Entropy poll callback that provides 0 entropy. |
| 37 | */ |
Simon Butcher | ab5df40 | 2016-06-11 02:31:21 +0100 | [diff] [blame] | 38 | #if defined(MBEDTLS_TEST_NULL_ENTROPY) |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 39 | int mbedtls_null_entropy_poll(void *data, |
| 40 | unsigned char *output, size_t len, size_t *olen); |
Janos Follath | 53de784 | 2016-06-08 15:29:18 +0100 | [diff] [blame] | 41 | #endif |
| 42 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 43 | #if !defined(MBEDTLS_NO_PLATFORM_ENTROPY) |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame] | 44 | /** |
| 45 | * \brief Platform-specific entropy poll callback |
| 46 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 47 | int mbedtls_platform_entropy_poll(void *data, |
| 48 | unsigned char *output, size_t len, size_t *olen); |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame] | 49 | #endif |
| 50 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 51 | #if defined(MBEDTLS_HAVEGE_C) |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame] | 52 | /** |
| 53 | * \brief HAVEGE based entropy poll callback |
| 54 | * |
| 55 | * Requires an HAVEGE state as its data pointer. |
| 56 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 57 | int mbedtls_havege_poll(void *data, |
| 58 | unsigned char *output, size_t len, size_t *olen); |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame] | 59 | #endif |
| 60 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 61 | #if defined(MBEDTLS_TIMING_C) |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame] | 62 | /** |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 63 | * \brief mbedtls_timing_hardclock-based entropy poll callback |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame] | 64 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 65 | int mbedtls_hardclock_poll(void *data, |
| 66 | unsigned char *output, size_t len, size_t *olen); |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame] | 67 | #endif |
| 68 | |
Manuel Pégourié-Gonnard | 3f77dfb | 2015-06-19 10:06:21 +0200 | [diff] [blame] | 69 | #if defined(MBEDTLS_ENTROPY_HARDWARE_ALT) |
| 70 | /** |
| 71 | * \brief Entropy poll callback for a hardware source |
| 72 | * |
Gilles Peskine | f08ca83 | 2023-09-12 19:21:54 +0200 | [diff] [blame] | 73 | * \warning This is not provided by Mbed TLS! |
Manuel Pégourié-Gonnard | 3f77dfb | 2015-06-19 10:06:21 +0200 | [diff] [blame] | 74 | * See \c MBEDTLS_ENTROPY_HARDWARE_ALT in config.h. |
| 75 | * |
| 76 | * \note This must accept NULL as its first argument. |
| 77 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 78 | int mbedtls_hardware_poll(void *data, |
| 79 | unsigned char *output, size_t len, size_t *olen); |
Manuel Pégourié-Gonnard | 3f77dfb | 2015-06-19 10:06:21 +0200 | [diff] [blame] | 80 | #endif |
| 81 | |
Paul Bakker | 9988d6b | 2016-06-01 11:29:42 +0100 | [diff] [blame] | 82 | #if defined(MBEDTLS_ENTROPY_NV_SEED) |
| 83 | /** |
| 84 | * \brief Entropy poll callback for a non-volatile seed file |
| 85 | * |
| 86 | * \note This must accept NULL as its first argument. |
| 87 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 88 | int mbedtls_nv_seed_poll(void *data, |
| 89 | unsigned char *output, size_t len, size_t *olen); |
Paul Bakker | 9988d6b | 2016-06-01 11:29:42 +0100 | [diff] [blame] | 90 | #endif |
| 91 | |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame] | 92 | #ifdef __cplusplus |
| 93 | } |
| 94 | #endif |
| 95 | |
| 96 | #endif /* entropy_poll.h */ |