blob: e1d7491aa218231019c1f38423d70fc8c15e978c [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
Darryl Greena40a1012018-01-05 15:33:17 +00005 */
6/*
Bence Szépkúti1e148272020-08-07 13:07:28 +02007 * Copyright The Mbed TLS Contributors
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02008 * 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.
Paul Bakker6083fd22011-12-03 21:45:14 +000021 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020022#ifndef MBEDTLS_ENTROPY_POLL_H
23#define MBEDTLS_ENTROPY_POLL_H
Paul Bakker6083fd22011-12-03 21:45:14 +000024
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020025#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010026#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020027#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#endif
Paul Bakker6083fd22011-12-03 21:45:14 +000030
Rich Evans00ab4702015-02-06 13:43:58 +000031#include <stddef.h>
32
Paul Bakker6083fd22011-12-03 21:45:14 +000033#ifdef __cplusplus
34extern "C" {
35#endif
36
Paul Bakkerbd4a9d02011-12-10 17:02:19 +000037/*
Manuel Pégourié-Gonnardbf82ff02015-06-19 09:40:51 +020038 * Default thresholds for built-in sources, in bytes
Paul Bakkerbd4a9d02011-12-10 17:02:19 +000039 */
Manuel Pégourié-Gonnardbf82ff02015-06-19 09:40:51 +020040#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() */
Andres AG7abc9742016-09-23 17:58:49 +010043#if !defined(MBEDTLS_ENTROPY_MIN_HARDWARE)
Manuel Pégourié-Gonnard3f77dfb2015-06-19 10:06:21 +020044#define MBEDTLS_ENTROPY_MIN_HARDWARE 32 /**< Minimum for the hardware source */
Andres AG7abc9742016-09-23 17:58:49 +010045#endif
Paul Bakkerbd4a9d02011-12-10 17:02:19 +000046
Janos Follath53de7842016-06-08 15:29:18 +010047/**
48 * \brief Entropy poll callback that provides 0 entropy.
49 */
Simon Butcherab5df402016-06-11 02:31:21 +010050#if defined(MBEDTLS_TEST_NULL_ENTROPY)
Simon Butcher4157b602016-06-12 00:31:33 +010051 int mbedtls_null_entropy_poll( void *data,
Janos Follath53de7842016-06-08 15:29:18 +010052 unsigned char *output, size_t len, size_t *olen );
53#endif
54
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
Paul Bakker6083fd22011-12-03 21:45:14 +000056/**
57 * \brief Platform-specific entropy poll callback
58 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020059int mbedtls_platform_entropy_poll( void *data,
Paul Bakker6083fd22011-12-03 21:45:14 +000060 unsigned char *output, size_t len, size_t *olen );
61#endif
62
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063#if defined(MBEDTLS_HAVEGE_C)
Paul Bakker6083fd22011-12-03 21:45:14 +000064/**
65 * \brief HAVEGE based entropy poll callback
66 *
67 * Requires an HAVEGE state as its data pointer.
68 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020069int mbedtls_havege_poll( void *data,
Paul Bakker6083fd22011-12-03 21:45:14 +000070 unsigned char *output, size_t len, size_t *olen );
71#endif
72
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020073#if defined(MBEDTLS_TIMING_C)
Paul Bakker6083fd22011-12-03 21:45:14 +000074/**
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075 * \brief mbedtls_timing_hardclock-based entropy poll callback
Paul Bakker6083fd22011-12-03 21:45:14 +000076 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077int mbedtls_hardclock_poll( void *data,
Paul Bakker6083fd22011-12-03 21:45:14 +000078 unsigned char *output, size_t len, size_t *olen );
79#endif
80
Manuel Pégourié-Gonnard3f77dfb2015-06-19 10:06:21 +020081#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 */
90int mbedtls_hardware_poll( void *data,
91 unsigned char *output, size_t len, size_t *olen );
92#endif
93
Paul Bakker9988d6b2016-06-01 11:29:42 +010094#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 */
100int mbedtls_nv_seed_poll( void *data,
101 unsigned char *output, size_t len, size_t *olen );
102#endif
103
Paul Bakker6083fd22011-12-03 21:45:14 +0000104#ifdef __cplusplus
105}
106#endif
107
108#endif /* entropy_poll.h */