blob: cdaf8a89ae8121c94618fbba74e0687b50739e44 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file havege.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakkerf3b86c12011-01-27 15:24:17 +00004 * \brief HAVEGE: HArdware Volatile Entropy Gathering and Expansion
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 Bakker5121ce52009-01-03 21:22:43 +00009 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020010#ifndef MBEDTLS_HAVEGE_H
11#define MBEDTLS_HAVEGE_H
Paul Bakker5121ce52009-01-03 21:22:43 +000012
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050013#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010014#include "mbedtls/config.h"
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050015#else
16#include MBEDTLS_CONFIG_FILE
17#endif
18
Rich Evans00ab4702015-02-06 13:43:58 +000019#include <stddef.h>
Gilles Peskine78462992019-06-07 16:38:28 +020020#include <stdint.h>
Paul Bakkera3d195c2011-11-27 21:07:34 +000021
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020022#define MBEDTLS_HAVEGE_COLLECT_SIZE 1024
Paul Bakker5121ce52009-01-03 21:22:43 +000023
Paul Bakker407a0da2013-06-27 14:29:21 +020024#ifdef __cplusplus
25extern "C" {
26#endif
27
Paul Bakker5121ce52009-01-03 21:22:43 +000028/**
29 * \brief HAVEGE state structure
30 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010031typedef struct mbedtls_havege_state {
Gilles Peskine78462992019-06-07 16:38:28 +020032 uint32_t PT1, PT2, offset[2];
33 uint32_t pool[MBEDTLS_HAVEGE_COLLECT_SIZE];
34 uint32_t WALK[8192];
Paul Bakker5121ce52009-01-03 21:22:43 +000035}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020036mbedtls_havege_state;
Paul Bakker5121ce52009-01-03 21:22:43 +000037
Paul Bakker5121ce52009-01-03 21:22:43 +000038/**
39 * \brief HAVEGE initialization
40 *
41 * \param hs HAVEGE state to be initialized
42 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010043void mbedtls_havege_init(mbedtls_havege_state *hs);
Paul Bakker5121ce52009-01-03 21:22:43 +000044
45/**
Paul Bakkera317a982014-06-18 16:44:11 +020046 * \brief Clear HAVEGE state
47 *
48 * \param hs HAVEGE state to be cleared
49 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010050void mbedtls_havege_free(mbedtls_havege_state *hs);
Paul Bakkera317a982014-06-18 16:44:11 +020051
52/**
Paul Bakker5121ce52009-01-03 21:22:43 +000053 * \brief HAVEGE rand function
54 *
Paul Bakker13e2dfe2009-07-28 07:18:38 +000055 * \param p_rng A HAVEGE state
Paul Bakkera3d195c2011-11-27 21:07:34 +000056 * \param output Buffer to fill
57 * \param len Length of buffer
Paul Bakker5121ce52009-01-03 21:22:43 +000058 *
Paul Bakkere708e5c2012-02-03 08:13:57 +000059 * \return 0
Paul Bakker5121ce52009-01-03 21:22:43 +000060 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010061int mbedtls_havege_random(void *p_rng, unsigned char *output, size_t len);
Paul Bakker5121ce52009-01-03 21:22:43 +000062
63#ifdef __cplusplus
64}
65#endif
66
67#endif /* havege.h */