-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsha256_example.c~
52 lines (46 loc) · 1.17 KB
/
sha256_example.c~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include "sha256.h"
#include <string.h>
/*
Output should be:
ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1
cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0
*/
void print_hash(unsigned char hash[])
{
int idx;
for (idx=0; idx < 32; idx++)
printf("%02x",hash[idx]);
printf("\n");
}
int main()
{
unsigned char text1[]={"abc"},
text2[]={"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"},
text3[]={"z"},
hash[32];
int idx;
SHA256_CTX ctx;
// Hash one
sha256_init(&ctx);
sha256_update(&ctx,text1,strlen(text1));
sha256_final(&ctx,hash);
printf("%s",hash);
print_hash(hash);
// Hash two
sha256_init(&ctx);
sha256_update(&ctx,text2,strlen(text2));
sha256_final(&ctx,hash);
print_hash(hash);
printf("Pito %d\n",strlen(hash));
// Hash three
sha256_init(&ctx);
for (idx=0; idx < 100000; ++idx)
sha256_update(&ctx,text3,strlen(text3));
sha256_final(&ctx,hash);
print_hash(hash);
printf("Pito %d\n",strlen(hash));
//getchar();
return 0;
}