1 /**
2  * \file entropy_poll.h
3  *
4  * \brief Platform-specific and custom entropy polling functions
5  */
6 /*
7  *  Copyright The Mbed TLS Contributors
8  *  SPDX-License-Identifier: Apache-2.0
9  *
10  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
11  *  not use this file except in compliance with the License.
12  *  You may obtain a copy of the License at
13  *
14  *  http://www.apache.org/licenses/LICENSE-2.0
15  *
16  *  Unless required by applicable law or agreed to in writing, software
17  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  *  See the License for the specific language governing permissions and
20  *  limitations under the License.
21  */
22 #ifndef MBEDTLS_ENTROPY_POLL_H
23 #define MBEDTLS_ENTROPY_POLL_H
24 
25 #if !defined(MBEDTLS_CONFIG_FILE)
26 #include "mbedtls/config.h"
27 #else
28 #include MBEDTLS_CONFIG_FILE
29 #endif
30 
31 #include <stddef.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 /*
38  * Default thresholds for built-in sources, in bytes
39  */
40 #define MBEDTLS_ENTROPY_MIN_PLATFORM     32     /**< Minimum for platform source    */
41 #define MBEDTLS_ENTROPY_MIN_HAVEGE       32     /**< Minimum for HAVEGE             */
42 #define MBEDTLS_ENTROPY_MIN_HARDCLOCK     4     /**< Minimum for mbedtls_timing_hardclock()        */
43 #if !defined(MBEDTLS_ENTROPY_MIN_HARDWARE)
44 #define MBEDTLS_ENTROPY_MIN_HARDWARE     32     /**< Minimum for the hardware source */
45 #endif
46 
47 /**
48  * \brief           Entropy poll callback that provides 0 entropy.
49  */
50 #if defined(MBEDTLS_TEST_NULL_ENTROPY)
51     int mbedtls_null_entropy_poll( void *data,
52                                 unsigned char *output, size_t len, size_t *olen );
53 #endif
54 
55 #if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
56 /**
57  * \brief           Platform-specific entropy poll callback
58  */
59 int mbedtls_platform_entropy_poll( void *data,
60                            unsigned char *output, size_t len, size_t *olen );
61 #endif
62 
63 #if defined(MBEDTLS_HAVEGE_C)
64 /**
65  * \brief           HAVEGE based entropy poll callback
66  *
67  * Requires an HAVEGE state as its data pointer.
68  */
69 int mbedtls_havege_poll( void *data,
70                  unsigned char *output, size_t len, size_t *olen );
71 #endif
72 
73 #if defined(MBEDTLS_TIMING_C)
74 /**
75  * \brief           mbedtls_timing_hardclock-based entropy poll callback
76  */
77 int mbedtls_hardclock_poll( void *data,
78                     unsigned char *output, size_t len, size_t *olen );
79 #endif
80 
81 #if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
82 /**
83  * \brief           Entropy poll callback for a hardware source
84  *
85  * \warning         This is not provided by mbed TLS!
86  *                  See \c MBEDTLS_ENTROPY_HARDWARE_ALT in config.h.
87  *
88  * \note            This must accept NULL as its first argument.
89  */
90 int mbedtls_hardware_poll( void *data,
91                            unsigned char *output, size_t len, size_t *olen );
92 #endif
93 
94 #if defined(MBEDTLS_ENTROPY_NV_SEED)
95 /**
96  * \brief           Entropy poll callback for a non-volatile seed file
97  *
98  * \note            This must accept NULL as its first argument.
99  */
100 int mbedtls_nv_seed_poll( void *data,
101                           unsigned char *output, size_t len, size_t *olen );
102 #endif
103 
104 #ifdef __cplusplus
105 }
106 #endif
107 
108 #endif /* entropy_poll.h */
109