소스 검색

[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 년 전
부모
커밋
fb6a33360f
5개의 변경된 파일101개의 추가작업 그리고 95개의 파일을 삭제
  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 파일 보기

454
 		/* 5.4.  tmp = tmp XOR
454
 		/* 5.4.  tmp = tmp XOR
455
 		 *             df ( ( nonce || entropy_bitstring ), n )
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
 		for ( i = 0 ; i < tmp_len ; i++ )
459
 		for ( i = 0 ; i < tmp_len ; i++ )
459
 			tmp[i] ^= df_buf[i];
460
 			tmp[i] ^= df_buf[i];
460
 
461
 

+ 9
- 8
src/crypto/hash_df.c 파일 보기

45
 /**
45
 /**
46
  * Distribute entropy throughout a buffer
46
  * Distribute entropy throughout a buffer
47
  *
47
  *
48
+ * @v hash		Underlying hash algorithm
48
  * @v input		Input data
49
  * @v input		Input data
49
  * @v input_len		Length of input data, in bytes
50
  * @v input_len		Length of input data, in bytes
50
  * @v output		Output buffer
51
  * @v output		Output buffer
63
  * There is no way for the Hash_df function to fail.  The returned
64
  * There is no way for the Hash_df function to fail.  The returned
64
  * status SUCCESS is implicit.
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
 	size_t frag_len;
71
 	size_t frag_len;
71
 	struct {
72
 	struct {
72
 		uint8_t pad[3];
73
 		uint8_t pad[3];
106
 		 *                            || input_string )
107
 		 *                            || input_string )
107
 		 */
108
 		 */
108
 		prefix.no_of_bits_to_return = htonl ( output_len * 8 );
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
 				( sizeof ( prefix ) -
112
 				( sizeof ( prefix ) -
112
 				  offsetof ( typeof ( prefix ), counter ) ) );
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
 		/* 4.2  counter = counter + 1 */
117
 		/* 4.2  counter = counter + 1 */
117
 		prefix.counter++;
118
 		prefix.counter++;

+ 12
- 1
src/include/ipxe/entropy.h 파일 보기

14
 #include <assert.h>
14
 #include <assert.h>
15
 #include <ipxe/api.h>
15
 #include <ipxe/api.h>
16
 #include <ipxe/hash_df.h>
16
 #include <ipxe/hash_df.h>
17
+#include <ipxe/sha1.h>
17
 #include <config/entropy.h>
18
 #include <config/entropy.h>
18
 
19
 
19
 /**
20
 /**
99
 extern int get_entropy_input_tmp ( unsigned int num_samples,
100
 extern int get_entropy_input_tmp ( unsigned int num_samples,
100
 				   uint8_t *tmp, size_t tmp_len );
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
  * Obtain entropy input
113
  * Obtain entropy input
104
  *
114
  *
192
 		return min_len;
202
 		return min_len;
193
 	} else if ( tmp_len > max_len ) {
203
 	} else if ( tmp_len > max_len ) {
194
 		linker_assert ( ( tmp == tmp_buf ), data_inplace );
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
 		return max_len;
207
 		return max_len;
197
 	} else {
208
 	} else {
198
 		/* (Data is already in-place.) */
209
 		/* (Data is already in-place.) */

+ 3
- 15
src/include/ipxe/hash_df.h 파일 보기

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
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
 #endif /* _IPXE_HASH_DF_H */
18
 #endif /* _IPXE_HASH_DF_H */

+ 75
- 70
src/tests/hash_df_test.c 파일 보기

35
 #include <assert.h>
35
 #include <assert.h>
36
 #include <string.h>
36
 #include <string.h>
37
 #include <ipxe/hash_df.h>
37
 #include <ipxe/hash_df.h>
38
+#include <ipxe/sha1.h>
38
 #include <ipxe/test.h>
39
 #include <ipxe/test.h>
39
 
40
 
40
 /** Define inline input data */
41
 /** Define inline input data */
45
 
46
 
46
 /** A Hash_df test */
47
 /** A Hash_df test */
47
 struct hash_df_test {
48
 struct hash_df_test {
49
+	/** Underlying hash algorithm */
50
+	struct digest_algorithm *hash;
48
 	/** Input data */
51
 	/** Input data */
49
 	const void *input;
52
 	const void *input;
50
 	/** Length of input data */
53
 	/** Length of input data */
59
  * Define a Hash_df test
62
  * Define a Hash_df test
60
  *
63
  *
61
  * @v name		Test name
64
  * @v name		Test name
65
+ * @v hash_algorithm	Underlying hash algorithm
62
  * @v input_array	Input data
66
  * @v input_array	Input data
63
  * @v expected_array	Expected output data
67
  * @v expected_array	Expected output data
64
  * @ret test		Hash_df test
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
 	INPUT ( 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
83
 	INPUT ( 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
79
 		0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
84
 		0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
80
 		0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
85
 		0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
88
 		 0x67, 0x67, 0xb0, 0x5e, 0x83, 0xa9, 0x80, 0x40, 0x6d, 0x94,
93
 		 0x67, 0x67, 0xb0, 0x5e, 0x83, 0xa9, 0x80, 0x40, 0x6d, 0x94,
89
 		 0xbe, 0xe3, 0x3c, 0xbb, 0x89 ) );
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
 	INPUT ( 0x00, 0xd0, 0x8f, 0xb4, 0x41, 0xf2, 0xf4, 0xcb, 0x37, 0xcf,
98
 	INPUT ( 0x00, 0xd0, 0x8f, 0xb4, 0x41, 0xf2, 0xf4, 0xcb, 0x37, 0xcf,
94
 		0x6c, 0x24, 0x20, 0xa8, 0x2c, 0x74, 0x27, 0xac, 0xf7, 0xfc,
99
 		0x6c, 0x24, 0x20, 0xa8, 0x2c, 0x74, 0x27, 0xac, 0xf7, 0xfc,
95
 		0xfd, 0x79, 0x90, 0x14, 0x38, 0x34, 0xa5, 0xc2, 0x56, 0xab,
100
 		0xfd, 0x79, 0x90, 0x14, 0x38, 0x34, 0xa5, 0xc2, 0x56, 0xab,
103
 		 0x86, 0x3d, 0xa8, 0x81, 0xff, 0xcb, 0xb4, 0x34, 0xa6, 0xcc,
108
 		 0x86, 0x3d, 0xa8, 0x81, 0xff, 0xcb, 0xb4, 0x34, 0xa6, 0xcc,
104
 		 0xb7, 0xda, 0x2f, 0xb2, 0x10 ) );
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
 	INPUT ( 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
113
 	INPUT ( 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
109
 		0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
114
 		0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
110
 		0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
115
 		0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
124
 		 0xe0, 0x2e, 0x85, 0xa2, 0x31, 0x4c, 0xe3, 0xd7, 0x4a, 0x93,
129
 		 0xe0, 0x2e, 0x85, 0xa2, 0x31, 0x4c, 0xe3, 0xd7, 0x4a, 0x93,
125
 		 0x32, 0x4b, 0x27, 0xbd, 0xe8 ) );
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
 	INPUT ( 0x00, 0x99, 0xb9, 0x53, 0x7b, 0x84, 0x27, 0xb8, 0xce, 0x23,
134
 	INPUT ( 0x00, 0x99, 0xb9, 0x53, 0x7b, 0x84, 0x27, 0xb8, 0xce, 0x23,
130
 		0x21, 0x9a, 0x61, 0x1c, 0xbe, 0x61, 0x06, 0x44, 0xcf, 0x85,
135
 		0x21, 0x9a, 0x61, 0x1c, 0xbe, 0x61, 0x06, 0x44, 0xcf, 0x85,
131
 		0x03, 0xee, 0xc5, 0xba, 0x22, 0xde, 0x1a, 0xb2, 0x12, 0xc3,
136
 		0x03, 0xee, 0xc5, 0xba, 0x22, 0xde, 0x1a, 0xb2, 0x12, 0xc3,
139
 		 0xf4, 0x85, 0xda, 0x6c, 0xbf, 0x04, 0x16, 0xdc, 0xdc, 0x5f,
144
 		 0xf4, 0x85, 0xda, 0x6c, 0xbf, 0x04, 0x16, 0xdc, 0xdc, 0x5f,
140
 		 0xb8, 0xbc, 0x9c, 0x94, 0xb6 ) );
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
 	INPUT ( 0x01, 0xd0, 0x8f, 0xb4, 0x41, 0xf2, 0xf4, 0xcb, 0x37, 0xcf,
149
 	INPUT ( 0x01, 0xd0, 0x8f, 0xb4, 0x41, 0xf2, 0xf4, 0xcb, 0x37, 0xcf,
145
 		0x6c, 0x24, 0x20, 0xa8, 0x2c, 0x74, 0x27, 0xac, 0xf7, 0xfc,
150
 		0x6c, 0x24, 0x20, 0xa8, 0x2c, 0x74, 0x27, 0xac, 0xf7, 0xfc,
146
 		0xfd, 0x79, 0x90, 0x14, 0x38, 0x34, 0xa5, 0xc2, 0x56, 0xab,
151
 		0xfd, 0x79, 0x90, 0x14, 0x38, 0x34, 0xa5, 0xc2, 0x56, 0xab,
160
 		 0xb7, 0xc9, 0x89, 0x4f, 0xb8, 0x84, 0x65, 0xe0, 0xcf, 0xd1,
165
 		 0xb7, 0xc9, 0x89, 0x4f, 0xb8, 0x84, 0x65, 0xe0, 0xcf, 0xd1,
161
 		 0xcc, 0x26, 0x1e, 0x22, 0xc5 ) );
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
 	INPUT ( 0x00, 0x0a, 0x04, 0x41, 0xa5, 0x2b, 0xed, 0xf7, 0x94, 0xf5,
170
 	INPUT ( 0x00, 0x0a, 0x04, 0x41, 0xa5, 0x2b, 0xed, 0xf7, 0x94, 0xf5,
166
 		0xaa, 0x62, 0x7b, 0xcb, 0xd8, 0x1f, 0x93, 0xe0, 0x11, 0xd5,
171
 		0xaa, 0x62, 0x7b, 0xcb, 0xd8, 0x1f, 0x93, 0xe0, 0x11, 0xd5,
167
 		0x1f, 0x34, 0x74, 0x80, 0x2c, 0x37, 0x50, 0x76, 0x75, 0x51,
172
 		0x1f, 0x34, 0x74, 0x80, 0x2c, 0x37, 0x50, 0x76, 0x75, 0x51,
175
 		 0x8a, 0xf8, 0x47, 0xca, 0xcc, 0x4c, 0x92, 0xc6, 0x14, 0x44,
180
 		 0x8a, 0xf8, 0x47, 0xca, 0xcc, 0x4c, 0x92, 0xc6, 0x14, 0x44,
176
 		 0x85, 0xc2, 0x27, 0xca, 0x05 ) );
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
 	INPUT ( 0x01, 0x0e, 0x16, 0x0a, 0x56, 0x07, 0x95, 0x4e, 0x7d, 0x79,
185
 	INPUT ( 0x01, 0x0e, 0x16, 0x0a, 0x56, 0x07, 0x95, 0x4e, 0x7d, 0x79,
181
 		0xd5, 0xa2, 0x2b, 0xf9, 0x08, 0x0b, 0x10, 0xce, 0xb7, 0x3c,
186
 		0xd5, 0xa2, 0x2b, 0xf9, 0x08, 0x0b, 0x10, 0xce, 0xb7, 0x3c,
182
 		0x62, 0x23, 0x07, 0xf9, 0xf5, 0x45, 0xbd, 0xb1, 0xa4, 0x61,
187
 		0x62, 0x23, 0x07, 0xf9, 0xf5, 0x45, 0xbd, 0xb1, 0xa4, 0x61,
196
 		 0x51, 0x64, 0x54, 0x37, 0x28, 0x71, 0x7f, 0x17, 0x1f, 0xdb,
201
 		 0x51, 0x64, 0x54, 0x37, 0x28, 0x71, 0x7f, 0x17, 0x1f, 0xdb,
197
 		 0x02, 0xb2, 0xad, 0x57, 0x95 ) );
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
 	INPUT ( 0x00, 0xdc, 0x24, 0xdf, 0x10, 0x2f, 0xa9, 0xf9, 0x6c, 0xc1,
206
 	INPUT ( 0x00, 0xdc, 0x24, 0xdf, 0x10, 0x2f, 0xa9, 0xf9, 0x6c, 0xc1,
202
 		0xcf, 0xf8, 0xc1, 0x16, 0xc7, 0x9d, 0x14, 0x97, 0xd7, 0xc2,
207
 		0xcf, 0xf8, 0xc1, 0x16, 0xc7, 0x9d, 0x14, 0x97, 0xd7, 0xc2,
203
 		0x7b, 0xba, 0x5b, 0xa8, 0x01, 0xe1, 0x56, 0x21, 0x93, 0x35,
208
 		0x7b, 0xba, 0x5b, 0xa8, 0x01, 0xe1, 0x56, 0x21, 0x93, 0x35,
211
 		 0xd6, 0x41, 0x5f, 0x37, 0x83, 0xb0, 0x15, 0x67, 0x89, 0x1b,
216
 		 0xd6, 0x41, 0x5f, 0x37, 0x83, 0xb0, 0x15, 0x67, 0x89, 0x1b,
212
 		 0x57, 0x66, 0x2a, 0xbb, 0x39 ) );
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
 	INPUT ( 0x01, 0xd0, 0x8f, 0xb4, 0x41, 0xf2, 0xf4, 0xcb, 0x37, 0xcf,
221
 	INPUT ( 0x01, 0xd0, 0x8f, 0xb4, 0x41, 0xf2, 0xf4, 0xcb, 0x37, 0xcf,
217
 		0x6c, 0x24, 0x20, 0xa8, 0x2c, 0x74, 0x27, 0xac, 0xf7, 0xfc,
222
 		0x6c, 0x24, 0x20, 0xa8, 0x2c, 0x74, 0x27, 0xac, 0xf7, 0xfc,
218
 		0xfd, 0x79, 0x90, 0x14, 0x38, 0x34, 0xa5, 0xc2, 0x56, 0xab,
223
 		0xfd, 0x79, 0x90, 0x14, 0x38, 0x34, 0xa5, 0xc2, 0x56, 0xab,
237
 		 0xb4, 0x5d, 0x89, 0xdb, 0x61, 0x2c, 0xd9, 0xd2, 0x8a, 0x55,
242
 		 0xb4, 0x5d, 0x89, 0xdb, 0x61, 0x2c, 0xd9, 0xd2, 0x8a, 0x55,
238
 		 0xc0, 0xf0, 0xd1, 0xf8, 0xf9 ) );
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
 	INPUT ( 0x00, 0x8f, 0xde, 0xc9, 0xe6, 0x18, 0x96, 0x36, 0xf0, 0xa5,
247
 	INPUT ( 0x00, 0x8f, 0xde, 0xc9, 0xe6, 0x18, 0x96, 0x36, 0xf0, 0xa5,
243
 		0xce, 0x53, 0xe8, 0x1c, 0x13, 0xac, 0x93, 0x84, 0xfa, 0xfb,
248
 		0xce, 0x53, 0xe8, 0x1c, 0x13, 0xac, 0x93, 0x84, 0xfa, 0xfb,
244
 		0xa0, 0xee, 0x50, 0xc1, 0xe2, 0xc8, 0xa0, 0x99, 0xde, 0x41,
249
 		0xa0, 0xee, 0x50, 0xc1, 0xe2, 0xc8, 0xa0, 0x99, 0xde, 0x41,
252
 		 0x51, 0x95, 0xf4, 0x79, 0xcd, 0x76, 0x20, 0x22, 0x35, 0x10,
257
 		 0x51, 0x95, 0xf4, 0x79, 0xcd, 0x76, 0x20, 0x22, 0x35, 0x10,
253
 		 0x2e, 0xf6, 0x27, 0x29, 0x19 ) );
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
 	INPUT ( 0x01, 0x27, 0xaf, 0x40, 0x17, 0xca, 0xc5, 0xb3, 0x86, 0x24,
262
 	INPUT ( 0x01, 0x27, 0xaf, 0x40, 0x17, 0xca, 0xc5, 0xb3, 0x86, 0x24,
258
 		0xe8, 0x4c, 0x2d, 0x10, 0xef, 0xd7, 0x8d, 0xf4, 0xf4, 0x77,
263
 		0xe8, 0x4c, 0x2d, 0x10, 0xef, 0xd7, 0x8d, 0xf4, 0xf4, 0x77,
259
 		0xd6, 0x54, 0x69, 0x5a, 0x04, 0x32, 0x32, 0x6b, 0x3a, 0x1c,
264
 		0xd6, 0x54, 0x69, 0x5a, 0x04, 0x32, 0x32, 0x6b, 0x3a, 0x1c,
278
 		 0xa3, 0xfe, 0xa1, 0xc7, 0x11, 0x7d, 0x6f, 0x7d, 0xd2, 0xef,
283
 		 0xa3, 0xfe, 0xa1, 0xc7, 0x11, 0x7d, 0x6f, 0x7d, 0xd2, 0xef,
279
 		 0x77, 0x7d, 0x7c, 0xf3, 0xeb ) );
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
 	INPUT ( 0x00, 0x2c, 0x9c, 0x0d, 0x80, 0x03, 0xe3, 0x40, 0x23, 0xbe,
288
 	INPUT ( 0x00, 0x2c, 0x9c, 0x0d, 0x80, 0x03, 0xe3, 0x40, 0x23, 0xbe,
284
 		0x5b, 0x63, 0xfd, 0xb9, 0xd2, 0x24, 0xb4, 0x25, 0x0c, 0xc8,
289
 		0x5b, 0x63, 0xfd, 0xb9, 0xd2, 0x24, 0xb4, 0x25, 0x0c, 0xc8,
285
 		0x15, 0x5b, 0xd1, 0xee, 0xd8, 0xe5, 0x5d, 0x91, 0x06, 0x2f,
290
 		0x15, 0x5b, 0xd1, 0xee, 0xd8, 0xe5, 0x5d, 0x91, 0x06, 0x2f,
293
 		 0x0e, 0x8b, 0xff, 0xf6, 0x0c, 0xb7, 0x7f, 0xa5, 0x4b, 0xb1,
298
 		 0x0e, 0x8b, 0xff, 0xf6, 0x0c, 0xb7, 0x7f, 0xa5, 0x4b, 0xb1,
294
 		 0x1a, 0x83, 0x31, 0xcb, 0x24 ) );
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
 	INPUT ( 0x01, 0x99, 0xb9, 0x53, 0x7b, 0x84, 0x27, 0xb8, 0xce, 0x23,
303
 	INPUT ( 0x01, 0x99, 0xb9, 0x53, 0x7b, 0x84, 0x27, 0xb8, 0xce, 0x23,
299
 		0x21, 0x9a, 0x61, 0x1c, 0xbe, 0x61, 0x06, 0x44, 0xcf, 0x85,
304
 		0x21, 0x9a, 0x61, 0x1c, 0xbe, 0x61, 0x06, 0x44, 0xcf, 0x85,
300
 		0x03, 0xee, 0xc5, 0xba, 0x22, 0xde, 0x1a, 0xb2, 0x12, 0xc3,
305
 		0x03, 0xee, 0xc5, 0xba, 0x22, 0xde, 0x1a, 0xb2, 0x12, 0xc3,
314
 		 0xf0, 0x0c, 0x3b, 0xda, 0x59, 0x6b, 0x10, 0x88, 0x61, 0xf0,
319
 		 0xf0, 0x0c, 0x3b, 0xda, 0x59, 0x6b, 0x10, 0x88, 0x61, 0xf0,
315
 		 0x6b, 0xf9, 0x1b, 0x45, 0xd6 ) );
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
 	INPUT ( 0x00, 0xe5, 0x04, 0x3d, 0x1b, 0x95, 0x4b, 0x34, 0xba, 0x60,
324
 	INPUT ( 0x00, 0xe5, 0x04, 0x3d, 0x1b, 0x95, 0x4b, 0x34, 0xba, 0x60,
320
 		0xd2, 0x48, 0xe8, 0x83, 0xef, 0x49, 0x8c, 0x5c, 0x52, 0x36,
325
 		0xd2, 0x48, 0xe8, 0x83, 0xef, 0x49, 0x8c, 0x5c, 0x52, 0x36,
321
 		0xb8, 0x26, 0x0e, 0x23, 0x8e, 0x02, 0xc8, 0xd4, 0xfc, 0x5f,
326
 		0xb8, 0x26, 0x0e, 0x23, 0x8e, 0x02, 0xc8, 0xd4, 0xfc, 0x5f,
329
 		 0xa6, 0xbc, 0xfc, 0xfc, 0x0f, 0x51, 0xfe, 0x2f, 0x77, 0xc1,
334
 		 0xa6, 0xbc, 0xfc, 0xfc, 0x0f, 0x51, 0xfe, 0x2f, 0x77, 0xc1,
330
 		 0xc9, 0x9d, 0xf0, 0xa2, 0x09 ) );
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
 	INPUT ( 0x01, 0x04, 0x43, 0xa0, 0x2c, 0x82, 0x5c, 0x31, 0x59, 0xf4,
339
 	INPUT ( 0x01, 0x04, 0x43, 0xa0, 0x2c, 0x82, 0x5c, 0x31, 0x59, 0xf4,
335
 		0x5e, 0x8c, 0x0a, 0xe5, 0x9e, 0x8c, 0x76, 0x45, 0x69, 0x95,
340
 		0x5e, 0x8c, 0x0a, 0xe5, 0x9e, 0x8c, 0x76, 0x45, 0x69, 0x95,
336
 		0xc0, 0x35, 0x40, 0x46, 0x6a, 0x14, 0x54, 0x7c, 0xcb, 0xe8,
341
 		0xc0, 0x35, 0x40, 0x46, 0x6a, 0x14, 0x54, 0x7c, 0xcb, 0xe8,
350
 		 0xd2, 0x7e, 0x2b, 0x2e, 0x42, 0x2b, 0x32, 0xb9, 0x7f, 0x05,
355
 		 0xd2, 0x7e, 0x2b, 0x2e, 0x42, 0x2b, 0x32, 0xb9, 0x7f, 0x05,
351
 		 0x0d, 0x1b, 0xd2, 0xb4, 0x90 ) );
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
 	INPUT ( 0x00, 0x9d, 0xc3, 0x52, 0x08, 0xee, 0x2b, 0x8c, 0x58, 0x1e,
360
 	INPUT ( 0x00, 0x9d, 0xc3, 0x52, 0x08, 0xee, 0x2b, 0x8c, 0x58, 0x1e,
356
 		0xa3, 0x0b, 0xaa, 0xcb, 0x5d, 0x74, 0x31, 0x7a, 0x87, 0x94,
361
 		0xa3, 0x0b, 0xaa, 0xcb, 0x5d, 0x74, 0x31, 0x7a, 0x87, 0x94,
357
 		0x54, 0x10, 0x71, 0x7e, 0x58, 0xd3, 0x70, 0x5f, 0xbd, 0xc7,
362
 		0x54, 0x10, 0x71, 0x7e, 0x58, 0xd3, 0x70, 0x5f, 0xbd, 0xc7,
365
 		 0xef, 0x85, 0x76, 0xe7, 0x5c, 0xb3, 0xcf, 0xe8, 0x22, 0x07,
370
 		 0xef, 0x85, 0x76, 0xe7, 0x5c, 0xb3, 0xcf, 0xe8, 0x22, 0x07,
366
 		 0x68, 0xb2, 0x6c, 0xe7, 0x7a ) );
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
 	INPUT ( 0x01, 0x99, 0xb9, 0x53, 0x7b, 0x84, 0x27, 0xb8, 0xce, 0x23,
375
 	INPUT ( 0x01, 0x99, 0xb9, 0x53, 0x7b, 0x84, 0x27, 0xb8, 0xce, 0x23,
371
 		0x21, 0x9a, 0x61, 0x1c, 0xbe, 0x61, 0x06, 0x44, 0xcf, 0x85,
376
 		0x21, 0x9a, 0x61, 0x1c, 0xbe, 0x61, 0x06, 0x44, 0xcf, 0x85,
372
 		0x03, 0xee, 0xc5, 0xba, 0x22, 0xde, 0x1a, 0xb2, 0x12, 0xc3,
377
 		0x03, 0xee, 0xc5, 0xba, 0x22, 0xde, 0x1a, 0xb2, 0x12, 0xc3,
391
 		 0xaa, 0x8a, 0x6e, 0x6b, 0x8e, 0x6d, 0x56, 0xa4, 0x31, 0x33,
396
 		 0xaa, 0x8a, 0x6e, 0x6b, 0x8e, 0x6d, 0x56, 0xa4, 0x31, 0x33,
392
 		 0x3b, 0x40, 0x8e, 0x6f, 0xa8 ) );
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
 	INPUT ( 0x00, 0x56, 0x3a, 0x5d, 0x20, 0x7d, 0x37, 0x70, 0x7b, 0xf5,
401
 	INPUT ( 0x00, 0x56, 0x3a, 0x5d, 0x20, 0x7d, 0x37, 0x70, 0x7b, 0xf5,
397
 		0xf2, 0x4d, 0x0b, 0xd4, 0x93, 0x5d, 0xc3, 0x8d, 0xbe, 0x04,
402
 		0xf2, 0x4d, 0x0b, 0xd4, 0x93, 0x5d, 0xc3, 0x8d, 0xbe, 0x04,
398
 		0x36, 0x37, 0xb3, 0xff, 0x8a, 0xb6, 0x8c, 0xfc, 0xe2, 0xf2,
403
 		0x36, 0x37, 0xb3, 0xff, 0x8a, 0xb6, 0x8c, 0xfc, 0xe2, 0xf2,
406
 		 0xf6, 0xbc, 0xda, 0xf8, 0x1d, 0x28, 0x9c, 0xf4, 0xbd, 0x3c,
411
 		 0xf6, 0xbc, 0xda, 0xf8, 0x1d, 0x28, 0x9c, 0xf4, 0xbd, 0x3c,
407
 		 0x91, 0xb7, 0x00, 0x5c, 0x18 ) );
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
 	INPUT ( 0x01, 0x1c, 0x0e, 0x46, 0x75, 0x9b, 0x38, 0x55, 0x6a, 0x28,
416
 	INPUT ( 0x01, 0x1c, 0x0e, 0x46, 0x75, 0x9b, 0x38, 0x55, 0x6a, 0x28,
412
 		0xa4, 0x5e, 0x7b, 0x83, 0xe1, 0x4d, 0xb8, 0x62, 0x8d, 0xb1,
417
 		0xa4, 0x5e, 0x7b, 0x83, 0xe1, 0x4d, 0xb8, 0x62, 0x8d, 0xb1,
413
 		0x62, 0x13, 0xe1, 0xba, 0x2d, 0x97, 0x74, 0xf6, 0xc0, 0xac,
418
 		0x62, 0x13, 0xe1, 0xba, 0x2d, 0x97, 0x74, 0xf6, 0xc0, 0xac,
432
 		 0x0a, 0xb0, 0x7d, 0x12, 0x08, 0xb6, 0xbd, 0x66, 0x5b, 0x30,
437
 		 0x0a, 0xb0, 0x7d, 0x12, 0x08, 0xb6, 0xbd, 0x66, 0x5b, 0x30,
433
 		 0x0a, 0xa4, 0xdb, 0x9c, 0x3e ) );
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
 	INPUT ( 0x00, 0x60, 0x01, 0x93, 0xc8, 0xf6, 0x03, 0x1a, 0x2d, 0x49,
442
 	INPUT ( 0x00, 0x60, 0x01, 0x93, 0xc8, 0xf6, 0x03, 0x1a, 0x2d, 0x49,
438
 		0x37, 0x2a, 0x8b, 0x0f, 0x60, 0xf6, 0x8c, 0x1d, 0xfd, 0xac,
443
 		0x37, 0x2a, 0x8b, 0x0f, 0x60, 0xf6, 0x8c, 0x1d, 0xfd, 0xac,
439
 		0xd4, 0xf8, 0xea, 0x01, 0x37, 0x47, 0xd7, 0x14, 0x82, 0x33,
444
 		0xd4, 0xf8, 0xea, 0x01, 0x37, 0x47, 0xd7, 0x14, 0x82, 0x33,
454
  */
459
  */
455
 #define hash_df_ok( test ) do {						\
460
 #define hash_df_ok( test ) do {						\
456
 	uint8_t output[ (test)->expected_len ];				\
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
 	ok ( memcmp ( (test)->expected, output,				\
464
 	ok ( memcmp ( (test)->expected, output,				\
460
 		      sizeof ( output ) ) == 0 );			\
465
 		      sizeof ( output ) ) == 0 );			\
461
 	} while ( 0 )
466
 	} while ( 0 )
466
  */
471
  */
467
 static void hash_df_test_exec ( void ) {
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
 /** Hash_df self-test */
496
 /** Hash_df self-test */

Loading…
취소
저장