-
Notifications
You must be signed in to change notification settings - Fork 1
/
sha2.c
executable file
·73 lines (57 loc) · 1.08 KB
/
sha2.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Sample Implementation of SHA-256 for Message "abc"
* Ritobroto Maitra, 2015
*/
/**
* ALWAYS USE UNSIGNED
*
*/
#include "sha2.h"
int main() {
int i;
unsigned int test[64]={0};
for(i=0;i<16;i++)
test[i] = 0;
test[0] = 0x61626380;
test[15] = 0x00000018;
/**
* Message Expansion
*/
for(i=16;i<64;i++)
test[i] = (s1(test[i-2])) + test[i-7] + (s0(test[i-15])) + test[i-16];
unsigned int a, b, c, d, e, f, g, h;
a = h0;
b = h1;
c = h2;
d = h3;
e = h4;
f = h5;
g = h6;
h = h7;
i = 0;
printf("\nStep: %2d\t%8x %8x %8x %8x\n\t\t%8x %8x %8x %8x\n", i,a, b, c, d, e, f, g, h);
int t1, t2;
for(i=0;i<64;i++) {
t1 = h + (S1(e)) + (ch(e, f, g)) + k[i] + test[i];
t2 = (S0(a)) + (mj(a,b,c));
h = g;
g = f;
f = e;
e = d + t1;
d = c;
c = b;
b = a;
a = t1 + t2;
printf("\nStep: %2d\t%8x %8x %8x %8x\n\t\t%8x %8x %8x %8x\n", i+1,a, b, c, d, e, f, g, h);
}
a += h0;
b += h1;
c += h2;
d += h3;
e += h4;
f += h5;
g += h6;
h += h7;
printf("\n%8x %8x %8x %8x\n%8x %8x %8x %8x\n", a, b, c, d, e, f, g, h);
}
/* End of Implementation */