Browse Source

[rng] Allow HMAC_DRBG to use multiple underlying hash algorithms

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
b9d9c3f1d5
4 changed files with 442 additions and 267 deletions
  1. 73
    59
      src/crypto/hmac_drbg.c
  2. 23
    7
      src/include/ipxe/drbg.h
  3. 130
    30
      src/include/ipxe/hmac_drbg.h
  4. 216
    171
      src/tests/hmac_drbg_test.c

+ 73
- 59
src/crypto/hmac_drbg.c View File

46
 /**
46
 /**
47
  * Update the HMAC_DRBG key
47
  * Update the HMAC_DRBG key
48
  *
48
  *
49
+ * @v hash		Underlying hash algorithm
49
  * @v state		HMAC_DRBG internal state
50
  * @v state		HMAC_DRBG internal state
50
  * @v data		Provided data
51
  * @v data		Provided data
51
  * @v len		Length of provided data
52
  * @v len		Length of provided data
57
  *
58
  *
58
  * as used by hmac_drbg_update()
59
  * as used by hmac_drbg_update()
59
  */
60
  */
60
-static void hmac_drbg_update_key ( struct hmac_drbg_state *state,
61
+static void hmac_drbg_update_key ( struct digest_algorithm *hash,
62
+				   struct hmac_drbg_state *state,
61
 				   const void *data, size_t len,
63
 				   const void *data, size_t len,
62
 				   const uint8_t single ) {
64
 				   const uint8_t single ) {
63
-	uint8_t context[HMAC_DRBG_CTX_SIZE];
64
-	size_t key_len = sizeof ( state->key );
65
+	uint8_t context[ hash->ctxsize ];
66
+	size_t out_len = hash->digestsize;
65
 
67
 
66
-	DBGC ( state, "HMAC_DRBG %p provided data :\n", state );
68
+	DBGC ( state, "HMAC_DRBG_%s %p provided data :\n", hash->name, state );
67
 	DBGC_HDA ( state, 0, data, len );
69
 	DBGC_HDA ( state, 0, data, len );
68
 
70
 
69
 	/* Sanity checks */
71
 	/* Sanity checks */
72
+	assert ( hash != NULL );
70
 	assert ( state != NULL );
73
 	assert ( state != NULL );
71
 	assert ( ( data != NULL ) || ( len == 0 ) );
74
 	assert ( ( data != NULL ) || ( len == 0 ) );
72
 	assert ( ( single == 0x00 ) || ( single == 0x01 ) );
75
 	assert ( ( single == 0x00 ) || ( single == 0x01 ) );
73
 
76
 
74
 	/* K = HMAC ( K, V || single || provided_data ) */
77
 	/* K = HMAC ( K, V || single || provided_data ) */
75
-	hmac_init ( &hmac_drbg_algorithm, context, state->key, &key_len );
76
-	assert ( key_len == sizeof ( state->key ) );
77
-	hmac_update ( &hmac_drbg_algorithm, context,
78
-		      state->value, sizeof ( state->value ) );
79
-	hmac_update ( &hmac_drbg_algorithm, context,
80
-		      &single, sizeof ( single ) );
81
-	hmac_update ( &hmac_drbg_algorithm, context, data, len );
82
-	hmac_final ( &hmac_drbg_algorithm, context, state->key, &key_len,
83
-		     state->key );
84
-	assert ( key_len == sizeof ( state->key ) );
85
-
86
-	DBGC ( state, "HMAC_DRBG %p K = HMAC ( K, V || %#02x || "
87
-	       "provided_data ) :\n", state, single );
88
-	DBGC_HDA ( state, 0, state->key, sizeof ( state->key ) );
78
+	hmac_init ( hash, context, state->key, &out_len );
79
+	assert ( out_len == hash->digestsize );
80
+	hmac_update ( hash, context, state->value, out_len );
81
+	hmac_update ( hash, context, &single, sizeof ( single ) );
82
+	hmac_update ( hash, context, data, len );
83
+	hmac_final ( hash, context, state->key, &out_len, state->key );
84
+	assert ( out_len == hash->digestsize );
85
+
86
+	DBGC ( state, "HMAC_DRBG_%s %p K = HMAC ( K, V || %#02x || "
87
+	       "provided_data ) :\n", hash->name, state, single );
88
+	DBGC_HDA ( state, 0, state->key, out_len );
89
 }
89
 }
90
 
90
 
91
 /**
91
 /**
92
  * Update the HMAC_DRBG value
92
  * Update the HMAC_DRBG value
93
  *
93
  *
94
+ * @v hash		Underlying hash algorithm
94
  * @v state		HMAC_DRBG internal state
95
  * @v state		HMAC_DRBG internal state
95
  * @v data		Provided data
96
  * @v data		Provided data
96
  * @v len		Length of provided data
97
  * @v len		Length of provided data
102
  *
103
  *
103
  * as used by hmac_drbg_update() and hmac_drbg_generate()
104
  * as used by hmac_drbg_update() and hmac_drbg_generate()
104
  */
105
  */
105
-static void hmac_drbg_update_value ( struct hmac_drbg_state *state ) {
106
-	uint8_t context[HMAC_DRBG_CTX_SIZE];
107
-	size_t key_len = sizeof ( state->key );
106
+static void hmac_drbg_update_value ( struct digest_algorithm *hash,
107
+				     struct hmac_drbg_state *state ) {
108
+	uint8_t context[ hash->ctxsize ];
109
+	size_t out_len = hash->digestsize;
108
 
110
 
109
 	/* Sanity checks */
111
 	/* Sanity checks */
112
+	assert ( hash != NULL );
110
 	assert ( state != NULL );
113
 	assert ( state != NULL );
111
 
114
 
112
 	/* V = HMAC ( K, V ) */
115
 	/* V = HMAC ( K, V ) */
113
-	hmac_init ( &hmac_drbg_algorithm, context, state->key, &key_len );
114
-	assert ( key_len == sizeof ( state->key ) );
115
-	hmac_update ( &hmac_drbg_algorithm, context,
116
-		      state->value, sizeof ( state->value ) );
117
-	hmac_final ( &hmac_drbg_algorithm, context, state->key, &key_len,
118
-		     state->value );
119
-	assert ( key_len == sizeof ( state->key ) );
120
-
121
-	DBGC ( state, "HMAC_DRBG %p V = HMAC ( K, V ) :\n", state );
122
-	DBGC_HDA ( state, 0, state->value, sizeof ( state->value ) );
116
+	hmac_init ( hash, context, state->key, &out_len );
117
+	assert ( out_len == hash->digestsize );
118
+	hmac_update ( hash, context, state->value, out_len );
119
+	hmac_final ( hash, context, state->key, &out_len, state->value );
120
+	assert ( out_len == hash->digestsize );
121
+
122
+	DBGC ( state, "HMAC_DRBG_%s %p V = HMAC ( K, V ) :\n",
123
+	       hash->name, state );
124
+	DBGC_HDA ( state, 0, state->value, out_len );
123
 }
125
 }
124
 
126
 
125
 /**
127
 /**
126
  * Update HMAC_DRBG internal state
128
  * Update HMAC_DRBG internal state
127
  *
129
  *
130
+ * @v hash		Underlying hash algorithm
128
  * @v state		HMAC_DRBG internal state
131
  * @v state		HMAC_DRBG internal state
129
  * @v data		Provided data
132
  * @v data		Provided data
130
  * @v len		Length of provided data
133
  * @v len		Length of provided data
135
  * The key and value are updated in-place within the HMAC_DRBG
138
  * The key and value are updated in-place within the HMAC_DRBG
136
  * internal state.
139
  * internal state.
137
  */
140
  */
138
-static void hmac_drbg_update ( struct hmac_drbg_state *state,
141
+static void hmac_drbg_update ( struct digest_algorithm *hash,
142
+			       struct hmac_drbg_state *state,
139
 			       const void *data, size_t len ) {
143
 			       const void *data, size_t len ) {
140
 
144
 
141
-	DBGC ( state, "HMAC_DRBG %p update\n", state );
145
+	DBGC ( state, "HMAC_DRBG_%s %p update\n", hash->name, state );
142
 
146
 
143
 	/* Sanity checks */
147
 	/* Sanity checks */
148
+	assert ( hash != NULL );
144
 	assert ( state != NULL );
149
 	assert ( state != NULL );
145
 	assert ( ( data != NULL ) || ( len == 0 ) );
150
 	assert ( ( data != NULL ) || ( len == 0 ) );
146
 
151
 
147
 	/* 1.  K = HMAC ( K, V || 0x00 || provided_data ) */
152
 	/* 1.  K = HMAC ( K, V || 0x00 || provided_data ) */
148
-	hmac_drbg_update_key ( state, data, len, 0x00 );
153
+	hmac_drbg_update_key ( hash, state, data, len, 0x00 );
149
 
154
 
150
 	/* 2.  V = HMAC ( K, V ) */
155
 	/* 2.  V = HMAC ( K, V ) */
151
-	hmac_drbg_update_value ( state );
156
+	hmac_drbg_update_value ( hash, state );
152
 
157
 
153
 	/* 3.  If ( provided_data = Null ), then return K and V */
158
 	/* 3.  If ( provided_data = Null ), then return K and V */
154
 	if ( ! len )
159
 	if ( ! len )
155
 		return;
160
 		return;
156
 
161
 
157
 	/* 4.  K = HMAC ( K, V || 0x01 || provided_data ) */
162
 	/* 4.  K = HMAC ( K, V || 0x01 || provided_data ) */
158
-	hmac_drbg_update_key ( state, data, len, 0x01 );
163
+	hmac_drbg_update_key ( hash, state, data, len, 0x01 );
159
 
164
 
160
 	/* 5.  V = HMAC ( K, V ) */
165
 	/* 5.  V = HMAC ( K, V ) */
161
-	hmac_drbg_update_value ( state );
166
+	hmac_drbg_update_value ( hash, state );
162
 
167
 
163
 	/* 6.  Return K and V */
168
 	/* 6.  Return K and V */
164
 }
169
 }
166
 /**
171
 /**
167
  * Instantiate HMAC_DRBG
172
  * Instantiate HMAC_DRBG
168
  *
173
  *
174
+ * @v hash		Underlying hash algorithm
169
  * @v state		HMAC_DRBG internal state to be initialised
175
  * @v state		HMAC_DRBG internal state to be initialised
170
  * @v entropy		Entropy input
176
  * @v entropy		Entropy input
171
  * @v entropy_len	Length of entropy input
177
  * @v entropy_len	Length of entropy input
184
  * The key, value and reseed counter are updated in-place within the
190
  * The key, value and reseed counter are updated in-place within the
185
  * HMAC_DRBG internal state.
191
  * HMAC_DRBG internal state.
186
  */
192
  */
187
-void hmac_drbg_instantiate ( struct hmac_drbg_state *state,
193
+void hmac_drbg_instantiate ( struct digest_algorithm *hash,
194
+			     struct hmac_drbg_state *state,
188
 			     const void *entropy, size_t entropy_len,
195
 			     const void *entropy, size_t entropy_len,
189
 			     const void *personal, size_t personal_len ){
196
 			     const void *personal, size_t personal_len ){
197
+	size_t out_len = hash->digestsize;
190
 
198
 
191
-	DBGC ( state, "HMAC_DRBG %p instantiate\n", state );
199
+	DBGC ( state, "HMAC_DRBG_%s %p instantiate\n", hash->name, state );
192
 
200
 
193
 	/* Sanity checks */
201
 	/* Sanity checks */
202
+	assert ( hash != NULL );
194
 	assert ( state != NULL );
203
 	assert ( state != NULL );
195
 	assert ( entropy != NULL );
204
 	assert ( entropy != NULL );
196
-	assert ( ( 8 * entropy_len ) >=
197
-		 ( 3 * HMAC_DRBG_SECURITY_STRENGTH / 2 ) );
198
 	assert ( ( personal != NULL ) || ( personal_len == 0 ) );
205
 	assert ( ( personal != NULL ) || ( personal_len == 0 ) );
199
 
206
 
200
 	/* 1.  seed_material = entropy_input || nonce ||
207
 	/* 1.  seed_material = entropy_input || nonce ||
202
 	 */
209
 	 */
203
 
210
 
204
 	/* 2.  Key = 0x00 00..00 */
211
 	/* 2.  Key = 0x00 00..00 */
205
-	memset ( state->key, 0x00, sizeof ( state->key ) );
212
+	memset ( state->key, 0x00, out_len );
206
 
213
 
207
 	/* 3.  V = 0x01 01...01 */
214
 	/* 3.  V = 0x01 01...01 */
208
-	memset ( state->value, 0x01, sizeof ( state->value ) );
215
+	memset ( state->value, 0x01, out_len );
209
 
216
 
210
 	/* 4.  ( Key, V ) = HMAC_DBRG_Update ( seed_material, Key, V )
217
 	/* 4.  ( Key, V ) = HMAC_DBRG_Update ( seed_material, Key, V )
211
 	 * 5.  reseed_counter = 1
218
 	 * 5.  reseed_counter = 1
212
 	 * 6.  Return V, Key and reseed_counter as the
219
 	 * 6.  Return V, Key and reseed_counter as the
213
 	 *     initial_working_state
220
 	 *     initial_working_state
214
 	 */
221
 	 */
215
-	hmac_drbg_reseed ( state, entropy, entropy_len,
222
+	hmac_drbg_reseed ( hash, state, entropy, entropy_len,
216
 			   personal, personal_len );
223
 			   personal, personal_len );
217
 }
224
 }
218
 
225
 
219
 /**
226
 /**
220
  * Reseed HMAC_DRBG
227
  * Reseed HMAC_DRBG
221
  *
228
  *
229
+ * @v hash		Underlying hash algorithm
222
  * @v state		HMAC_DRBG internal state
230
  * @v state		HMAC_DRBG internal state
223
  * @v entropy		Entropy input
231
  * @v entropy		Entropy input
224
  * @v entropy_len	Length of entropy input
232
  * @v entropy_len	Length of entropy input
231
  * The key, value and reseed counter are updated in-place within the
239
  * The key, value and reseed counter are updated in-place within the
232
  * HMAC_DRBG internal state.
240
  * HMAC_DRBG internal state.
233
  */
241
  */
234
-void hmac_drbg_reseed ( struct hmac_drbg_state *state,
242
+void hmac_drbg_reseed ( struct digest_algorithm *hash,
243
+			struct hmac_drbg_state *state,
235
 			const void *entropy, size_t entropy_len,
244
 			const void *entropy, size_t entropy_len,
236
 			const void *additional, size_t additional_len ) {
245
 			const void *additional, size_t additional_len ) {
237
 	uint8_t seed_material[ entropy_len + additional_len ];
246
 	uint8_t seed_material[ entropy_len + additional_len ];
238
 
247
 
239
-	DBGC ( state, "HMAC_DRBG %p (re)seed\n", state );
248
+	DBGC ( state, "HMAC_DRBG_%s %p (re)seed\n", hash->name, state );
240
 
249
 
241
 	/* Sanity checks */
250
 	/* Sanity checks */
251
+	assert ( hash != NULL );
242
 	assert ( state != NULL );
252
 	assert ( state != NULL );
243
 	assert ( entropy != NULL );
253
 	assert ( entropy != NULL );
244
-	assert ( ( 8 * entropy_len ) >= HMAC_DRBG_SECURITY_STRENGTH );
245
 	assert ( ( additional != NULL ) || ( additional_len == 0 ) );
254
 	assert ( ( additional != NULL ) || ( additional_len == 0 ) );
246
 
255
 
247
 	/* 1.  seed_material = entropy_input || additional_input */
256
 	/* 1.  seed_material = entropy_input || additional_input */
248
 	memcpy ( seed_material, entropy, entropy_len );
257
 	memcpy ( seed_material, entropy, entropy_len );
249
 	memcpy ( ( seed_material + entropy_len ), additional, additional_len );
258
 	memcpy ( ( seed_material + entropy_len ), additional, additional_len );
250
-	DBGC ( state, "HMAC_DRBG %p seed material :\n", state );
259
+	DBGC ( state, "HMAC_DRBG_%s %p seed material :\n", hash->name, state );
251
 	DBGC_HDA ( state, 0, seed_material, sizeof ( seed_material ) );
260
 	DBGC_HDA ( state, 0, seed_material, sizeof ( seed_material ) );
252
 
261
 
253
 	/* 2.  ( Key, V ) = HMAC_DBRG_Update ( seed_material, Key, V ) */
262
 	/* 2.  ( Key, V ) = HMAC_DBRG_Update ( seed_material, Key, V ) */
254
-	hmac_drbg_update ( state, seed_material, sizeof ( seed_material ) );
263
+	hmac_drbg_update ( hash, state, seed_material,
264
+			   sizeof ( seed_material ) );
255
 
265
 
256
 	/* 3.  reseed_counter = 1 */
266
 	/* 3.  reseed_counter = 1 */
257
 	state->reseed_counter = 1;
267
 	state->reseed_counter = 1;
262
 /**
272
 /**
263
  * Generate pseudorandom bits using HMAC_DRBG
273
  * Generate pseudorandom bits using HMAC_DRBG
264
  *
274
  *
275
+ * @v hash		Underlying hash algorithm
265
  * @v state		HMAC_DRBG internal state
276
  * @v state		HMAC_DRBG internal state
266
  * @v additional	Additional input
277
  * @v additional	Additional input
267
  * @v additional_len	Length of additional input
278
  * @v additional_len	Length of additional input
279
  *
290
  *
280
  * Note that the only permitted error is "reseed required".
291
  * Note that the only permitted error is "reseed required".
281
  */
292
  */
282
-int hmac_drbg_generate ( struct hmac_drbg_state *state,
293
+int hmac_drbg_generate ( struct digest_algorithm *hash,
294
+			 struct hmac_drbg_state *state,
283
 			 const void *additional, size_t additional_len,
295
 			 const void *additional, size_t additional_len,
284
 			 void *data, size_t len ) {
296
 			 void *data, size_t len ) {
297
+	size_t out_len = hash->digestsize;
285
 	void *orig_data = data;
298
 	void *orig_data = data;
286
 	size_t orig_len = len;
299
 	size_t orig_len = len;
287
 	size_t frag_len;
300
 	size_t frag_len;
288
 
301
 
289
-	DBGC ( state, "HMAC_DRBG %p generate\n", state );
302
+	DBGC ( state, "HMAC_DRBG_%s %p generate\n", hash->name, state );
290
 
303
 
291
 	/* Sanity checks */
304
 	/* Sanity checks */
305
+	assert ( hash != NULL );
292
 	assert ( state != NULL );
306
 	assert ( state != NULL );
293
 	assert ( data != NULL );
307
 	assert ( data != NULL );
294
 	assert ( ( additional != NULL ) || ( additional_len == 0 ) );
308
 	assert ( ( additional != NULL ) || ( additional_len == 0 ) );
297
 	 *     indication that a reseed is required
311
 	 *     indication that a reseed is required
298
 	 */
312
 	 */
299
 	if ( state->reseed_counter > HMAC_DRBG_RESEED_INTERVAL ) {
313
 	if ( state->reseed_counter > HMAC_DRBG_RESEED_INTERVAL ) {
300
-		DBGC ( state, "HMAC_DRBG %p reseed interval exceeded\n",
301
-		       state );
314
+		DBGC ( state, "HMAC_DRBG_%s %p reseed interval exceeded\n",
315
+		       hash->name, state );
302
 		return -ESTALE;
316
 		return -ESTALE;
303
 	}
317
 	}
304
 
318
 
306
 	 *     ( Key, V ) = HMAC_DRBG_Update ( additional_input, Key, V )
320
 	 *     ( Key, V ) = HMAC_DRBG_Update ( additional_input, Key, V )
307
 	 */
321
 	 */
308
 	if ( additional_len )
322
 	if ( additional_len )
309
-		hmac_drbg_update ( state, additional, additional_len );
323
+		hmac_drbg_update ( hash, state, additional, additional_len );
310
 
324
 
311
 	/* 3.  temp = Null
325
 	/* 3.  temp = Null
312
 	 * 4.  While ( len ( temp ) < requested_number_of_bits ) do:
326
 	 * 4.  While ( len ( temp ) < requested_number_of_bits ) do:
314
 	while ( len ) {
328
 	while ( len ) {
315
 
329
 
316
 		/* 4.1  V = HMAC ( Key, V ) */
330
 		/* 4.1  V = HMAC ( Key, V ) */
317
-		hmac_drbg_update_value ( state );
331
+		hmac_drbg_update_value ( hash, state );
318
 
332
 
319
 		/* 4.2.  temp = temp || V
333
 		/* 4.2.  temp = temp || V
320
 		 * 5.    returned_bits = Leftmost requested_number_of_bits
334
 		 * 5.    returned_bits = Leftmost requested_number_of_bits
321
 		 *       of temp
335
 		 *       of temp
322
 		 */
336
 		 */
323
 		frag_len = len;
337
 		frag_len = len;
324
-		if ( frag_len > sizeof ( state->value ) )
325
-			frag_len = sizeof ( state->value );
338
+		if ( frag_len > out_len )
339
+			frag_len = out_len;
326
 		memcpy ( data, state->value, frag_len );
340
 		memcpy ( data, state->value, frag_len );
327
 		data += frag_len;
341
 		data += frag_len;
328
 		len -= frag_len;
342
 		len -= frag_len;
329
 	}
343
 	}
330
 
344
 
331
 	/* 6.  ( Key, V ) = HMAC_DRBG_Update ( additional_input, Key, V ) */
345
 	/* 6.  ( Key, V ) = HMAC_DRBG_Update ( additional_input, Key, V ) */
332
-	hmac_drbg_update ( state, additional, additional_len );
346
+	hmac_drbg_update ( hash, state, additional, additional_len );
333
 
347
 
334
 	/* 7.  reseed_counter = reseed_counter + 1 */
348
 	/* 7.  reseed_counter = reseed_counter + 1 */
335
 	state->reseed_counter++;
349
 	state->reseed_counter++;
336
 
350
 
337
-	DBGC ( state, "HMAC_DRBG %p generated :\n", state );
351
+	DBGC ( state, "HMAC_DRBG_%s %p generated :\n", hash->name, state );
338
 	DBGC_HDA ( state, 0, orig_data, orig_len );
352
 	DBGC_HDA ( state, 0, orig_data, orig_len );
339
 
353
 
340
 	/* 8.  Return SUCCESS, returned_bits, and the new values of
354
 	/* 8.  Return SUCCESS, returned_bits, and the new values of

+ 23
- 7
src/include/ipxe/drbg.h View File

10
 FILE_LICENCE ( GPL2_OR_LATER );
10
 FILE_LICENCE ( GPL2_OR_LATER );
11
 
11
 
12
 #include <stdint.h>
12
 #include <stdint.h>
13
+#include <ipxe/sha1.h>
13
 #include <ipxe/hmac_drbg.h>
14
 #include <ipxe/hmac_drbg.h>
14
 
15
 
16
+/** Choose HMAC_DRBG using SHA-1
17
+ *
18
+ * HMAC_DRBG using SHA-1 is an Approved algorithm in ANS X9.82.
19
+ */
20
+#define HMAC_DRBG_ALGORITHM HMAC_DRBG_SHA1
21
+
15
 /** Maximum security strength */
22
 /** Maximum security strength */
16
-#define DRBG_MAX_SECURITY_STRENGTH HMAC_DRBG_MAX_SECURITY_STRENGTH
23
+#define DRBG_MAX_SECURITY_STRENGTH \
24
+	HMAC_DRBG_MAX_SECURITY_STRENGTH ( HMAC_DRBG_ALGORITHM )
17
 
25
 
18
-/** Security strength */
19
-#define DRBG_SECURITY_STRENGTH HMAC_DRBG_SECURITY_STRENGTH
26
+/** Security strength
27
+ *
28
+ * We choose to operate at the maximum security strength supported by
29
+ * the algorithm.
30
+ */
31
+#define DRBG_SECURITY_STRENGTH DRBG_MAX_SECURITY_STRENGTH
20
 
32
 
21
 /** Minimum entropy input length */
33
 /** Minimum entropy input length */
22
-#define DRBG_MIN_ENTROPY_LEN_BYTES HMAC_DRBG_MIN_ENTROPY_LEN_BYTES
34
+#define DRBG_MIN_ENTROPY_LEN_BYTES \
35
+	HMAC_DRBG_MIN_ENTROPY_LEN_BYTES ( DRBG_SECURITY_STRENGTH )
23
 
36
 
24
 /** Maximum entropy input length */
37
 /** Maximum entropy input length */
25
 #define DRBG_MAX_ENTROPY_LEN_BYTES HMAC_DRBG_MAX_ENTROPY_LEN_BYTES
38
 #define DRBG_MAX_ENTROPY_LEN_BYTES HMAC_DRBG_MAX_ENTROPY_LEN_BYTES
60
 						size_t entropy_len,
73
 						size_t entropy_len,
61
 						const void *personal,
74
 						const void *personal,
62
 						size_t personal_len ) {
75
 						size_t personal_len ) {
63
-	hmac_drbg_instantiate ( &state->internal, entropy, entropy_len,
76
+	hmac_drbg_instantiate ( HMAC_DRBG_HASH ( HMAC_DRBG_ALGORITHM ),
77
+				&state->internal, entropy, entropy_len,
64
 				personal, personal_len );
78
 				personal, personal_len );
65
 }
79
 }
66
 
80
 
81
 					   size_t entropy_len,
95
 					   size_t entropy_len,
82
 					   const void *additional,
96
 					   const void *additional,
83
 					   size_t additional_len ) {
97
 					   size_t additional_len ) {
84
-	hmac_drbg_reseed ( &state->internal, entropy, entropy_len,
98
+	hmac_drbg_reseed ( HMAC_DRBG_HASH ( HMAC_DRBG_ALGORITHM ),
99
+			   &state->internal, entropy, entropy_len,
85
 			   additional, additional_len );
100
 			   additional, additional_len );
86
 }
101
 }
87
 
102
 
104
 					    const void *additional,
119
 					    const void *additional,
105
 					    size_t additional_len,
120
 					    size_t additional_len,
106
 					    void *data, size_t len ) {
121
 					    void *data, size_t len ) {
107
-	return hmac_drbg_generate ( &state->internal, additional,
122
+	return hmac_drbg_generate ( HMAC_DRBG_HASH ( HMAC_DRBG_ALGORITHM ),
123
+				    &state->internal, additional,
108
 				    additional_len, data, len );
124
 				    additional_len, data, len );
109
 }
125
 }
110
 
126
 

+ 130
- 30
src/include/ipxe/hmac_drbg.h View File

10
 FILE_LICENCE ( GPL2_OR_LATER );
10
 FILE_LICENCE ( GPL2_OR_LATER );
11
 
11
 
12
 #include <stdint.h>
12
 #include <stdint.h>
13
-#include <ipxe/sha1.h>
13
+#include <ipxe/crypto.h>
14
 
14
 
15
-/** Use SHA-1 as the underlying hash algorithm
15
+/** Declare an HMAC_DRBG algorithm
16
  *
16
  *
17
- * HMAC_DRBG using SHA-1 is an Approved algorithm in ANS X9.82.
17
+ * @v hash			Underlying hash algorithm
18
+ * @v max_security_strength	Maxmimum security strength
19
+ * @v out_len_bits		Output block length, in bits
20
+ * @ret hmac_drbg		HMAC_DRBG algorithm
18
  */
21
  */
19
-#define hmac_drbg_algorithm sha1_algorithm
22
+#define HMAC_DRBG( hash, max_security_strength, out_len_bits ) \
23
+	( hash, max_security_strength, out_len_bits )
20
 
24
 
21
-/** Maximum security strength
25
+/** HMAC_DRBG using SHA-1
22
  *
26
  *
23
  * The maximum security strength of HMAC_DRBG using SHA-1 is 128 bits
27
  * The maximum security strength of HMAC_DRBG using SHA-1 is 128 bits
24
- * (according to the list of maximum security strengths documented in
25
- * NIST SP 800-57 Part 1 Section 5.6.1 Table 3).
28
+ * according to the list of maximum security strengths documented in
29
+ * NIST SP 800-57 Part 1 Section 5.6.1 Table 3.
30
+ *
31
+ * The output block length of HMAC_DRBG using SHA-1 is 160 bits
32
+ * according to ANS X9.82 Part 3-2007 Section 10.2.1 Table 2 (NIST SP
33
+ * 800-90 Section 10.1 Table 2).
26
  */
34
  */
27
-#define HMAC_DRBG_MAX_SECURITY_STRENGTH 128
35
+#define HMAC_DRBG_SHA1 HMAC_DRBG ( &sha1_algorithm, 128, 160 )
28
 
36
 
29
-/** Security strength
37
+/** HMAC_DRBG using SHA-224
38
+ *
39
+ * The maximum security strength of HMAC_DRBG using SHA-224 is 192
40
+ * bits according to the list of maximum security strengths documented
41
+ * in NIST SP 800-57 Part 1 Section 5.6.1 Table 3.
30
  *
42
  *
31
- * For the sake of implementation simplicity, only a single security
32
- * strength is supported, which is the maximum security strength
33
- * supported by the algorithm.
43
+ * The output block length of HMAC_DRBG using SHA-224 is 224 bits
44
+ * according to ANS X9.82 Part 3-2007 Section 10.2.1 Table 2 (NIST SP
45
+ * 800-90 Section 10.1 Table 2).
34
  */
46
  */
35
-#define HMAC_DRBG_SECURITY_STRENGTH HMAC_DRBG_MAX_SECURITY_STRENGTH
47
+#define HMAC_DRBG_SHA224 HMAC_DRBG ( &sha224_algorithm, 192, 224 )
36
 
48
 
37
-/** Underlying hash algorithm output length (in bytes) */
38
-#define HMAC_DRBG_OUTLEN_BYTES SHA1_DIGEST_SIZE
49
+/** HMAC_DRBG using SHA-256
50
+ *
51
+ * The maximum security strength of HMAC_DRBG using SHA-256 is 256
52
+ * bits according to the list of maximum security strengths documented
53
+ * in NIST SP 800-57 Part 1 Section 5.6.1 Table 3.
54
+ *
55
+ * The output block length of HMAC_DRBG using SHA-256 is 256 bits
56
+ * according to ANS X9.82 Part 3-2007 Section 10.2.1 Table 2 (NIST SP
57
+ * 800-90 Section 10.1 Table 2).
58
+ */
59
+#define HMAC_DRBG_SHA256 HMAC_DRBG ( &sha256_algorithm, 256, 256 )
60
+
61
+/** HMAC_DRBG using SHA-384
62
+ *
63
+ * The maximum security strength of HMAC_DRBG using SHA-384 is 256
64
+ * bits according to the list of maximum security strengths documented
65
+ * in NIST SP 800-57 Part 1 Section 5.6.1 Table 3.
66
+ *
67
+ * The output block length of HMAC_DRBG using SHA-384 is 384 bits
68
+ * according to ANS X9.82 Part 3-2007 Section 10.2.1 Table 2 (NIST SP
69
+ * 800-90 Section 10.1 Table 2).
70
+ */
71
+#define HMAC_DRBG_SHA384 HMAC_DRBG ( &sha384_algorithm, 256, 384 )
72
+
73
+/** HMAC_DRBG using SHA-512
74
+ *
75
+ * The maximum security strength of HMAC_DRBG using SHA-512 is 256
76
+ * bits according to the list of maximum security strengths documented
77
+ * in NIST SP 800-57 Part 1 Section 5.6.1 Table 3.
78
+ *
79
+ * The output block length of HMAC_DRBG using SHA-512 is 512 bits
80
+ * according to ANS X9.82 Part 3-2007 Section 10.2.1 Table 2 (NIST SP
81
+ * 800-90 Section 10.1 Table 2).
82
+ */
83
+#define HMAC_DRBG_SHA512 HMAC_DRBG ( &sha512_algorithm, 256, 512 )
84
+
85
+/** Underlying hash algorithm
86
+ *
87
+ * @v hmac_drbg			HMAC_DRBG algorithm
88
+ * @ret hash			Underlying hash algorithm
89
+ */
90
+#define HMAC_DRBG_HASH( hmac_drbg ) \
91
+	HMAC_DRBG_EXTRACT_HASH hmac_drbg
92
+#define HMAC_DRBG_EXTRACT_HASH( hash, max_security_strength, out_len_bits ) \
93
+	hash
94
+
95
+/** Maximum security strength
96
+ *
97
+ * @v hmac_drbg			HMAC_DRBG algorithm
98
+ * @ret max_security_strength	Maxmimum security strength
99
+ */
100
+#define HMAC_DRBG_MAX_SECURITY_STRENGTH( hmac_drbg ) \
101
+	HMAC_DRBG_EXTRACT_MAX_SECURITY_STRENGTH hmac_drbg
102
+#define HMAC_DRBG_EXTRACT_MAX_SECURITY_STRENGTH( hash, max_security_strength, \
103
+						 out_len_bits ) \
104
+	max_security_strength
105
+
106
+/** Output block length, in bits
107
+ *
108
+ * @v hmac_drbg			HMAC_DRBG algorithm
109
+ * @ret out_len_bits		Output block length, in bits
110
+ */
111
+#define HMAC_DRBG_OUTLEN_BITS( hmac_drbg ) \
112
+	HMAC_DRBG_EXTRACT_OUTLEN_BITS hmac_drbg
113
+#define HMAC_DRBG_EXTRACT_OUTLEN_BITS( hash, max_security_strength, \
114
+				       out_len_bits ) \
115
+	out_len_bits
116
+
117
+/** Output block length, in bytes
118
+ *
119
+ * @v hmac_drbg			HMAC_DRBG algorithm
120
+ * @ret out_len_bytes		Output block length, in bytes
121
+ */
122
+#define HMAC_DRBG_OUTLEN_BYTES( hmac_drbg ) \
123
+	( HMAC_DRBG_OUTLEN_BITS ( hmac_drbg ) / 8 )
124
+
125
+/** Maximum output block length, in bytes
126
+ *
127
+ * The maximum output block length for HMAC_DRBG is 512 bits for
128
+ * SHA-512 according to ANS X9.82 Part 3-2007 Section 10.2.1 Table 2
129
+ * (NIST SP 800-90 Section 10.1 Table 2).
130
+ */
131
+#define HMAC_DRBG_MAX_OUTLEN_BYTES HMAC_DRBG_OUTLEN_BYTES ( HMAC_DRBG_SHA512 )
39
 
132
 
40
 /** Required minimum entropy for instantiate and reseed
133
 /** Required minimum entropy for instantiate and reseed
134
+ *
135
+ * @v security_strength		Security strength
136
+ * @ret min_entropy		Required minimum entropy
41
  *
137
  *
42
  * The minimum required entropy for HMAC_DRBG is equal to the security
138
  * The minimum required entropy for HMAC_DRBG is equal to the security
43
  * strength according to ANS X9.82 Part 3-2007 Section 10.2.1 Table 2
139
  * strength according to ANS X9.82 Part 3-2007 Section 10.2.1 Table 2
44
  * (NIST SP 800-90 Section 10.1 Table 2).
140
  * (NIST SP 800-90 Section 10.1 Table 2).
45
  */
141
  */
46
-#define HMAC_DRBG_MIN_ENTROPY_BYTES ( HMAC_DRBG_SECURITY_STRENGTH / 8 )
142
+#define HMAC_DRBG_MIN_ENTROPY( security_strength ) (security_strength)
47
 
143
 
48
 /** Minimum entropy input length
144
 /** Minimum entropy input length
145
+ *
146
+ * @v security_strength		Security strength
147
+ * @ret min_entropy_len_bytes	Required minimum entropy length (in bytes)
49
  *
148
  *
50
  * The minimum entropy input length for HMAC_DRBG is equal to the
149
  * The minimum entropy input length for HMAC_DRBG is equal to the
51
  * security strength according to ANS X9.82 Part 3-2007 Section 10.2.1
150
  * security strength according to ANS X9.82 Part 3-2007 Section 10.2.1
52
  * Table 2 (NIST SP 800-90 Section 10.1 Table 2).
151
  * Table 2 (NIST SP 800-90 Section 10.1 Table 2).
53
  */
152
  */
54
-#define HMAC_DRBG_MIN_ENTROPY_LEN_BYTES ( HMAC_DRBG_SECURITY_STRENGTH / 8 )
153
+#define HMAC_DRBG_MIN_ENTROPY_LEN_BYTES( security_strength ) \
154
+	( (security_strength) / 8 )
55
 
155
 
56
 /** Maximum entropy input length
156
 /** Maximum entropy input length
57
  *
157
  *
95
 
195
 
96
 /** Reseed interval
196
 /** Reseed interval
97
  *
197
  *
98
- * The maximum permitted reseed interval for HMAC_DRBG using SHA-1 is
99
- * 2^48 according to ANS X9.82 Part 3-2007 Section 10.2.1 Table 2
100
- * (NIST SP 800-90 Section 10.1 Table 2).  However, the sample
101
- * implementation given in ANS X9.82 Part 3-2007 Annex E.2.1 (NIST SP
102
- * 800-90 Appendix F.2) shows a reseed interval of 10000.
198
+ * The maximum permitted reseed interval for HMAC_DRBG is 2^48
199
+ * according to ANS X9.82 Part 3-2007 Section 10.2.1 Table 2 (NIST SP
200
+ * 800-90 Section 10.1 Table 2).  However, the sample implementation
201
+ * given in ANS X9.82 Part 3-2007 Annex E.2.1 (NIST SP 800-90 Appendix
202
+ * F.2) shows a reseed interval of 10000.
103
  *
203
  *
104
  * We choose a very conservative reseed interval.
204
  * We choose a very conservative reseed interval.
105
  */
205
  */
106
 #define HMAC_DRBG_RESEED_INTERVAL 1024
206
 #define HMAC_DRBG_RESEED_INTERVAL 1024
107
 
207
 
108
-/** Underlying hash algorithm context size (in bytes) */
109
-#define HMAC_DRBG_CTX_SIZE SHA1_CTX_SIZE
110
-
111
 /**
208
 /**
112
  * HMAC_DRBG internal state
209
  * HMAC_DRBG internal state
113
  *
210
  *
124
 	 * "The value V of outlen bits, which is updated each time
221
 	 * "The value V of outlen bits, which is updated each time
125
 	 * another outlen bits of output are produced"
222
 	 * another outlen bits of output are produced"
126
 	 */
223
 	 */
127
-	uint8_t value[HMAC_DRBG_OUTLEN_BYTES];
224
+	uint8_t value[HMAC_DRBG_MAX_OUTLEN_BYTES];
128
 	/** Current key
225
 	/** Current key
129
 	 *
226
 	 *
130
 	 * "The outlen-bit Key, which is updated at least once each
227
 	 * "The outlen-bit Key, which is updated at least once each
131
 	 * time that the DRBG mechanism generates pseudorandom bits."
228
 	 * time that the DRBG mechanism generates pseudorandom bits."
132
 	 */
229
 	 */
133
-	uint8_t key[HMAC_DRBG_OUTLEN_BYTES];
230
+	uint8_t key[HMAC_DRBG_MAX_OUTLEN_BYTES];
134
 	/** Reseed counter
231
 	/** Reseed counter
135
 	 *
232
 	 *
136
 	 * "A counter (reseed_counter) that indicates the number of
233
 	 * "A counter (reseed_counter) that indicates the number of
140
 	unsigned int reseed_counter;
237
 	unsigned int reseed_counter;
141
 };
238
 };
142
 
239
 
143
-extern void hmac_drbg_instantiate ( struct hmac_drbg_state *state,
240
+extern void hmac_drbg_instantiate ( struct digest_algorithm *hash,
241
+				    struct hmac_drbg_state *state,
144
 				    const void *entropy, size_t entropy_len,
242
 				    const void *entropy, size_t entropy_len,
145
 				    const void *personal, size_t personal_len );
243
 				    const void *personal, size_t personal_len );
146
-extern void hmac_drbg_reseed ( struct hmac_drbg_state *state,
244
+extern void hmac_drbg_reseed ( struct digest_algorithm *hash,
245
+			       struct hmac_drbg_state *state,
147
 			       const void *entropy, size_t entropy_len,
246
 			       const void *entropy, size_t entropy_len,
148
 			       const void *additional, size_t additional_len );
247
 			       const void *additional, size_t additional_len );
149
-extern int hmac_drbg_generate ( struct hmac_drbg_state *state,
248
+extern int hmac_drbg_generate ( struct digest_algorithm *hash,
249
+				struct hmac_drbg_state *state,
150
 				const void *additional, size_t additional_len,
250
 				const void *additional, size_t additional_len,
151
 				void *data, size_t len );
251
 				void *data, size_t len );
152
 
252
 

+ 216
- 171
src/tests/hmac_drbg_test.c View File

35
 #include <assert.h>
35
 #include <assert.h>
36
 #include <string.h>
36
 #include <string.h>
37
 #include <ipxe/hmac_drbg.h>
37
 #include <ipxe/hmac_drbg.h>
38
+#include <ipxe/sha1.h>
38
 #include <ipxe/test.h>
39
 #include <ipxe/test.h>
39
 
40
 
40
 /** Define inline expected data */
41
 /** Define inline expected data */
42
 
43
 
43
 /** An HMAC_DRBG instantiation test */
44
 /** An HMAC_DRBG instantiation test */
44
 struct hmac_drbg_test_instantiate {
45
 struct hmac_drbg_test_instantiate {
45
-	/** Entropy (including nonce) */
46
+	/** Underlying hash algorithm */
47
+	struct digest_algorithm *hash;
48
+	/** Output block length */
49
+	size_t out_len;
50
+	/** Entropy */
46
 	const void *entropy;
51
 	const void *entropy;
47
-	/** Length of entropy (including nonce) */
52
+	/** Length of entropy */
48
 	size_t entropy_len;
53
 	size_t entropy_len;
54
+	/** Nonce */
55
+	const void *nonce;
56
+	/** Length of nonce */
57
+	size_t nonce_len;
49
 	/** Personalisation string */
58
 	/** Personalisation string */
50
 	const void *personal;
59
 	const void *personal;
51
 	/** Length of personalisation string */
60
 	/** Length of personalisation string */
64
  * Define an HMAC_DRBG instantiation test
73
  * Define an HMAC_DRBG instantiation test
65
  *
74
  *
66
  * @v name		Test name
75
  * @v name		Test name
67
- * @v entropy_array	Entropy input (including nonce)
76
+ * @v hmac_drbg		HMAC_DRBG algorithm
77
+ * @v entropy_array	Entropy input
78
+ * @v nonce_array	Nonce
68
  * @v personal_array	Personalisation string
79
  * @v personal_array	Personalisation string
69
  * @v key		Expected key
80
  * @v key		Expected key
70
  * @v value		Expected value
81
  * @v value		Expected value
71
  * @ret test		Instantiation test
82
  * @ret test		Instantiation test
72
  */
83
  */
73
-#define HMAC_DRBG_TEST_INSTANTIATE( name, entropy_array,		\
74
-				    personal_array, key, value )	\
84
+#define HMAC_DRBG_TEST_INSTANTIATE( name, hmac_drbg, entropy_array,	\
85
+				    nonce_array, personal_array,	\
86
+				    key, value )			\
75
 	static const uint8_t name ## _key [] = key;			\
87
 	static const uint8_t name ## _key [] = key;			\
76
 	static const uint8_t name ## _value [] = value;			\
88
 	static const uint8_t name ## _value [] = value;			\
77
 	static const struct hmac_drbg_test_instantiate name = {		\
89
 	static const struct hmac_drbg_test_instantiate name = {		\
90
+		.hash = HMAC_DRBG_HASH ( hmac_drbg ),			\
91
+		.out_len = HMAC_DRBG_OUTLEN_BYTES ( hmac_drbg ),	\
78
 		.entropy = entropy_array,				\
92
 		.entropy = entropy_array,				\
79
 		.entropy_len = sizeof ( entropy_array ),		\
93
 		.entropy_len = sizeof ( entropy_array ),		\
94
+		.nonce = nonce_array,					\
95
+		.nonce_len = sizeof ( nonce_array ),			\
80
 		.personal = personal_array,				\
96
 		.personal = personal_array,				\
81
 		.personal_len = sizeof ( personal_array ),		\
97
 		.personal_len = sizeof ( personal_array ),		\
82
 		.expected_key = name ## _key,				\
98
 		.expected_key = name ## _key,				\
92
  * @v test		Instantiation test
108
  * @v test		Instantiation test
93
  */
109
  */
94
 #define instantiate_ok( state, test ) do {				\
110
 #define instantiate_ok( state, test ) do {				\
95
-	assert ( (test)->expected_key_len == HMAC_DRBG_OUTLEN_BYTES );	\
96
-	assert ( (test)->expected_value_len == HMAC_DRBG_OUTLEN_BYTES ); \
97
-	hmac_drbg_instantiate ( (state), (test)->entropy,		\
98
-				(test)->entropy_len, (test)->personal,	\
111
+	struct {							\
112
+		uint8_t entropy[(test)->entropy_len];			\
113
+		uint8_t nonce[(test)->nonce_len];			\
114
+	} __attribute__ (( packed )) entropy_nonce;			\
115
+									\
116
+	assert ( (test)->expected_key_len == (test)->out_len );		\
117
+	assert ( (test)->expected_value_len == (test)->out_len );	\
118
+	memcpy ( entropy_nonce.entropy, (test)->entropy,		\
119
+		 sizeof ( entropy_nonce.entropy ) );			\
120
+	memcpy ( entropy_nonce.nonce, (test)->nonce,			\
121
+		 sizeof ( entropy_nonce.nonce ) );			\
122
+	hmac_drbg_instantiate ( (test)->hash, (state), &entropy_nonce,	\
123
+				sizeof ( entropy_nonce ),		\
124
+				(test)->personal,			\
99
 				(test)->personal_len );			\
125
 				(test)->personal_len );			\
100
 	ok ( memcmp ( (state)->key, (test)->expected_key,		\
126
 	ok ( memcmp ( (state)->key, (test)->expected_key,		\
101
-		      sizeof ( (state)->key ) ) == 0 );			\
127
+		      (test)->expected_key_len ) == 0 );		\
102
 	ok ( memcmp ( (state)->value, (test)->expected_value,		\
128
 	ok ( memcmp ( (state)->value, (test)->expected_value,		\
103
-		      sizeof ( (state)->value ) ) == 0 );		\
129
+		      (test)->expected_value_len ) == 0 );		\
104
 	} while ( 0 )
130
 	} while ( 0 )
105
 
131
 
106
 /** An HMAC_DRBG reseed test */
132
 /** An HMAC_DRBG reseed test */
107
 struct hmac_drbg_test_reseed {
133
 struct hmac_drbg_test_reseed {
134
+	/** Underlying hash algorithm */
135
+	struct digest_algorithm *hash;
136
+	/** Output block length */
137
+	size_t out_len;
108
 	/** Entropy */
138
 	/** Entropy */
109
 	const void *entropy;
139
 	const void *entropy;
110
 	/** Length of entropy */
140
 	/** Length of entropy */
127
  * Define an HMAC_DRBG reseed test
157
  * Define an HMAC_DRBG reseed test
128
  *
158
  *
129
  * @v name		Test name
159
  * @v name		Test name
160
+ * @v hmac_drbg		HMAC_DRBG algorithm
130
  * @v entropy_array	Entropy input
161
  * @v entropy_array	Entropy input
131
  * @v additional_array	Additional input
162
  * @v additional_array	Additional input
132
  * @v key		Expected key
163
  * @v key		Expected key
133
  * @v value		Expected value
164
  * @v value		Expected value
134
  * @ret test		Reseed test
165
  * @ret test		Reseed test
135
  */
166
  */
136
-#define HMAC_DRBG_TEST_RESEED( name, entropy_array, additional_array,	\
137
-			       key, value )		\
167
+#define HMAC_DRBG_TEST_RESEED( name, hmac_drbg, entropy_array,		\
168
+			       additional_array, key, value )		\
138
 	static const uint8_t name ## _key [] = key;			\
169
 	static const uint8_t name ## _key [] = key;			\
139
 	static const uint8_t name ## _value [] = value;			\
170
 	static const uint8_t name ## _value [] = value;			\
140
 	static const struct hmac_drbg_test_reseed name = {		\
171
 	static const struct hmac_drbg_test_reseed name = {		\
172
+		.hash = HMAC_DRBG_HASH ( hmac_drbg ),			\
173
+		.out_len = HMAC_DRBG_OUTLEN_BYTES ( hmac_drbg ),	\
141
 		.entropy = entropy_array,				\
174
 		.entropy = entropy_array,				\
142
 		.entropy_len = sizeof ( entropy_array ),		\
175
 		.entropy_len = sizeof ( entropy_array ),		\
143
 		.additional = additional_array,				\
176
 		.additional = additional_array,				\
155
  * @v test		Reseed test
188
  * @v test		Reseed test
156
  */
189
  */
157
 #define reseed_ok( state, test ) do {					\
190
 #define reseed_ok( state, test ) do {					\
158
-	assert ( (test)->expected_key_len == HMAC_DRBG_OUTLEN_BYTES );	\
159
-	assert ( (test)->expected_value_len == HMAC_DRBG_OUTLEN_BYTES ); \
160
-	hmac_drbg_reseed ( (state), (test)->entropy,			\
191
+	assert ( (test)->expected_key_len == (test)->out_len );		\
192
+	assert ( (test)->expected_value_len == (test)->out_len );	\
193
+	hmac_drbg_reseed ( (test)->hash, (state), (test)->entropy,	\
161
 			   (test)->entropy_len, (test)->additional,	\
194
 			   (test)->entropy_len, (test)->additional,	\
162
 			   (test)->additional_len );			\
195
 			   (test)->additional_len );			\
163
 	ok ( memcmp ( (state)->key, (test)->expected_key,		\
196
 	ok ( memcmp ( (state)->key, (test)->expected_key,		\
164
-		      sizeof ( (state)->key ) ) == 0 );			\
197
+		      (test)->expected_key_len ) == 0 );		\
165
 	ok ( memcmp ( (state)->value, (test)->expected_value,		\
198
 	ok ( memcmp ( (state)->value, (test)->expected_value,		\
166
-		      sizeof ( (state)->value ) ) == 0 );		\
199
+		      (test)->expected_value_len ) == 0 );		\
167
 	} while ( 0 )
200
 	} while ( 0 )
168
 
201
 
169
 /** An HMAC_DRBG generation test */
202
 /** An HMAC_DRBG generation test */
170
 struct hmac_drbg_test_generate {
203
 struct hmac_drbg_test_generate {
204
+	/** Underlying hash algorithm */
205
+	struct digest_algorithm *hash;
206
+	/** Output block length */
207
+	size_t out_len;
171
 	/** Additional input */
208
 	/** Additional input */
172
 	const void *additional;
209
 	const void *additional;
173
 	/** Length of additional_input */
210
 	/** Length of additional_input */
183
 	/** Expected pseudorandom data */
220
 	/** Expected pseudorandom data */
184
 	const void *expected_data;
221
 	const void *expected_data;
185
 	/** Length of data */
222
 	/** Length of data */
186
-	size_t len;
223
+	size_t expected_data_len;
187
 };
224
 };
188
 
225
 
189
 /**
226
 /**
190
  * Define an HMAC_DRBG generation test
227
  * Define an HMAC_DRBG generation test
191
  *
228
  *
192
  * @v name		Test name
229
  * @v name		Test name
230
+ * @v hmac_drbg		HMAC_DRBG algorithm
193
  * @v additional_array	Additional input
231
  * @v additional_array	Additional input
194
  * @v key		Expected key
232
  * @v key		Expected key
195
  * @v value		Expected value
233
  * @v value		Expected value
196
  * @v data		Expected pseudorandom data
234
  * @v data		Expected pseudorandom data
197
  * @ret test		Generation test
235
  * @ret test		Generation test
198
  */
236
  */
199
-#define HMAC_DRBG_TEST_GENERATE( name, additional_array, key, value,	\
200
-				 data )					\
237
+#define HMAC_DRBG_TEST_GENERATE( name, hmac_drbg, additional_array,	\
238
+				 key, value, data )			\
201
 	static const uint8_t name ## _key [] = key;			\
239
 	static const uint8_t name ## _key [] = key;			\
202
 	static const uint8_t name ## _value [] = value;			\
240
 	static const uint8_t name ## _value [] = value;			\
203
 	static const uint8_t name ## _data [] = data;			\
241
 	static const uint8_t name ## _data [] = data;			\
204
 	static const struct hmac_drbg_test_generate name = {		\
242
 	static const struct hmac_drbg_test_generate name = {		\
243
+		.hash = HMAC_DRBG_HASH ( hmac_drbg ),			\
244
+		.out_len = HMAC_DRBG_OUTLEN_BYTES ( hmac_drbg ),	\
205
 		.additional = additional_array,				\
245
 		.additional = additional_array,				\
206
 		.additional_len = sizeof ( additional_array ),		\
246
 		.additional_len = sizeof ( additional_array ),		\
207
 		.expected_key = name ## _key,				\
247
 		.expected_key = name ## _key,				\
209
 		.expected_value = name ## _value,			\
249
 		.expected_value = name ## _value,			\
210
 		.expected_value_len = sizeof ( name ## _value ),	\
250
 		.expected_value_len = sizeof ( name ## _value ),	\
211
 		.expected_data = name ## _data,				\
251
 		.expected_data = name ## _data,				\
212
-		.len = sizeof ( name ## _data ),			\
252
+		.expected_data_len = sizeof ( name ## _data ),		\
213
 	}
253
 	}
214
 
254
 
215
 /**
255
 /**
219
  * @v test		Generation test
259
  * @v test		Generation test
220
  */
260
  */
221
 #define generate_ok( state, test ) do {					\
261
 #define generate_ok( state, test ) do {					\
222
-	uint8_t data[ (test)->len ];					\
262
+	uint8_t data[ (test)->expected_data_len ];			\
223
 	int rc;								\
263
 	int rc;								\
224
 									\
264
 									\
225
-	assert ( (test)->expected_key_len == HMAC_DRBG_OUTLEN_BYTES );	\
226
-	assert ( (test)->expected_value_len == HMAC_DRBG_OUTLEN_BYTES );\
227
-	rc = hmac_drbg_generate ( (state), (test)->additional,		\
228
-				  (test)->additional_len, data,		\
229
-				  sizeof ( data ) );			\
265
+	assert ( (test)->expected_key_len == (test)->out_len );		\
266
+	assert ( (test)->expected_value_len == (test)->out_len );	\
267
+	rc = hmac_drbg_generate ( (test)->hash, (state),		\
268
+				  (test)->additional,			\
269
+				  (test)->additional_len,		\
270
+				  data, sizeof ( data ) );		\
230
 	ok ( rc == 0 );							\
271
 	ok ( rc == 0 );							\
231
 	ok ( memcmp ( (state)->key, (test)->expected_key,		\
272
 	ok ( memcmp ( (state)->key, (test)->expected_key,		\
232
-		      sizeof ( (state)->key ) ) == 0 );			\
273
+		      (test)->expected_key_len ) == 0 );		\
233
 	ok ( memcmp ( (state)->value, (test)->expected_value,		\
274
 	ok ( memcmp ( (state)->value, (test)->expected_value,		\
234
-		      sizeof ( (state)->value ) ) == 0 );		\
275
+		      (test)->expected_value_len ) == 0 );		\
235
 	ok ( memcmp ( data, (test)->expected_data,			\
276
 	ok ( memcmp ( data, (test)->expected_data,			\
236
-		      sizeof ( data ) ) == 0 );				\
277
+		      (test)->expected_data_len ) == 0 );		\
237
 	} while ( 0 )
278
 	} while ( 0 )
238
 
279
 
239
 /** An HMAC_DRBG generation failure test */
280
 /** An HMAC_DRBG generation failure test */
240
 struct hmac_drbg_test_generate_fail {
281
 struct hmac_drbg_test_generate_fail {
282
+	/** Underlying hash algorithm */
283
+	struct digest_algorithm *hash;
241
 	/** Additional input */
284
 	/** Additional input */
242
 	const void *additional;
285
 	const void *additional;
243
 	/** Length of additional_input */
286
 	/** Length of additional_input */
250
  * Define an HMAC_DRBG generation failure test
293
  * Define an HMAC_DRBG generation failure test
251
  *
294
  *
252
  * @v name		Test name
295
  * @v name		Test name
296
+ * @v hmac_drbg		HMAC_DRBG algorithm
253
  * @v additional_array	Additional input
297
  * @v additional_array	Additional input
254
  * @ret test		Generation failure test
298
  * @ret test		Generation failure test
255
  */
299
  */
256
-#define HMAC_DRBG_TEST_GENERATE_FAIL( name, additional_array, len )	\
300
+#define HMAC_DRBG_TEST_GENERATE_FAIL( name, hmac_drbg,			\
301
+				      additional_array, len )		\
257
 	static const struct hmac_drbg_test_generate_fail name = {	\
302
 	static const struct hmac_drbg_test_generate_fail name = {	\
303
+		.hash = HMAC_DRBG_HASH ( hmac_drbg ),			\
258
 		.additional = additional_array,				\
304
 		.additional = additional_array,				\
259
 		.additional_len = sizeof ( additional_array ),		\
305
 		.additional_len = sizeof ( additional_array ),		\
260
 		.requested_len = len,					\
306
 		.requested_len = len,					\
270
 	uint8_t data[ (test)->requested_len ];				\
316
 	uint8_t data[ (test)->requested_len ];				\
271
 	int rc;								\
317
 	int rc;								\
272
 									\
318
 									\
273
-	rc = hmac_drbg_generate ( (state), (test)->additional,		\
319
+	rc = hmac_drbg_generate ( (test)->hash, (state),		\
320
+				  (test)->additional,			\
274
 				  (test)->additional_len, data,		\
321
 				  (test)->additional_len, data,		\
275
 				  sizeof ( data ) );			\
322
 				  sizeof ( data ) );			\
276
 	ok ( rc != 0 );							\
323
 	ok ( rc != 0 );							\
277
 	} while ( 0 )
324
 	} while ( 0 )
278
 
325
 
279
-/** "EntropyInput" and "Nonce"
280
- *
281
- * These are pre-concatenated since our implementation expects to
282
- * receive the nonce in the form of additional entropy.
283
- */
326
+/** "EntropyInput" */
284
 static const uint8_t entropy_input[] = {
327
 static const uint8_t entropy_input[] = {
285
-	/* "EntropyInput" */
286
 	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
328
 	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
287
 	0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
329
 	0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
288
 	0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
330
 	0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
289
 	0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
331
 	0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
290
-	0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
291
-	/* "Nonce" */
332
+	0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36
333
+};
334
+
335
+/** "Nonce" for SHA-1 */
336
+static const uint8_t nonce_sha1[] = {
292
 	0x20, 0x21, 0x22, 0x23, 0x24
337
 	0x20, 0x21, 0x22, 0x23, 0x24
293
 };
338
 };
294
 
339
 
343
 	0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6
388
 	0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6
344
 };
389
 };
345
 
390
 
346
-/** Test 1 : Instantiation */
347
-HMAC_DRBG_TEST_INSTANTIATE ( instantiate_1,
348
-	entropy_input, personalisation_string_empty,
391
+/** SHA-1 Test 1 : Instantiation */
392
+HMAC_DRBG_TEST_INSTANTIATE ( sha1_instantiate_1, HMAC_DRBG_SHA1,
393
+	entropy_input, nonce_sha1, personalisation_string_empty,
349
 	EXPECT ( 0xab, 0x16, 0x0d, 0xd2, 0x1c, 0x30, 0x98, 0x0c, 0xa3, 0xca,
394
 	EXPECT ( 0xab, 0x16, 0x0d, 0xd2, 0x1c, 0x30, 0x98, 0x0c, 0xa3, 0xca,
350
 		 0x5a, 0x9c, 0x77, 0xb7, 0xbd, 0xf0, 0x50, 0xe6, 0x4e, 0xe9 ),
395
 		 0x5a, 0x9c, 0x77, 0xb7, 0xbd, 0xf0, 0x50, 0xe6, 0x4e, 0xe9 ),
351
 	EXPECT ( 0x61, 0x44, 0x99, 0xea, 0x98, 0x0c, 0xfb, 0x3d, 0xaa, 0x2c,
396
 	EXPECT ( 0x61, 0x44, 0x99, 0xea, 0x98, 0x0c, 0xfb, 0x3d, 0xaa, 0x2c,
352
 		 0xa8, 0x6d, 0x65, 0xa4, 0x6b, 0xf4, 0x48, 0x8d, 0x8c, 0xc5 ) );
397
 		 0xa8, 0x6d, 0x65, 0xa4, 0x6b, 0xf4, 0x48, 0x8d, 0x8c, 0xc5 ) );
353
 
398
 
354
-/** Test 1.1 : First call to Generate */
355
-HMAC_DRBG_TEST_GENERATE ( generate_1_1,
399
+/** SHA-1 Test 1.1 : First call to Generate */
400
+HMAC_DRBG_TEST_GENERATE ( sha1_generate_1_1, HMAC_DRBG_SHA1,
356
 	additional_input_empty,
401
 	additional_input_empty,
357
 	EXPECT ( 0x7b, 0xb1, 0x80, 0x28, 0xe0, 0x1d, 0x03, 0x42, 0xdf, 0x4f,
402
 	EXPECT ( 0x7b, 0xb1, 0x80, 0x28, 0xe0, 0x1d, 0x03, 0x42, 0xdf, 0x4f,
358
 		 0x54, 0xda, 0x51, 0x22, 0xfa, 0x5f, 0x2c, 0x3a, 0x05, 0xe4 ),
403
 		 0x54, 0xda, 0x51, 0x22, 0xfa, 0x5f, 0x2c, 0x3a, 0x05, 0xe4 ),
363
 		 0x8c, 0x0b, 0x22, 0xcd, 0x06, 0x30, 0xbf, 0xb0, 0x12, 0x7f,
408
 		 0x8c, 0x0b, 0x22, 0xcd, 0x06, 0x30, 0xbf, 0xb0, 0x12, 0x7f,
364
 		 0xb5, 0x40, 0x8c, 0x8e, 0xfc, 0x17, 0xa9, 0x29, 0x89, 0x6e ) );
409
 		 0xb5, 0x40, 0x8c, 0x8e, 0xfc, 0x17, 0xa9, 0x29, 0x89, 0x6e ) );
365
 
410
 
366
-/** Test 1.2 : Second call to Generate */
367
-HMAC_DRBG_TEST_GENERATE ( generate_1_2,
411
+/** SHA-1 Test 1.2 : Second call to Generate */
412
+HMAC_DRBG_TEST_GENERATE ( sha1_generate_1_2, HMAC_DRBG_SHA1,
368
 	additional_input_empty,
413
 	additional_input_empty,
369
 	EXPECT ( 0x3d, 0x4d, 0x73, 0x77, 0xe9, 0x17, 0x2a, 0xaf, 0xa7, 0x76,
414
 	EXPECT ( 0x3d, 0x4d, 0x73, 0x77, 0xe9, 0x17, 0x2a, 0xaf, 0xa7, 0x76,
370
 		 0xb0, 0xdd, 0xcb, 0x89, 0x42, 0x00, 0x4a, 0x44, 0xb7, 0xfd ),
415
 		 0xb0, 0xdd, 0xcb, 0x89, 0x42, 0x00, 0x4a, 0x44, 0xb7, 0xfd ),
375
 		 0x9c, 0xe3, 0x67, 0xd0, 0x3a, 0xea, 0xde, 0x37, 0x82, 0x7f,
420
 		 0x9c, 0xe3, 0x67, 0xd0, 0x3a, 0xea, 0xde, 0x37, 0x82, 0x7f,
376
 		 0xa8, 0xe9, 0xcb, 0x6a, 0x08, 0x19, 0x61, 0x15, 0xd9, 0x48 ) );
421
 		 0xa8, 0xe9, 0xcb, 0x6a, 0x08, 0x19, 0x61, 0x15, 0xd9, 0x48 ) );
377
 
422
 
378
-/** Test 2 : Instantiation */
379
-#define instantiate_2 instantiate_1
423
+/** SHA-1 Test 2 : Instantiation */
424
+#define sha1_instantiate_2 sha1_instantiate_1
380
 
425
 
381
-/** Test 2.1 : First call to Generate */
382
-HMAC_DRBG_TEST_GENERATE ( generate_2_1,
426
+/** SHA-1 Test 2.1 : First call to Generate */
427
+HMAC_DRBG_TEST_GENERATE ( sha1_generate_2_1, HMAC_DRBG_SHA1,
383
 	additional_input_1,
428
 	additional_input_1,
384
 	EXPECT ( 0x3a, 0x06, 0x2e, 0x6b, 0x79, 0xfe, 0x70, 0xdb, 0xff, 0xeb,
429
 	EXPECT ( 0x3a, 0x06, 0x2e, 0x6b, 0x79, 0xfe, 0x70, 0xdb, 0xff, 0xeb,
385
 		 0x3a, 0x2b, 0x6b, 0xe8, 0x03, 0x23, 0xf7, 0xd6, 0x74, 0xc5 ),
430
 		 0x3a, 0x2b, 0x6b, 0xe8, 0x03, 0x23, 0xf7, 0xd6, 0x74, 0xc5 ),
390
 		 0x9a, 0xd0, 0xbb, 0x26, 0xfa, 0xc0, 0x49, 0x7b, 0x5c, 0x57,
435
 		 0x9a, 0xd0, 0xbb, 0x26, 0xfa, 0xc0, 0x49, 0x7b, 0x5c, 0x57,
391
 		 0xe1, 0x61, 0xe3, 0x66, 0x81, 0xbc, 0xc9, 0x30, 0xce, 0x80 ) );
436
 		 0xe1, 0x61, 0xe3, 0x66, 0x81, 0xbc, 0xc9, 0x30, 0xce, 0x80 ) );
392
 
437
 
393
-/** Test 2.2 : Second call to Generate */
394
-HMAC_DRBG_TEST_GENERATE ( generate_2_2,
438
+/** SHA-1 Test 2.2 : Second call to Generate */
439
+HMAC_DRBG_TEST_GENERATE ( sha1_generate_2_2, HMAC_DRBG_SHA1,
395
 	additional_input_2,
440
 	additional_input_2,
396
 	EXPECT ( 0x8a, 0xd7, 0xe3, 0x47, 0x72, 0xb5, 0xfc, 0x7c, 0x3b, 0x3b,
441
 	EXPECT ( 0x8a, 0xd7, 0xe3, 0x47, 0x72, 0xb5, 0xfc, 0x7c, 0x3b, 0x3b,
397
 		 0x27, 0x62, 0x4f, 0x0b, 0x91, 0x77, 0x6a, 0x8a, 0x71, 0x12 ),
442
 		 0x27, 0x62, 0x4f, 0x0b, 0x91, 0x77, 0x6a, 0x8a, 0x71, 0x12 ),
402
 		 0xb9, 0xc3, 0x7b, 0x7f, 0xe8, 0x1b, 0xa9, 0x40, 0x45, 0xa1,
447
 		 0xb9, 0xc3, 0x7b, 0x7f, 0xe8, 0x1b, 0xa9, 0x40, 0x45, 0xa1,
403
 		 0x4a, 0x7c, 0xb5, 0x14, 0xb4, 0x46, 0x66, 0x6e, 0xa5, 0xa7 ) );
448
 		 0x4a, 0x7c, 0xb5, 0x14, 0xb4, 0x46, 0x66, 0x6e, 0xa5, 0xa7 ) );
404
 
449
 
405
-/** Test 3 : Instantiation */
406
-HMAC_DRBG_TEST_INSTANTIATE ( instantiate_3,
407
-	entropy_input, personalisation_string,
450
+/** SHA-1 Test 3 : Instantiation */
451
+HMAC_DRBG_TEST_INSTANTIATE ( sha1_instantiate_3, HMAC_DRBG_SHA1,
452
+	entropy_input, nonce_sha1, personalisation_string,
408
 	EXPECT ( 0xb7, 0xd9, 0x66, 0xd7, 0x0d, 0x4e, 0x27, 0xa7, 0xfa, 0x83,
453
 	EXPECT ( 0xb7, 0xd9, 0x66, 0xd7, 0x0d, 0x4e, 0x27, 0xa7, 0xfa, 0x83,
409
 		 0x8f, 0x7d, 0x61, 0x12, 0x6c, 0x0e, 0xdc, 0x84, 0x76, 0x1c ),
454
 		 0x8f, 0x7d, 0x61, 0x12, 0x6c, 0x0e, 0xdc, 0x84, 0x76, 0x1c ),
410
 	EXPECT ( 0xda, 0xb2, 0xa7, 0x18, 0x83, 0xf1, 0x00, 0x5c, 0x5d, 0xd0,
455
 	EXPECT ( 0xda, 0xb2, 0xa7, 0x18, 0x83, 0xf1, 0x00, 0x5c, 0x5d, 0xd0,
411
 		 0x39, 0x32, 0x4d, 0x3c, 0x36, 0x4d, 0x6e, 0x18, 0xf9, 0x54 ) );
456
 		 0x39, 0x32, 0x4d, 0x3c, 0x36, 0x4d, 0x6e, 0x18, 0xf9, 0x54 ) );
412
 
457
 
413
-/** Test 3.1 : First call to Generate */
414
-HMAC_DRBG_TEST_GENERATE ( generate_3_1,
458
+/** SHA-1 Test 3.1 : First call to Generate */
459
+HMAC_DRBG_TEST_GENERATE ( sha1_generate_3_1, HMAC_DRBG_SHA1,
415
 	additional_input_empty,
460
 	additional_input_empty,
416
 	EXPECT ( 0x87, 0xd3, 0x82, 0x8b, 0xe0, 0x3a, 0x80, 0x7d, 0xd3, 0x40,
461
 	EXPECT ( 0x87, 0xd3, 0x82, 0x8b, 0xe0, 0x3a, 0x80, 0x7d, 0xd3, 0x40,
417
 		 0x29, 0x41, 0xbe, 0xd6, 0xde, 0x98, 0x6e, 0xe7, 0xa2, 0x86 ),
462
 		 0x29, 0x41, 0xbe, 0xd6, 0xde, 0x98, 0x6e, 0xe7, 0xa2, 0x86 ),
422
 		 0x9b, 0xd0, 0x60, 0x20, 0x8e, 0xea, 0x7d, 0x71, 0xf9, 0xd1,
467
 		 0x9b, 0xd0, 0x60, 0x20, 0x8e, 0xea, 0x7d, 0x71, 0xf9, 0xd1,
423
 		 0x23, 0xdf, 0x47, 0xb3, 0xce, 0x06, 0x9d, 0x98, 0xed, 0xe6 ) );
468
 		 0x23, 0xdf, 0x47, 0xb3, 0xce, 0x06, 0x9d, 0x98, 0xed, 0xe6 ) );
424
 
469
 
425
-/** Test 3.2 : Second call to Generate */
426
-HMAC_DRBG_TEST_GENERATE ( generate_3_2,
470
+/** SHA-1 Test 3.2 : Second call to Generate */
471
+HMAC_DRBG_TEST_GENERATE ( sha1_generate_3_2, HMAC_DRBG_SHA1,
427
 	additional_input_empty,
472
 	additional_input_empty,
428
 	EXPECT ( 0x26, 0xab, 0xbf, 0x54, 0xb2, 0x8b, 0x93, 0xff, 0x90, 0x08,
473
 	EXPECT ( 0x26, 0xab, 0xbf, 0x54, 0xb2, 0x8b, 0x93, 0xff, 0x90, 0x08,
429
 		 0x67, 0x0e, 0xbf, 0xee, 0x86, 0xcd, 0xd7, 0x22, 0x8e, 0xd5 ),
474
 		 0x67, 0x0e, 0xbf, 0xee, 0x86, 0xcd, 0xd7, 0x22, 0x8e, 0xd5 ),
434
 		 0x63, 0x97, 0x65, 0x47, 0x2b, 0x71, 0xac, 0xeb, 0xe2, 0xea,
479
 		 0x63, 0x97, 0x65, 0x47, 0x2b, 0x71, 0xac, 0xeb, 0xe2, 0xea,
435
 		 0x8b, 0x1b, 0x6b, 0x49, 0x62, 0x9c, 0xb6, 0x73, 0x17, 0xe0 ) );
480
 		 0x8b, 0x1b, 0x6b, 0x49, 0x62, 0x9c, 0xb6, 0x73, 0x17, 0xe0 ) );
436
 
481
 
437
-/** Test 4 : Instantiation */
438
-#define instantiate_4 instantiate_3
482
+/** SHA-1 Test 4 : Instantiation */
483
+#define sha1_instantiate_4 sha1_instantiate_3
439
 
484
 
440
-/** Test 4.1 : First call to Generate */
441
-HMAC_DRBG_TEST_GENERATE ( generate_4_1,
485
+/** SHA-1 Test 4.1 : First call to Generate */
486
+HMAC_DRBG_TEST_GENERATE ( sha1_generate_4_1, HMAC_DRBG_SHA1,
442
 	additional_input_1,
487
 	additional_input_1,
443
 	EXPECT ( 0x17, 0xa5, 0xd7, 0x9f, 0x07, 0x67, 0x87, 0x6f, 0x3a, 0x45,
488
 	EXPECT ( 0x17, 0xa5, 0xd7, 0x9f, 0x07, 0x67, 0x87, 0x6f, 0x3a, 0x45,
444
 		 0xe0, 0xc9, 0xc3, 0x3e, 0xc8, 0x8b, 0x03, 0xce, 0xea, 0x13 ),
489
 		 0xe0, 0xc9, 0xc3, 0x3e, 0xc8, 0x8b, 0x03, 0xce, 0xea, 0x13 ),
449
 		 0x6d, 0xfc, 0x30, 0x2e, 0xad, 0x4c, 0xe3, 0xf5, 0x54, 0xc7,
494
 		 0x6d, 0xfc, 0x30, 0x2e, 0xad, 0x4c, 0xe3, 0xf5, 0x54, 0xc7,
450
 		 0x9b, 0x0d, 0x44, 0x23, 0x9e, 0xba, 0x56, 0xa7, 0xea, 0x2d ) );
495
 		 0x9b, 0x0d, 0x44, 0x23, 0x9e, 0xba, 0x56, 0xa7, 0xea, 0x2d ) );
451
 
496
 
452
-/** Test 4.2 : Second call to Generate */
453
-HMAC_DRBG_TEST_GENERATE ( generate_4_2,
497
+/** SHA-1 Test 4.2 : Second call to Generate */
498
+HMAC_DRBG_TEST_GENERATE ( sha1_generate_4_2, HMAC_DRBG_SHA1,
454
 	additional_input_2,
499
 	additional_input_2,
455
 	EXPECT ( 0x07, 0x9b, 0x57, 0xd9, 0x40, 0x6e, 0x11, 0xc2, 0xf8, 0x7c,
500
 	EXPECT ( 0x07, 0x9b, 0x57, 0xd9, 0x40, 0x6e, 0x11, 0xc2, 0xf8, 0x7c,
456
 		 0x8c, 0x82, 0x8c, 0x8c, 0x6f, 0xa7, 0x6e, 0x40, 0xea, 0x01 ),
501
 		 0x8c, 0x82, 0x8c, 0x8c, 0x6f, 0xa7, 0x6e, 0x40, 0xea, 0x01 ),
461
 		 0xdc, 0x91, 0x21, 0x5d, 0x44, 0xb1, 0x07, 0xb4, 0xd5, 0xa7,
506
 		 0xdc, 0x91, 0x21, 0x5d, 0x44, 0xb1, 0x07, 0xb4, 0xd5, 0xa7,
462
 		 0x79, 0x01, 0x59, 0x25, 0x09, 0x76, 0x52, 0x80, 0xf9, 0x69 ) );
507
 		 0x79, 0x01, 0x59, 0x25, 0x09, 0x76, 0x52, 0x80, 0xf9, 0x69 ) );
463
 
508
 
464
-/** Test 5 : Instantiation */
465
-#define instantiate_5 instantiate_1
509
+/** SHA-1 Test 5 : Instantiation */
510
+#define sha1_instantiate_5 sha1_instantiate_1
466
 
511
 
467
-/** Test 5.1 : First call to Generate */
468
-HMAC_DRBG_TEST_GENERATE_FAIL ( generate_fail_5_1,
512
+/** SHA-1 Test 5.1 : First call to Generate */
513
+HMAC_DRBG_TEST_GENERATE_FAIL ( sha1_generate_fail_5_1, HMAC_DRBG_SHA1,
469
 	additional_input_empty, ( 320 / 8 ) );
514
 	additional_input_empty, ( 320 / 8 ) );
470
 
515
 
471
-/** Test 5.2 : Reseed */
472
-HMAC_DRBG_TEST_RESEED ( reseed_5_2,
516
+/** SHA-1 Test 5.2 : Reseed */
517
+HMAC_DRBG_TEST_RESEED ( sha1_reseed_5_2, HMAC_DRBG_SHA1,
473
 	entropy_input_1, additional_input_empty,
518
 	entropy_input_1, additional_input_empty,
474
 	EXPECT ( 0xcd, 0x4c, 0xab, 0x38, 0xc8, 0xad, 0x65, 0x71, 0x22, 0xbf,
519
 	EXPECT ( 0xcd, 0x4c, 0xab, 0x38, 0xc8, 0xad, 0x65, 0x71, 0x22, 0xbf,
475
 		 0x5d, 0x3d, 0x00, 0xd0, 0xac, 0x9b, 0x13, 0xd6, 0x29, 0xbb ),
520
 		 0x5d, 0x3d, 0x00, 0xd0, 0xac, 0x9b, 0x13, 0xd6, 0x29, 0xbb ),
476
 	EXPECT ( 0xf6, 0x60, 0xe2, 0x3e, 0x91, 0x00, 0x6b, 0x62, 0xc6, 0x54,
521
 	EXPECT ( 0xf6, 0x60, 0xe2, 0x3e, 0x91, 0x00, 0x6b, 0x62, 0xc6, 0x54,
477
 		 0x3a, 0xb1, 0x34, 0x4d, 0x23, 0xa3, 0x1a, 0xb4, 0xcf, 0x2c ) );
522
 		 0x3a, 0xb1, 0x34, 0x4d, 0x23, 0xa3, 0x1a, 0xb4, 0xcf, 0x2c ) );
478
 
523
 
479
-/** Test 5.3 : Retried first call to Generate */
480
-HMAC_DRBG_TEST_GENERATE ( generate_5_3,
524
+/** SHA-1 Test 5.3 : Retried first call to Generate */
525
+HMAC_DRBG_TEST_GENERATE ( sha1_generate_5_3, HMAC_DRBG_SHA1,
481
 	additional_input_empty,
526
 	additional_input_empty,
482
 	EXPECT ( 0x58, 0x7f, 0xd8, 0x21, 0xef, 0x6c, 0x9d, 0xa4, 0xa8, 0x3c,
527
 	EXPECT ( 0x58, 0x7f, 0xd8, 0x21, 0xef, 0x6c, 0x9d, 0xa4, 0xa8, 0x3c,
483
 		 0x19, 0x21, 0x1f, 0x10, 0x56, 0xca, 0xcd, 0x23, 0xfc, 0x1a ),
528
 		 0x19, 0x21, 0x1f, 0x10, 0x56, 0xca, 0xcd, 0x23, 0xfc, 0x1a ),
488
 		 0xbc, 0x0e, 0xfc, 0x28, 0x2a, 0xbd, 0x87, 0x60, 0x5c, 0xc9,
533
 		 0xbc, 0x0e, 0xfc, 0x28, 0x2a, 0xbd, 0x87, 0x60, 0x5c, 0xc9,
489
 		 0x0c, 0xba, 0x9b, 0x86, 0x33, 0xdc, 0xb1, 0xda, 0xe0, 0x2e ) );
534
 		 0x0c, 0xba, 0x9b, 0x86, 0x33, 0xdc, 0xb1, 0xda, 0xe0, 0x2e ) );
490
 
535
 
491
-/** Test 5.4 : Second call to Generate */
492
-HMAC_DRBG_TEST_GENERATE_FAIL ( generate_fail_5_4,
536
+/** SHA-1 Test 5.4 : Second call to Generate */
537
+HMAC_DRBG_TEST_GENERATE_FAIL ( sha1_generate_fail_5_4, HMAC_DRBG_SHA1,
493
 	additional_input_empty, ( 320 / 8 ) );
538
 	additional_input_empty, ( 320 / 8 ) );
494
 
539
 
495
-/** Test 5.5 : Reseed */
496
-HMAC_DRBG_TEST_RESEED ( reseed_5_5,
540
+/** SHA-1 Test 5.5 : Reseed */
541
+HMAC_DRBG_TEST_RESEED ( sha1_reseed_5_5, HMAC_DRBG_SHA1,
497
 	entropy_input_2, additional_input_empty,
542
 	entropy_input_2, additional_input_empty,
498
 	EXPECT ( 0xdb, 0xa1, 0xcf, 0xf4, 0x87, 0x95, 0x46, 0xa0, 0x38, 0xa5,
543
 	EXPECT ( 0xdb, 0xa1, 0xcf, 0xf4, 0x87, 0x95, 0x46, 0xa0, 0x38, 0xa5,
499
 		 0x59, 0xb2, 0xa2, 0x4d, 0xf2, 0xc0, 0x30, 0x08, 0x9a, 0x41 ),
544
 		 0x59, 0xb2, 0xa2, 0x4d, 0xf2, 0xc0, 0x30, 0x08, 0x9a, 0x41 ),
500
 	EXPECT ( 0x2f, 0x88, 0x3c, 0x46, 0x48, 0xe1, 0x31, 0xe8, 0x6d, 0xdf,
545
 	EXPECT ( 0x2f, 0x88, 0x3c, 0x46, 0x48, 0xe1, 0x31, 0xe8, 0x6d, 0xdf,
501
 		 0x9d, 0xca, 0x0d, 0x74, 0xf3, 0x0c, 0xa1, 0xce, 0x6e, 0xfb ) );
546
 		 0x9d, 0xca, 0x0d, 0x74, 0xf3, 0x0c, 0xa1, 0xce, 0x6e, 0xfb ) );
502
 
547
 
503
-/** Test 5.6 : Retried second call to Generate */
504
-HMAC_DRBG_TEST_GENERATE ( generate_5_6,
548
+/** SHA-1 Test 5.6 : Retried second call to Generate */
549
+HMAC_DRBG_TEST_GENERATE ( sha1_generate_5_6, HMAC_DRBG_SHA1,
505
 	additional_input_empty,
550
 	additional_input_empty,
506
 	EXPECT ( 0xf9, 0x39, 0xa5, 0xab, 0x08, 0xa3, 0x9f, 0x23, 0x10, 0x70,
551
 	EXPECT ( 0xf9, 0x39, 0xa5, 0xab, 0x08, 0xa3, 0x9f, 0x23, 0x10, 0x70,
507
 		 0xb0, 0xd4, 0xc9, 0x6d, 0xc2, 0x37, 0x90, 0xba, 0x01, 0x53 ),
552
 		 0xb0, 0xd4, 0xc9, 0x6d, 0xc2, 0x37, 0x90, 0xba, 0x01, 0x53 ),
512
 		 0x1a, 0x0a, 0xd3, 0x9b, 0xd1, 0x5e, 0x86, 0x2e, 0x64, 0x4f,
557
 		 0x1a, 0x0a, 0xd3, 0x9b, 0xd1, 0x5e, 0x86, 0x2e, 0x64, 0x4f,
513
 		 0x31, 0xe4, 0xa2, 0xd7, 0xd8, 0x43, 0xe5, 0x7c, 0x59, 0x68 ) );
558
 		 0x31, 0xe4, 0xa2, 0xd7, 0xd8, 0x43, 0xe5, 0x7c, 0x59, 0x68 ) );
514
 
559
 
515
-/** Test 6 : Instantiate */
516
-#define instantiate_6 instantiate_1
560
+/** SHA-1 Test 6 : Instantiate */
561
+#define sha1_instantiate_6 sha1_instantiate_1
517
 
562
 
518
-/** Test 6.1 : First call to Generate */
519
-HMAC_DRBG_TEST_GENERATE_FAIL ( generate_fail_6_1,
563
+/** SHA-1 Test 6.1 : First call to Generate */
564
+HMAC_DRBG_TEST_GENERATE_FAIL ( sha1_generate_fail_6_1, HMAC_DRBG_SHA1,
520
 	additional_input_1, ( 320 / 8 ) );
565
 	additional_input_1, ( 320 / 8 ) );
521
 
566
 
522
-/** Test 6.2 : Reseed */
523
-HMAC_DRBG_TEST_RESEED ( reseed_6_2,
567
+/** SHA-1 Test 6.2 : Reseed */
568
+HMAC_DRBG_TEST_RESEED ( sha1_reseed_6_2, HMAC_DRBG_SHA1,
524
 	entropy_input_1, additional_input_1,
569
 	entropy_input_1, additional_input_1,
525
 	EXPECT ( 0x52, 0x28, 0xa4, 0xb6, 0xa4, 0x46, 0x92, 0x90, 0x5e, 0xc0,
570
 	EXPECT ( 0x52, 0x28, 0xa4, 0xb6, 0xa4, 0x46, 0x92, 0x90, 0x5e, 0xc0,
526
 		 0x44, 0xbf, 0xf0, 0xbb, 0x4e, 0x25, 0xa3, 0x87, 0xca, 0xc1 ),
571
 		 0x44, 0xbf, 0xf0, 0xbb, 0x4e, 0x25, 0xa3, 0x87, 0xca, 0xc1 ),
527
 	EXPECT ( 0x24, 0x77, 0x32, 0xd0, 0x4c, 0xb8, 0x4e, 0xd4, 0x1a, 0xdd,
572
 	EXPECT ( 0x24, 0x77, 0x32, 0xd0, 0x4c, 0xb8, 0x4e, 0xd4, 0x1a, 0xdd,
528
 		 0x95, 0xa4, 0xb7, 0x8b, 0x50, 0xcd, 0x9b, 0x3d, 0x3f, 0x32 ) );
573
 		 0x95, 0xa4, 0xb7, 0x8b, 0x50, 0xcd, 0x9b, 0x3d, 0x3f, 0x32 ) );
529
 
574
 
530
-/** Test 6.3 : Retried first call to Generate */
531
-HMAC_DRBG_TEST_GENERATE ( generate_6_3,
575
+/** SHA-1 Test 6.3 : Retried first call to Generate */
576
+HMAC_DRBG_TEST_GENERATE ( sha1_generate_6_3, HMAC_DRBG_SHA1,
532
 	additional_input_empty,
577
 	additional_input_empty,
533
 	EXPECT ( 0xab, 0x3d, 0xd4, 0x89, 0x5b, 0xc8, 0xcd, 0x22, 0x71, 0xde,
578
 	EXPECT ( 0xab, 0x3d, 0xd4, 0x89, 0x5b, 0xc8, 0xcd, 0x22, 0x71, 0xde,
534
 		 0xba, 0x5f, 0x3c, 0x13, 0x63, 0x52, 0x6b, 0x8b, 0x74, 0x52 ),
579
 		 0xba, 0x5f, 0x3c, 0x13, 0x63, 0x52, 0x6b, 0x8b, 0x74, 0x52 ),
539
 		 0x57, 0xae, 0xe8, 0x15, 0xb9, 0xc0, 0x70, 0x04, 0xc7, 0xe9,
584
 		 0x57, 0xae, 0xe8, 0x15, 0xb9, 0xc0, 0x70, 0x04, 0xc7, 0xe9,
540
 		 0x92, 0xeb, 0x8c, 0x7e, 0x59, 0x19, 0x64, 0xaf, 0xee, 0xa2 ) );
585
 		 0x92, 0xeb, 0x8c, 0x7e, 0x59, 0x19, 0x64, 0xaf, 0xee, 0xa2 ) );
541
 
586
 
542
-/** Test 6.4 : Second call to Generate */
543
-HMAC_DRBG_TEST_GENERATE_FAIL ( generate_fail_6_4,
587
+/** SHA-1 Test 6.4 : Second call to Generate */
588
+HMAC_DRBG_TEST_GENERATE_FAIL ( sha1_generate_fail_6_4, HMAC_DRBG_SHA1,
544
 	additional_input_2, ( 320 / 8 ) );
589
 	additional_input_2, ( 320 / 8 ) );
545
 
590
 
546
-/** Test 6.5 : Reseed */
547
-HMAC_DRBG_TEST_RESEED ( reseed_6_5,
591
+/** SHA-1 Test 6.5 : Reseed */
592
+HMAC_DRBG_TEST_RESEED ( sha1_reseed_6_5, HMAC_DRBG_SHA1,
548
 	entropy_input_2, additional_input_2,
593
 	entropy_input_2, additional_input_2,
549
 	EXPECT ( 0xe5, 0x73, 0x9f, 0x9c, 0xf7, 0xff, 0x43, 0x84, 0xd1, 0x27,
594
 	EXPECT ( 0xe5, 0x73, 0x9f, 0x9c, 0xf7, 0xff, 0x43, 0x84, 0xd1, 0x27,
550
 		 0x3e, 0x02, 0x6b, 0x45, 0x31, 0x21, 0x36, 0x49, 0x4f, 0x41 ),
595
 		 0x3e, 0x02, 0x6b, 0x45, 0x31, 0x21, 0x36, 0x49, 0x4f, 0x41 ),
551
 	EXPECT ( 0x30, 0xc3, 0x43, 0x05, 0xc2, 0xc6, 0x48, 0xb0, 0x57, 0xa6,
596
 	EXPECT ( 0x30, 0xc3, 0x43, 0x05, 0xc2, 0xc6, 0x48, 0xb0, 0x57, 0xa6,
552
 		 0x40, 0x22, 0x1b, 0x5c, 0x56, 0x57, 0x26, 0xcd, 0x32, 0xb2 ) );
597
 		 0x40, 0x22, 0x1b, 0x5c, 0x56, 0x57, 0x26, 0xcd, 0x32, 0xb2 ) );
553
 
598
 
554
-/** Test 6.6 : Retried second call to Generate */
555
-HMAC_DRBG_TEST_GENERATE ( generate_6_6,
599
+/** SHA-1 Test 6.6 : Retried second call to Generate */
600
+HMAC_DRBG_TEST_GENERATE ( sha1_generate_6_6, HMAC_DRBG_SHA1,
556
 	additional_input_empty,
601
 	additional_input_empty,
557
 	EXPECT ( 0x61, 0x91, 0xca, 0x9b, 0xf0, 0x00, 0xd1, 0x0a, 0x71, 0x69,
602
 	EXPECT ( 0x61, 0x91, 0xca, 0x9b, 0xf0, 0x00, 0xd1, 0x0a, 0x71, 0x69,
558
 		 0x0a, 0xc1, 0x0e, 0x09, 0xff, 0xc8, 0x92, 0xab, 0xde, 0x9a ),
603
 		 0x0a, 0xc1, 0x0e, 0x09, 0xff, 0xc8, 0x92, 0xab, 0xde, 0x9a ),
563
 		 0x2d, 0xc6, 0x4a, 0x16, 0x42, 0x11, 0x88, 0x9a, 0x01, 0x0f,
608
 		 0x2d, 0xc6, 0x4a, 0x16, 0x42, 0x11, 0x88, 0x9a, 0x01, 0x0f,
564
 		 0x24, 0x71, 0xa0, 0x91, 0x2f, 0xfe, 0xa1, 0xbf, 0x01, 0x95 ) );
609
 		 0x24, 0x71, 0xa0, 0x91, 0x2f, 0xfe, 0xa1, 0xbf, 0x01, 0x95 ) );
565
 
610
 
566
-/** Test 7 : Instantiation */
567
-#define instantiate_7 instantiate_3
611
+/** SHA-1 Test 7 : Instantiation */
612
+#define sha1_instantiate_7 sha1_instantiate_3
568
 
613
 
569
-/** Test 7.1 : First call to Generate */
570
-HMAC_DRBG_TEST_GENERATE_FAIL ( generate_fail_7_1,
614
+/** SHA-1 Test 7.1 : First call to Generate */
615
+HMAC_DRBG_TEST_GENERATE_FAIL ( sha1_generate_fail_7_1, HMAC_DRBG_SHA1,
571
 	additional_input_empty, ( 320 / 8 ) );
616
 	additional_input_empty, ( 320 / 8 ) );
572
 
617
 
573
-/** Test 7.2 : Reseed */
574
-HMAC_DRBG_TEST_RESEED ( reseed_7_2,
618
+/** SHA-1 Test 7.2 : Reseed */
619
+HMAC_DRBG_TEST_RESEED ( sha1_reseed_7_2, HMAC_DRBG_SHA1,
575
 	entropy_input_1, additional_input_empty,
620
 	entropy_input_1, additional_input_empty,
576
 	EXPECT ( 0xb9, 0x25, 0x4d, 0x8a, 0xac, 0xba, 0x43, 0xfb, 0xda, 0xe6,
621
 	EXPECT ( 0xb9, 0x25, 0x4d, 0x8a, 0xac, 0xba, 0x43, 0xfb, 0xda, 0xe6,
577
 		 0x39, 0x4f, 0x2b, 0x3a, 0xfc, 0x5d, 0x58, 0x08, 0x00, 0xbf ),
622
 		 0x39, 0x4f, 0x2b, 0x3a, 0xfc, 0x5d, 0x58, 0x08, 0x00, 0xbf ),
578
 	EXPECT ( 0x28, 0x40, 0x3b, 0x60, 0x36, 0x38, 0xd0, 0x7d, 0x79, 0x66,
623
 	EXPECT ( 0x28, 0x40, 0x3b, 0x60, 0x36, 0x38, 0xd0, 0x7d, 0x79, 0x66,
579
 		 0x66, 0x1e, 0xf6, 0x7b, 0x9d, 0x39, 0x05, 0xf4, 0x6d, 0xb9 ) );
624
 		 0x66, 0x1e, 0xf6, 0x7b, 0x9d, 0x39, 0x05, 0xf4, 0x6d, 0xb9 ) );
580
 
625
 
581
-/** Test 7.3 : Retried first call to Generate */
582
-HMAC_DRBG_TEST_GENERATE ( generate_7_3,
626
+/** SHA-1 Test 7.3 : Retried first call to Generate */
627
+HMAC_DRBG_TEST_GENERATE ( sha1_generate_7_3, HMAC_DRBG_SHA1,
583
 	additional_input_empty,
628
 	additional_input_empty,
584
 	EXPECT ( 0x64, 0xfe, 0x07, 0x4a, 0x6e, 0x77, 0x97, 0xd1, 0xa4, 0x35,
629
 	EXPECT ( 0x64, 0xfe, 0x07, 0x4a, 0x6e, 0x77, 0x97, 0xd1, 0xa4, 0x35,
585
 		 0xda, 0x89, 0x64, 0x48, 0x4d, 0x6c, 0xf8, 0xbd, 0xc0, 0x1b ),
630
 		 0xda, 0x89, 0x64, 0x48, 0x4d, 0x6c, 0xf8, 0xbd, 0xc0, 0x1b ),
590
 		 0xb5, 0x70, 0x81, 0xe4, 0x22, 0x0f, 0x22, 0xc5, 0xc2, 0x83,
635
 		 0xb5, 0x70, 0x81, 0xe4, 0x22, 0x0f, 0x22, 0xc5, 0xc2, 0x83,
591
 		 0xe2, 0xc9, 0x1b, 0x8e, 0x30, 0x5a, 0xb8, 0x69, 0xc6, 0x25 ) );
636
 		 0xe2, 0xc9, 0x1b, 0x8e, 0x30, 0x5a, 0xb8, 0x69, 0xc6, 0x25 ) );
592
 
637
 
593
-/** Test 7.4 : Second call to Generate */
594
-HMAC_DRBG_TEST_GENERATE_FAIL ( generate_fail_7_4,
638
+/** SHA-1 Test 7.4 : Second call to Generate */
639
+HMAC_DRBG_TEST_GENERATE_FAIL ( sha1_generate_fail_7_4, HMAC_DRBG_SHA1,
595
 	additional_input_empty, ( 320 / 8 ) );
640
 	additional_input_empty, ( 320 / 8 ) );
596
 
641
 
597
-/** Test 7.5 : Reseed */
598
-HMAC_DRBG_TEST_RESEED ( reseed_7_5,
642
+/** SHA-1 Test 7.5 : Reseed */
643
+HMAC_DRBG_TEST_RESEED ( sha1_reseed_7_5, HMAC_DRBG_SHA1,
599
 	entropy_input_2, additional_input_empty,
644
 	entropy_input_2, additional_input_empty,
600
 	EXPECT ( 0x02, 0xbc, 0x57, 0x7f, 0xd1, 0x0e, 0xf7, 0x19, 0x3c, 0x1d,
645
 	EXPECT ( 0x02, 0xbc, 0x57, 0x7f, 0xd1, 0x0e, 0xf7, 0x19, 0x3c, 0x1d,
601
 		 0xb0, 0x98, 0xbd, 0x5b, 0x75, 0xc7, 0xc4, 0xb6, 0x79, 0x59 ),
646
 		 0xb0, 0x98, 0xbd, 0x5b, 0x75, 0xc7, 0xc4, 0xb6, 0x79, 0x59 ),
602
 	EXPECT ( 0xbc, 0xbd, 0xf0, 0x52, 0xe0, 0xe0, 0x2a, 0xe8, 0x9a, 0x77,
647
 	EXPECT ( 0xbc, 0xbd, 0xf0, 0x52, 0xe0, 0xe0, 0x2a, 0xe8, 0x9a, 0x77,
603
 		 0x67, 0x94, 0x3f, 0x98, 0x65, 0xb8, 0xb7, 0x22, 0x90, 0x2d ) );
648
 		 0x67, 0x94, 0x3f, 0x98, 0x65, 0xb8, 0xb7, 0x22, 0x90, 0x2d ) );
604
 
649
 
605
-/** Test 7.6 : Retried second call to Generate */
606
-HMAC_DRBG_TEST_GENERATE ( generate_7_6,
650
+/** SHA-1 Test 7.6 : Retried second call to Generate */
651
+HMAC_DRBG_TEST_GENERATE ( sha1_generate_7_6, HMAC_DRBG_SHA1,
607
 	additional_input_empty,
652
 	additional_input_empty,
608
 	EXPECT ( 0x1a, 0xa4, 0x24, 0x1c, 0x69, 0x5e, 0x29, 0xc0, 0xa5, 0x9a,
653
 	EXPECT ( 0x1a, 0xa4, 0x24, 0x1c, 0x69, 0x5e, 0x29, 0xc0, 0xa5, 0x9a,
609
 		 0xd1, 0x8a, 0x60, 0x70, 0xe3, 0x38, 0xa5, 0x48, 0xbe, 0x92 ),
654
 		 0xd1, 0x8a, 0x60, 0x70, 0xe3, 0x38, 0xa5, 0x48, 0xbe, 0x92 ),
614
 		 0x61, 0x48, 0x2c, 0xa5, 0x4d, 0x5f, 0xa7, 0x23, 0xf4, 0xc8,
659
 		 0x61, 0x48, 0x2c, 0xa5, 0x4d, 0x5f, 0xa7, 0x23, 0xf4, 0xc8,
615
 		 0x8b, 0x4f, 0xa5, 0x04, 0xbf, 0x03, 0x27, 0x7f, 0xa7, 0x83 ) );
660
 		 0x8b, 0x4f, 0xa5, 0x04, 0xbf, 0x03, 0x27, 0x7f, 0xa7, 0x83 ) );
616
 
661
 
617
-/** Test 8 : Instantiate */
618
-#define instantiate_8 instantiate_3
662
+/** SHA-1 Test 8 : Instantiate */
663
+#define sha1_instantiate_8 sha1_instantiate_3
619
 
664
 
620
-/** Test 8.1 : First call to Generate */
621
-HMAC_DRBG_TEST_GENERATE_FAIL ( generate_fail_8_1,
665
+/** SHA-1 Test 8.1 : First call to Generate */
666
+HMAC_DRBG_TEST_GENERATE_FAIL ( sha1_generate_fail_8_1, HMAC_DRBG_SHA1,
622
 	additional_input_1, ( 320 / 8 ) );
667
 	additional_input_1, ( 320 / 8 ) );
623
 
668
 
624
-/** Test 8.2 : Reseed */
625
-HMAC_DRBG_TEST_RESEED ( reseed_8_2,
669
+/** SHA-1 Test 8.2 : Reseed */
670
+HMAC_DRBG_TEST_RESEED ( sha1_reseed_8_2, HMAC_DRBG_SHA1,
626
 	entropy_input_1, additional_input_1,
671
 	entropy_input_1, additional_input_1,
627
 	EXPECT ( 0xc0, 0x95, 0x48, 0xc0, 0xd3, 0xc8, 0x61, 0xd7, 0x40, 0xf2,
672
 	EXPECT ( 0xc0, 0x95, 0x48, 0xc0, 0xd3, 0xc8, 0x61, 0xd7, 0x40, 0xf2,
628
 		 0x83, 0x7d, 0x72, 0xb5, 0x07, 0x23, 0x5c, 0x26, 0xdb, 0x82 ),
673
 		 0x83, 0x7d, 0x72, 0xb5, 0x07, 0x23, 0x5c, 0x26, 0xdb, 0x82 ),
629
 	EXPECT ( 0x17, 0x4b, 0x3f, 0x84, 0xc3, 0x53, 0x1f, 0x7c, 0x0a, 0x2e,
674
 	EXPECT ( 0x17, 0x4b, 0x3f, 0x84, 0xc3, 0x53, 0x1f, 0x7c, 0x0a, 0x2e,
630
 		 0x54, 0x21, 0x23, 0x4e, 0xa1, 0x6b, 0x70, 0x8d, 0xdf, 0x0d ) );
675
 		 0x54, 0x21, 0x23, 0x4e, 0xa1, 0x6b, 0x70, 0x8d, 0xdf, 0x0d ) );
631
 
676
 
632
-/** Test 8.3 : Retried first call to Generate */
633
-HMAC_DRBG_TEST_GENERATE ( generate_8_3,
677
+/** SHA-1 Test 8.3 : Retried first call to Generate */
678
+HMAC_DRBG_TEST_GENERATE ( sha1_generate_8_3, HMAC_DRBG_SHA1,
634
 	additional_input_empty,
679
 	additional_input_empty,
635
 	EXPECT ( 0x60, 0x3f, 0x09, 0x49, 0x27, 0x9c, 0x70, 0xe8, 0xc6, 0x6c,
680
 	EXPECT ( 0x60, 0x3f, 0x09, 0x49, 0x27, 0x9c, 0x70, 0xe8, 0xc6, 0x6c,
636
 		 0x0f, 0x56, 0x37, 0xc0, 0xf3, 0x75, 0x60, 0x07, 0xe5, 0xac ),
681
 		 0x0f, 0x56, 0x37, 0xc0, 0xf3, 0x75, 0x60, 0x07, 0xe5, 0xac ),
641
 		 0x34, 0x71, 0xfd, 0xa5, 0x5c, 0x6d, 0xdd, 0x2c, 0x03, 0xef,
686
 		 0x34, 0x71, 0xfd, 0xa5, 0x5c, 0x6d, 0xdd, 0x2c, 0x03, 0xef,
642
 		 0xa3, 0xb9, 0x64, 0x3a, 0xb3, 0xbb, 0x22, 0xf6, 0xc9, 0xf2 ) );
687
 		 0xa3, 0xb9, 0x64, 0x3a, 0xb3, 0xbb, 0x22, 0xf6, 0xc9, 0xf2 ) );
643
 
688
 
644
-/** Test 8.4 : Second call to Generate */
645
-HMAC_DRBG_TEST_GENERATE_FAIL ( generate_fail_8_4,
689
+/** SHA-1 Test 8.4 : Second call to Generate */
690
+HMAC_DRBG_TEST_GENERATE_FAIL ( sha1_generate_fail_8_4, HMAC_DRBG_SHA1,
646
 	additional_input_2, ( 320 / 8 ) );
691
 	additional_input_2, ( 320 / 8 ) );
647
 
692
 
648
-/** Test 8.5 : Reseed */
649
-HMAC_DRBG_TEST_RESEED ( reseed_8_5,
693
+/** SHA-1 Test 8.5 : Reseed */
694
+HMAC_DRBG_TEST_RESEED ( sha1_reseed_8_5, HMAC_DRBG_SHA1,
650
 	entropy_input_2, additional_input_2,
695
 	entropy_input_2, additional_input_2,
651
 	EXPECT ( 0x89, 0x42, 0xa5, 0x4f, 0x34, 0x9e, 0x28, 0x1b, 0x84, 0xaa,
696
 	EXPECT ( 0x89, 0x42, 0xa5, 0x4f, 0x34, 0x9e, 0x28, 0x1b, 0x84, 0xaa,
652
 		 0x46, 0x95, 0x87, 0xfb, 0xdd, 0xaf, 0x9d, 0x11, 0x40, 0x82 ),
697
 		 0x46, 0x95, 0x87, 0xfb, 0xdd, 0xaf, 0x9d, 0x11, 0x40, 0x82 ),
653
 	EXPECT ( 0x07, 0x73, 0x0e, 0x3c, 0xbf, 0xfd, 0x3c, 0xaf, 0xd7, 0xa8,
698
 	EXPECT ( 0x07, 0x73, 0x0e, 0x3c, 0xbf, 0xfd, 0x3c, 0xaf, 0xd7, 0xa8,
654
 		 0xaa, 0xe2, 0xbf, 0x01, 0xd6, 0x01, 0x43, 0x01, 0xe2, 0x4d ) );
699
 		 0xaa, 0xe2, 0xbf, 0x01, 0xd6, 0x01, 0x43, 0x01, 0xe2, 0x4d ) );
655
 
700
 
656
-/** Test 8.6 : Retried second call to Generate */
657
-HMAC_DRBG_TEST_GENERATE ( generate_8_6,
701
+/** SHA-1 Test 8.6 : Retried second call to Generate */
702
+HMAC_DRBG_TEST_GENERATE ( sha1_generate_8_6, HMAC_DRBG_SHA1,
658
 	additional_input_empty,
703
 	additional_input_empty,
659
 	EXPECT ( 0xbd, 0xe1, 0xb4, 0x6c, 0xdc, 0x54, 0x13, 0xb3, 0xd9, 0xf7,
704
 	EXPECT ( 0xbd, 0xe1, 0xb4, 0x6c, 0xdc, 0x54, 0x13, 0xb3, 0xd9, 0xf7,
660
 		 0x35, 0xac, 0xdb, 0x80, 0xb1, 0x3c, 0x57, 0xbf, 0xe4, 0x73 ),
705
 		 0x35, 0xac, 0xdb, 0x80, 0xb1, 0x3c, 0x57, 0xbf, 0xe4, 0x73 ),
724
 	 * greater than the reseed_interval.
769
 	 * greater than the reseed_interval.
725
 	 */
770
 	 */
726
 
771
 
727
-	/* Test 1 */
728
-	instantiate_ok ( &state, &instantiate_1 );
729
-	generate_ok ( &state, &generate_1_1 );
730
-	generate_ok ( &state, &generate_1_2 );
772
+	/* SHA-1 Test 1 */
773
+	instantiate_ok ( &state, &sha1_instantiate_1 );
774
+	generate_ok ( &state, &sha1_generate_1_1 );
775
+	generate_ok ( &state, &sha1_generate_1_2 );
731
 
776
 
732
-	/* Test 2 */
733
-	instantiate_ok ( &state, &instantiate_2 );
734
-	generate_ok ( &state, &generate_2_1 );
735
-	generate_ok ( &state, &generate_2_2 );
777
+	/* SHA-1 Test 2 */
778
+	instantiate_ok ( &state, &sha1_instantiate_2 );
779
+	generate_ok ( &state, &sha1_generate_2_1 );
780
+	generate_ok ( &state, &sha1_generate_2_2 );
736
 
781
 
737
-	/* Test 3 */
738
-	instantiate_ok ( &state, &instantiate_3 );
739
-	generate_ok ( &state, &generate_3_1 );
740
-	generate_ok ( &state, &generate_3_2 );
782
+	/* SHA-1 Test 3 */
783
+	instantiate_ok ( &state, &sha1_instantiate_3 );
784
+	generate_ok ( &state, &sha1_generate_3_1 );
785
+	generate_ok ( &state, &sha1_generate_3_2 );
741
 
786
 
742
-	/* Test 4 */
743
-	instantiate_ok ( &state, &instantiate_4 );
744
-	generate_ok ( &state, &generate_4_1 );
745
-	generate_ok ( &state, &generate_4_2 );
787
+	/* SHA-1 Test 4 */
788
+	instantiate_ok ( &state, &sha1_instantiate_4 );
789
+	generate_ok ( &state, &sha1_generate_4_1 );
790
+	generate_ok ( &state, &sha1_generate_4_2 );
746
 
791
 
747
-	/* Test 5 */
748
-	instantiate_ok ( &state, &instantiate_5 );
792
+	/* SHA-1 Test 5 */
793
+	instantiate_ok ( &state, &sha1_instantiate_5 );
749
 	force_reseed_required ( &state ); /* See above comments */
794
 	force_reseed_required ( &state ); /* See above comments */
750
-	generate_fail_ok ( &state, &generate_fail_5_1 );
751
-	reseed_ok ( &state, &reseed_5_2 );
752
-	generate_ok ( &state, &generate_5_3 );
795
+	generate_fail_ok ( &state, &sha1_generate_fail_5_1 );
796
+	reseed_ok ( &state, &sha1_reseed_5_2 );
797
+	generate_ok ( &state, &sha1_generate_5_3 );
753
 	force_reseed_required ( &state ); /* See above comments */
798
 	force_reseed_required ( &state ); /* See above comments */
754
-	generate_fail_ok ( &state, &generate_fail_5_4 );
755
-	reseed_ok ( &state, &reseed_5_5 );
756
-	generate_ok ( &state, &generate_5_6 );
799
+	generate_fail_ok ( &state, &sha1_generate_fail_5_4 );
800
+	reseed_ok ( &state, &sha1_reseed_5_5 );
801
+	generate_ok ( &state, &sha1_generate_5_6 );
757
 
802
 
758
-	/* Test 6 */
759
-	instantiate_ok ( &state, &instantiate_6 );
803
+	/* SHA-1 Test 6 */
804
+	instantiate_ok ( &state, &sha1_instantiate_6 );
760
 	force_reseed_required ( &state ); /* See above comments */
805
 	force_reseed_required ( &state ); /* See above comments */
761
-	generate_fail_ok ( &state, &generate_fail_6_1 );
762
-	reseed_ok ( &state, &reseed_6_2 );
763
-	generate_ok ( &state, &generate_6_3 );
806
+	generate_fail_ok ( &state, &sha1_generate_fail_6_1 );
807
+	reseed_ok ( &state, &sha1_reseed_6_2 );
808
+	generate_ok ( &state, &sha1_generate_6_3 );
764
 	force_reseed_required ( &state ); /* See above comments */
809
 	force_reseed_required ( &state ); /* See above comments */
765
-	generate_fail_ok ( &state, &generate_fail_6_4 );
766
-	reseed_ok ( &state, &reseed_6_5 );
767
-	generate_ok ( &state, &generate_6_6 );
810
+	generate_fail_ok ( &state, &sha1_generate_fail_6_4 );
811
+	reseed_ok ( &state, &sha1_reseed_6_5 );
812
+	generate_ok ( &state, &sha1_generate_6_6 );
768
 
813
 
769
-	/* Test 7 */
770
-	instantiate_ok ( &state, &instantiate_7 );
814
+	/* SHA-1 Test 7 */
815
+	instantiate_ok ( &state, &sha1_instantiate_7 );
771
 	force_reseed_required ( &state ); /* See above comments */
816
 	force_reseed_required ( &state ); /* See above comments */
772
-	generate_fail_ok ( &state, &generate_fail_7_1 );
773
-	reseed_ok ( &state, &reseed_7_2 );
774
-	generate_ok ( &state, &generate_7_3 );
817
+	generate_fail_ok ( &state, &sha1_generate_fail_7_1 );
818
+	reseed_ok ( &state, &sha1_reseed_7_2 );
819
+	generate_ok ( &state, &sha1_generate_7_3 );
775
 	force_reseed_required ( &state ); /* See above comments */
820
 	force_reseed_required ( &state ); /* See above comments */
776
-	generate_fail_ok ( &state, &generate_fail_7_4 );
777
-	reseed_ok ( &state, &reseed_7_5 );
778
-	generate_ok ( &state, &generate_7_6 );
821
+	generate_fail_ok ( &state, &sha1_generate_fail_7_4 );
822
+	reseed_ok ( &state, &sha1_reseed_7_5 );
823
+	generate_ok ( &state, &sha1_generate_7_6 );
779
 
824
 
780
-	/* Test 8 */
781
-	instantiate_ok ( &state, &instantiate_8 );
825
+	/* SHA-1 Test 8 */
826
+	instantiate_ok ( &state, &sha1_instantiate_8 );
782
 	force_reseed_required ( &state ); /* See above comments */
827
 	force_reseed_required ( &state ); /* See above comments */
783
-	generate_fail_ok ( &state, &generate_fail_8_1 );
784
-	reseed_ok ( &state, &reseed_8_2 );
785
-	generate_ok ( &state, &generate_8_3 );
828
+	generate_fail_ok ( &state, &sha1_generate_fail_8_1 );
829
+	reseed_ok ( &state, &sha1_reseed_8_2 );
830
+	generate_ok ( &state, &sha1_generate_8_3 );
786
 	force_reseed_required ( &state ); /* See above comments */
831
 	force_reseed_required ( &state ); /* See above comments */
787
-	generate_fail_ok ( &state, &generate_fail_8_4 );
788
-	reseed_ok ( &state, &reseed_8_5 );
789
-	generate_ok ( &state, &generate_8_6 );
832
+	generate_fail_ok ( &state, &sha1_generate_fail_8_4 );
833
+	reseed_ok ( &state, &sha1_reseed_8_5 );
834
+	generate_ok ( &state, &sha1_generate_8_6 );
790
 }
835
 }
791
 
836
 
792
 /** HMAC_DRBG self-test */
837
 /** HMAC_DRBG self-test */

Loading…
Cancel
Save