summaryrefslogtreecommitdiff
path: root/nacl/crypto_hashblocks/sha256
diff options
context:
space:
mode:
Diffstat (limited to 'nacl/crypto_hashblocks/sha256')
-rw-r--r--nacl/crypto_hashblocks/sha256/checksum1
-rw-r--r--nacl/crypto_hashblocks/sha256/inplace/api.h2
-rw-r--r--nacl/crypto_hashblocks/sha256/inplace/blocks.c228
-rw-r--r--nacl/crypto_hashblocks/sha256/inplace/implementors1
-rw-r--r--nacl/crypto_hashblocks/sha256/ref/api.h2
-rw-r--r--nacl/crypto_hashblocks/sha256/ref/blocks.c212
-rw-r--r--nacl/crypto_hashblocks/sha256/ref/implementors1
-rw-r--r--nacl/crypto_hashblocks/sha256/used0
8 files changed, 0 insertions, 447 deletions
diff --git a/nacl/crypto_hashblocks/sha256/checksum b/nacl/crypto_hashblocks/sha256/checksum
deleted file mode 100644
index edde1d4f..00000000
--- a/nacl/crypto_hashblocks/sha256/checksum
+++ /dev/null
@@ -1 +0,0 @@
169a9dc2464f9593161e462d3dbb634b84f1d68d67d26df29aaa805f9dcd8f656
diff --git a/nacl/crypto_hashblocks/sha256/inplace/api.h b/nacl/crypto_hashblocks/sha256/inplace/api.h
deleted file mode 100644
index 005a4f47..00000000
--- a/nacl/crypto_hashblocks/sha256/inplace/api.h
+++ /dev/null
@@ -1,2 +0,0 @@
1#define CRYPTO_STATEBYTES 32
2#define CRYPTO_BLOCKBYTES 64
diff --git a/nacl/crypto_hashblocks/sha256/inplace/blocks.c b/nacl/crypto_hashblocks/sha256/inplace/blocks.c
deleted file mode 100644
index 4a191501..00000000
--- a/nacl/crypto_hashblocks/sha256/inplace/blocks.c
+++ /dev/null
@@ -1,228 +0,0 @@
1#include "crypto_hashblocks.h"
2
3typedef unsigned int uint32;
4
5static uint32 load_bigendian(const unsigned char *x)
6{
7 return
8 (uint32) (x[3]) \
9 | (((uint32) (x[2])) << 8) \
10 | (((uint32) (x[1])) << 16) \
11 | (((uint32) (x[0])) << 24)
12 ;
13}
14
15static void store_bigendian(unsigned char *x,uint32 u)
16{
17 x[3] = u; u >>= 8;
18 x[2] = u; u >>= 8;
19 x[1] = u; u >>= 8;
20 x[0] = u;
21}
22
23#define SHR(x,c) ((x) >> (c))
24#define ROTR(x,c) (((x) >> (c)) | ((x) << (32 - (c))))
25
26#define Ch(x,y,z) ((x & y) ^ (~x & z))
27#define Maj(x,y,z) ((x & y) ^ (x & z) ^ (y & z))
28#define Sigma0(x) (ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22))
29#define Sigma1(x) (ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25))
30#define sigma0(x) (ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3))
31#define sigma1(x) (ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10))
32
33#define M(w0,w14,w9,w1) w0 += sigma1(w14) + w9 + sigma0(w1);
34
35#define EXPAND \
36 M(w0 ,w14,w9 ,w1 ) \
37 M(w1 ,w15,w10,w2 ) \
38 M(w2 ,w0 ,w11,w3 ) \
39 M(w3 ,w1 ,w12,w4 ) \
40 M(w4 ,w2 ,w13,w5 ) \
41 M(w5 ,w3 ,w14,w6 ) \
42 M(w6 ,w4 ,w15,w7 ) \
43 M(w7 ,w5 ,w0 ,w8 ) \
44 M(w8 ,w6 ,w1 ,w9 ) \
45 M(w9 ,w7 ,w2 ,w10) \
46 M(w10,w8 ,w3 ,w11) \
47 M(w11,w9 ,w4 ,w12) \
48 M(w12,w10,w5 ,w13) \
49 M(w13,w11,w6 ,w14) \
50 M(w14,w12,w7 ,w15) \
51 M(w15,w13,w8 ,w0 )
52
53#define F(r0,r1,r2,r3,r4,r5,r6,r7,w,k) \
54 r7 += Sigma1(r4) + Ch(r4,r5,r6) + k + w; \
55 r3 += r7; \
56 r7 += Sigma0(r0) + Maj(r0,r1,r2);
57
58#define G(r0,r1,r2,r3,r4,r5,r6,r7,i) \
59 F(r0,r1,r2,r3,r4,r5,r6,r7,w0 ,round[i + 0]) \
60 F(r7,r0,r1,r2,r3,r4,r5,r6,w1 ,round[i + 1]) \
61 F(r6,r7,r0,r1,r2,r3,r4,r5,w2 ,round[i + 2]) \
62 F(r5,r6,r7,r0,r1,r2,r3,r4,w3 ,round[i + 3]) \
63 F(r4,r5,r6,r7,r0,r1,r2,r3,w4 ,round[i + 4]) \
64 F(r3,r4,r5,r6,r7,r0,r1,r2,w5 ,round[i + 5]) \
65 F(r2,r3,r4,r5,r6,r7,r0,r1,w6 ,round[i + 6]) \
66 F(r1,r2,r3,r4,r5,r6,r7,r0,w7 ,round[i + 7]) \
67 F(r0,r1,r2,r3,r4,r5,r6,r7,w8 ,round[i + 8]) \
68 F(r7,r0,r1,r2,r3,r4,r5,r6,w9 ,round[i + 9]) \
69 F(r6,r7,r0,r1,r2,r3,r4,r5,w10,round[i + 10]) \
70 F(r5,r6,r7,r0,r1,r2,r3,r4,w11,round[i + 11]) \
71 F(r4,r5,r6,r7,r0,r1,r2,r3,w12,round[i + 12]) \
72 F(r3,r4,r5,r6,r7,r0,r1,r2,w13,round[i + 13]) \
73 F(r2,r3,r4,r5,r6,r7,r0,r1,w14,round[i + 14]) \
74 F(r1,r2,r3,r4,r5,r6,r7,r0,w15,round[i + 15])
75
76static const uint32 round[64] = {
77 0x428a2f98
78, 0x71374491
79, 0xb5c0fbcf
80, 0xe9b5dba5
81, 0x3956c25b
82, 0x59f111f1
83, 0x923f82a4
84, 0xab1c5ed5
85, 0xd807aa98
86, 0x12835b01
87, 0x243185be
88, 0x550c7dc3
89, 0x72be5d74
90, 0x80deb1fe
91, 0x9bdc06a7
92, 0xc19bf174
93, 0xe49b69c1
94, 0xefbe4786
95, 0x0fc19dc6
96, 0x240ca1cc
97, 0x2de92c6f
98, 0x4a7484aa
99, 0x5cb0a9dc
100, 0x76f988da
101, 0x983e5152
102, 0xa831c66d
103, 0xb00327c8
104, 0xbf597fc7
105, 0xc6e00bf3
106, 0xd5a79147
107, 0x06ca6351
108, 0x14292967
109, 0x27b70a85
110, 0x2e1b2138
111, 0x4d2c6dfc
112, 0x53380d13
113, 0x650a7354
114, 0x766a0abb
115, 0x81c2c92e
116, 0x92722c85
117, 0xa2bfe8a1
118, 0xa81a664b
119, 0xc24b8b70
120, 0xc76c51a3
121, 0xd192e819
122, 0xd6990624
123, 0xf40e3585
124, 0x106aa070
125, 0x19a4c116
126, 0x1e376c08
127, 0x2748774c
128, 0x34b0bcb5
129, 0x391c0cb3
130, 0x4ed8aa4a
131, 0x5b9cca4f
132, 0x682e6ff3
133, 0x748f82ee
134, 0x78a5636f
135, 0x84c87814
136, 0x8cc70208
137, 0x90befffa
138, 0xa4506ceb
139, 0xbef9a3f7
140, 0xc67178f2
141} ;
142
143int crypto_hashblocks(unsigned char *statebytes,const unsigned char *in,unsigned long long inlen)
144{
145 uint32 state[8];
146 uint32 r0;
147 uint32 r1;
148 uint32 r2;
149 uint32 r3;
150 uint32 r4;
151 uint32 r5;
152 uint32 r6;
153 uint32 r7;
154
155 r0 = load_bigendian(statebytes + 0); state[0] = r0;
156 r1 = load_bigendian(statebytes + 4); state[1] = r1;
157 r2 = load_bigendian(statebytes + 8); state[2] = r2;
158 r3 = load_bigendian(statebytes + 12); state[3] = r3;
159 r4 = load_bigendian(statebytes + 16); state[4] = r4;
160 r5 = load_bigendian(statebytes + 20); state[5] = r5;
161 r6 = load_bigendian(statebytes + 24); state[6] = r6;
162 r7 = load_bigendian(statebytes + 28); state[7] = r7;
163
164 while (inlen >= 64) {
165 uint32 w0 = load_bigendian(in + 0);
166 uint32 w1 = load_bigendian(in + 4);
167 uint32 w2 = load_bigendian(in + 8);
168 uint32 w3 = load_bigendian(in + 12);
169 uint32 w4 = load_bigendian(in + 16);
170 uint32 w5 = load_bigendian(in + 20);
171 uint32 w6 = load_bigendian(in + 24);
172 uint32 w7 = load_bigendian(in + 28);
173 uint32 w8 = load_bigendian(in + 32);
174 uint32 w9 = load_bigendian(in + 36);
175 uint32 w10 = load_bigendian(in + 40);
176 uint32 w11 = load_bigendian(in + 44);
177 uint32 w12 = load_bigendian(in + 48);
178 uint32 w13 = load_bigendian(in + 52);
179 uint32 w14 = load_bigendian(in + 56);
180 uint32 w15 = load_bigendian(in + 60);
181
182 G(r0,r1,r2,r3,r4,r5,r6,r7,0)
183
184 EXPAND
185
186 G(r0,r1,r2,r3,r4,r5,r6,r7,16)
187
188 EXPAND
189
190 G(r0,r1,r2,r3,r4,r5,r6,r7,32)
191
192 EXPAND
193
194 G(r0,r1,r2,r3,r4,r5,r6,r7,48)
195
196 r0 += state[0];
197 r1 += state[1];
198 r2 += state[2];
199 r3 += state[3];
200 r4 += state[4];
201 r5 += state[5];
202 r6 += state[6];
203 r7 += state[7];
204
205 state[0] = r0;
206 state[1] = r1;
207 state[2] = r2;
208 state[3] = r3;
209 state[4] = r4;
210 state[5] = r5;
211 state[6] = r6;
212 state[7] = r7;
213
214 in += 64;
215 inlen -= 64;
216 }
217
218 store_bigendian(statebytes + 0,state[0]);
219 store_bigendian(statebytes + 4,state[1]);
220 store_bigendian(statebytes + 8,state[2]);
221 store_bigendian(statebytes + 12,state[3]);
222 store_bigendian(statebytes + 16,state[4]);
223 store_bigendian(statebytes + 20,state[5]);
224 store_bigendian(statebytes + 24,state[6]);
225 store_bigendian(statebytes + 28,state[7]);
226
227 return 0;
228}
diff --git a/nacl/crypto_hashblocks/sha256/inplace/implementors b/nacl/crypto_hashblocks/sha256/inplace/implementors
deleted file mode 100644
index f6fb3c73..00000000
--- a/nacl/crypto_hashblocks/sha256/inplace/implementors
+++ /dev/null
@@ -1 +0,0 @@
1Daniel J. Bernstein
diff --git a/nacl/crypto_hashblocks/sha256/ref/api.h b/nacl/crypto_hashblocks/sha256/ref/api.h
deleted file mode 100644
index 005a4f47..00000000
--- a/nacl/crypto_hashblocks/sha256/ref/api.h
+++ /dev/null
@@ -1,2 +0,0 @@
1#define CRYPTO_STATEBYTES 32
2#define CRYPTO_BLOCKBYTES 64
diff --git a/nacl/crypto_hashblocks/sha256/ref/blocks.c b/nacl/crypto_hashblocks/sha256/ref/blocks.c
deleted file mode 100644
index ad977945..00000000
--- a/nacl/crypto_hashblocks/sha256/ref/blocks.c
+++ /dev/null
@@ -1,212 +0,0 @@
1#include "crypto_hashblocks.h"
2
3typedef unsigned int uint32;
4
5static uint32 load_bigendian(const unsigned char *x)
6{
7 return
8 (uint32) (x[3]) \
9 | (((uint32) (x[2])) << 8) \
10 | (((uint32) (x[1])) << 16) \
11 | (((uint32) (x[0])) << 24)
12 ;
13}
14
15static void store_bigendian(unsigned char *x,uint32 u)
16{
17 x[3] = u; u >>= 8;
18 x[2] = u; u >>= 8;
19 x[1] = u; u >>= 8;
20 x[0] = u;
21}
22
23#define SHR(x,c) ((x) >> (c))
24#define ROTR(x,c) (((x) >> (c)) | ((x) << (32 - (c))))
25
26#define Ch(x,y,z) ((x & y) ^ (~x & z))
27#define Maj(x,y,z) ((x & y) ^ (x & z) ^ (y & z))
28#define Sigma0(x) (ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22))
29#define Sigma1(x) (ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25))
30#define sigma0(x) (ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3))
31#define sigma1(x) (ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10))
32
33#define M(w0,w14,w9,w1) w0 = sigma1(w14) + w9 + sigma0(w1) + w0;
34
35#define EXPAND \
36 M(w0 ,w14,w9 ,w1 ) \
37 M(w1 ,w15,w10,w2 ) \
38 M(w2 ,w0 ,w11,w3 ) \
39 M(w3 ,w1 ,w12,w4 ) \
40 M(w4 ,w2 ,w13,w5 ) \
41 M(w5 ,w3 ,w14,w6 ) \
42 M(w6 ,w4 ,w15,w7 ) \
43 M(w7 ,w5 ,w0 ,w8 ) \
44 M(w8 ,w6 ,w1 ,w9 ) \
45 M(w9 ,w7 ,w2 ,w10) \
46 M(w10,w8 ,w3 ,w11) \
47 M(w11,w9 ,w4 ,w12) \
48 M(w12,w10,w5 ,w13) \
49 M(w13,w11,w6 ,w14) \
50 M(w14,w12,w7 ,w15) \
51 M(w15,w13,w8 ,w0 )
52
53#define F(w,k) \
54 T1 = h + Sigma1(e) + Ch(e,f,g) + k + w; \
55 T2 = Sigma0(a) + Maj(a,b,c); \
56 h = g; \
57 g = f; \
58 f = e; \
59 e = d + T1; \
60 d = c; \
61 c = b; \
62 b = a; \
63 a = T1 + T2;
64
65int crypto_hashblocks(unsigned char *statebytes,const unsigned char *in,unsigned long long inlen)
66{
67 uint32 state[8];
68 uint32 a;
69 uint32 b;
70 uint32 c;
71 uint32 d;
72 uint32 e;
73 uint32 f;
74 uint32 g;
75 uint32 h;
76 uint32 T1;
77 uint32 T2;
78
79 a = load_bigendian(statebytes + 0); state[0] = a;
80 b = load_bigendian(statebytes + 4); state[1] = b;
81 c = load_bigendian(statebytes + 8); state[2] = c;
82 d = load_bigendian(statebytes + 12); state[3] = d;
83 e = load_bigendian(statebytes + 16); state[4] = e;
84 f = load_bigendian(statebytes + 20); state[5] = f;
85 g = load_bigendian(statebytes + 24); state[6] = g;
86 h = load_bigendian(statebytes + 28); state[7] = h;
87
88 while (inlen >= 64) {
89 uint32 w0 = load_bigendian(in + 0);
90 uint32 w1 = load_bigendian(in + 4);
91 uint32 w2 = load_bigendian(in + 8);
92 uint32 w3 = load_bigendian(in + 12);
93 uint32 w4 = load_bigendian(in + 16);
94 uint32 w5 = load_bigendian(in + 20);
95 uint32 w6 = load_bigendian(in + 24);
96 uint32 w7 = load_bigendian(in + 28);
97 uint32 w8 = load_bigendian(in + 32);
98 uint32 w9 = load_bigendian(in + 36);
99 uint32 w10 = load_bigendian(in + 40);
100 uint32 w11 = load_bigendian(in + 44);
101 uint32 w12 = load_bigendian(in + 48);
102 uint32 w13 = load_bigendian(in + 52);
103 uint32 w14 = load_bigendian(in + 56);
104 uint32 w15 = load_bigendian(in + 60);
105
106 F(w0 ,0x428a2f98)
107 F(w1 ,0x71374491)
108 F(w2 ,0xb5c0fbcf)
109 F(w3 ,0xe9b5dba5)
110 F(w4 ,0x3956c25b)
111 F(w5 ,0x59f111f1)
112 F(w6 ,0x923f82a4)
113 F(w7 ,0xab1c5ed5)
114 F(w8 ,0xd807aa98)
115 F(w9 ,0x12835b01)
116 F(w10,0x243185be)
117 F(w11,0x550c7dc3)
118 F(w12,0x72be5d74)
119 F(w13,0x80deb1fe)
120 F(w14,0x9bdc06a7)
121 F(w15,0xc19bf174)
122
123 EXPAND
124
125 F(w0 ,0xe49b69c1)
126 F(w1 ,0xefbe4786)
127 F(w2 ,0x0fc19dc6)
128 F(w3 ,0x240ca1cc)
129 F(w4 ,0x2de92c6f)
130 F(w5 ,0x4a7484aa)
131 F(w6 ,0x5cb0a9dc)
132 F(w7 ,0x76f988da)
133 F(w8 ,0x983e5152)
134 F(w9 ,0xa831c66d)
135 F(w10,0xb00327c8)
136 F(w11,0xbf597fc7)
137 F(w12,0xc6e00bf3)
138 F(w13,0xd5a79147)
139 F(w14,0x06ca6351)
140 F(w15,0x14292967)
141
142 EXPAND
143
144 F(w0 ,0x27b70a85)
145 F(w1 ,0x2e1b2138)
146 F(w2 ,0x4d2c6dfc)
147 F(w3 ,0x53380d13)
148 F(w4 ,0x650a7354)
149 F(w5 ,0x766a0abb)
150 F(w6 ,0x81c2c92e)
151 F(w7 ,0x92722c85)
152 F(w8 ,0xa2bfe8a1)
153 F(w9 ,0xa81a664b)
154 F(w10,0xc24b8b70)
155 F(w11,0xc76c51a3)
156 F(w12,0xd192e819)
157 F(w13,0xd6990624)
158 F(w14,0xf40e3585)
159 F(w15,0x106aa070)
160
161 EXPAND
162
163 F(w0 ,0x19a4c116)
164 F(w1 ,0x1e376c08)
165 F(w2 ,0x2748774c)
166 F(w3 ,0x34b0bcb5)
167 F(w4 ,0x391c0cb3)
168 F(w5 ,0x4ed8aa4a)
169 F(w6 ,0x5b9cca4f)
170 F(w7 ,0x682e6ff3)
171 F(w8 ,0x748f82ee)
172 F(w9 ,0x78a5636f)
173 F(w10,0x84c87814)
174 F(w11,0x8cc70208)
175 F(w12,0x90befffa)
176 F(w13,0xa4506ceb)
177 F(w14,0xbef9a3f7)
178 F(w15,0xc67178f2)
179
180 a += state[0];
181 b += state[1];
182 c += state[2];
183 d += state[3];
184 e += state[4];
185 f += state[5];
186 g += state[6];
187 h += state[7];
188
189 state[0] = a;
190 state[1] = b;
191 state[2] = c;
192 state[3] = d;
193 state[4] = e;
194 state[5] = f;
195 state[6] = g;
196 state[7] = h;
197
198 in += 64;
199 inlen -= 64;
200 }
201
202 store_bigendian(statebytes + 0,state[0]);
203 store_bigendian(statebytes + 4,state[1]);
204 store_bigendian(statebytes + 8,state[2]);
205 store_bigendian(statebytes + 12,state[3]);
206 store_bigendian(statebytes + 16,state[4]);
207 store_bigendian(statebytes + 20,state[5]);
208 store_bigendian(statebytes + 24,state[6]);
209 store_bigendian(statebytes + 28,state[7]);
210
211 return 0;
212}
diff --git a/nacl/crypto_hashblocks/sha256/ref/implementors b/nacl/crypto_hashblocks/sha256/ref/implementors
deleted file mode 100644
index f6fb3c73..00000000
--- a/nacl/crypto_hashblocks/sha256/ref/implementors
+++ /dev/null
@@ -1 +0,0 @@
1Daniel J. Bernstein
diff --git a/nacl/crypto_hashblocks/sha256/used b/nacl/crypto_hashblocks/sha256/used
deleted file mode 100644
index e69de29b..00000000
--- a/nacl/crypto_hashblocks/sha256/used
+++ /dev/null