@@ -70,24 +70,11 @@ use SHA1_ prefix for public api
70
70
move public api to sha1.h
71
71
*/
72
72
73
- /*
74
- Test Vectors (from FIPS PUB 180-1)
75
- "abc"
76
- A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
77
- "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
78
- 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
79
- A million repetitions of "a"
80
- 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
81
- */
82
-
83
73
/* #define SHA1HANDSOFF */
84
74
85
- #include <stdio.h>
86
75
#include <string.h>
87
76
88
- /* make sure the stdint.h types are available */
89
77
#include "ostypes.h"
90
-
91
78
#include "sha1.h"
92
79
93
80
static uint32_t host_to_be (uint32_t i );
@@ -109,19 +96,6 @@ static void SHA1_Transform(uint32_t state[5], const uint8_t buffer[64]);
109
96
#define R4 (v ,w ,x ,y ,z ,i ) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
110
97
111
98
112
- #ifdef VERBOSE /* SAK */
113
- void SHAPrintContext (SHA1_CTX * context , char * msg ){
114
- printf ("%s (%d,%d) %x %x %x %x %x\n" ,
115
- msg ,
116
- context -> count [0 ], context -> count [1 ],
117
- context -> state [0 ],
118
- context -> state [1 ],
119
- context -> state [2 ],
120
- context -> state [3 ],
121
- context -> state [4 ]);
122
- }
123
- #endif /* VERBOSE */
124
-
125
99
static uint32_t host_to_be (uint32_t i )
126
100
{
127
101
#define le_to_be (i ) ((rol((i),24) & 0xFF00FF00) | (rol((i),8) & 0x00FF00FF))
@@ -220,10 +194,6 @@ void crypto_SHA1_Update(SHA1_CTX* context, const uint8_t* data,
220
194
{
221
195
size_t i , j ;
222
196
223
- #ifdef VERBOSE
224
- SHAPrintContext (context , "before" );
225
- #endif
226
-
227
197
j = (context -> count [0 ] >> 3 ) & 63 ;
228
198
if ((context -> count [0 ] += len << 3 ) < (len << 3 )) context -> count [1 ]++ ;
229
199
context -> count [1 ] += (len >> 29 );
@@ -237,10 +207,6 @@ void crypto_SHA1_Update(SHA1_CTX* context, const uint8_t* data,
237
207
}
238
208
else i = 0 ;
239
209
memcpy (& context -> buffer [j ], & data [i ], len - i );
240
-
241
- #ifdef VERBOSE
242
- SHAPrintContext (context , "after " );
243
- #endif
244
210
}
245
211
246
212
@@ -284,120 +250,3 @@ void crypto_SHA1(const uint8_t* data, size_t len, uint8_t* digest)
284
250
crypto_SHA1_Update (& ctx , data , len );
285
251
crypto_SHA1_Final (& ctx , digest );
286
252
}
287
-
288
- /*************************************************************/
289
-
290
- #if 0
291
- int main (int argc , char * * argv )
292
- {
293
- int i , j ;
294
- SHA1_CTX context ;
295
- unsigned char digest [SHA1_DIGEST_SIZE ], buffer [16384 ];
296
- FILE * file ;
297
-
298
- if (argc > 2 ) {
299
- puts ("Public domain SHA-1 implementation - by Steve Reid <sreid@sea-to-sky.net>" );
300
- puts ("Modified for 16 bit environments 7/98 - by James H. Brown <jbrown@burgoyne.com>" ); /* JHB */
301
- puts ("Produces the SHA-1 hash of a file, or stdin if no file is specified." );
302
- return (0 );
303
- }
304
- if (argc < 2 ) {
305
- file = stdin ;
306
- }
307
- else {
308
- if (!(file = fopen (argv [1 ], "rb" ))) {
309
- fputs ("Unable to open file." , stderr );
310
- return (-1 );
311
- }
312
- }
313
- crypto_SHA1_Init (& context );
314
- while (!feof (file )) { /* note: what if ferror(file) */
315
- i = fread (buffer , 1 , 16384 , file );
316
- crypto_SHA1_Update (& context , buffer , i );
317
- }
318
- crypto_SHA1_Final (& context , digest );
319
- fclose (file );
320
- for (i = 0 ; i < SHA1_DIGEST_SIZE /4 ; i ++ ) {
321
- for (j = 0 ; j < 4 ; j ++ ) {
322
- printf ("%02X" , digest [i * 4 + j ]);
323
- }
324
- putchar (' ' );
325
- }
326
- putchar ('\n' );
327
- return (0 ); /* JHB */
328
- }
329
- #endif
330
-
331
- /* self test */
332
-
333
- #ifdef TEST
334
-
335
- static char * test_data [] = {
336
- "abc" ,
337
- "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" ,
338
- "A million repetitions of 'a'" };
339
- static char * test_results [] = {
340
- "A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D" ,
341
- "84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1" ,
342
- "34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F" };
343
-
344
-
345
- void digest_to_hex (const uint8_t digest [SHA1_DIGEST_SIZE ], char * output )
346
- {
347
- int i ,j ;
348
- char * c = output ;
349
-
350
- for (i = 0 ; i < SHA1_DIGEST_SIZE /4 ; i ++ ) {
351
- for (j = 0 ; j < 4 ; j ++ ) {
352
- sprintf (c ,"%02X" , digest [i * 4 + j ]);
353
- c += 2 ;
354
- }
355
- sprintf (c , " " );
356
- c += 1 ;
357
- }
358
- * (c - 1 ) = '\0' ;
359
- }
360
-
361
- int main (int argc , char * * argv )
362
- {
363
- int k ;
364
- SHA1_CTX context ;
365
- uint8_t digest [20 ];
366
- char output [80 ];
367
-
368
- fprintf (stdout , "verifying SHA-1 implementation... " );
369
-
370
- for (k = 0 ; k < 2 ; k ++ ){
371
- crypto_SHA1_Init (& context );
372
- crypto_SHA1_Update (& context , (uint8_t * )test_data [k ],
373
- strlen (test_data [k ]));
374
- crypto_SHA1_Final (& context , digest );
375
- digest_to_hex (digest , output );
376
-
377
- if (strcmp (output , test_results [k ])) {
378
- fprintf (stdout , "FAIL\n" );
379
- fprintf (stderr ,"* hash of \"%s\" incorrect:\n" , test_data [k ]);
380
- fprintf (stderr ,"\t%s returned\n" , output );
381
- fprintf (stderr ,"\t%s is correct\n" , test_results [k ]);
382
- return (1 );
383
- }
384
- }
385
- /* million 'a' vector we feed separately */
386
- crypto_SHA1_Init (& context );
387
- for (k = 0 ; k < 1000000 ; k ++ )
388
- crypto_SHA1_Update (& context , (uint8_t * )"a" , 1 );
389
- crypto_SHA1_Final (& context , digest );
390
- digest_to_hex (digest , output );
391
- if (strcmp (output , test_results [2 ])) {
392
- fprintf (stdout , "FAIL\n" );
393
- fprintf (stderr ,"* hash of \"%s\" incorrect:\n" , test_data [2 ]);
394
- fprintf (stderr ,"\t%s returned\n" , output );
395
- fprintf (stderr ,"\t%s is correct\n" , test_results [2 ]);
396
- return (1 );
397
- }
398
-
399
- /* success */
400
- fprintf (stdout , "ok\n" );
401
- return (0 );
402
- }
403
- #endif /* TEST */
0 commit comments