]> pd.if.org Git - uuid/blob - t/sha1.c
Removed unused node variable.
[uuid] / t / sha1.c
1 /*
2  * test program for uuid library
3  *
4  * written by nathan wagner and placed in the public domain
5  */
6 #include <stdio.h>
7 #include <string.h>
8 #include <stdlib.h>
9 #include <time.h>
10
11 #include "hash.h"
12 #include "ctap.h"
13
14 static void bytestr(unsigned char *h, char *s, int len) {
15         int i;
16         for (i=0; i < len; i++) {
17                 s+= sprintf(s, "%02x", h[i]);
18         }
19 }
20
21 #if 0
22 static int strbytes(char *s, unsigned char *d) {
23         unsigned int byte;
24         int i = 0;
25
26         if (!s) return 0;
27         if (*s == 0) return 0;
28
29         while (*s) {
30                 if (*s == '-' || *s == ':' || *s == ' ') s++;
31
32                 if (sscanf(s, "%02x", &byte) != 1) {
33                         return 0;
34                 }
35                 s += 2;
36                 d[i++] = byte & 0xff;
37         }
38         return i;
39 }
40 #endif
41
42 int main(int ac, char *av[]) {
43         unsigned char tmp[20];
44         hash_state md;
45         int i, j;
46         char want[64];
47         char have[64];
48
49         static struct {
50                 char *msg;
51                 int repeat;
52                 unsigned char hash[20];
53         } tests[] = {
54         { "abc", 1, 
55         { 0xa9, 0x99, 0x3e, 0x36, 0x47, 0x06, 0x81, 0x6a,
56         0xba, 0x3e, 0x25, 0x71, 0x78, 0x50, 0xc2, 0x6c,
57         0x9c, 0xd0, 0xd8, 0x9d }
58         },
59         { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1, 
60         { 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E,
61         0xBA, 0xAE, 0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5,
62         0xE5, 0x46, 0x70, 0xF1 }
63         },
64         { "a", 1000000, 
65         { 0x34, 0xAA, 0x97, 0x3C, 0xD4, 0xC4, 0xDA, 0xA4,
66         0xF6, 0x1E, 0xEB, 0x2B, 0xDB, 0xAD, 0x27, 0x31,
67         0x65, 0x34, 0x01, 0x6F },
68         },
69         { "0123456701234567012345670123456701234567012345670123456701234567", 10, 
70         {0xDE, 0xA3, 0x56, 0xA2, 0xCD, 0xDD, 0x90, 0xC7, 0xA7, 0xEC, 0xED, 0xC5, 0xEB, 0xB5, 0x63, 0x93, 0x4F, 0x46, 0x04, 0x52},
71         },
72     { NULL, 0, { 0 } }
73   };
74
75         plan(8);
76
77         for (i = 0; tests[i].msg != NULL; i++) {
78                 sha1_init(&md);
79                 for (j=0; j<tests[i].repeat; j++) {
80                 sha1_process(&md, (unsigned char *)tests[i].msg, (unsigned long)strlen(tests[i].msg));
81                 }
82                 sha1_done(&md, tmp);
83                 ok(memcmp(tmp, tests[i].hash, 20) == 0, "sha1 %s", tests[i].msg);
84                 bytestr(tmp, have, 20);
85                 bytestr(tests[i].hash, want, 20);
86                 is_string(want, have, "sha1 string %s", tests[1].msg);
87         }
88
89         return 0;
90 }