blob: 76538e9f96fc78825aa597ced56c7f749614eb42 [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é-Gonnarda658a402015-01-23 09:45:19 +00006 * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +00008 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakkerb96f1542010-07-18 20:36:00 +00009 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Paul Bakker5121ce52009-01-03 21:22:43 +000023 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020024#ifndef MBEDTLS_HAVEGE_H
25#define MBEDTLS_HAVEGE_H
Paul Bakker5121ce52009-01-03 21:22:43 +000026
Rich Evans00ab4702015-02-06 13:43:58 +000027#include <stddef.h>
Paul Bakkera3d195c2011-11-27 21:07:34 +000028
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020029#define MBEDTLS_HAVEGE_COLLECT_SIZE 1024
Paul Bakker5121ce52009-01-03 21:22:43 +000030
Paul Bakker407a0da2013-06-27 14:29:21 +020031#ifdef __cplusplus
32extern "C" {
33#endif
34
Paul Bakker5121ce52009-01-03 21:22:43 +000035/**
36 * \brief HAVEGE state structure
37 */
38typedef struct
39{
40 int PT1, PT2, offset[2];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020041 int pool[MBEDTLS_HAVEGE_COLLECT_SIZE];
Paul Bakker5121ce52009-01-03 21:22:43 +000042 int WALK[8192];
43}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020044mbedtls_havege_state;
Paul Bakker5121ce52009-01-03 21:22:43 +000045
Paul Bakker5121ce52009-01-03 21:22:43 +000046/**
47 * \brief HAVEGE initialization
48 *
49 * \param hs HAVEGE state to be initialized
50 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020051void mbedtls_havege_init( mbedtls_havege_state *hs );
Paul Bakker5121ce52009-01-03 21:22:43 +000052
53/**
Paul Bakkera317a982014-06-18 16:44:11 +020054 * \brief Clear HAVEGE state
55 *
56 * \param hs HAVEGE state to be cleared
57 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020058void mbedtls_havege_free( mbedtls_havege_state *hs );
Paul Bakkera317a982014-06-18 16:44:11 +020059
60/**
Paul Bakker5121ce52009-01-03 21:22:43 +000061 * \brief HAVEGE rand function
62 *
Paul Bakker13e2dfe2009-07-28 07:18:38 +000063 * \param p_rng A HAVEGE state
Paul Bakkera3d195c2011-11-27 21:07:34 +000064 * \param output Buffer to fill
65 * \param len Length of buffer
Paul Bakker5121ce52009-01-03 21:22:43 +000066 *
Paul Bakkere708e5c2012-02-03 08:13:57 +000067 * \return 0
Paul Bakker5121ce52009-01-03 21:22:43 +000068 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020069int mbedtls_havege_random( void *p_rng, unsigned char *output, size_t len );
Paul Bakker5121ce52009-01-03 21:22:43 +000070
71#ifdef __cplusplus
72}
73#endif
74
75#endif /* havege.h */