1 // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
11 uint8_t entropy
[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
12 uint8_t digest
[SHA1_DIGEST_LENGTH
];
15 SHA1Update(&ctx
, entropy
, __arraycount(entropy
));
16 SHA1Final(digest
, &ctx
);
19 for (size_t i
= 0; i
< __arraycount(digest
); i
++)
20 printf("%02x", digest
[i
]);
24 void local_SHA1Update(SHA1_CTX
*context
, const uint8_t *data
, unsigned int len
)
28 b
= context
->count
[0];
29 context
->count
[0] += len
<< 3;
30 if (context
->count
[0] < b
)
31 context
->count
[1] += (len
>> 29) + 1;
34 memcpy(&context
->buffer
[b
], data
, (a
= 64 - b
));
35 SHA1Transform(context
->state
, context
->buffer
);
36 for ( ; a
+ 63 < len
; a
+= 64)
37 SHA1Transform(context
->state
, &data
[a
]);
42 memcpy(&context
->buffer
[b
], &data
[a
], len
- a
);
47 uint8_t entropy
[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
48 uint8_t digest
[SHA1_DIGEST_LENGTH
];
51 local_SHA1Update(&ctx
, entropy
, __arraycount(entropy
));
52 SHA1Final(digest
, &ctx
);
55 for (size_t i
= 0; i
< __arraycount(digest
); i
++)
56 printf("%02x", digest
[i
]);
62 uint8_t entropy
[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
63 char digest
[SHA1_DIGEST_STRING_LENGTH
];
66 SHA1Update(&ctx
, entropy
, __arraycount(entropy
));
67 char *p
= SHA1End(&ctx
, digest
);
70 printf("test3: '%s'\n", digest
);
75 uint8_t entropy
[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
78 SHA1Update(&ctx
, entropy
, __arraycount(entropy
));
79 char *p
= SHA1End(&ctx
, NULL
);
80 assert(strlen(p
) == SHA1_DIGEST_STRING_LENGTH
- 1);
82 printf("test4: '%s'\n", p
);
88 char digest
[SHA1_DIGEST_STRING_LENGTH
];
90 char *p
= SHA1File("/etc/fstab", digest
);
93 printf("test5: '%s'\n", p
);
97 char *p
= SHA1File("/etc/fstab", NULL
);
98 assert(strlen(p
) == SHA1_DIGEST_STRING_LENGTH
- 1);
100 printf("test6: '%s'\n", p
);
106 char digest
[SHA1_DIGEST_STRING_LENGTH
];
108 char *p
= SHA1FileChunk("/etc/fstab", digest
, 10, 20);
111 printf("test7: '%s'\n", p
);
115 char *p
= SHA1FileChunk("/etc/fstab", NULL
, 10, 20);
116 assert(strlen(p
) == SHA1_DIGEST_STRING_LENGTH
- 1);
118 printf("test8: '%s'\n", p
);
124 uint8_t entropy
[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
125 char digest
[SHA1_DIGEST_STRING_LENGTH
];
127 char *p
= SHA1Data(entropy
, __arraycount(entropy
), digest
);
130 printf("test9: '%s'\n", p
);
134 uint8_t entropy
[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
136 char *p
= SHA1Data(entropy
, __arraycount(entropy
), NULL
);
137 assert(strlen(p
) == SHA1_DIGEST_STRING_LENGTH
- 1);
139 printf("test10: '%s'\n", p
);
159 // CHECK: test1: '57d1b759bf3d1811135748cb0328c73b51fa6f57'
160 // CHECK: test2: '57d1b759bf3d1811135748cb0328c73b51fa6f57'
161 // CHECK: test3: '57d1b759bf3d1811135748cb0328c73b51fa6f57'
162 // CHECK: test4: '57d1b759bf3d1811135748cb0328c73b51fa6f57'
163 // CHECK: test5: '{{.*}}'
164 // CHECK: test6: '{{.*}}'
165 // CHECK: test7: '{{.*}}'
166 // CHECK: test8: '{{.*}}'
167 // CHECK: test9: '57d1b759bf3d1811135748cb0328c73b51fa6f57'
168 // CHECK: test10: '57d1b759bf3d1811135748cb0328c73b51fa6f57'