blob: 4c1c86087a8c510373272beab7d3c4e58c94d102 [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/*
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02007 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
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 Bakkerb96f1542010-07-18 20:36:00 +000021 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000022 * This file is part of mbed TLS (https://tls.mbed.org)
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
Ron Eldor9cbd1b22018-12-16 12:14:37 +020027#if !defined(MBEDTLS_CONFIG_FILE)
28#include "config.h"
29#else
30#include MBEDTLS_CONFIG_FILE
31#endif
32
Rich Evans00ab4702015-02-06 13:43:58 +000033#include <stddef.h>
Paul Bakkera3d195c2011-11-27 21:07:34 +000034
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020035#define MBEDTLS_HAVEGE_COLLECT_SIZE 1024
Paul Bakker5121ce52009-01-03 21:22:43 +000036
Paul Bakker407a0da2013-06-27 14:29:21 +020037#ifdef __cplusplus
38extern "C" {
39#endif
40
Paul Bakker5121ce52009-01-03 21:22:43 +000041/**
42 * \brief HAVEGE state structure
43 */
Dawid Drozd428cc522018-07-24 10:02:47 +020044typedef struct mbedtls_havege_state
Paul Bakker5121ce52009-01-03 21:22:43 +000045{
46 int PT1, PT2, offset[2];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020047 int pool[MBEDTLS_HAVEGE_COLLECT_SIZE];
Paul Bakker5121ce52009-01-03 21:22:43 +000048 int WALK[8192];
49}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020050mbedtls_havege_state;
Paul Bakker5121ce52009-01-03 21:22:43 +000051
Paul Bakker5121ce52009-01-03 21:22:43 +000052/**
53 * \brief HAVEGE initialization
54 *
55 * \param hs HAVEGE state to be initialized
56 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020057void mbedtls_havege_init( mbedtls_havege_state *hs );
Paul Bakker5121ce52009-01-03 21:22:43 +000058
59/**
Paul Bakkera317a982014-06-18 16:44:11 +020060 * \brief Clear HAVEGE state
61 *
62 * \param hs HAVEGE state to be cleared
63 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064void mbedtls_havege_free( mbedtls_havege_state *hs );
Paul Bakkera317a982014-06-18 16:44:11 +020065
66/**
Paul Bakker5121ce52009-01-03 21:22:43 +000067 * \brief HAVEGE rand function
68 *
Paul Bakker13e2dfe2009-07-28 07:18:38 +000069 * \param p_rng A HAVEGE state
Paul Bakkera3d195c2011-11-27 21:07:34 +000070 * \param output Buffer to fill
71 * \param len Length of buffer
Paul Bakker5121ce52009-01-03 21:22:43 +000072 *
Paul Bakkere708e5c2012-02-03 08:13:57 +000073 * \return 0
Paul Bakker5121ce52009-01-03 21:22:43 +000074 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075int mbedtls_havege_random( void *p_rng, unsigned char *output, size_t len );
Paul Bakker5121ce52009-01-03 21:22:43 +000076
77#ifdef __cplusplus
78}
79#endif
80
81#endif /* havege.h */