54#if !defined(MBEDTLS_CONFIG_FILE)
57#include MBEDTLS_CONFIG_FILE
60#if defined(MBEDTLS_HAVEGE_C)
72#if INT_MIN + 1 != -0x7fffffff
73#error "The HAVEGE module requires int to be exactly 32 bits, with INT_MIN = -2^31."
75#if UINT_MAX != 0xffffffff
76#error "The HAVEGE module requires unsigned to be exactly 32 bits."
93#define SWAP(X,Y) { unsigned *T = (X); (X) = (Y); (Y) = T; }
95#define TST1_ENTER if( PTEST & 1 ) { PTEST ^= 3; PTEST >>= 1;
96#define TST2_ENTER if( PTEST & 1 ) { PTEST ^= 3; PTEST >>= 1;
98#define TST1_LEAVE U1++; }
99#define TST2_LEAVE U2++; }
101#define ONE_ITERATION \
105 TST1_ENTER TST1_ENTER TST1_ENTER TST1_ENTER \
106 TST1_ENTER TST1_ENTER TST1_ENTER TST1_ENTER \
107 TST1_ENTER TST1_ENTER TST1_ENTER TST1_ENTER \
109 TST1_LEAVE TST1_LEAVE TST1_LEAVE TST1_LEAVE \
110 TST1_LEAVE TST1_LEAVE TST1_LEAVE TST1_LEAVE \
111 TST1_LEAVE TST1_LEAVE TST1_LEAVE TST1_LEAVE \
113 PTX = (PT1 >> 18) & 7; \
116 CLK = (unsigned) mbedtls_timing_hardclock(); \
119 A = &WALK[PT1 ]; RES[i++] ^= *A; \
120 B = &WALK[PT2 ]; RES[i++] ^= *B; \
121 C = &WALK[PT1 ^ 1]; RES[i++] ^= *C; \
122 D = &WALK[PT2 ^ 4]; RES[i++] ^= *D; \
124 IN = (*A >> (1)) ^ (*A << (31)) ^ CLK; \
125 *A = (*B >> (2)) ^ (*B << (30)) ^ CLK; \
127 *C = (*C >> (3)) ^ (*C << (29)) ^ CLK; \
128 *D = (*D >> (4)) ^ (*D << (28)) ^ CLK; \
130 A = &WALK[PT1 ^ 2]; RES[i++] ^= *A; \
131 B = &WALK[PT2 ^ 2]; RES[i++] ^= *B; \
132 C = &WALK[PT1 ^ 3]; RES[i++] ^= *C; \
133 D = &WALK[PT2 ^ 6]; RES[i++] ^= *D; \
135 if( PTEST & 1 ) SWAP( A, C ); \
137 IN = (*A >> (5)) ^ (*A << (27)) ^ CLK; \
138 *A = (*B >> (6)) ^ (*B << (26)) ^ CLK; \
139 *B = IN; CLK = (unsigned) mbedtls_timing_hardclock(); \
140 *C = (*C >> (7)) ^ (*C << (25)) ^ CLK; \
141 *D = (*D >> (8)) ^ (*D << (24)) ^ CLK; \
143 A = &WALK[PT1 ^ 4]; \
144 B = &WALK[PT2 ^ 1]; \
148 PT2 = (RES[(i - 8) ^ PTY] ^ WALK[PT2 ^ PTY ^ 7]); \
149 PT2 = ((PT2 & 0x1FFF) & (~8)) ^ ((PT1 ^ 8) & 0x8); \
150 PTY = (PT2 >> 10) & 7; \
152 TST2_ENTER TST2_ENTER TST2_ENTER TST2_ENTER \
153 TST2_ENTER TST2_ENTER TST2_ENTER TST2_ENTER \
154 TST2_ENTER TST2_ENTER TST2_ENTER TST2_ENTER \
156 TST2_LEAVE TST2_LEAVE TST2_LEAVE TST2_LEAVE \
157 TST2_LEAVE TST2_LEAVE TST2_LEAVE TST2_LEAVE \
158 TST2_LEAVE TST2_LEAVE TST2_LEAVE TST2_LEAVE \
160 C = &WALK[PT1 ^ 5]; \
161 D = &WALK[PT2 ^ 5]; \
168 IN = (*A >> ( 9)) ^ (*A << (23)) ^ CLK; \
169 *A = (*B >> (10)) ^ (*B << (22)) ^ CLK; \
171 *C = (*C >> (11)) ^ (*C << (21)) ^ CLK; \
172 *D = (*D >> (12)) ^ (*D << (20)) ^ CLK; \
174 A = &WALK[PT1 ^ 6]; RES[i++] ^= *A; \
175 B = &WALK[PT2 ^ 3]; RES[i++] ^= *B; \
176 C = &WALK[PT1 ^ 7]; RES[i++] ^= *C; \
177 D = &WALK[PT2 ^ 7]; RES[i++] ^= *D; \
179 IN = (*A >> (13)) ^ (*A << (19)) ^ CLK; \
180 *A = (*B >> (14)) ^ (*B << (18)) ^ CLK; \
182 *C = (*C >> (15)) ^ (*C << (17)) ^ CLK; \
183 *D = (*D >> (16)) ^ (*D << (16)) ^ CLK; \
185 PT1 = ( RES[( i - 8 ) ^ PTX] ^ \
186 WALK[PT1 ^ PTX ^ 7] ) & (~1); \
187 PT1 ^= (PT2 ^ 0x10) & 0x10; \
189 for( n++, i = 0; i < 16; i++ ) \
190 POOL[n % MBEDTLS_HAVEGE_COLLECT_SIZE] ^= RES[i];
199 unsigned PT1, PT2, *WALK, *POOL, RES[16];
200 unsigned PTX, PTY, CLK,
PTEST,
IN;
202 WALK = (
unsigned *) hs->
WALK;
203 POOL = (
unsigned *) hs->
pool;
212 memset( RES, 0,
sizeof( RES ) );
255 unsigned char *
p =
buf;
260 if( use_len >
sizeof(
int) )
261 use_len =
sizeof(
int);
GLenum GLuint GLenum GLsizei const GLchar * buf
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
HAVEGE: HArdware Volatile Entropy Gathering and Expansion.
void mbedtls_havege_free(mbedtls_havege_state *hs)
Clear HAVEGE state.
void mbedtls_havege_init(mbedtls_havege_state *hs)
HAVEGE initialization.
int mbedtls_havege_random(void *p_rng, unsigned char *output, size_t len)
HAVEGE rand function.
#define MBEDTLS_HAVEGE_COLLECT_SIZE
#define memcpy(s1, s2, n)
Configuration options (set of defines)
int pool[MBEDTLS_HAVEGE_COLLECT_SIZE]
Portable interface to timeouts and to the CPU cycle counter.