Browse Source

[rng] Add NIST self-tests for HMAC_DRBG

NIST provides a set of known-answer tests for the HMAC_DRBG algorithm,
which can be used as part of the conformance testing for ANS X9.82.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
9ec80a3df1
2 changed files with 796 additions and 0 deletions
  1. 795
    0
      src/tests/hmac_drbg_test.c
  2. 1
    0
      src/tests/test.c

+ 795
- 0
src/tests/hmac_drbg_test.c View File

@@ -0,0 +1,795 @@
1
+/*
2
+ * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+FILE_LICENCE ( GPL2_OR_LATER );
20
+
21
+/** @file
22
+ *
23
+ * HMAC_DRBG tests
24
+ *
25
+ * These test vectors are provided by NIST as part of the
26
+ * Cryptographic Toolkit Examples, downloadable from:
27
+ *
28
+ *    http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/HMAC_DRBG.pdf
29
+ *
30
+ */
31
+
32
+/* Forcibly enable assertions */
33
+#undef NDEBUG
34
+
35
+#include <assert.h>
36
+#include <ipxe/hmac_drbg.h>
37
+#include <ipxe/test.h>
38
+
39
+/** Define inline expected data */
40
+#define EXPECT(...) { __VA_ARGS__ }
41
+
42
+/** An HMAC_DRBG instantiation test */
43
+struct hmac_drbg_test_instantiate {
44
+	/** Entropy (including nonce) */
45
+	const void *entropy;
46
+	/** Length of entropy (including nonce) */
47
+	size_t entropy_len;
48
+	/** Personalisation string */
49
+	const void *personal;
50
+	/** Length of personalisation string */
51
+	size_t personal_len;
52
+	/** Expected key */
53
+	const void *expected_key;
54
+	/** Length of expected key */
55
+	size_t expected_key_len;
56
+	/** Expected value */
57
+	const void *expected_value;
58
+	/** Length of expected value */
59
+	size_t expected_value_len;
60
+};
61
+
62
+/**
63
+ * Define an HMAC_DRBG instantiation test
64
+ *
65
+ * @v name		Test name
66
+ * @v entropy_array	Entropy input (including nonce)
67
+ * @v personal_array	Personalisation string
68
+ * @v key		Expected key
69
+ * @v value		Expected value
70
+ * @ret test		Instantiation test
71
+ */
72
+#define HMAC_DRBG_TEST_INSTANTIATE( name, entropy_array,		\
73
+				    personal_array, key, value )	\
74
+	static const uint8_t name ## _key [] = key;			\
75
+	static const uint8_t name ## _value [] = value;			\
76
+	static const struct hmac_drbg_test_instantiate name = {		\
77
+		.entropy = entropy_array,				\
78
+		.entropy_len = sizeof ( entropy_array ),		\
79
+		.personal = personal_array,				\
80
+		.personal_len = sizeof ( personal_array ),		\
81
+		.expected_key = name ## _key,				\
82
+		.expected_key_len = sizeof ( name ## _key ),		\
83
+		.expected_value = name ## _value,			\
84
+		.expected_value_len = sizeof ( name ## _value ),	\
85
+	}
86
+
87
+/**
88
+ * Report instantiation test result
89
+ *
90
+ * @v state		HMAC_DRBG internal state
91
+ * @v test		Instantiation test
92
+ */
93
+#define instantiate_ok( state, test ) do {				\
94
+	assert ( (test)->expected_key_len == HMAC_DRBG_OUTLEN_BYTES );	\
95
+	assert ( (test)->expected_value_len == HMAC_DRBG_OUTLEN_BYTES ); \
96
+	hmac_drbg_instantiate ( (state), (test)->entropy,		\
97
+				(test)->entropy_len, (test)->personal,	\
98
+				(test)->personal_len );			\
99
+	ok ( memcmp ( (state)->key, (test)->expected_key,		\
100
+		      sizeof ( (state)->key ) ) == 0 );			\
101
+	ok ( memcmp ( (state)->value, (test)->expected_value,		\
102
+		      sizeof ( (state)->value ) ) == 0 );		\
103
+	} while ( 0 )
104
+
105
+/** An HMAC_DRBG reseed test */
106
+struct hmac_drbg_test_reseed {
107
+	/** Entropy */
108
+	const void *entropy;
109
+	/** Length of entropy */
110
+	size_t entropy_len;
111
+	/** Additional input */
112
+	const void *additional;
113
+	/** Length of additional_input */
114
+	size_t additional_len;
115
+	/** Expected key */
116
+	const void *expected_key;
117
+	/** Length of expected key */
118
+	size_t expected_key_len;
119
+	/** Expected value */
120
+	const void *expected_value;
121
+	/** Length of expected value */
122
+	size_t expected_value_len;
123
+};
124
+
125
+/**
126
+ * Define an HMAC_DRBG reseed test
127
+ *
128
+ * @v name		Test name
129
+ * @v entropy_array	Entropy input
130
+ * @v additional_array	Additional input
131
+ * @v key		Expected key
132
+ * @v value		Expected value
133
+ * @ret test		Reseed test
134
+ */
135
+#define HMAC_DRBG_TEST_RESEED( name, entropy_array, additional_array,	\
136
+			       key, value )		\
137
+	static const uint8_t name ## _key [] = key;			\
138
+	static const uint8_t name ## _value [] = value;			\
139
+	static const struct hmac_drbg_test_reseed name = {		\
140
+		.entropy = entropy_array,				\
141
+		.entropy_len = sizeof ( entropy_array ),		\
142
+		.additional = additional_array,				\
143
+		.additional_len = sizeof ( additional_array ),		\
144
+		.expected_key = name ## _key,				\
145
+		.expected_key_len = sizeof ( name ## _key ),		\
146
+		.expected_value = name ## _value,			\
147
+		.expected_value_len = sizeof ( name ## _value ),	\
148
+	}
149
+
150
+/**
151
+ * Report reseed test result
152
+ *
153
+ * @v state		HMAC_DRBG internal state
154
+ * @v test		Reseed test
155
+ */
156
+#define reseed_ok( state, test ) do {					\
157
+	assert ( (test)->expected_key_len == HMAC_DRBG_OUTLEN_BYTES );	\
158
+	assert ( (test)->expected_value_len == HMAC_DRBG_OUTLEN_BYTES ); \
159
+	hmac_drbg_reseed ( (state), (test)->entropy,			\
160
+			   (test)->entropy_len, (test)->additional,	\
161
+			   (test)->additional_len );			\
162
+	ok ( memcmp ( (state)->key, (test)->expected_key,		\
163
+		      sizeof ( (state)->key ) ) == 0 );			\
164
+	ok ( memcmp ( (state)->value, (test)->expected_value,		\
165
+		      sizeof ( (state)->value ) ) == 0 );		\
166
+	} while ( 0 )
167
+
168
+/** An HMAC_DRBG generation test */
169
+struct hmac_drbg_test_generate {
170
+	/** Additional input */
171
+	const void *additional;
172
+	/** Length of additional_input */
173
+	size_t additional_len;
174
+	/** Expected key */
175
+	const void *expected_key;
176
+	/** Length of expected key */
177
+	size_t expected_key_len;
178
+	/** Expected value */
179
+	const void *expected_value;
180
+	/** Length of expected value */
181
+	size_t expected_value_len;
182
+	/** Expected pseudorandom data */
183
+	const void *expected_data;
184
+	/** Length of data */
185
+	size_t len;
186
+};
187
+
188
+/**
189
+ * Define an HMAC_DRBG generation test
190
+ *
191
+ * @v name		Test name
192
+ * @v additional_array	Additional input
193
+ * @v key		Expected key
194
+ * @v value		Expected value
195
+ * @v data		Expected pseudorandom data
196
+ * @ret test		Generation test
197
+ */
198
+#define HMAC_DRBG_TEST_GENERATE( name, additional_array, key, value,	\
199
+				 data )					\
200
+	static const uint8_t name ## _key [] = key;			\
201
+	static const uint8_t name ## _value [] = value;			\
202
+	static const uint8_t name ## _data [] = data;			\
203
+	static const struct hmac_drbg_test_generate name = {		\
204
+		.additional = additional_array,				\
205
+		.additional_len = sizeof ( additional_array ),		\
206
+		.expected_key = name ## _key,				\
207
+		.expected_key_len = sizeof ( name ## _key ),		\
208
+		.expected_value = name ## _value,			\
209
+		.expected_value_len = sizeof ( name ## _value ),	\
210
+		.expected_data = name ## _data,				\
211
+		.len = sizeof ( name ## _data ),			\
212
+	}
213
+
214
+/**
215
+ * Report generation test result
216
+ *
217
+ * @v state		HMAC_DRBG internal state
218
+ * @v test		Generation test
219
+ */
220
+#define generate_ok( state, test ) do {					\
221
+	uint8_t data[ (test)->len ];					\
222
+	int rc;								\
223
+									\
224
+	assert ( (test)->expected_key_len == HMAC_DRBG_OUTLEN_BYTES );	\
225
+	assert ( (test)->expected_value_len == HMAC_DRBG_OUTLEN_BYTES );\
226
+	rc = hmac_drbg_generate ( (state), (test)->additional,		\
227
+				  (test)->additional_len, data,		\
228
+				  sizeof ( data ) );			\
229
+	ok ( rc == 0 );							\
230
+	ok ( memcmp ( (state)->key, (test)->expected_key,		\
231
+		      sizeof ( (state)->key ) ) == 0 );			\
232
+	ok ( memcmp ( (state)->value, (test)->expected_value,		\
233
+		      sizeof ( (state)->value ) ) == 0 );		\
234
+	ok ( memcmp ( data, (test)->expected_data,			\
235
+		      sizeof ( data ) ) == 0 );				\
236
+	} while ( 0 )
237
+
238
+/** An HMAC_DRBG generation failure test */
239
+struct hmac_drbg_test_generate_fail {
240
+	/** Additional input */
241
+	const void *additional;
242
+	/** Length of additional_input */
243
+	size_t additional_len;
244
+	/** Length of requested data */
245
+	size_t requested_len;
246
+};
247
+
248
+/**
249
+ * Define an HMAC_DRBG generation failure test
250
+ *
251
+ * @v name		Test name
252
+ * @v additional_array	Additional input
253
+ * @ret test		Generation failure test
254
+ */
255
+#define HMAC_DRBG_TEST_GENERATE_FAIL( name, additional_array, len )	\
256
+	static const struct hmac_drbg_test_generate_fail name = {	\
257
+		.additional = additional_array,				\
258
+		.additional_len = sizeof ( additional_array ),		\
259
+		.requested_len = len,					\
260
+	}
261
+
262
+/**
263
+ * Report generation failure test result
264
+ *
265
+ * @v state		HMAC_DRBG internal state
266
+ * @v test		Generation failure test
267
+ */
268
+#define generate_fail_ok( state, test ) do {				\
269
+	uint8_t data[ (test)->requested_len ];				\
270
+	int rc;								\
271
+									\
272
+	rc = hmac_drbg_generate ( (state), (test)->additional,		\
273
+				  (test)->additional_len, data,		\
274
+				  sizeof ( data ) );			\
275
+	ok ( rc != 0 );							\
276
+	} while ( 0 )
277
+
278
+/** "EntropyInput" and "Nonce"
279
+ *
280
+ * These are pre-concatenated since our implementation expects to
281
+ * receive the nonce in the form of additional entropy.
282
+ */
283
+static const uint8_t entropy_input[] = {
284
+	/* "EntropyInput" */
285
+	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
286
+	0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
287
+	0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
288
+	0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
289
+	0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
290
+	/* "Nonce" */
291
+	0x20, 0x21, 0x22, 0x23, 0x24
292
+};
293
+
294
+/** "EntropyInput1 (for Reseed1) */
295
+static const uint8_t entropy_input_1[] = {
296
+	0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b,
297
+	0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
298
+	0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3,
299
+	0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
300
+	0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6
301
+};
302
+
303
+/** "EntropyInput2 (for Reseed2) */
304
+static const uint8_t entropy_input_2[] = {
305
+	0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,
306
+	0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
307
+	0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,
308
+	0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
309
+	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6
310
+};
311
+
312
+/** "PersonalizationString = <empty>" */
313
+static const uint8_t personalisation_string_empty[] = {};
314
+
315
+/** "PersonalizationString" */
316
+static const uint8_t personalisation_string[] = {
317
+	0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
318
+	0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
319
+	0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63,
320
+	0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
321
+	0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76
322
+};
323
+
324
+/** "AdditionalInput = <empty>" */
325
+static const uint8_t additional_input_empty[] = {};
326
+
327
+/** "AdditionalInput1" */
328
+static const uint8_t additional_input_1[] = {
329
+	0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
330
+	0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
331
+	0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,
332
+	0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
333
+	0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96
334
+};
335
+
336
+/** "AdditionalInput2" */
337
+static const uint8_t additional_input_2[] = {
338
+	0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab,
339
+	0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
340
+	0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3,
341
+	0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
342
+	0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6
343
+};
344
+
345
+/** Test 1 : Instantiation */
346
+HMAC_DRBG_TEST_INSTANTIATE ( instantiate_1,
347
+	entropy_input, personalisation_string_empty,
348
+	EXPECT ( 0xab, 0x16, 0x0d, 0xd2, 0x1c, 0x30, 0x98, 0x0c, 0xa3, 0xca,
349
+		 0x5a, 0x9c, 0x77, 0xb7, 0xbd, 0xf0, 0x50, 0xe6, 0x4e, 0xe9 ),
350
+	EXPECT ( 0x61, 0x44, 0x99, 0xea, 0x98, 0x0c, 0xfb, 0x3d, 0xaa, 0x2c,
351
+		 0xa8, 0x6d, 0x65, 0xa4, 0x6b, 0xf4, 0x48, 0x8d, 0x8c, 0xc5 ) );
352
+
353
+/** Test 1.1 : First call to Generate */
354
+HMAC_DRBG_TEST_GENERATE ( generate_1_1,
355
+	additional_input_empty,
356
+	EXPECT ( 0x7b, 0xb1, 0x80, 0x28, 0xe0, 0x1d, 0x03, 0x42, 0xdf, 0x4f,
357
+		 0x54, 0xda, 0x51, 0x22, 0xfa, 0x5f, 0x2c, 0x3a, 0x05, 0xe4 ),
358
+	EXPECT ( 0x2f, 0x89, 0x4f, 0x28, 0xcc, 0x2f, 0x53, 0x82, 0x96, 0x40,
359
+		 0x64, 0x3a, 0xd1, 0x7b, 0x84, 0xb0, 0xcd, 0x3c, 0x79, 0x79 ),
360
+	EXPECT ( 0x5a, 0x7d, 0x3b, 0x44, 0x9f, 0x48, 0x1c, 0xb3, 0x8d, 0xf7,
361
+		 0x9a, 0xd2, 0xb1, 0xfc, 0xc0, 0x1e, 0x57, 0xf8, 0x13, 0x5e,
362
+		 0x8c, 0x0b, 0x22, 0xcd, 0x06, 0x30, 0xbf, 0xb0, 0x12, 0x7f,
363
+		 0xb5, 0x40, 0x8c, 0x8e, 0xfc, 0x17, 0xa9, 0x29, 0x89, 0x6e ) );
364
+
365
+/** Test 1.2 : Second call to Generate */
366
+HMAC_DRBG_TEST_GENERATE ( generate_1_2,
367
+	additional_input_empty,
368
+	EXPECT ( 0x3d, 0x4d, 0x73, 0x77, 0xe9, 0x17, 0x2a, 0xaf, 0xa7, 0x76,
369
+		 0xb0, 0xdd, 0xcb, 0x89, 0x42, 0x00, 0x4a, 0x44, 0xb7, 0xfd ),
370
+	EXPECT ( 0x1a, 0x26, 0xbd, 0x9b, 0xfc, 0x97, 0x44, 0xbd, 0x29, 0xf6,
371
+		 0xae, 0xbe, 0x24, 0x37, 0xe2, 0x09, 0xf1, 0xf7, 0x16, 0x25 ),
372
+	EXPECT ( 0x82, 0xcf, 0x77, 0x2e, 0xc3, 0xe8, 0x4b, 0x00, 0xfc, 0x74,
373
+		 0xf5, 0xdf, 0x10, 0x4e, 0xfb, 0xfb, 0x24, 0x28, 0x55, 0x4e,
374
+		 0x9c, 0xe3, 0x67, 0xd0, 0x3a, 0xea, 0xde, 0x37, 0x82, 0x7f,
375
+		 0xa8, 0xe9, 0xcb, 0x6a, 0x08, 0x19, 0x61, 0x15, 0xd9, 0x48 ) );
376
+
377
+/** Test 2 : Instantiation */
378
+#define instantiate_2 instantiate_1
379
+
380
+/** Test 2.1 : First call to Generate */
381
+HMAC_DRBG_TEST_GENERATE ( generate_2_1,
382
+	additional_input_1,
383
+	EXPECT ( 0x3a, 0x06, 0x2e, 0x6b, 0x79, 0xfe, 0x70, 0xdb, 0xff, 0xeb,
384
+		 0x3a, 0x2b, 0x6b, 0xe8, 0x03, 0x23, 0xf7, 0xd6, 0x74, 0xc5 ),
385
+	EXPECT ( 0xbd, 0x36, 0x31, 0x28, 0xbf, 0x58, 0x0d, 0x7a, 0x54, 0x42,
386
+		 0x9d, 0xdd, 0x58, 0xe8, 0x19, 0x3b, 0x98, 0x43, 0xbd, 0x2b ),
387
+	EXPECT ( 0xc7, 0xaa, 0xac, 0x58, 0x3c, 0x6e, 0xf6, 0x30, 0x07, 0x14,
388
+		 0xc2, 0xcc, 0x5d, 0x06, 0xc1, 0x48, 0xcf, 0xfb, 0x40, 0x44,
389
+		 0x9a, 0xd0, 0xbb, 0x26, 0xfa, 0xc0, 0x49, 0x7b, 0x5c, 0x57,
390
+		 0xe1, 0x61, 0xe3, 0x66, 0x81, 0xbc, 0xc9, 0x30, 0xce, 0x80 ) );
391
+
392
+/** Test 2.2 : Second call to Generate */
393
+HMAC_DRBG_TEST_GENERATE ( generate_2_2,
394
+	additional_input_2,
395
+	EXPECT ( 0x8a, 0xd7, 0xe3, 0x47, 0x72, 0xb5, 0xfc, 0x7c, 0x3b, 0x3b,
396
+		 0x27, 0x62, 0x4f, 0x0b, 0x91, 0x77, 0x6a, 0x8a, 0x71, 0x12 ),
397
+	EXPECT ( 0xd7, 0x13, 0x76, 0xa4, 0x6d, 0x76, 0x4b, 0x17, 0xc3, 0xb7,
398
+		 0x39, 0x34, 0x7b, 0x38, 0x4e, 0x51, 0x51, 0xe8, 0x7e, 0x88 ),
399
+	EXPECT ( 0x6e, 0xbd, 0x2b, 0x7b, 0x5e, 0x0a, 0x2a, 0xd7, 0xa2, 0x4b,
400
+		 0x1b, 0xf9, 0xa1, 0xdb, 0xa4, 0x7d, 0x43, 0x27, 0x17, 0x19,
401
+		 0xb9, 0xc3, 0x7b, 0x7f, 0xe8, 0x1b, 0xa9, 0x40, 0x45, 0xa1,
402
+		 0x4a, 0x7c, 0xb5, 0x14, 0xb4, 0x46, 0x66, 0x6e, 0xa5, 0xa7 ) );
403
+
404
+/** Test 3 : Instantiation */
405
+HMAC_DRBG_TEST_INSTANTIATE ( instantiate_3,
406
+	entropy_input, personalisation_string,
407
+	EXPECT ( 0xb7, 0xd9, 0x66, 0xd7, 0x0d, 0x4e, 0x27, 0xa7, 0xfa, 0x83,
408
+		 0x8f, 0x7d, 0x61, 0x12, 0x6c, 0x0e, 0xdc, 0x84, 0x76, 0x1c ),
409
+	EXPECT ( 0xda, 0xb2, 0xa7, 0x18, 0x83, 0xf1, 0x00, 0x5c, 0x5d, 0xd0,
410
+		 0x39, 0x32, 0x4d, 0x3c, 0x36, 0x4d, 0x6e, 0x18, 0xf9, 0x54 ) );
411
+
412
+/** Test 3.1 : First call to Generate */
413
+HMAC_DRBG_TEST_GENERATE ( generate_3_1,
414
+	additional_input_empty,
415
+	EXPECT ( 0x87, 0xd3, 0x82, 0x8b, 0xe0, 0x3a, 0x80, 0x7d, 0xd3, 0x40,
416
+		 0x29, 0x41, 0xbe, 0xd6, 0xde, 0x98, 0x6e, 0xe7, 0xa2, 0x86 ),
417
+	EXPECT ( 0x6a, 0xe1, 0xd0, 0x08, 0x6f, 0x53, 0xb1, 0xb7, 0x63, 0xa4,
418
+		 0x51, 0x5b, 0x19, 0x06, 0xfe, 0xe4, 0x76, 0x61, 0xfd, 0x47 ),
419
+	EXPECT ( 0xb3, 0xbd, 0x05, 0x24, 0x6c, 0xba, 0x12, 0xa6, 0x47, 0x35,
420
+		 0xa4, 0xe3, 0xfd, 0xe5, 0x99, 0xbc, 0x1b, 0xe3, 0x0f, 0x43,
421
+		 0x9b, 0xd0, 0x60, 0x20, 0x8e, 0xea, 0x7d, 0x71, 0xf9, 0xd1,
422
+		 0x23, 0xdf, 0x47, 0xb3, 0xce, 0x06, 0x9d, 0x98, 0xed, 0xe6 ) );
423
+
424
+/** Test 3.2 : Second call to Generate */
425
+HMAC_DRBG_TEST_GENERATE ( generate_3_2,
426
+	additional_input_empty,
427
+	EXPECT ( 0x26, 0xab, 0xbf, 0x54, 0xb2, 0x8b, 0x93, 0xff, 0x90, 0x08,
428
+		 0x67, 0x0e, 0xbf, 0xee, 0x86, 0xcd, 0xd7, 0x22, 0x8e, 0xd5 ),
429
+	EXPECT ( 0xe9, 0x25, 0x47, 0x29, 0xe0, 0x02, 0x04, 0xa1, 0xb6, 0xc0,
430
+		 0x21, 0x58, 0xa6, 0xc7, 0x27, 0x86, 0x47, 0x14, 0xf1, 0xf7 ),
431
+	EXPECT ( 0xb5, 0xda, 0xda, 0x38, 0x0e, 0x28, 0x72, 0xdf, 0x93, 0x5b,
432
+		 0xca, 0x55, 0xb8, 0x82, 0xc8, 0xc9, 0x37, 0x69, 0x02, 0xab,
433
+		 0x63, 0x97, 0x65, 0x47, 0x2b, 0x71, 0xac, 0xeb, 0xe2, 0xea,
434
+		 0x8b, 0x1b, 0x6b, 0x49, 0x62, 0x9c, 0xb6, 0x73, 0x17, 0xe0 ) );
435
+
436
+/** Test 4 : Instantiation */
437
+#define instantiate_4 instantiate_3
438
+
439
+/** Test 4.1 : First call to Generate */
440
+HMAC_DRBG_TEST_GENERATE ( generate_4_1,
441
+	additional_input_1,
442
+	EXPECT ( 0x17, 0xa5, 0xd7, 0x9f, 0x07, 0x67, 0x87, 0x6f, 0x3a, 0x45,
443
+		 0xe0, 0xc9, 0xc3, 0x3e, 0xc8, 0x8b, 0x03, 0xce, 0xea, 0x13 ),
444
+	EXPECT ( 0x4d, 0x2f, 0x3b, 0xc7, 0x77, 0x50, 0x5c, 0x45, 0xf7, 0xe1,
445
+		 0x7d, 0xcd, 0x3d, 0x86, 0xbf, 0x37, 0x9c, 0xb6, 0x02, 0x5e ),
446
+	EXPECT ( 0x1f, 0x8f, 0xec, 0x7b, 0xc7, 0xcf, 0xa9, 0xa8, 0x80, 0x34,
447
+		 0x5d, 0x28, 0x0b, 0x13, 0xc6, 0x32, 0xb8, 0x52, 0x77, 0x0a,
448
+		 0x6d, 0xfc, 0x30, 0x2e, 0xad, 0x4c, 0xe3, 0xf5, 0x54, 0xc7,
449
+		 0x9b, 0x0d, 0x44, 0x23, 0x9e, 0xba, 0x56, 0xa7, 0xea, 0x2d ) );
450
+
451
+/** Test 4.2 : Second call to Generate */
452
+HMAC_DRBG_TEST_GENERATE ( generate_4_2,
453
+	additional_input_2,
454
+	EXPECT ( 0x07, 0x9b, 0x57, 0xd9, 0x40, 0x6e, 0x11, 0xc2, 0xf8, 0x7c,
455
+		 0x8c, 0x82, 0x8c, 0x8c, 0x6f, 0xa7, 0x6e, 0x40, 0xea, 0x01 ),
456
+	EXPECT ( 0xa6, 0x54, 0xfe, 0x72, 0xf8, 0xa7, 0x7b, 0xb8, 0xf0, 0x3d,
457
+		 0xff, 0x07, 0xc7, 0x9a, 0x51, 0x53, 0x00, 0x9e, 0xdd, 0xda ),
458
+	EXPECT ( 0xaf, 0x97, 0xcd, 0xe1, 0xe8, 0xab, 0x32, 0x2a, 0x2e, 0xac,
459
+		 0xa8, 0xe6, 0xf4, 0xe5, 0xbf, 0x78, 0xa1, 0x1b, 0xde, 0xf7,
460
+		 0xdc, 0x91, 0x21, 0x5d, 0x44, 0xb1, 0x07, 0xb4, 0xd5, 0xa7,
461
+		 0x79, 0x01, 0x59, 0x25, 0x09, 0x76, 0x52, 0x80, 0xf9, 0x69 ) );
462
+
463
+/** Test 5 : Instantiation */
464
+#define instantiate_5 instantiate_1
465
+
466
+/** Test 5.1 : First call to Generate */
467
+HMAC_DRBG_TEST_GENERATE_FAIL ( generate_fail_5_1,
468
+	additional_input_empty, ( 320 / 8 ) );
469
+
470
+/** Test 5.2 : Reseed */
471
+HMAC_DRBG_TEST_RESEED ( reseed_5_2,
472
+	entropy_input_1, additional_input_empty,
473
+	EXPECT ( 0xcd, 0x4c, 0xab, 0x38, 0xc8, 0xad, 0x65, 0x71, 0x22, 0xbf,
474
+		 0x5d, 0x3d, 0x00, 0xd0, 0xac, 0x9b, 0x13, 0xd6, 0x29, 0xbb ),
475
+	EXPECT ( 0xf6, 0x60, 0xe2, 0x3e, 0x91, 0x00, 0x6b, 0x62, 0xc6, 0x54,
476
+		 0x3a, 0xb1, 0x34, 0x4d, 0x23, 0xa3, 0x1a, 0xb4, 0xcf, 0x2c ) );
477
+
478
+/** Test 5.3 : Retried first call to Generate */
479
+HMAC_DRBG_TEST_GENERATE ( generate_5_3,
480
+	additional_input_empty,
481
+	EXPECT ( 0x58, 0x7f, 0xd8, 0x21, 0xef, 0x6c, 0x9d, 0xa4, 0xa8, 0x3c,
482
+		 0x19, 0x21, 0x1f, 0x10, 0x56, 0xca, 0xcd, 0x23, 0xfc, 0x1a ),
483
+	EXPECT ( 0x84, 0x8f, 0xd1, 0x4c, 0x13, 0xb7, 0xea, 0x93, 0x72, 0x0c,
484
+		 0xcf, 0xde, 0x71, 0xf2, 0xf6, 0x44, 0x39, 0xdb, 0x79, 0x5d ),
485
+	EXPECT ( 0xfe, 0xc4, 0x59, 0x7f, 0x06, 0xa3, 0xa8, 0xcc, 0x85, 0x29,
486
+		 0xd5, 0x95, 0x57, 0xb9, 0xe6, 0x61, 0x05, 0x38, 0x09, 0xc0,
487
+		 0xbc, 0x0e, 0xfc, 0x28, 0x2a, 0xbd, 0x87, 0x60, 0x5c, 0xc9,
488
+		 0x0c, 0xba, 0x9b, 0x86, 0x33, 0xdc, 0xb1, 0xda, 0xe0, 0x2e ) );
489
+
490
+/** Test 5.4 : Second call to Generate */
491
+HMAC_DRBG_TEST_GENERATE_FAIL ( generate_fail_5_4,
492
+	additional_input_empty, ( 320 / 8 ) );
493
+
494
+/** Test 5.5 : Reseed */
495
+HMAC_DRBG_TEST_RESEED ( reseed_5_5,
496
+	entropy_input_2, additional_input_empty,
497
+	EXPECT ( 0xdb, 0xa1, 0xcf, 0xf4, 0x87, 0x95, 0x46, 0xa0, 0x38, 0xa5,
498
+		 0x59, 0xb2, 0xa2, 0x4d, 0xf2, 0xc0, 0x30, 0x08, 0x9a, 0x41 ),
499
+	EXPECT ( 0x2f, 0x88, 0x3c, 0x46, 0x48, 0xe1, 0x31, 0xe8, 0x6d, 0xdf,
500
+		 0x9d, 0xca, 0x0d, 0x74, 0xf3, 0x0c, 0xa1, 0xce, 0x6e, 0xfb ) );
501
+
502
+/** Test 5.6 : Retried second call to Generate */
503
+HMAC_DRBG_TEST_GENERATE ( generate_5_6,
504
+	additional_input_empty,
505
+	EXPECT ( 0xf9, 0x39, 0xa5, 0xab, 0x08, 0xa3, 0x9f, 0x23, 0x10, 0x70,
506
+		 0xb0, 0xd4, 0xc9, 0x6d, 0xc2, 0x37, 0x90, 0xba, 0x01, 0x53 ),
507
+	EXPECT ( 0xce, 0x6d, 0x08, 0xb4, 0xae, 0x2c, 0xe3, 0x83, 0xfd, 0xab,
508
+		 0xb0, 0x1e, 0xaa, 0xfc, 0x9c, 0x8e, 0x76, 0xa0, 0xd4, 0x72 ),
509
+	EXPECT ( 0x84, 0xad, 0xd5, 0xe2, 0xd2, 0x04, 0x1c, 0x01, 0x72, 0x3a,
510
+		 0x4d, 0xe4, 0x33, 0x5b, 0x13, 0xef, 0xdf, 0x16, 0xb0, 0xe5,
511
+		 0x1a, 0x0a, 0xd3, 0x9b, 0xd1, 0x5e, 0x86, 0x2e, 0x64, 0x4f,
512
+		 0x31, 0xe4, 0xa2, 0xd7, 0xd8, 0x43, 0xe5, 0x7c, 0x59, 0x68 ) );
513
+
514
+/** Test 6 : Instantiate */
515
+#define instantiate_6 instantiate_1
516
+
517
+/** Test 6.1 : First call to Generate */
518
+HMAC_DRBG_TEST_GENERATE_FAIL ( generate_fail_6_1,
519
+	additional_input_1, ( 320 / 8 ) );
520
+
521
+/** Test 6.2 : Reseed */
522
+HMAC_DRBG_TEST_RESEED ( reseed_6_2,
523
+	entropy_input_1, additional_input_1,
524
+	EXPECT ( 0x52, 0x28, 0xa4, 0xb6, 0xa4, 0x46, 0x92, 0x90, 0x5e, 0xc0,
525
+		 0x44, 0xbf, 0xf0, 0xbb, 0x4e, 0x25, 0xa3, 0x87, 0xca, 0xc1 ),
526
+	EXPECT ( 0x24, 0x77, 0x32, 0xd0, 0x4c, 0xb8, 0x4e, 0xd4, 0x1a, 0xdd,
527
+		 0x95, 0xa4, 0xb7, 0x8b, 0x50, 0xcd, 0x9b, 0x3d, 0x3f, 0x32 ) );
528
+
529
+/** Test 6.3 : Retried first call to Generate */
530
+HMAC_DRBG_TEST_GENERATE ( generate_6_3,
531
+	additional_input_empty,
532
+	EXPECT ( 0xab, 0x3d, 0xd4, 0x89, 0x5b, 0xc8, 0xcd, 0x22, 0x71, 0xde,
533
+		 0xba, 0x5f, 0x3c, 0x13, 0x63, 0x52, 0x6b, 0x8b, 0x74, 0x52 ),
534
+	EXPECT ( 0xa8, 0x66, 0xc5, 0xef, 0xf2, 0xaf, 0x04, 0x2b, 0x11, 0x86,
535
+		 0x44, 0x94, 0x45, 0x23, 0x7f, 0x9c, 0x02, 0x44, 0x98, 0x64 ),
536
+	EXPECT ( 0xa1, 0xba, 0x8f, 0xa5, 0x8b, 0xb5, 0x01, 0x3f, 0x43, 0xf7,
537
+		 0xb6, 0xed, 0x52, 0xb4, 0x53, 0x9f, 0xa1, 0x6d, 0xc7, 0x79,
538
+		 0x57, 0xae, 0xe8, 0x15, 0xb9, 0xc0, 0x70, 0x04, 0xc7, 0xe9,
539
+		 0x92, 0xeb, 0x8c, 0x7e, 0x59, 0x19, 0x64, 0xaf, 0xee, 0xa2 ) );
540
+
541
+/** Test 6.4 : Second call to Generate */
542
+HMAC_DRBG_TEST_GENERATE_FAIL ( generate_fail_6_4,
543
+	additional_input_2, ( 320 / 8 ) );
544
+
545
+/** Test 6.5 : Reseed */
546
+HMAC_DRBG_TEST_RESEED ( reseed_6_5,
547
+	entropy_input_2, additional_input_2,
548
+	EXPECT ( 0xe5, 0x73, 0x9f, 0x9c, 0xf7, 0xff, 0x43, 0x84, 0xd1, 0x27,
549
+		 0x3e, 0x02, 0x6b, 0x45, 0x31, 0x21, 0x36, 0x49, 0x4f, 0x41 ),
550
+	EXPECT ( 0x30, 0xc3, 0x43, 0x05, 0xc2, 0xc6, 0x48, 0xb0, 0x57, 0xa6,
551
+		 0x40, 0x22, 0x1b, 0x5c, 0x56, 0x57, 0x26, 0xcd, 0x32, 0xb2 ) );
552
+
553
+/** Test 6.6 : Retried second call to Generate */
554
+HMAC_DRBG_TEST_GENERATE ( generate_6_6,
555
+	additional_input_empty,
556
+	EXPECT ( 0x61, 0x91, 0xca, 0x9b, 0xf0, 0x00, 0xd1, 0x0a, 0x71, 0x69,
557
+		 0x0a, 0xc1, 0x0e, 0x09, 0xff, 0xc8, 0x92, 0xab, 0xde, 0x9a ),
558
+	EXPECT ( 0x1e, 0xc0, 0x49, 0x0f, 0xa0, 0xb7, 0x65, 0x52, 0x7e, 0x5e,
559
+		 0xa1, 0x8b, 0x53, 0x22, 0xb2, 0x8b, 0xdd, 0x0e, 0x7b, 0xc0 ),
560
+	EXPECT ( 0x84, 0x26, 0x4a, 0x73, 0xa8, 0x18, 0xc9, 0x5c, 0x2f, 0x42,
561
+		 0x4b, 0x37, 0xd3, 0xcc, 0x99, 0x0b, 0x04, 0x6f, 0xb5, 0x0c,
562
+		 0x2d, 0xc6, 0x4a, 0x16, 0x42, 0x11, 0x88, 0x9a, 0x01, 0x0f,
563
+		 0x24, 0x71, 0xa0, 0x91, 0x2f, 0xfe, 0xa1, 0xbf, 0x01, 0x95 ) );
564
+
565
+/** Test 7 : Instantiation */
566
+#define instantiate_7 instantiate_3
567
+
568
+/** Test 7.1 : First call to Generate */
569
+HMAC_DRBG_TEST_GENERATE_FAIL ( generate_fail_7_1,
570
+	additional_input_empty, ( 320 / 8 ) );
571
+
572
+/** Test 7.2 : Reseed */
573
+HMAC_DRBG_TEST_RESEED ( reseed_7_2,
574
+	entropy_input_1, additional_input_empty,
575
+	EXPECT ( 0xb9, 0x25, 0x4d, 0x8a, 0xac, 0xba, 0x43, 0xfb, 0xda, 0xe6,
576
+		 0x39, 0x4f, 0x2b, 0x3a, 0xfc, 0x5d, 0x58, 0x08, 0x00, 0xbf ),
577
+	EXPECT ( 0x28, 0x40, 0x3b, 0x60, 0x36, 0x38, 0xd0, 0x7d, 0x79, 0x66,
578
+		 0x66, 0x1e, 0xf6, 0x7b, 0x9d, 0x39, 0x05, 0xf4, 0x6d, 0xb9 ) );
579
+
580
+/** Test 7.3 : Retried first call to Generate */
581
+HMAC_DRBG_TEST_GENERATE ( generate_7_3,
582
+	additional_input_empty,
583
+	EXPECT ( 0x64, 0xfe, 0x07, 0x4a, 0x6e, 0x77, 0x97, 0xd1, 0xa4, 0x35,
584
+		 0xda, 0x89, 0x64, 0x48, 0x4d, 0x6c, 0xf8, 0xbd, 0xc0, 0x1b ),
585
+	EXPECT ( 0x43, 0xe0, 0xc0, 0x52, 0x15, 0x86, 0xe9, 0x47, 0x3b, 0x06,
586
+		 0x0d, 0x87, 0xd0, 0x8a, 0x23, 0x25, 0xfa, 0xe1, 0x49, 0xd1 ),
587
+	EXPECT ( 0x6c, 0x37, 0xfd, 0xd7, 0x29, 0xaa, 0x40, 0xf8, 0x0b, 0xc6,
588
+		 0xab, 0x08, 0xca, 0x7c, 0xc6, 0x49, 0x79, 0x4f, 0x69, 0x98,
589
+		 0xb5, 0x70, 0x81, 0xe4, 0x22, 0x0f, 0x22, 0xc5, 0xc2, 0x83,
590
+		 0xe2, 0xc9, 0x1b, 0x8e, 0x30, 0x5a, 0xb8, 0x69, 0xc6, 0x25 ) );
591
+
592
+/** Test 7.4 : Second call to Generate */
593
+HMAC_DRBG_TEST_GENERATE_FAIL ( generate_fail_7_4,
594
+	additional_input_empty, ( 320 / 8 ) );
595
+
596
+/** Test 7.5 : Reseed */
597
+HMAC_DRBG_TEST_RESEED ( reseed_7_5,
598
+	entropy_input_2, additional_input_empty,
599
+	EXPECT ( 0x02, 0xbc, 0x57, 0x7f, 0xd1, 0x0e, 0xf7, 0x19, 0x3c, 0x1d,
600
+		 0xb0, 0x98, 0xbd, 0x5b, 0x75, 0xc7, 0xc4, 0xb6, 0x79, 0x59 ),
601
+	EXPECT ( 0xbc, 0xbd, 0xf0, 0x52, 0xe0, 0xe0, 0x2a, 0xe8, 0x9a, 0x77,
602
+		 0x67, 0x94, 0x3f, 0x98, 0x65, 0xb8, 0xb7, 0x22, 0x90, 0x2d ) );
603
+
604
+/** Test 7.6 : Retried second call to Generate */
605
+HMAC_DRBG_TEST_GENERATE ( generate_7_6,
606
+	additional_input_empty,
607
+	EXPECT ( 0x1a, 0xa4, 0x24, 0x1c, 0x69, 0x5e, 0x29, 0xc0, 0xa5, 0x9a,
608
+		 0xd1, 0x8a, 0x60, 0x70, 0xe3, 0x38, 0xa5, 0x48, 0xbe, 0x92 ),
609
+	EXPECT ( 0x03, 0x47, 0x35, 0x9b, 0xc9, 0xc7, 0xf8, 0x8c, 0xc8, 0x33,
610
+		 0x0d, 0x4f, 0x59, 0xfb, 0xc7, 0x70, 0xb0, 0xb7, 0x7b, 0x03 ),
611
+	EXPECT ( 0xca, 0xf5, 0x7d, 0xcf, 0xea, 0x39, 0x3b, 0x92, 0x36, 0xbf,
612
+		 0x69, 0x1f, 0xa4, 0x56, 0xfe, 0xa7, 0xfd, 0xf1, 0xdf, 0x83,
613
+		 0x61, 0x48, 0x2c, 0xa5, 0x4d, 0x5f, 0xa7, 0x23, 0xf4, 0xc8,
614
+		 0x8b, 0x4f, 0xa5, 0x04, 0xbf, 0x03, 0x27, 0x7f, 0xa7, 0x83 ) );
615
+
616
+/** Test 8 : Instantiate */
617
+#define instantiate_8 instantiate_3
618
+
619
+/** Test 8.1 : First call to Generate */
620
+HMAC_DRBG_TEST_GENERATE_FAIL ( generate_fail_8_1,
621
+	additional_input_1, ( 320 / 8 ) );
622
+
623
+/** Test 8.2 : Reseed */
624
+HMAC_DRBG_TEST_RESEED ( reseed_8_2,
625
+	entropy_input_1, additional_input_1,
626
+	EXPECT ( 0xc0, 0x95, 0x48, 0xc0, 0xd3, 0xc8, 0x61, 0xd7, 0x40, 0xf2,
627
+		 0x83, 0x7d, 0x72, 0xb5, 0x07, 0x23, 0x5c, 0x26, 0xdb, 0x82 ),
628
+	EXPECT ( 0x17, 0x4b, 0x3f, 0x84, 0xc3, 0x53, 0x1f, 0x7c, 0x0a, 0x2e,
629
+		 0x54, 0x21, 0x23, 0x4e, 0xa1, 0x6b, 0x70, 0x8d, 0xdf, 0x0d ) );
630
+
631
+/** Test 8.3 : Retried first call to Generate */
632
+HMAC_DRBG_TEST_GENERATE ( generate_8_3,
633
+	additional_input_empty,
634
+	EXPECT ( 0x60, 0x3f, 0x09, 0x49, 0x27, 0x9c, 0x70, 0xe8, 0xc6, 0x6c,
635
+		 0x0f, 0x56, 0x37, 0xc0, 0xf3, 0x75, 0x60, 0x07, 0xe5, 0xac ),
636
+	EXPECT ( 0xf2, 0xb3, 0x3b, 0x21, 0x15, 0x1f, 0xaf, 0x61, 0x20, 0x01,
637
+		 0x83, 0x10, 0xf4, 0x4e, 0x4c, 0xd0, 0xbf, 0xe3, 0x68, 0xea ),
638
+	EXPECT ( 0xbd, 0x07, 0xc2, 0x5c, 0xfd, 0x7c, 0x5e, 0x3a, 0x4e, 0xaa,
639
+		 0x6e, 0x2e, 0xdc, 0x5a, 0xb7, 0xea, 0x49, 0x42, 0xa0, 0x91,
640
+		 0x34, 0x71, 0xfd, 0xa5, 0x5c, 0x6d, 0xdd, 0x2c, 0x03, 0xef,
641
+		 0xa3, 0xb9, 0x64, 0x3a, 0xb3, 0xbb, 0x22, 0xf6, 0xc9, 0xf2 ) );
642
+
643
+/** Test 8.4 : Second call to Generate */
644
+HMAC_DRBG_TEST_GENERATE_FAIL ( generate_fail_8_4,
645
+	additional_input_2, ( 320 / 8 ) );
646
+
647
+/** Test 8.5 : Reseed */
648
+HMAC_DRBG_TEST_RESEED ( reseed_8_5,
649
+	entropy_input_2, additional_input_2,
650
+	EXPECT ( 0x89, 0x42, 0xa5, 0x4f, 0x34, 0x9e, 0x28, 0x1b, 0x84, 0xaa,
651
+		 0x46, 0x95, 0x87, 0xfb, 0xdd, 0xaf, 0x9d, 0x11, 0x40, 0x82 ),
652
+	EXPECT ( 0x07, 0x73, 0x0e, 0x3c, 0xbf, 0xfd, 0x3c, 0xaf, 0xd7, 0xa8,
653
+		 0xaa, 0xe2, 0xbf, 0x01, 0xd6, 0x01, 0x43, 0x01, 0xe2, 0x4d ) );
654
+
655
+/** Test 8.6 : Retried second call to Generate */
656
+HMAC_DRBG_TEST_GENERATE ( generate_8_6,
657
+	additional_input_empty,
658
+	EXPECT ( 0xbd, 0xe1, 0xb4, 0x6c, 0xdc, 0x54, 0x13, 0xb3, 0xd9, 0xf7,
659
+		 0x35, 0xac, 0xdb, 0x80, 0xb1, 0x3c, 0x57, 0xbf, 0xe4, 0x73 ),
660
+	EXPECT ( 0x72, 0x5a, 0x3c, 0x78, 0x20, 0xde, 0x1a, 0x06, 0xd0, 0x95,
661
+		 0x81, 0x9c, 0xcf, 0x6f, 0x2c, 0x9b, 0x3a, 0x67, 0xf2, 0xce ),
662
+	EXPECT ( 0xd1, 0xa9, 0xc1, 0xa2, 0x2c, 0x84, 0xfc, 0x23, 0xff, 0x22,
663
+		 0x27, 0xef, 0x98, 0xec, 0x8b, 0xa9, 0xdf, 0x2a, 0x20, 0x9b,
664
+		 0xa1, 0xdb, 0x09, 0x80, 0x9f, 0x57, 0xbf, 0xea, 0xe5, 0xb3,
665
+		 0xe5, 0xf1, 0x46, 0xc7, 0x5f, 0x2d, 0x8d, 0xbb, 0x5e, 0x4a ) );
666
+
667
+/**
668
+ * Force a "reseed required" state
669
+ *
670
+ * @v state		HMAC_DRBG internal state
671
+ */
672
+static inline void force_reseed_required ( struct hmac_drbg_state *state ) {
673
+	state->reseed_counter = ( HMAC_DRBG_RESEED_INTERVAL + 1 );
674
+}
675
+
676
+/**
677
+ * Perform HMAC_DRBG self-test
678
+ *
679
+ */
680
+static void hmac_drbg_test_exec ( void ) {
681
+	struct hmac_drbg_state state;
682
+
683
+	/*
684
+	 * IMPORTANT NOTE
685
+	 *
686
+	 * The NIST test vector set includes several calls to
687
+	 * HMAC_DRBG_Generate() that are expected to fail with a
688
+	 * status of "Reseed required".  The pattern seems to be that
689
+	 * when prediction resistance is requested, any call to
690
+	 * HMAC_DRBG_Generate() is at first expected to fail.  After
691
+	 * an explicit reseeding, the call to HMAC_DRBG_Generate() is
692
+	 * retried, and on this second time it is expected to succeed.
693
+	 *
694
+	 * This pattern does not match the specifications for
695
+	 * HMAC_DRBG_Generate(): neither HMAC_DRBG_Generate_algorithm
696
+	 * (defined in ANS X9.82 Part 3-2007 Section 10.2.2.2.5 (NIST
697
+	 * SP 800-90 Section 10.1.2.5)) nor the higher-level wrapper
698
+	 * Generate_function defined in ANS X9.82 Part 3-2007 Section
699
+	 * 9.4 (NIST SP 800-90 Section 9.3)) can possibly exhibit this
700
+	 * behaviour:
701
+	 *
702
+	 * a) HMAC_DRBG_Generate_algorithm can return a "reseed
703
+	 *    required" status only as a result of the test
704
+	 *
705
+	 *      "1. If reseed_counter > reseed_interval, then return
706
+	 *       an indication that a reseed is required."
707
+	 *
708
+	 *    Since the reseed interval is independent of any request
709
+	 *    for prediction resistance, and since the reseed interval
710
+	 *    is not specified as part of the NIST test vector set,
711
+	 *    then this cannot be the source of the "Reseed required"
712
+	 *    failure expected by the NIST test vector set.
713
+	 *
714
+	 * b) Generate_function cannot return a "reseed required"
715
+	 *    status under any circumstances.  If the underlying
716
+	 *    HMAC_DRBG_Generate_algorithm call returns "reseed
717
+	 *    required", then Generate_function will automatically
718
+	 *    reseed and try again.
719
+	 *
720
+	 * To produce the behaviour expected by the NIST test vector
721
+	 * set, we therefore contrive to produce a "reseed required"
722
+	 * state where necessary by setting the reseed_counter to
723
+	 * greater than the reseed_interval.
724
+	 */
725
+
726
+	/* Test 1 */
727
+	instantiate_ok ( &state, &instantiate_1 );
728
+	generate_ok ( &state, &generate_1_1 );
729
+	generate_ok ( &state, &generate_1_2 );
730
+
731
+	/* Test 2 */
732
+	instantiate_ok ( &state, &instantiate_2 );
733
+	generate_ok ( &state, &generate_2_1 );
734
+	generate_ok ( &state, &generate_2_2 );
735
+
736
+	/* Test 3 */
737
+	instantiate_ok ( &state, &instantiate_3 );
738
+	generate_ok ( &state, &generate_3_1 );
739
+	generate_ok ( &state, &generate_3_2 );
740
+
741
+	/* Test 4 */
742
+	instantiate_ok ( &state, &instantiate_4 );
743
+	generate_ok ( &state, &generate_4_1 );
744
+	generate_ok ( &state, &generate_4_2 );
745
+
746
+	/* Test 5 */
747
+	instantiate_ok ( &state, &instantiate_5 );
748
+	force_reseed_required ( &state ); /* See above comments */
749
+	generate_fail_ok ( &state, &generate_fail_5_1 );
750
+	reseed_ok ( &state, &reseed_5_2 );
751
+	generate_ok ( &state, &generate_5_3 );
752
+	force_reseed_required ( &state ); /* See above comments */
753
+	generate_fail_ok ( &state, &generate_fail_5_4 );
754
+	reseed_ok ( &state, &reseed_5_5 );
755
+	generate_ok ( &state, &generate_5_6 );
756
+
757
+	/* Test 6 */
758
+	instantiate_ok ( &state, &instantiate_6 );
759
+	force_reseed_required ( &state ); /* See above comments */
760
+	generate_fail_ok ( &state, &generate_fail_6_1 );
761
+	reseed_ok ( &state, &reseed_6_2 );
762
+	generate_ok ( &state, &generate_6_3 );
763
+	force_reseed_required ( &state ); /* See above comments */
764
+	generate_fail_ok ( &state, &generate_fail_6_4 );
765
+	reseed_ok ( &state, &reseed_6_5 );
766
+	generate_ok ( &state, &generate_6_6 );
767
+
768
+	/* Test 7 */
769
+	instantiate_ok ( &state, &instantiate_7 );
770
+	force_reseed_required ( &state ); /* See above comments */
771
+	generate_fail_ok ( &state, &generate_fail_7_1 );
772
+	reseed_ok ( &state, &reseed_7_2 );
773
+	generate_ok ( &state, &generate_7_3 );
774
+	force_reseed_required ( &state ); /* See above comments */
775
+	generate_fail_ok ( &state, &generate_fail_7_4 );
776
+	reseed_ok ( &state, &reseed_7_5 );
777
+	generate_ok ( &state, &generate_7_6 );
778
+
779
+	/* Test 8 */
780
+	instantiate_ok ( &state, &instantiate_8 );
781
+	force_reseed_required ( &state ); /* See above comments */
782
+	generate_fail_ok ( &state, &generate_fail_8_1 );
783
+	reseed_ok ( &state, &reseed_8_2 );
784
+	generate_ok ( &state, &generate_8_3 );
785
+	force_reseed_required ( &state ); /* See above comments */
786
+	generate_fail_ok ( &state, &generate_fail_8_4 );
787
+	reseed_ok ( &state, &reseed_8_5 );
788
+	generate_ok ( &state, &generate_8_6 );
789
+}
790
+
791
+/** HMAC_DRBG self-test */
792
+struct self_test hmac_drbg_test __self_test = {
793
+	.name = "hmac_drbg",
794
+	.exec = hmac_drbg_test_exec,
795
+};

+ 1
- 0
src/tests/test.c View File

@@ -141,3 +141,4 @@ struct init_fn test_init_fn __init_fn ( INIT_NORMAL ) = {
141 141
 /* Drag in all applicable self-tests */
142 142
 REQUIRE_OBJECT ( list_test );
143 143
 REQUIRE_OBJECT ( sha1_test );
144
+REQUIRE_OBJECT ( hmac_drbg_test );

Loading…
Cancel
Save