blob: 81258d5f396b98774a6fb9987adb05c0fc610aa3 [file] [log] [blame]
Paul Bakker6083fd22011-12-03 21:45:14 +00001/**
2 * \file entropy_poll.h
3 *
4 * \brief Platform-specific and custom entropy polling functions
5 *
Paul Bakker9988d6b2016-06-01 11:29:42 +01006 * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02007 * 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.
Paul Bakker6083fd22011-12-03 21:45:14 +000020 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000021 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker6083fd22011-12-03 21:45:14 +000022 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020023#ifndef MBEDTLS_ENTROPY_POLL_H
24#define MBEDTLS_ENTROPY_POLL_H
Paul Bakker6083fd22011-12-03 21:45:14 +000025
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker6083fd22011-12-03 21:45:14 +000027#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020028#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020029#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#endif
Paul Bakker6083fd22011-12-03 21:45:14 +000031
Rich Evans00ab4702015-02-06 13:43:58 +000032#include <stddef.h>
33
Paul Bakker6083fd22011-12-03 21:45:14 +000034#ifdef __cplusplus
35extern "C" {
36#endif
37
Paul Bakkerbd4a9d02011-12-10 17:02:19 +000038/*
Manuel Pégourié-Gonnardbf82ff02015-06-19 09:40:51 +020039 * Default thresholds for built-in sources, in bytes
Paul Bakkerbd4a9d02011-12-10 17:02:19 +000040 */
Manuel Pégourié-Gonnardbf82ff02015-06-19 09:40:51 +020041#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() */
Andres AG7abc9742016-09-23 17:58:49 +010044#if !defined(MBEDTLS_ENTROPY_MIN_HARDWARE)
Manuel Pégourié-Gonnard3f77dfb2015-06-19 10:06:21 +020045#define MBEDTLS_ENTROPY_MIN_HARDWARE 32 /**< Minimum for the hardware source */
Andres AG7abc9742016-09-23 17:58:49 +010046#endif
Paul Bakkerbd4a9d02011-12-10 17:02:19 +000047
Janos Follath53de7842016-06-08 15:29:18 +010048/**
49 * \brief Entropy poll callback that provides 0 entropy.
50 */
Simon Butcherab5df402016-06-11 02:31:21 +010051#if defined(MBEDTLS_TEST_NULL_ENTROPY)
Simon Butcher4157b602016-06-12 00:31:33 +010052 int mbedtls_null_entropy_poll( void *data,
Janos Follath53de7842016-06-08 15:29:18 +010053 unsigned char *output, size_t len, size_t *olen );
54#endif
55
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
Paul Bakker6083fd22011-12-03 21:45:14 +000057/**
58 * \brief Platform-specific entropy poll callback
59 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060int mbedtls_platform_entropy_poll( void *data,
Paul Bakker6083fd22011-12-03 21:45:14 +000061 unsigned char *output, size_t len, size_t *olen );
62#endif
63
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064#if defined(MBEDTLS_HAVEGE_C)
Paul Bakker6083fd22011-12-03 21:45:14 +000065/**
66 * \brief HAVEGE based entropy poll callback
67 *
68 * Requires an HAVEGE state as its data pointer.
69 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020070int mbedtls_havege_poll( void *data,
Paul Bakker6083fd22011-12-03 21:45:14 +000071 unsigned char *output, size_t len, size_t *olen );
72#endif
73
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020074#if defined(MBEDTLS_TIMING_C)
Paul Bakker6083fd22011-12-03 21:45:14 +000075/**
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020076 * \brief mbedtls_timing_hardclock-based entropy poll callback
Paul Bakker6083fd22011-12-03 21:45:14 +000077 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020078int mbedtls_hardclock_poll( void *data,
Paul Bakker6083fd22011-12-03 21:45:14 +000079 unsigned char *output, size_t len, size_t *olen );
80#endif
81
Manuel Pégourié-Gonnard3f77dfb2015-06-19 10:06:21 +020082#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 */
91int mbedtls_hardware_poll( void *data,
92 unsigned char *output, size_t len, size_t *olen );
93#endif
94
Paul Bakker9988d6b2016-06-01 11:29:42 +010095#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 */
101int mbedtls_nv_seed_poll( void *data,
102 unsigned char *output, size_t len, size_t *olen );
103#endif
104
Paul Bakker6083fd22011-12-03 21:45:14 +0000105#ifdef __cplusplus
106}
107#endif
108
109#endif /* entropy_poll.h */