• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * \file havege.h
3  *
4  * \brief HAVEGE: HArdware Volatile Entropy Gathering and Expansion
5  */
6 /*
7  *  Copyright The Mbed TLS Contributors
8  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9  */
10 #ifndef MBEDTLS_HAVEGE_H
11 #define MBEDTLS_HAVEGE_H
12 
13 #if !defined(MBEDTLS_CONFIG_FILE)
14 #include "mbedtls/config.h"
15 #else
16 #include MBEDTLS_CONFIG_FILE
17 #endif
18 
19 #include <stddef.h>
20 #include <stdint.h>
21 
22 #define MBEDTLS_HAVEGE_COLLECT_SIZE 1024
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /**
29  * \brief          HAVEGE state structure
30  */
31 typedef struct mbedtls_havege_state {
32     uint32_t PT1, PT2, offset[2];
33     uint32_t pool[MBEDTLS_HAVEGE_COLLECT_SIZE];
34     uint32_t WALK[8192];
35 }
36 mbedtls_havege_state;
37 
38 /**
39  * \brief          HAVEGE initialization
40  *
41  * \param hs       HAVEGE state to be initialized
42  */
43 void mbedtls_havege_init(mbedtls_havege_state *hs);
44 
45 /**
46  * \brief          Clear HAVEGE state
47  *
48  * \param hs       HAVEGE state to be cleared
49  */
50 void mbedtls_havege_free(mbedtls_havege_state *hs);
51 
52 /**
53  * \brief          HAVEGE rand function
54  *
55  * \param p_rng    A HAVEGE state
56  * \param output   Buffer to fill
57  * \param len      Length of buffer
58  *
59  * \return         0
60  */
61 int mbedtls_havege_random(void *p_rng, unsigned char *output, size_t len);
62 
63 #ifdef __cplusplus
64 }
65 #endif
66 
67 #endif /* havege.h */
68