1 /*---------------------------------------------------------------------------*
2 Project: NET demo
3 File: digest.c
4
5 Copyright (C) 2006 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Log: digest.c,v $
14 Revision 1.10 2006/10/11 04:29:16 yosizaki
15 added USING_HMAC_CONTEXT switch.
16
17 Revision 1.9 2006/08/29 07:07:02 seiki_masashi
18 Changed so that NETCalcMD5 and NETCalcSHA1 are also used.
19
20 Revision 1.8 2006/08/29 06:48:52 kitase_hirotake
21 rename function
22
23 Revision 1.7 2006/08/29 06:35:55 seiki_masashi
24 Added test of HMAC-SHA1.
25
26 Revision 1.6 2006/08/29 06:27:00 yosizaki
27 small fix.
28
29 Revision 1.5 2006/08/29 05:55:02 seiki_masashi
30 Added test of SHA-1.
31
32 Revision 1.4 2006/08/29 05:50:07 kitase_hirotake
33 Added HMAC-MD5 test
34
35 Revision 1.3 2006/08/28 08:20:58 seiki_masashi
36 added MD5 tests
37
38 Revision 1.2 2006/08/28 05:51:03 seiki_masashi
39 Initial revision
40
41 $NoKeywords: $
42 *---------------------------------------------------------------------------*/
43 #include <demo.h>
44 #include <revolution/net.h>
45 #include <string.h>
46
47 #define LINES 24
48 #define STACK_SIZE 4000
49
50 static void DoReport(void);
51 static void* DoTest(void* arg);
52
53 GXColor Black = { 0, 0, 0, 0 };
54 GXColor Blue = { 0, 0, 192, 0 };
55 GXColor Red = { 255, 0, 0, 0 };
56 GXColor Green = { 0, 224, 0, 0 };
57 GXColor White = { 255, 255, 255, 0 };
58
59 GXColor SucceededGreen = { 0, 128, 0, 0 };
60 GXColor FailedRed = { 128, 0, 0, 0 };
61
62 static char ReportBuffer[4096];
63 static char PrintBuffer[4096];
64
65 static OSThread testThread;
66 static u8 testThreadStack[STACK_SIZE] ATTRIBUTE_ALIGN(32);
67
68
69 /*---------------------------------------------------------------------------*
70 Application main loop
71 *---------------------------------------------------------------------------*/
main(void)72 void main(void)
73 {
74 DEMOInit(NULL);
75 if ( ! DEMOInitROMFont() )
76 {
77 OSHalt("DEMOInitROMFont()");
78 }
79
80 // Clear EFB
81 GXSetCopyClear(Blue, GX_MAX_Z24);
82 GXCopyDisp(DEMOGetCurrentBuffer(), GX_TRUE);
83
84 (void)OSReport("NET Demo: Test digest functions\n");
85
86 // Launch the test thread
87 if( ! OSCreateThread( &testThread, DoTest, NULL,
88 (void*)((u32)testThreadStack + STACK_SIZE), STACK_SIZE,
89 20, 0 ) )
90 {
91 OSHalt( "OSCrateThread()" );
92 }
93 if ( OSResumeThread( &testThread ) < 0 )
94 {
95 OSHalt( "OSResumeThread()" );
96 }
97
98 while ( ! OSIsThreadTerminated(&testThread) )
99 {
100 DEMOBeforeRender();
101 DoReport();
102 DEMODoneRender();
103 }
104
105 {
106 BOOL result;
107
108 if( ! OSJoinThread( &testThread, (void**)&result ) )
109 {
110 OSHalt( "OSJoinThread()" );
111 }
112 if ( result )
113 {
114 // succeeded
115 OSReport("------ Test Succeeded ------\n");
116 GXSetCopyClear(SucceededGreen, GX_MAX_Z24);
117 GXCopyDisp(DEMOGetCurrentBuffer(), GX_TRUE);
118 }
119 else
120 {
121 // failed
122 OSReport("****** Test Failed ******\n");
123 GXSetCopyClear(FailedRed, GX_MAX_Z24);
124 GXCopyDisp(DEMOGetCurrentBuffer(), GX_TRUE);
125 }
126 }
127
128 while ( TRUE )
129 {
130 DEMOBeforeRender();
131 DoReport();
132 DEMODoneRender();
133 }
134 }
135
136 /*---------------------------------------------------------------------------*
137 Display Settings
138 *---------------------------------------------------------------------------*/
139
DoReport(void)140 static void DoReport(void)
141 {
142 GXRenderModeObj* rmp;
143
144 rmp = DEMOGetRenderModeObj();
145 DEMOInitCaption(DM_FT_XLU, (s16) rmp->fbWidth, (s16) rmp->efbHeight);
146 DEMOSetROMFontSize(16, -1);
147 (void)DEMORFPuts(25, 25, 0, ReportBuffer);
148 }
149
150 // Define program-specific OSReport() function.
OSReport(const char * msg,...)151 void OSReport(const char* msg, ...)
152 {
153 BOOL enabled;
154 va_list marker;
155 u32 len;
156 int c;
157 char* p;
158 char* q;
159
160 va_start(marker, msg);
161 (void)vsnprintf(PrintBuffer, sizeof(PrintBuffer)-1, msg, marker);
162 va_end(marker);
163 PrintBuffer[sizeof(PrintBuffer)-1] = 0;
164
165 (void)printf("%s", PrintBuffer);
166
167 enabled = OSDisableInterrupts();
168
169 (void)strncat(ReportBuffer, PrintBuffer, sizeof(ReportBuffer)-1);
170 ReportBuffer[sizeof(ReportBuffer)-1] = 0;
171 len = strlen(ReportBuffer);
172
173 c = 0;
174 q = ReportBuffer;
175 for (p = ReportBuffer; p < ReportBuffer + len; ++p)
176 {
177 if (*p == '\n')
178 {
179 ++c;
180 if (LINES <= c)
181 {
182 q = strchr(q, '\n');
183 }
184 }
185 }
186 if (LINES <= c)
187 {
188 (void)memmove(ReportBuffer, q + 1, len - (q - ReportBuffer));
189 }
190
191 (void)OSRestoreInterrupts(enabled);
192 }
193
194
195 /*---------------------------------------------------------------------------*
196 Tests
197 *---------------------------------------------------------------------------*/
198
199 #define PrintResultEq( a, b, f ) \
200 do { OSReport( ((a) == (b)) ? "[--OK--] " : "[**NG**] " ); (f) = (f) && ((a) == (b)); } while( FALSE )
201 #define PrintResultDigestEq( a, b, l, f ) \
202 do { OSReport( (memcmp((a), (b), (l)) == 0) ? "[--OK--] " : "[**NG**] " ); (f) = (f) && (memcmp((a), (b), (l)) == 0); } while( FALSE )
203
DoTest(void * arg)204 static void* DoTest(void* arg)
205 {
206 BOOL flag = TRUE;
207 int i, j;
208
209 (void)arg;
210
211 // Test CRC-16
212 {
213 char *a[] = {
214 "123456789",
215 };
216 u16 result_crc16[] = {
217 0xbb3d,
218 };
219 for (i = 0; i < sizeof(a) / sizeof(char *); i++)
220 {
221 u16 result;
222
223 result = NETCalcCRC16(a[i], strlen(a[i]));
224 PrintResultEq(result, result_crc16[i], flag);
225 OSReport("NETCalcCRC16(%s) = %04x\n", a[i], result);
226 }
227 }
228
229 // Test CRC-32
230 {
231 char *a[] = {
232 "123456789",
233 };
234 u32 result_crc32[] = {
235 0xcbf43926,
236 };
237 for (i = 0; i < sizeof(a) / sizeof(char *); i++)
238 {
239 u32 result;
240
241 result = NETCalcCRC32(a[i], strlen(a[i]));
242 PrintResultEq(result, result_crc32[i], flag);
243 OSReport("NETCalcCRC32(%s) = %04x\n", a[i], result);
244 }
245 }
246
247 // Test MD5
248 // see: RFC1321 A.5 Test suite
249 {
250 char *a[] = {
251 "",
252 "a",
253 "abc",
254 "message digest",
255 "abcdefghijklmnopqrstuvwxyz",
256 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
257 "1234567890",
258 "FHXXKCVGGOFRILWGDLFQLZBLQSNYXWUCTXCBBVHUDWXLSFNIFTBNCGOMLXPQQFFJEOBXFBZNEDWMSKPPEWXONABBPRBHVDNQXPRHQGMLUHJVUPOXYUHDEXYMZBJCFNYZSKMPNLPYADWGXEKPYPKGNHQZMPBMSCYYYUPVPQZSYPPPIGKBQZUWOUCMVLFKORUIZWVWFVBEPZBXASLDAVBEHMJGYPYBQZAKHNLOFCPQVRRGKOVVRNERIFFJZIYAECMNHTRCUWGAKRZXPORLXLRXVRVVJIRTNDDIEFNGWFXBFDPPFOMPFWRGXQUBJYTNCCXKTUGRQYYGRFMDPKTWWFREVAUNHSAWUQQJOPIGRWHJDDOVHZHHGXDKVSDYRGXGCWMKQSENCIMJQOGNGAZFTDXYEVNRDWDKCKPJPIXZKCGJPEGFIJANNPJYHIRLPUBQAJSFMYLVGCPQZRUNKRRWEBLZYYOQUHGEMKGCXPKBWRXRANLRRHLGZSMONYDRIFPHOYSVYKZJRUSOVVUCULTSBOSGKYUVYCVHMIASIBFKGPRCKLVXZAGKCQUKMIHOIQJRBCJBKOYRNACLNHPSDBKUFBXAODNVHVTVVHHZEBAVRVMKBBEOYJSABXUDBJQEFLLYVBPWMSQQVLTGCASWRSHPIDOZRPZUCHYREWFCDZJOMMUGPHPTKWEIJIIGEHNFXKLWIHPKYORNBXESRYZMUNTJDGNQFGAFFRAWCKYRBZGNBZKOWAGWXZCOOEERHWPYIVXHDSZAVYFUBXNRJCVDDUJWWMYYXMCTXANZOPVULYAGPXZUQRBOAWEJKTUKIIDZVBVQRKINSAMSYKZVCINUUWVBVVUGGXLKMVBTFEESRQTNPOEYZRZVJBUEEXIQOXEWLMUUJQUWNOQTQQNJFBDNTCXMNJMJBIOCQZUCKCZFECNAXBXHLTCVURSEBLVAUIJKVGWZETIVGHWOFGRFPLIWQAUMTZOELCXBMVLHBRFZUIEIYWWUY",
259 "YEDCGPVKFGWXYSDLTQOYAFHSJYABKIMQHJGDCKUSLRDQFJDGPVWBSBQ",
260 "YEDCGPVKFGWXYSDLTQOYAFHSJYABKIMQHJGDCKUSLRDQFJDGPVWBSBQZ",
261 "YEDCGPVKFGWXYSDLTQOYAFHSJYABKIMQHJGDCKUSLRDQFJDGPVWBSBQZZ",
262 };
263 int c[] = { 1, 1, 1, 1, 1, 1, 8, 1, 2, 2, 2 };
264 char *result_md5[] = {
265 "\xD4\x1D\x8C\xD9\x8F\x00\xB2\x04\xE9\x80\x09\x98\xEC\xF8\x42\x7E",
266 "\x0C\xC1\x75\xB9\xC0\xF1\xB6\xA8\x31\xC3\x99\xE2\x69\x77\x26\x61",
267 "\x90\x01\x50\x98\x3C\xD2\x4F\xB0\xD6\x96\x3F\x7D\x28\xE1\x7F\x72",
268 "\xF9\x6B\x69\x7D\x7C\xB7\x93\x8D\x52\x5A\x2F\x31\xAA\xF1\x61\xD0",
269 "\xC3\xFC\xD3\xD7\x61\x92\xE4\x00\x7D\xFB\x49\x6C\xCA\x67\xE1\x3B",
270 "\xD1\x74\xAB\x98\xD2\x77\xD9\xF5\xA5\x61\x1C\x2C\x9F\x41\x9D\x9F",
271 "\x57\xED\xF4\xA2\x2B\xE3\xC9\x55\xAC\x49\xDA\x2E\x21\x07\xB6\x7A",
272 "\x72\xcc\x6a\x07\x35\x47\x48\x5d\xe7\x53\xcd\xa5\x90\xcb\x90\xbd",
273 "\x5c\x07\x79\xcb\x86\xb1\x89\x2b\xe5\x3b\xdc\x72\x7b\x3b\x9b\x41",
274 "\xc8\x69\xd4\x26\xf3\x4f\x78\x1b\xed\xaf\xdc\x9d\x29\xaf\x75\x7f",
275 "\xa3\x1b\xd7\x8a\x72\x15\xa7\xc8\x59\x41\x51\xd5\x4b\xc8\x7d\x30",
276 };
277 for (i = 0; i < sizeof(a) / sizeof(char *); i++)
278 {
279 u8 result[NET_MD5_DIGEST_SIZE];
280
281 if( c[i] == 1 )
282 {
283 NETCalcMD5(result, a[i], strlen(a[i]));
284 }
285 else
286 {
287 NETMD5Context context;
288
289 NETMD5Init(&context);
290 for (j = 0; j < c[i]; j++)
291 {
292 NETMD5Update(&context, a[i], strlen(a[i]));
293 }
294 NETMD5GetDigest(&context, result);
295 }
296 PrintResultDigestEq(result, (u8 *)result_md5[i], sizeof(result), flag);
297 OSReport("NET_MD5(%.70s) * %d\n", a[i], c[i]);
298 }
299 }
300
301 #define USING_HMAC_CONTEXT
302
303 // Perform HMAC-MD5 operation test.
304 // See RFC2202.
305 {
306 char *d[] = {
307 "Hi There",
308 "what do ya want for nothing?",
309 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
310 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
311 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
312 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
313 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
314 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd",
315 "Test With Truncation", // This test program does not use truncation.
316 "Test Using Larger Than Block-Size Key - Hash Key First",
317 "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
318 };
319 int dl[] = { 8, 28, 50, 50, 20, 54, 73 };
320 char *k[] = {
321 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
322 "Jefe",
323 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
324 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
325 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c",
326 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
327 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
328 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
329 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
330 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
331 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
332 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
333 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
334 };
335 int kl[] = { 16, 4, 16, 25, 16, 80, 80 };
336 char *result_hmacmd5[] = {
337 "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc\x9d",
338 "\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7\x38",
339 "\x56\xbe\x34\x52\x1d\x14\x4c\x88\xdb\xb8\xc7\x33\xf0\xe8\xb3\xf6",
340 "\x69\x7e\xaf\x0a\xca\x3a\x3a\xea\x3a\x75\x16\x47\x46\xff\xaa\x79",
341 "\x56\x46\x1e\xf2\x34\x2e\xdc\x00\xf9\xba\xb9\x95\x69\x0e\xfd\x4c",
342 "\x6b\x1a\xb7\xfe\x4b\xd7\xbf\x8f\x0b\x62\xe6\xce\x61\xb9\xd0\xcd",
343 "\x6f\x63\x0f\xad\x67\xcd\xa0\xee\x1f\xb1\xf5\x62\xdb\x3a\xa5\x3e",
344 };
345 for (i = 0; i < sizeof(d) / sizeof(char *); i++)
346 {
347 u8 result[NET_MD5_DIGEST_SIZE];
348
349 #ifndef USING_HMAC_CONTEXT
350 NETCalcHMACMD5(result, d[i], dl[i], k[i], kl[i]);
351 #else /* USING_HMAC_CONTEXT */
352 {
353 NETHMACContext hmac[1];
354 NETHMACInit(hmac, NET_HASH_INTERFACE_MD5, k[i], (u32)kl[i]);
355 NETHMACUpdate(hmac, d[i], (u32)dl[i]);
356 NETHMACGetDigest(hmac, result);
357 }
358 #endif /* USING_HMAC_CONTEXT */
359 PrintResultDigestEq(result, (u8 *)result_hmacmd5[i], sizeof(result), flag);
360 OSReport("NETCalcHMACMD5: Test Case %d\n", i + 1);
361 }
362 }
363
364 // Perform SHA-1 operation test.
365 // See RFC3174 7.3 Test Driver.
366 {
367 char *a[] = {
368 "abc",
369 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
370 "a",
371 "0123456701234567012345670123456701234567012345670123456701234567",
372 };
373 int c[] = { 1, 1, 1000000, 10 };
374 char *result_sha1[] = {
375 "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D",
376 "\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29\xE5\xE5\x46\x70\xF1",
377 "\x34\xAA\x97\x3C\xD4\xC4\xDA\xA4\xF6\x1E\xEB\x2B\xDB\xAD\x27\x31\x65\x34\x01\x6F",
378 "\xDE\xA3\x56\xA2\xCD\xDD\x90\xC7\xA7\xEC\xED\xC5\xEB\xB5\x63\x93\x4F\x46\x04\x52",
379 };
380 for (i = 0; i < sizeof(a) / sizeof(char *); i++)
381 {
382 u8 result[NET_SHA1_DIGEST_SIZE];
383
384 if( c[i] == 1 )
385 {
386 NETCalcSHA1(result, a[i], strlen(a[i]));
387 }
388 else
389 {
390 NETSHA1Context context;
391
392 NETSHA1Init(&context);
393 for (j = 0; j < c[i]; j++)
394 {
395 NETSHA1Update(&context, a[i], strlen(a[i]));
396 }
397 NETSHA1GetDigest(&context, result);
398 }
399 PrintResultDigestEq(result, (u8 *)result_sha1[i], sizeof(result), flag);
400 OSReport("NET_SHA1(%.70s) * %d\n", a[i], c[i]);
401 }
402 }
403
404 // Perform HMAC-SHA-1 operation test.
405 // See RFC2202.
406 {
407 char *d[] = {
408 "Hi There",
409 "what do ya want for nothing?",
410 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
411 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
412 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
413 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
414 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
415 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd",
416 "Test With Truncation", // This test program does not use truncation.
417 "Test Using Larger Than Block-Size Key - Hash Key First",
418 "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
419 };
420 int dl[] = { 8, 28, 50, 50, 20, 54, 73 };
421 char *k[] = {
422 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
423 "Jefe",
424 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
425 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
426 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c",
427 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
428 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
429 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
430 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
431 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
432 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
433 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
434 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
435 };
436 int kl[] = { 20, 4, 20, 25, 20, 80, 80 };
437 char *result_hmacsha1[] = {
438 "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c\x8e\xf1\x46\xbe\x00",
439 "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79",
440 "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f\x63\xf1\x75\xd3",
441 "\x4c\x90\x07\xf4\x02\x62\x50\xc6\xbc\x84\x14\xf9\xbf\x50\xc8\x6c\x2d\x72\x35\xda",
442 "\x4c\x1a\x03\x42\x4b\x55\xe0\x7f\xe7\xf2\x7b\xe1\xd5\x8b\xb9\x32\x4a\x9a\x5a\x04",
443 "\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70\x56\x37\xce\x8a\x3b\x55\xed\x40\x21\x12",
444 "\xe8\xe9\x9d\x0f\x45\x23\x7d\x78\x6d\x6b\xba\xa7\x96\x5c\x78\x08\xbb\xff\x1a\x91",
445 };
446 for (i = 0; i < sizeof(d) / sizeof(char *); i++)
447 {
448 u8 result[NET_SHA1_DIGEST_SIZE];
449
450 #ifndef USING_HMAC_CONTEXT
451 NETCalcHMACSHA1(result, d[i], dl[i], k[i], kl[i]);
452 #else /* USING_HMAC_CONTEXT */
453 {
454 NETHMACContext hmac[1];
455 NETHMACInit(hmac, NET_HASH_INTERFACE_SHA1, k[i], (u32)kl[i]);
456 NETHMACUpdate(hmac, d[i], (u32)dl[i]);
457 NETHMACGetDigest(hmac, result);
458 }
459 #endif /* USING_HMAC_CONTEXT */
460 PrintResultDigestEq(result, (u8 *)result_hmacsha1[i], sizeof(result), flag);
461 OSReport("NETCalcHMACSHA1: Test Case %d\n", i + 1);
462 }
463 }
464
465 return (void*)flag;
466 }
467