comparison sha1.c @ 15:6362d3854bb4 libtomcrypt-orig

0.96 release of LibTomCrypt
author Matt Johnston <matt@ucc.asn.au>
date Tue, 15 Jun 2004 14:07:21 +0000
parents 7faae8f46238
children 5d99163f7e32
comparison
equal deleted inserted replaced
3:7faae8f46238 15:6362d3854bb4
18 { 18 {
19 "sha1", 19 "sha1",
20 2, 20 2,
21 20, 21 20,
22 64, 22 64,
23
24 /* DER identifier */
25 { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E,
26 0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14 },
27 15,
28
23 &sha1_init, 29 &sha1_init,
24 &sha1_process, 30 &sha1_process,
25 &sha1_done, 31 &sha1_done,
26 &sha1_test 32 &sha1_test
27 }; 33 };
36 #else 42 #else
37 static void sha1_compress(hash_state *md, unsigned char *buf) 43 static void sha1_compress(hash_state *md, unsigned char *buf)
38 #endif 44 #endif
39 { 45 {
40 ulong32 a,b,c,d,e,W[80],i; 46 ulong32 a,b,c,d,e,W[80],i;
47 #ifdef SMALL_CODE
48 ulong32 t;
49 #endif
41 50
42 /* copy the state into 512-bits into W[0..15] */ 51 /* copy the state into 512-bits into W[0..15] */
43 for (i = 0; i < 16; i++) { 52 for (i = 0; i < 16; i++) {
44 LOAD32H(W[i], buf + (4*i)); 53 LOAD32H(W[i], buf + (4*i));
45 } 54 }
61 #define FF0(a,b,c,d,e,i) e = (ROL(a, 5) + F0(b,c,d) + e + W[i] + 0x5a827999UL); b = ROL(b, 30); 70 #define FF0(a,b,c,d,e,i) e = (ROL(a, 5) + F0(b,c,d) + e + W[i] + 0x5a827999UL); b = ROL(b, 30);
62 #define FF1(a,b,c,d,e,i) e = (ROL(a, 5) + F1(b,c,d) + e + W[i] + 0x6ed9eba1UL); b = ROL(b, 30); 71 #define FF1(a,b,c,d,e,i) e = (ROL(a, 5) + F1(b,c,d) + e + W[i] + 0x6ed9eba1UL); b = ROL(b, 30);
63 #define FF2(a,b,c,d,e,i) e = (ROL(a, 5) + F2(b,c,d) + e + W[i] + 0x8f1bbcdcUL); b = ROL(b, 30); 72 #define FF2(a,b,c,d,e,i) e = (ROL(a, 5) + F2(b,c,d) + e + W[i] + 0x8f1bbcdcUL); b = ROL(b, 30);
64 #define FF3(a,b,c,d,e,i) e = (ROL(a, 5) + F3(b,c,d) + e + W[i] + 0xca62c1d6UL); b = ROL(b, 30); 73 #define FF3(a,b,c,d,e,i) e = (ROL(a, 5) + F3(b,c,d) + e + W[i] + 0xca62c1d6UL); b = ROL(b, 30);
65 74
75 #ifdef SMALL_CODE
76
77 for (i = 0; i < 20; ) {
78 FF0(a,b,c,d,e,i++); t = e; e = d; d = c; c = b; b = a; a = t;
79 }
80
81 for (; i < 40; ) {
82 FF1(a,b,c,d,e,i++); t = e; e = d; d = c; c = b; b = a; a = t;
83 }
84
85 for (; i < 60; ) {
86 FF2(a,b,c,d,e,i++); t = e; e = d; d = c; c = b; b = a; a = t;
87 }
88
89 for (; i < 80; ) {
90 FF3(a,b,c,d,e,i++); t = e; e = d; d = c; c = b; b = a; a = t;
91 }
92
93 #else
94
66 for (i = 0; i < 20; ) { 95 for (i = 0; i < 20; ) {
67 FF0(a,b,c,d,e,i++); 96 FF0(a,b,c,d,e,i++);
68 FF0(e,a,b,c,d,i++); 97 FF0(e,a,b,c,d,i++);
69 FF0(d,e,a,b,c,i++); 98 FF0(d,e,a,b,c,i++);
70 FF0(c,d,e,a,b,i++); 99 FF0(c,d,e,a,b,i++);
95 FF3(e,a,b,c,d,i++); 124 FF3(e,a,b,c,d,i++);
96 FF3(d,e,a,b,c,i++); 125 FF3(d,e,a,b,c,i++);
97 FF3(c,d,e,a,b,i++); 126 FF3(c,d,e,a,b,i++);
98 FF3(b,c,d,e,a,i++); 127 FF3(b,c,d,e,a,i++);
99 } 128 }
129 #endif
100 130
101 #undef FF0 131 #undef FF0
102 #undef FF1 132 #undef FF1
103 #undef FF2 133 #undef FF2
104 #undef FF3 134 #undef FF3