blob: d7147b976b05602669e8c2f365fca892ede97e1a [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
Dave Rodgman7ff79652023-11-03 12:04:52 +00008 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Paul Bakker6083fd22011-12-03 21:45:14 +00009 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020010#ifndef MBEDTLS_ENTROPY_POLL_H
11#define MBEDTLS_ENTROPY_POLL_H
Paul Bakker6083fd22011-12-03 21:45:14 +000012
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020013#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010014#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020015#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020016#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020017#endif
Paul Bakker6083fd22011-12-03 21:45:14 +000018
Rich Evans00ab4702015-02-06 13:43:58 +000019#include <stddef.h>
20
Paul Bakker6083fd22011-12-03 21:45:14 +000021#ifdef __cplusplus
22extern "C" {
23#endif
24
Paul Bakkerbd4a9d02011-12-10 17:02:19 +000025/*
Manuel Pégourié-Gonnardbf82ff02015-06-19 09:40:51 +020026 * Default thresholds for built-in sources, in bytes
Paul Bakkerbd4a9d02011-12-10 17:02:19 +000027 */
Manuel Pégourié-Gonnardbf82ff02015-06-19 09:40:51 +020028#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 AG7abc9742016-09-23 17:58:49 +010031#if !defined(MBEDTLS_ENTROPY_MIN_HARDWARE)
Manuel Pégourié-Gonnard3f77dfb2015-06-19 10:06:21 +020032#define MBEDTLS_ENTROPY_MIN_HARDWARE 32 /**< Minimum for the hardware source */
Andres AG7abc9742016-09-23 17:58:49 +010033#endif
Paul Bakkerbd4a9d02011-12-10 17:02:19 +000034
Janos Follath53de7842016-06-08 15:29:18 +010035/**
36 * \brief Entropy poll callback that provides 0 entropy.
37 */
Simon Butcherab5df402016-06-11 02:31:21 +010038#if defined(MBEDTLS_TEST_NULL_ENTROPY)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010039int mbedtls_null_entropy_poll(void *data,
40 unsigned char *output, size_t len, size_t *olen);
Janos Follath53de7842016-06-08 15:29:18 +010041#endif
42
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020043#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
Paul Bakker6083fd22011-12-03 21:45:14 +000044/**
45 * \brief Platform-specific entropy poll callback
46 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010047int mbedtls_platform_entropy_poll(void *data,
48 unsigned char *output, size_t len, size_t *olen);
Paul Bakker6083fd22011-12-03 21:45:14 +000049#endif
50
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020051#if defined(MBEDTLS_HAVEGE_C)
Paul Bakker6083fd22011-12-03 21:45:14 +000052/**
53 * \brief HAVEGE based entropy poll callback
54 *
55 * Requires an HAVEGE state as its data pointer.
56 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010057int mbedtls_havege_poll(void *data,
58 unsigned char *output, size_t len, size_t *olen);
Paul Bakker6083fd22011-12-03 21:45:14 +000059#endif
60
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061#if defined(MBEDTLS_TIMING_C)
Paul Bakker6083fd22011-12-03 21:45:14 +000062/**
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063 * \brief mbedtls_timing_hardclock-based entropy poll callback
Paul Bakker6083fd22011-12-03 21:45:14 +000064 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010065int mbedtls_hardclock_poll(void *data,
66 unsigned char *output, size_t len, size_t *olen);
Paul Bakker6083fd22011-12-03 21:45:14 +000067#endif
68
Manuel Pégourié-Gonnard3f77dfb2015-06-19 10:06:21 +020069#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
70/**
71 * \brief Entropy poll callback for a hardware source
72 *
Gilles Peskinef08ca832023-09-12 19:21:54 +020073 * \warning This is not provided by Mbed TLS!
Manuel Pégourié-Gonnard3f77dfb2015-06-19 10:06:21 +020074 * See \c MBEDTLS_ENTROPY_HARDWARE_ALT in config.h.
75 *
76 * \note This must accept NULL as its first argument.
77 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010078int mbedtls_hardware_poll(void *data,
79 unsigned char *output, size_t len, size_t *olen);
Manuel Pégourié-Gonnard3f77dfb2015-06-19 10:06:21 +020080#endif
81
Paul Bakker9988d6b2016-06-01 11:29:42 +010082#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 Peskine1b6c09a2023-01-11 14:52:35 +010088int mbedtls_nv_seed_poll(void *data,
89 unsigned char *output, size_t len, size_t *olen);
Paul Bakker9988d6b2016-06-01 11:29:42 +010090#endif
91
Paul Bakker6083fd22011-12-03 21:45:14 +000092#ifdef __cplusplus
93}
94#endif
95
96#endif /* entropy_poll.h */