blob: 7d27039e8c70a9fd614442f52d7acf1393f4ee9a [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
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 Bakker5121ce52009-01-03 21:22:43 +000021 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020022#ifndef MBEDTLS_HAVEGE_H
23#define MBEDTLS_HAVEGE_H
Paul Bakker5121ce52009-01-03 21:22:43 +000024
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050025#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010026#include "mbedtls/config.h"
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050027#else
28#include MBEDTLS_CONFIG_FILE
29#endif
30
Rich Evans00ab4702015-02-06 13:43:58 +000031#include <stddef.h>
Gilles Peskine78462992019-06-07 16:38:28 +020032#include <stdint.h>
Paul Bakkera3d195c2011-11-27 21:07:34 +000033
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020034#define MBEDTLS_HAVEGE_COLLECT_SIZE 1024
Paul Bakker5121ce52009-01-03 21:22:43 +000035
Paul Bakker407a0da2013-06-27 14:29:21 +020036#ifdef __cplusplus
37extern "C" {
38#endif
39
Paul Bakker5121ce52009-01-03 21:22:43 +000040/**
41 * \brief HAVEGE state structure
42 */
Dawid Drozd428cc522018-07-24 10:02:47 +020043typedef struct mbedtls_havege_state
Paul Bakker5121ce52009-01-03 21:22:43 +000044{
Gilles Peskine78462992019-06-07 16:38:28 +020045 uint32_t PT1, PT2, offset[2];
46 uint32_t pool[MBEDTLS_HAVEGE_COLLECT_SIZE];
47 uint32_t WALK[8192];
Paul Bakker5121ce52009-01-03 21:22:43 +000048}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020049mbedtls_havege_state;
Paul Bakker5121ce52009-01-03 21:22:43 +000050
Paul Bakker5121ce52009-01-03 21:22:43 +000051/**
52 * \brief HAVEGE initialization
53 *
54 * \param hs HAVEGE state to be initialized
55 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056void mbedtls_havege_init( mbedtls_havege_state *hs );
Paul Bakker5121ce52009-01-03 21:22:43 +000057
58/**
Paul Bakkera317a982014-06-18 16:44:11 +020059 * \brief Clear HAVEGE state
60 *
61 * \param hs HAVEGE state to be cleared
62 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063void mbedtls_havege_free( mbedtls_havege_state *hs );
Paul Bakkera317a982014-06-18 16:44:11 +020064
65/**
Paul Bakker5121ce52009-01-03 21:22:43 +000066 * \brief HAVEGE rand function
67 *
Paul Bakker13e2dfe2009-07-28 07:18:38 +000068 * \param p_rng A HAVEGE state
Paul Bakkera3d195c2011-11-27 21:07:34 +000069 * \param output Buffer to fill
70 * \param len Length of buffer
Paul Bakker5121ce52009-01-03 21:22:43 +000071 *
Paul Bakkere708e5c2012-02-03 08:13:57 +000072 * \return 0
Paul Bakker5121ce52009-01-03 21:22:43 +000073 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020074int mbedtls_havege_random( void *p_rng, unsigned char *output, size_t len );
Paul Bakker5121ce52009-01-03 21:22:43 +000075
76#ifdef __cplusplus
77}
78#endif
79
80#endif /* havege.h */