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