blob: dac5d311381000eb4bf00019f1f790070a75e9c9 [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
Paul Bakker37ca75d2011-01-06 12:28:03 +00005 *
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02006 * Copyright (C) 2006-2015, 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 Bakkerb96f1542010-07-18 20:36:00 +000020 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000021 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker5121ce52009-01-03 21:22:43 +000022 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020023#ifndef MBEDTLS_HAVEGE_H
24#define MBEDTLS_HAVEGE_H
Paul Bakker5121ce52009-01-03 21:22:43 +000025
Rich Evans00ab4702015-02-06 13:43:58 +000026#include <stddef.h>
Paul Bakkera3d195c2011-11-27 21:07:34 +000027
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028#define MBEDTLS_HAVEGE_COLLECT_SIZE 1024
Paul Bakker5121ce52009-01-03 21:22:43 +000029
Paul Bakker407a0da2013-06-27 14:29:21 +020030#ifdef __cplusplus
31extern "C" {
32#endif
33
Paul Bakker5121ce52009-01-03 21:22:43 +000034/**
35 * \brief HAVEGE state structure
36 */
37typedef struct
38{
39 int PT1, PT2, offset[2];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020040 int pool[MBEDTLS_HAVEGE_COLLECT_SIZE];
Paul Bakker5121ce52009-01-03 21:22:43 +000041 int WALK[8192];
42}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020043mbedtls_havege_state;
Paul Bakker5121ce52009-01-03 21:22:43 +000044
Paul Bakker5121ce52009-01-03 21:22:43 +000045/**
46 * \brief HAVEGE initialization
47 *
48 * \param hs HAVEGE state to be initialized
49 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020050void mbedtls_havege_init( mbedtls_havege_state *hs );
Paul Bakker5121ce52009-01-03 21:22:43 +000051
52/**
Paul Bakkera317a982014-06-18 16:44:11 +020053 * \brief Clear HAVEGE state
54 *
55 * \param hs HAVEGE state to be cleared
56 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020057void mbedtls_havege_free( mbedtls_havege_state *hs );
Paul Bakkera317a982014-06-18 16:44:11 +020058
59/**
Paul Bakker5121ce52009-01-03 21:22:43 +000060 * \brief HAVEGE rand function
61 *
Paul Bakker13e2dfe2009-07-28 07:18:38 +000062 * \param p_rng A HAVEGE state
Paul Bakkera3d195c2011-11-27 21:07:34 +000063 * \param output Buffer to fill
64 * \param len Length of buffer
Paul Bakker5121ce52009-01-03 21:22:43 +000065 *
Paul Bakkere708e5c2012-02-03 08:13:57 +000066 * \return 0
Paul Bakker5121ce52009-01-03 21:22:43 +000067 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068int mbedtls_havege_random( void *p_rng, unsigned char *output, size_t len );
Paul Bakker5121ce52009-01-03 21:22:43 +000069
70#ifdef __cplusplus
71}
72#endif
73
74#endif /* havege.h */