Browse Source

[rng] Allow hash_df() to accept multiple underlying hash algorithms

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
fb6a33360f
5 changed files with 101 additions and 95 deletions
  1. 2
    1
      src/crypto/entropy.c
  2. 9
    8
      src/crypto/hash_df.c
  3. 12
    1
      src/include/ipxe/entropy.h
  4. 3
    15
      src/include/ipxe/hash_df.h
  5. 75
    70
      src/tests/hash_df_test.c

+ 2
- 1
src/crypto/entropy.c View File

@@ -454,7 +454,8 @@ int get_entropy_input_tmp ( unsigned int num_samples, uint8_t *tmp,
454 454
 		/* 5.4.  tmp = tmp XOR
455 455
 		 *             df ( ( nonce || entropy_bitstring ), n )
456 456
 		 */
457
-		hash_df ( &data, sizeof ( data ), df_buf, sizeof ( df_buf ) );
457
+		hash_df ( &entropy_hash_df_algorithm, &data, sizeof ( data ),
458
+			  df_buf, sizeof ( df_buf ) );
458 459
 		for ( i = 0 ; i < tmp_len ; i++ )
459 460
 			tmp[i] ^= df_buf[i];
460 461
 

+ 9
- 8
src/crypto/hash_df.c View File

@@ -45,6 +45,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
45 45
 /**
46 46
  * Distribute entropy throughout a buffer
47 47
  *
48
+ * @v hash		Underlying hash algorithm
48 49
  * @v input		Input data
49 50
  * @v input_len		Length of input data, in bytes
50 51
  * @v output		Output buffer
@@ -63,10 +64,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
63 64
  * There is no way for the Hash_df function to fail.  The returned
64 65
  * status SUCCESS is implicit.
65 66
  */
66
-void hash_df ( const void *input, size_t input_len, void *output,
67
-	      size_t output_len ) {
68
-	uint8_t context[HASH_DF_CTX_SIZE];
69
-	uint8_t digest[HASH_DF_OUTLEN_BYTES];
67
+void hash_df ( struct digest_algorithm *hash, const void *input,
68
+	       size_t input_len, void *output, size_t output_len ) {
69
+	uint8_t context[hash->ctxsize];
70
+	uint8_t digest[hash->digestsize];
70 71
 	size_t frag_len;
71 72
 	struct {
72 73
 		uint8_t pad[3];
@@ -106,12 +107,12 @@ void hash_df ( const void *input, size_t input_len, void *output,
106 107
 		 *                            || input_string )
107 108
 		 */
108 109
 		prefix.no_of_bits_to_return = htonl ( output_len * 8 );
109
-		digest_init ( &hash_df_algorithm, context );
110
-		digest_update ( &hash_df_algorithm, context, &prefix.counter,
110
+		digest_init ( hash, context );
111
+		digest_update ( hash, context, &prefix.counter,
111 112
 				( sizeof ( prefix ) -
112 113
 				  offsetof ( typeof ( prefix ), counter ) ) );
113
-		digest_update ( &hash_df_algorithm, context, input, input_len );
114
-		digest_final ( &hash_df_algorithm, context, digest );
114
+		digest_update ( hash, context, input, input_len );
115
+		digest_final ( hash, context, digest );
115 116
 
116 117
 		/* 4.2  counter = counter + 1 */
117 118
 		prefix.counter++;

+ 12
- 1
src/include/ipxe/entropy.h View File

@@ -14,6 +14,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
14 14
 #include <assert.h>
15 15
 #include <ipxe/api.h>
16 16
 #include <ipxe/hash_df.h>
17
+#include <ipxe/sha1.h>
17 18
 #include <config/entropy.h>
18 19
 
19 20
 /**
@@ -99,6 +100,15 @@ int get_noise ( noise_sample_t *noise );
99 100
 extern int get_entropy_input_tmp ( unsigned int num_samples,
100 101
 				   uint8_t *tmp, size_t tmp_len );
101 102
 
103
+/** Use SHA-1 as the underlying hash algorithm for Hash_df
104
+ *
105
+ * Hash_df using SHA-1 is an Approved algorithm in ANS X9.82.
106
+ */
107
+#define entropy_hash_df_algorithm sha1_algorithm
108
+
109
+/** Underlying hash algorithm output length (in bytes) */
110
+#define ENTROPY_HASH_DF_OUTLEN_BYTES SHA1_DIGEST_SIZE
111
+
102 112
 /**
103 113
  * Obtain entropy input
104 114
  *
@@ -192,7 +202,8 @@ get_entropy_input ( unsigned int min_entropy_bits, void *data, size_t min_len,
192 202
 		return min_len;
193 203
 	} else if ( tmp_len > max_len ) {
194 204
 		linker_assert ( ( tmp == tmp_buf ), data_inplace );
195
-		hash_df ( tmp, tmp_len, data, max_len );
205
+		hash_df ( &entropy_hash_df_algorithm, tmp, tmp_len,
206
+			  data, max_len );
196 207
 		return max_len;
197 208
 	} else {
198 209
 		/* (Data is already in-place.) */

+ 3
- 15
src/include/ipxe/hash_df.h View File

@@ -10,21 +10,9 @@
10 10
 FILE_LICENCE ( GPL2_OR_LATER );
11 11
 
12 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
16
- *
17
- * Hash_df using SHA-1 is an Approved algorithm in ANS X9.82.
18
- */
19
-#define hash_df_algorithm sha1_algorithm
20
-
21
-/** Underlying hash algorithm output length (in bytes) */
22
-#define HASH_DF_OUTLEN_BYTES SHA1_DIGEST_SIZE
23
-
24
-/** Underlying hash algorithm context size (in bytes) */
25
-#define HASH_DF_CTX_SIZE SHA1_CTX_SIZE
26
-
27
-extern void hash_df ( const void *input, size_t input_len, void *output,
28
-		      size_t output_len );
15
+extern void hash_df ( struct digest_algorithm *hash, const void *input,
16
+		      size_t input_len, void *output, size_t output_len );
29 17
 
30 18
 #endif /* _IPXE_HASH_DF_H */

+ 75
- 70
src/tests/hash_df_test.c View File

@@ -35,6 +35,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
35 35
 #include <assert.h>
36 36
 #include <string.h>
37 37
 #include <ipxe/hash_df.h>
38
+#include <ipxe/sha1.h>
38 39
 #include <ipxe/test.h>
39 40
 
40 41
 /** Define inline input data */
@@ -45,6 +46,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
45 46
 
46 47
 /** A Hash_df test */
47 48
 struct hash_df_test {
49
+	/** Underlying hash algorithm */
50
+	struct digest_algorithm *hash;
48 51
 	/** Input data */
49 52
 	const void *input;
50 53
 	/** Length of input data */
@@ -59,22 +62,24 @@ struct hash_df_test {
59 62
  * Define a Hash_df test
60 63
  *
61 64
  * @v name		Test name
65
+ * @v hash_algorithm	Underlying hash algorithm
62 66
  * @v input_array	Input data
63 67
  * @v expected_array	Expected output data
64 68
  * @ret test		Hash_df test
65 69
  */
66
-#define HASH_DF_TEST( name, input_array, expected_array )		\
67
-	static const uint8_t name ## _input [] = input_array;		\
68
-	static const uint8_t name ## _expected [] = expected_array;	\
69
-	static const struct hash_df_test name = {			\
70
-		.input = name ## _input,				\
71
-		.input_len = sizeof ( name ## _input ),			\
72
-		.expected = name ## _expected,				\
73
-		.expected_len = sizeof ( name ## _expected ),		\
70
+#define HASH_DF_TEST( name, hash_algorithm, input_array, expected_array ) \
71
+	static const uint8_t name ## _input [] = input_array;		  \
72
+	static const uint8_t name ## _expected [] = expected_array;	  \
73
+	static const struct hash_df_test name = {			  \
74
+		.hash = &(hash_algorithm),				  \
75
+		.input = name ## _input,				  \
76
+		.input_len = sizeof ( name ## _input ),			  \
77
+		.expected = name ## _expected,				  \
78
+		.expected_len = sizeof ( name ## _expected ),		  \
74 79
 	}
75 80
 
76
-/** Test 1 */
77
-HASH_DF_TEST ( test_1,
81
+/** SHA-1 Test 1 */
82
+HASH_DF_TEST ( test_sha1_1, sha1_algorithm,
78 83
 	INPUT ( 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
79 84
 		0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
80 85
 		0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
@@ -88,8 +93,8 @@ HASH_DF_TEST ( test_1,
88 93
 		 0x67, 0x67, 0xb0, 0x5e, 0x83, 0xa9, 0x80, 0x40, 0x6d, 0x94,
89 94
 		 0xbe, 0xe3, 0x3c, 0xbb, 0x89 ) );
90 95
 
91
-/** Test 2 */
92
-HASH_DF_TEST ( test_2,
96
+/** SHA-1 Test 2 */
97
+HASH_DF_TEST ( test_sha1_2, sha1_algorithm,
93 98
 	INPUT ( 0x00, 0xd0, 0x8f, 0xb4, 0x41, 0xf2, 0xf4, 0xcb, 0x37, 0xcf,
94 99
 		0x6c, 0x24, 0x20, 0xa8, 0x2c, 0x74, 0x27, 0xac, 0xf7, 0xfc,
95 100
 		0xfd, 0x79, 0x90, 0x14, 0x38, 0x34, 0xa5, 0xc2, 0x56, 0xab,
@@ -103,8 +108,8 @@ HASH_DF_TEST ( test_2,
103 108
 		 0x86, 0x3d, 0xa8, 0x81, 0xff, 0xcb, 0xb4, 0x34, 0xa6, 0xcc,
104 109
 		 0xb7, 0xda, 0x2f, 0xb2, 0x10 ) );
105 110
 
106
-/** Test 3 */
107
-HASH_DF_TEST ( test_3,
111
+/** SHA-1 Test 3 */
112
+HASH_DF_TEST ( test_sha1_3, sha1_algorithm,
108 113
 	INPUT ( 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
109 114
 		0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
110 115
 		0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
@@ -124,8 +129,8 @@ HASH_DF_TEST ( test_3,
124 129
 		 0xe0, 0x2e, 0x85, 0xa2, 0x31, 0x4c, 0xe3, 0xd7, 0x4a, 0x93,
125 130
 		 0x32, 0x4b, 0x27, 0xbd, 0xe8 ) );
126 131
 
127
-/** Test 4 */
128
-HASH_DF_TEST ( test_4,
132
+/** SHA-1 Test 4 */
133
+HASH_DF_TEST ( test_sha1_4, sha1_algorithm,
129 134
 	INPUT ( 0x00, 0x99, 0xb9, 0x53, 0x7b, 0x84, 0x27, 0xb8, 0xce, 0x23,
130 135
 		0x21, 0x9a, 0x61, 0x1c, 0xbe, 0x61, 0x06, 0x44, 0xcf, 0x85,
131 136
 		0x03, 0xee, 0xc5, 0xba, 0x22, 0xde, 0x1a, 0xb2, 0x12, 0xc3,
@@ -139,8 +144,8 @@ HASH_DF_TEST ( test_4,
139 144
 		 0xf4, 0x85, 0xda, 0x6c, 0xbf, 0x04, 0x16, 0xdc, 0xdc, 0x5f,
140 145
 		 0xb8, 0xbc, 0x9c, 0x94, 0xb6 ) );
141 146
 
142
-/** Test 5 */
143
-HASH_DF_TEST ( test_5,
147
+/** SHA-1 Test 5 */
148
+HASH_DF_TEST ( test_sha1_5, sha1_algorithm,
144 149
 	INPUT ( 0x01, 0xd0, 0x8f, 0xb4, 0x41, 0xf2, 0xf4, 0xcb, 0x37, 0xcf,
145 150
 		0x6c, 0x24, 0x20, 0xa8, 0x2c, 0x74, 0x27, 0xac, 0xf7, 0xfc,
146 151
 		0xfd, 0x79, 0x90, 0x14, 0x38, 0x34, 0xa5, 0xc2, 0x56, 0xab,
@@ -160,8 +165,8 @@ HASH_DF_TEST ( test_5,
160 165
 		 0xb7, 0xc9, 0x89, 0x4f, 0xb8, 0x84, 0x65, 0xe0, 0xcf, 0xd1,
161 166
 		 0xcc, 0x26, 0x1e, 0x22, 0xc5 ) );
162 167
 
163
-/** Test 6 */
164
-HASH_DF_TEST ( test_6,
168
+/** SHA-1 Test 6 */
169
+HASH_DF_TEST ( test_sha1_6, sha1_algorithm,
165 170
 	INPUT ( 0x00, 0x0a, 0x04, 0x41, 0xa5, 0x2b, 0xed, 0xf7, 0x94, 0xf5,
166 171
 		0xaa, 0x62, 0x7b, 0xcb, 0xd8, 0x1f, 0x93, 0xe0, 0x11, 0xd5,
167 172
 		0x1f, 0x34, 0x74, 0x80, 0x2c, 0x37, 0x50, 0x76, 0x75, 0x51,
@@ -175,8 +180,8 @@ HASH_DF_TEST ( test_6,
175 180
 		 0x8a, 0xf8, 0x47, 0xca, 0xcc, 0x4c, 0x92, 0xc6, 0x14, 0x44,
176 181
 		 0x85, 0xc2, 0x27, 0xca, 0x05 ) );
177 182
 
178
-/** Test 7 */
179
-HASH_DF_TEST ( test_7,
183
+/** SHA-1 Test 7 */
184
+HASH_DF_TEST ( test_sha1_7, sha1_algorithm,
180 185
 	INPUT ( 0x01, 0x0e, 0x16, 0x0a, 0x56, 0x07, 0x95, 0x4e, 0x7d, 0x79,
181 186
 		0xd5, 0xa2, 0x2b, 0xf9, 0x08, 0x0b, 0x10, 0xce, 0xb7, 0x3c,
182 187
 		0x62, 0x23, 0x07, 0xf9, 0xf5, 0x45, 0xbd, 0xb1, 0xa4, 0x61,
@@ -196,8 +201,8 @@ HASH_DF_TEST ( test_7,
196 201
 		 0x51, 0x64, 0x54, 0x37, 0x28, 0x71, 0x7f, 0x17, 0x1f, 0xdb,
197 202
 		 0x02, 0xb2, 0xad, 0x57, 0x95 ) );
198 203
 
199
-/** Test 8 */
200
-HASH_DF_TEST ( test_8,
204
+/** SHA-1 Test 8 */
205
+HASH_DF_TEST ( test_sha1_8, sha1_algorithm,
201 206
 	INPUT ( 0x00, 0xdc, 0x24, 0xdf, 0x10, 0x2f, 0xa9, 0xf9, 0x6c, 0xc1,
202 207
 		0xcf, 0xf8, 0xc1, 0x16, 0xc7, 0x9d, 0x14, 0x97, 0xd7, 0xc2,
203 208
 		0x7b, 0xba, 0x5b, 0xa8, 0x01, 0xe1, 0x56, 0x21, 0x93, 0x35,
@@ -211,8 +216,8 @@ HASH_DF_TEST ( test_8,
211 216
 		 0xd6, 0x41, 0x5f, 0x37, 0x83, 0xb0, 0x15, 0x67, 0x89, 0x1b,
212 217
 		 0x57, 0x66, 0x2a, 0xbb, 0x39 ) );
213 218
 
214
-/** Test 9 */
215
-HASH_DF_TEST ( test_9,
219
+/** SHA-1 Test 9 */
220
+HASH_DF_TEST ( test_sha1_9, sha1_algorithm,
216 221
 	INPUT ( 0x01, 0xd0, 0x8f, 0xb4, 0x41, 0xf2, 0xf4, 0xcb, 0x37, 0xcf,
217 222
 		0x6c, 0x24, 0x20, 0xa8, 0x2c, 0x74, 0x27, 0xac, 0xf7, 0xfc,
218 223
 		0xfd, 0x79, 0x90, 0x14, 0x38, 0x34, 0xa5, 0xc2, 0x56, 0xab,
@@ -237,8 +242,8 @@ HASH_DF_TEST ( test_9,
237 242
 		 0xb4, 0x5d, 0x89, 0xdb, 0x61, 0x2c, 0xd9, 0xd2, 0x8a, 0x55,
238 243
 		 0xc0, 0xf0, 0xd1, 0xf8, 0xf9 ) );
239 244
 
240
-/** Test 10 */
241
-HASH_DF_TEST ( test_10,
245
+/** SHA-1 Test 10 */
246
+HASH_DF_TEST ( test_sha1_10, sha1_algorithm,
242 247
 	INPUT ( 0x00, 0x8f, 0xde, 0xc9, 0xe6, 0x18, 0x96, 0x36, 0xf0, 0xa5,
243 248
 		0xce, 0x53, 0xe8, 0x1c, 0x13, 0xac, 0x93, 0x84, 0xfa, 0xfb,
244 249
 		0xa0, 0xee, 0x50, 0xc1, 0xe2, 0xc8, 0xa0, 0x99, 0xde, 0x41,
@@ -252,8 +257,8 @@ HASH_DF_TEST ( test_10,
252 257
 		 0x51, 0x95, 0xf4, 0x79, 0xcd, 0x76, 0x20, 0x22, 0x35, 0x10,
253 258
 		 0x2e, 0xf6, 0x27, 0x29, 0x19 ) );
254 259
 
255
-/** Test 11 */
256
-HASH_DF_TEST ( test_11,
260
+/** SHA-1 Test 11 */
261
+HASH_DF_TEST ( test_sha1_11, sha1_algorithm,
257 262
 	INPUT ( 0x01, 0x27, 0xaf, 0x40, 0x17, 0xca, 0xc5, 0xb3, 0x86, 0x24,
258 263
 		0xe8, 0x4c, 0x2d, 0x10, 0xef, 0xd7, 0x8d, 0xf4, 0xf4, 0x77,
259 264
 		0xd6, 0x54, 0x69, 0x5a, 0x04, 0x32, 0x32, 0x6b, 0x3a, 0x1c,
@@ -278,8 +283,8 @@ HASH_DF_TEST ( test_11,
278 283
 		 0xa3, 0xfe, 0xa1, 0xc7, 0x11, 0x7d, 0x6f, 0x7d, 0xd2, 0xef,
279 284
 		 0x77, 0x7d, 0x7c, 0xf3, 0xeb ) );
280 285
 
281
-/** Test 12 */
282
-HASH_DF_TEST ( test_12,
286
+/** SHA-1 Test 12 */
287
+HASH_DF_TEST ( test_sha1_12, sha1_algorithm,
283 288
 	INPUT ( 0x00, 0x2c, 0x9c, 0x0d, 0x80, 0x03, 0xe3, 0x40, 0x23, 0xbe,
284 289
 		0x5b, 0x63, 0xfd, 0xb9, 0xd2, 0x24, 0xb4, 0x25, 0x0c, 0xc8,
285 290
 		0x15, 0x5b, 0xd1, 0xee, 0xd8, 0xe5, 0x5d, 0x91, 0x06, 0x2f,
@@ -293,8 +298,8 @@ HASH_DF_TEST ( test_12,
293 298
 		 0x0e, 0x8b, 0xff, 0xf6, 0x0c, 0xb7, 0x7f, 0xa5, 0x4b, 0xb1,
294 299
 		 0x1a, 0x83, 0x31, 0xcb, 0x24 ) );
295 300
 
296
-/** Test 13 */
297
-HASH_DF_TEST ( test_13,
301
+/** SHA-1 Test 13 */
302
+HASH_DF_TEST ( test_sha1_13, sha1_algorithm,
298 303
 	INPUT ( 0x01, 0x99, 0xb9, 0x53, 0x7b, 0x84, 0x27, 0xb8, 0xce, 0x23,
299 304
 		0x21, 0x9a, 0x61, 0x1c, 0xbe, 0x61, 0x06, 0x44, 0xcf, 0x85,
300 305
 		0x03, 0xee, 0xc5, 0xba, 0x22, 0xde, 0x1a, 0xb2, 0x12, 0xc3,
@@ -314,8 +319,8 @@ HASH_DF_TEST ( test_13,
314 319
 		 0xf0, 0x0c, 0x3b, 0xda, 0x59, 0x6b, 0x10, 0x88, 0x61, 0xf0,
315 320
 		 0x6b, 0xf9, 0x1b, 0x45, 0xd6 ) );
316 321
 
317
-/** Test 14 */
318
-HASH_DF_TEST ( test_14,
322
+/** SHA-1 Test 14 */
323
+HASH_DF_TEST ( test_sha1_14, sha1_algorithm,
319 324
 	INPUT ( 0x00, 0xe5, 0x04, 0x3d, 0x1b, 0x95, 0x4b, 0x34, 0xba, 0x60,
320 325
 		0xd2, 0x48, 0xe8, 0x83, 0xef, 0x49, 0x8c, 0x5c, 0x52, 0x36,
321 326
 		0xb8, 0x26, 0x0e, 0x23, 0x8e, 0x02, 0xc8, 0xd4, 0xfc, 0x5f,
@@ -329,8 +334,8 @@ HASH_DF_TEST ( test_14,
329 334
 		 0xa6, 0xbc, 0xfc, 0xfc, 0x0f, 0x51, 0xfe, 0x2f, 0x77, 0xc1,
330 335
 		 0xc9, 0x9d, 0xf0, 0xa2, 0x09 ) );
331 336
 
332
-/** Test 15 */
333
-HASH_DF_TEST ( test_15,
337
+/** SHA-1 Test 15 */
338
+HASH_DF_TEST ( test_sha1_15, sha1_algorithm,
334 339
 	INPUT ( 0x01, 0x04, 0x43, 0xa0, 0x2c, 0x82, 0x5c, 0x31, 0x59, 0xf4,
335 340
 		0x5e, 0x8c, 0x0a, 0xe5, 0x9e, 0x8c, 0x76, 0x45, 0x69, 0x95,
336 341
 		0xc0, 0x35, 0x40, 0x46, 0x6a, 0x14, 0x54, 0x7c, 0xcb, 0xe8,
@@ -350,8 +355,8 @@ HASH_DF_TEST ( test_15,
350 355
 		 0xd2, 0x7e, 0x2b, 0x2e, 0x42, 0x2b, 0x32, 0xb9, 0x7f, 0x05,
351 356
 		 0x0d, 0x1b, 0xd2, 0xb4, 0x90 ) );
352 357
 
353
-/** Test 16 */
354
-HASH_DF_TEST ( test_16,
358
+/** SHA-1 Test 16 */
359
+HASH_DF_TEST ( test_sha1_16, sha1_algorithm,
355 360
 	INPUT ( 0x00, 0x9d, 0xc3, 0x52, 0x08, 0xee, 0x2b, 0x8c, 0x58, 0x1e,
356 361
 		0xa3, 0x0b, 0xaa, 0xcb, 0x5d, 0x74, 0x31, 0x7a, 0x87, 0x94,
357 362
 		0x54, 0x10, 0x71, 0x7e, 0x58, 0xd3, 0x70, 0x5f, 0xbd, 0xc7,
@@ -365,8 +370,8 @@ HASH_DF_TEST ( test_16,
365 370
 		 0xef, 0x85, 0x76, 0xe7, 0x5c, 0xb3, 0xcf, 0xe8, 0x22, 0x07,
366 371
 		 0x68, 0xb2, 0x6c, 0xe7, 0x7a ) );
367 372
 
368
-/** Test 17 */
369
-HASH_DF_TEST ( test_17,
373
+/** SHA-1 Test 17 */
374
+HASH_DF_TEST ( test_sha1_17, sha1_algorithm,
370 375
 	INPUT ( 0x01, 0x99, 0xb9, 0x53, 0x7b, 0x84, 0x27, 0xb8, 0xce, 0x23,
371 376
 		0x21, 0x9a, 0x61, 0x1c, 0xbe, 0x61, 0x06, 0x44, 0xcf, 0x85,
372 377
 		0x03, 0xee, 0xc5, 0xba, 0x22, 0xde, 0x1a, 0xb2, 0x12, 0xc3,
@@ -391,8 +396,8 @@ HASH_DF_TEST ( test_17,
391 396
 		 0xaa, 0x8a, 0x6e, 0x6b, 0x8e, 0x6d, 0x56, 0xa4, 0x31, 0x33,
392 397
 		 0x3b, 0x40, 0x8e, 0x6f, 0xa8 ) );
393 398
 
394
-/** Test 18 */
395
-HASH_DF_TEST ( test_18,
399
+/** SHA-1 Test 18 */
400
+HASH_DF_TEST ( test_sha1_18, sha1_algorithm,
396 401
 	INPUT ( 0x00, 0x56, 0x3a, 0x5d, 0x20, 0x7d, 0x37, 0x70, 0x7b, 0xf5,
397 402
 		0xf2, 0x4d, 0x0b, 0xd4, 0x93, 0x5d, 0xc3, 0x8d, 0xbe, 0x04,
398 403
 		0x36, 0x37, 0xb3, 0xff, 0x8a, 0xb6, 0x8c, 0xfc, 0xe2, 0xf2,
@@ -406,8 +411,8 @@ HASH_DF_TEST ( test_18,
406 411
 		 0xf6, 0xbc, 0xda, 0xf8, 0x1d, 0x28, 0x9c, 0xf4, 0xbd, 0x3c,
407 412
 		 0x91, 0xb7, 0x00, 0x5c, 0x18 ) );
408 413
 
409
-/** Test 19 */
410
-HASH_DF_TEST ( test_19,
414
+/** SHA-1 Test 19 */
415
+HASH_DF_TEST ( test_sha1_19, sha1_algorithm,
411 416
 	INPUT ( 0x01, 0x1c, 0x0e, 0x46, 0x75, 0x9b, 0x38, 0x55, 0x6a, 0x28,
412 417
 		0xa4, 0x5e, 0x7b, 0x83, 0xe1, 0x4d, 0xb8, 0x62, 0x8d, 0xb1,
413 418
 		0x62, 0x13, 0xe1, 0xba, 0x2d, 0x97, 0x74, 0xf6, 0xc0, 0xac,
@@ -432,8 +437,8 @@ HASH_DF_TEST ( test_19,
432 437
 		 0x0a, 0xb0, 0x7d, 0x12, 0x08, 0xb6, 0xbd, 0x66, 0x5b, 0x30,
433 438
 		 0x0a, 0xa4, 0xdb, 0x9c, 0x3e ) );
434 439
 
435
-/** Test 20 */
436
-HASH_DF_TEST ( test_20,
440
+/** SHA-1 Test 20 */
441
+HASH_DF_TEST ( test_sha1_20, sha1_algorithm,
437 442
 	INPUT ( 0x00, 0x60, 0x01, 0x93, 0xc8, 0xf6, 0x03, 0x1a, 0x2d, 0x49,
438 443
 		0x37, 0x2a, 0x8b, 0x0f, 0x60, 0xf6, 0x8c, 0x1d, 0xfd, 0xac,
439 444
 		0xd4, 0xf8, 0xea, 0x01, 0x37, 0x47, 0xd7, 0x14, 0x82, 0x33,
@@ -454,8 +459,8 @@ HASH_DF_TEST ( test_20,
454 459
  */
455 460
 #define hash_df_ok( test ) do {						\
456 461
 	uint8_t output[ (test)->expected_len ];				\
457
-	hash_df ( (test)->input, (test)->input_len, output,		\
458
-		  sizeof ( output ) );					\
462
+	hash_df ( (test)->hash, (test)->input, (test)->input_len,	\
463
+		  output, sizeof ( output ) );				\
459 464
 	ok ( memcmp ( (test)->expected, output,				\
460 465
 		      sizeof ( output ) ) == 0 );			\
461 466
 	} while ( 0 )
@@ -466,26 +471,26 @@ HASH_DF_TEST ( test_20,
466 471
  */
467 472
 static void hash_df_test_exec ( void ) {
468 473
 
469
-	hash_df_ok ( &test_1 );
470
-	hash_df_ok ( &test_2 );
471
-	hash_df_ok ( &test_3 );
472
-	hash_df_ok ( &test_4 );
473
-	hash_df_ok ( &test_5 );
474
-	hash_df_ok ( &test_6 );
475
-	hash_df_ok ( &test_7 );
476
-	hash_df_ok ( &test_8 );
477
-	hash_df_ok ( &test_9 );
478
-	hash_df_ok ( &test_10 );
479
-	hash_df_ok ( &test_11 );
480
-	hash_df_ok ( &test_12 );
481
-	hash_df_ok ( &test_13 );
482
-	hash_df_ok ( &test_14 );
483
-	hash_df_ok ( &test_15 );
484
-	hash_df_ok ( &test_16 );
485
-	hash_df_ok ( &test_17 );
486
-	hash_df_ok ( &test_18 );
487
-	hash_df_ok ( &test_19 );
488
-	hash_df_ok ( &test_20 );
474
+	hash_df_ok ( &test_sha1_1 );
475
+	hash_df_ok ( &test_sha1_2 );
476
+	hash_df_ok ( &test_sha1_3 );
477
+	hash_df_ok ( &test_sha1_4 );
478
+	hash_df_ok ( &test_sha1_5 );
479
+	hash_df_ok ( &test_sha1_6 );
480
+	hash_df_ok ( &test_sha1_7 );
481
+	hash_df_ok ( &test_sha1_8 );
482
+	hash_df_ok ( &test_sha1_9 );
483
+	hash_df_ok ( &test_sha1_10 );
484
+	hash_df_ok ( &test_sha1_11 );
485
+	hash_df_ok ( &test_sha1_12 );
486
+	hash_df_ok ( &test_sha1_13 );
487
+	hash_df_ok ( &test_sha1_14 );
488
+	hash_df_ok ( &test_sha1_15 );
489
+	hash_df_ok ( &test_sha1_16 );
490
+	hash_df_ok ( &test_sha1_17 );
491
+	hash_df_ok ( &test_sha1_18 );
492
+	hash_df_ok ( &test_sha1_19 );
493
+	hash_df_ok ( &test_sha1_20 );
489 494
 }
490 495
 
491 496
 /** Hash_df self-test */

Loading…
Cancel
Save