ed25519 1.0.0-jruby

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +5 -0
  4. data/.rubocop.yml +35 -0
  5. data/.travis.yml +13 -0
  6. data/CHANGES.md +16 -0
  7. data/CODE_OF_CONDUCT.md +74 -0
  8. data/Gemfile +12 -0
  9. data/LICENSE +22 -0
  10. data/README.md +159 -0
  11. data/Rakefile +27 -0
  12. data/ed25519.gemspec +32 -0
  13. data/ed25519.png +0 -0
  14. data/ext/ed25519_java/org/cryptosphere/ed25519.java +228 -0
  15. data/ext/ed25519_ref10/api.h +4 -0
  16. data/ext/ed25519_ref10/base.h +1344 -0
  17. data/ext/ed25519_ref10/base2.h +40 -0
  18. data/ext/ed25519_ref10/d.h +1 -0
  19. data/ext/ed25519_ref10/d2.h +1 -0
  20. data/ext/ed25519_ref10/ed25519_ref10.c +99 -0
  21. data/ext/ed25519_ref10/ed25519_ref10.h +33 -0
  22. data/ext/ed25519_ref10/extconf.rb +9 -0
  23. data/ext/ed25519_ref10/fe.h +56 -0
  24. data/ext/ed25519_ref10/fe_0.c +19 -0
  25. data/ext/ed25519_ref10/fe_1.c +19 -0
  26. data/ext/ed25519_ref10/fe_add.c +57 -0
  27. data/ext/ed25519_ref10/fe_cmov.c +63 -0
  28. data/ext/ed25519_ref10/fe_copy.c +29 -0
  29. data/ext/ed25519_ref10/fe_frombytes.c +71 -0
  30. data/ext/ed25519_ref10/fe_invert.c +14 -0
  31. data/ext/ed25519_ref10/fe_isnegative.c +16 -0
  32. data/ext/ed25519_ref10/fe_isnonzero.c +19 -0
  33. data/ext/ed25519_ref10/fe_mul.c +252 -0
  34. data/ext/ed25519_ref10/fe_neg.c +45 -0
  35. data/ext/ed25519_ref10/fe_pow22523.c +13 -0
  36. data/ext/ed25519_ref10/fe_sq.c +148 -0
  37. data/ext/ed25519_ref10/fe_sq2.c +159 -0
  38. data/ext/ed25519_ref10/fe_sub.c +57 -0
  39. data/ext/ed25519_ref10/fe_tobytes.c +119 -0
  40. data/ext/ed25519_ref10/ge.h +95 -0
  41. data/ext/ed25519_ref10/ge_add.c +11 -0
  42. data/ext/ed25519_ref10/ge_add.h +97 -0
  43. data/ext/ed25519_ref10/ge_double_scalarmult.c +96 -0
  44. data/ext/ed25519_ref10/ge_frombytes.c +50 -0
  45. data/ext/ed25519_ref10/ge_madd.c +11 -0
  46. data/ext/ed25519_ref10/ge_madd.h +88 -0
  47. data/ext/ed25519_ref10/ge_msub.c +11 -0
  48. data/ext/ed25519_ref10/ge_msub.h +88 -0
  49. data/ext/ed25519_ref10/ge_p1p1_to_p2.c +12 -0
  50. data/ext/ed25519_ref10/ge_p1p1_to_p3.c +13 -0
  51. data/ext/ed25519_ref10/ge_p2_0.c +8 -0
  52. data/ext/ed25519_ref10/ge_p2_dbl.c +11 -0
  53. data/ext/ed25519_ref10/ge_p2_dbl.h +73 -0
  54. data/ext/ed25519_ref10/ge_p3_0.c +9 -0
  55. data/ext/ed25519_ref10/ge_p3_dbl.c +12 -0
  56. data/ext/ed25519_ref10/ge_p3_to_cached.c +17 -0
  57. data/ext/ed25519_ref10/ge_p3_to_p2.c +12 -0
  58. data/ext/ed25519_ref10/ge_p3_tobytes.c +14 -0
  59. data/ext/ed25519_ref10/ge_precomp_0.c +8 -0
  60. data/ext/ed25519_ref10/ge_scalarmult_base.c +104 -0
  61. data/ext/ed25519_ref10/ge_sub.c +11 -0
  62. data/ext/ed25519_ref10/ge_sub.h +97 -0
  63. data/ext/ed25519_ref10/ge_tobytes.c +14 -0
  64. data/ext/ed25519_ref10/keypair.c +22 -0
  65. data/ext/ed25519_ref10/open.c +47 -0
  66. data/ext/ed25519_ref10/pow22523.h +160 -0
  67. data/ext/ed25519_ref10/pow225521.h +160 -0
  68. data/ext/ed25519_ref10/sc.h +17 -0
  69. data/ext/ed25519_ref10/sc_muladd.c +366 -0
  70. data/ext/ed25519_ref10/sc_reduce.c +272 -0
  71. data/ext/ed25519_ref10/sha512.c +304 -0
  72. data/ext/ed25519_ref10/sha512.h +8 -0
  73. data/ext/ed25519_ref10/sign.c +41 -0
  74. data/ext/ed25519_ref10/sqrtm1.h +1 -0
  75. data/ext/ed25519_ref10/verify.c +40 -0
  76. data/lib/ed25519.rb +65 -0
  77. data/lib/ed25519/provider/jruby.rb +39 -0
  78. data/lib/ed25519/signing_key.rb +39 -0
  79. data/lib/ed25519/verify_key.rb +44 -0
  80. data/lib/ed25519/version.rb +5 -0
  81. data/lib/ed25519_java.jar +0 -0
  82. metadata +138 -0
@@ -0,0 +1,272 @@
1
+ #include "sc.h"
2
+
3
+ static uint64_t load_3(const unsigned char *in)
4
+ {
5
+ uint64_t result;
6
+ result = (uint64_t) in[0];
7
+ result |= ((uint64_t) in[1]) << 8;
8
+ result |= ((uint64_t) in[2]) << 16;
9
+ return result;
10
+ }
11
+
12
+ static uint64_t load_4(const unsigned char *in)
13
+ {
14
+ uint64_t result;
15
+ result = (uint64_t) in[0];
16
+ result |= ((uint64_t) in[1]) << 8;
17
+ result |= ((uint64_t) in[2]) << 16;
18
+ result |= ((uint64_t) in[3]) << 24;
19
+ return result;
20
+ }
21
+
22
+ /*
23
+ Input:
24
+ s[0]+256*s[1]+...+256^63*s[63] = s
25
+
26
+ Output:
27
+ s[0]+256*s[1]+...+256^31*s[31] = s mod l
28
+ where l = 2^252 + 27742317777372353535851937790883648493.
29
+ Overwrites s in place.
30
+ */
31
+
32
+ void sc_reduce(uint8_t *s)
33
+ {
34
+ int64_t s0 = 2097151 & load_3(s);
35
+ int64_t s1 = 2097151 & (load_4(s + 2) >> 5);
36
+ int64_t s2 = 2097151 & (load_3(s + 5) >> 2);
37
+ int64_t s3 = 2097151 & (load_4(s + 7) >> 7);
38
+ int64_t s4 = 2097151 & (load_4(s + 10) >> 4);
39
+ int64_t s5 = 2097151 & (load_3(s + 13) >> 1);
40
+ int64_t s6 = 2097151 & (load_4(s + 15) >> 6);
41
+ int64_t s7 = 2097151 & (load_3(s + 18) >> 3);
42
+ int64_t s8 = 2097151 & load_3(s + 21);
43
+ int64_t s9 = 2097151 & (load_4(s + 23) >> 5);
44
+ int64_t s10 = 2097151 & (load_3(s + 26) >> 2);
45
+ int64_t s11 = 2097151 & (load_4(s + 28) >> 7);
46
+ int64_t s12 = 2097151 & (load_4(s + 31) >> 4);
47
+ int64_t s13 = 2097151 & (load_3(s + 34) >> 1);
48
+ int64_t s14 = 2097151 & (load_4(s + 36) >> 6);
49
+ int64_t s15 = 2097151 & (load_3(s + 39) >> 3);
50
+ int64_t s16 = 2097151 & load_3(s + 42);
51
+ int64_t s17 = 2097151 & (load_4(s + 44) >> 5);
52
+ int64_t s18 = 2097151 & (load_3(s + 47) >> 2);
53
+ int64_t s19 = 2097151 & (load_4(s + 49) >> 7);
54
+ int64_t s20 = 2097151 & (load_4(s + 52) >> 4);
55
+ int64_t s21 = 2097151 & (load_3(s + 55) >> 1);
56
+ int64_t s22 = 2097151 & (load_4(s + 57) >> 6);
57
+ int64_t s23 = (load_4(s + 60) >> 3);
58
+ int64_t carry0;
59
+ int64_t carry1;
60
+ int64_t carry2;
61
+ int64_t carry3;
62
+ int64_t carry4;
63
+ int64_t carry5;
64
+ int64_t carry6;
65
+ int64_t carry7;
66
+ int64_t carry8;
67
+ int64_t carry9;
68
+ int64_t carry10;
69
+ int64_t carry11;
70
+ int64_t carry12;
71
+ int64_t carry13;
72
+ int64_t carry14;
73
+ int64_t carry15;
74
+ int64_t carry16;
75
+
76
+ s11 += s23 * 666643;
77
+ s12 += s23 * 470296;
78
+ s13 += s23 * 654183;
79
+ s14 -= s23 * 997805;
80
+ s15 += s23 * 136657;
81
+ s16 -= s23 * 683901;
82
+ s23 = 0;
83
+
84
+ s10 += s22 * 666643;
85
+ s11 += s22 * 470296;
86
+ s12 += s22 * 654183;
87
+ s13 -= s22 * 997805;
88
+ s14 += s22 * 136657;
89
+ s15 -= s22 * 683901;
90
+ s22 = 0;
91
+
92
+ s9 += s21 * 666643;
93
+ s10 += s21 * 470296;
94
+ s11 += s21 * 654183;
95
+ s12 -= s21 * 997805;
96
+ s13 += s21 * 136657;
97
+ s14 -= s21 * 683901;
98
+ s21 = 0;
99
+
100
+ s8 += s20 * 666643;
101
+ s9 += s20 * 470296;
102
+ s10 += s20 * 654183;
103
+ s11 -= s20 * 997805;
104
+ s12 += s20 * 136657;
105
+ s13 -= s20 * 683901;
106
+ s20 = 0;
107
+
108
+ s7 += s19 * 666643;
109
+ s8 += s19 * 470296;
110
+ s9 += s19 * 654183;
111
+ s10 -= s19 * 997805;
112
+ s11 += s19 * 136657;
113
+ s12 -= s19 * 683901;
114
+ s19 = 0;
115
+
116
+ s6 += s18 * 666643;
117
+ s7 += s18 * 470296;
118
+ s8 += s18 * 654183;
119
+ s9 -= s18 * 997805;
120
+ s10 += s18 * 136657;
121
+ s11 -= s18 * 683901;
122
+ s18 = 0;
123
+
124
+ carry6 = (s6 + (1<<20)) >> 21; s7 += carry6; s6 -= carry6 << 21;
125
+ carry8 = (s8 + (1<<20)) >> 21; s9 += carry8; s8 -= carry8 << 21;
126
+ carry10 = (s10 + (1<<20)) >> 21; s11 += carry10; s10 -= carry10 << 21;
127
+ carry12 = (s12 + (1<<20)) >> 21; s13 += carry12; s12 -= carry12 << 21;
128
+ carry14 = (s14 + (1<<20)) >> 21; s15 += carry14; s14 -= carry14 << 21;
129
+ carry16 = (s16 + (1<<20)) >> 21; s17 += carry16; s16 -= carry16 << 21;
130
+
131
+ carry7 = (s7 + (1<<20)) >> 21; s8 += carry7; s7 -= carry7 << 21;
132
+ carry9 = (s9 + (1<<20)) >> 21; s10 += carry9; s9 -= carry9 << 21;
133
+ carry11 = (s11 + (1<<20)) >> 21; s12 += carry11; s11 -= carry11 << 21;
134
+ carry13 = (s13 + (1<<20)) >> 21; s14 += carry13; s13 -= carry13 << 21;
135
+ carry15 = (s15 + (1<<20)) >> 21; s16 += carry15; s15 -= carry15 << 21;
136
+
137
+ s5 += s17 * 666643;
138
+ s6 += s17 * 470296;
139
+ s7 += s17 * 654183;
140
+ s8 -= s17 * 997805;
141
+ s9 += s17 * 136657;
142
+ s10 -= s17 * 683901;
143
+ s17 = 0;
144
+
145
+ s4 += s16 * 666643;
146
+ s5 += s16 * 470296;
147
+ s6 += s16 * 654183;
148
+ s7 -= s16 * 997805;
149
+ s8 += s16 * 136657;
150
+ s9 -= s16 * 683901;
151
+ s16 = 0;
152
+
153
+ s3 += s15 * 666643;
154
+ s4 += s15 * 470296;
155
+ s5 += s15 * 654183;
156
+ s6 -= s15 * 997805;
157
+ s7 += s15 * 136657;
158
+ s8 -= s15 * 683901;
159
+ s15 = 0;
160
+
161
+ s2 += s14 * 666643;
162
+ s3 += s14 * 470296;
163
+ s4 += s14 * 654183;
164
+ s5 -= s14 * 997805;
165
+ s6 += s14 * 136657;
166
+ s7 -= s14 * 683901;
167
+ s14 = 0;
168
+
169
+ s1 += s13 * 666643;
170
+ s2 += s13 * 470296;
171
+ s3 += s13 * 654183;
172
+ s4 -= s13 * 997805;
173
+ s5 += s13 * 136657;
174
+ s6 -= s13 * 683901;
175
+ s13 = 0;
176
+
177
+ s0 += s12 * 666643;
178
+ s1 += s12 * 470296;
179
+ s2 += s12 * 654183;
180
+ s3 -= s12 * 997805;
181
+ s4 += s12 * 136657;
182
+ s5 -= s12 * 683901;
183
+ s12 = 0;
184
+
185
+ carry0 = (s0 + (1<<20)) >> 21; s1 += carry0; s0 -= carry0 << 21;
186
+ carry2 = (s2 + (1<<20)) >> 21; s3 += carry2; s2 -= carry2 << 21;
187
+ carry4 = (s4 + (1<<20)) >> 21; s5 += carry4; s4 -= carry4 << 21;
188
+ carry6 = (s6 + (1<<20)) >> 21; s7 += carry6; s6 -= carry6 << 21;
189
+ carry8 = (s8 + (1<<20)) >> 21; s9 += carry8; s8 -= carry8 << 21;
190
+ carry10 = (s10 + (1<<20)) >> 21; s11 += carry10; s10 -= carry10 << 21;
191
+
192
+ carry1 = (s1 + (1<<20)) >> 21; s2 += carry1; s1 -= carry1 << 21;
193
+ carry3 = (s3 + (1<<20)) >> 21; s4 += carry3; s3 -= carry3 << 21;
194
+ carry5 = (s5 + (1<<20)) >> 21; s6 += carry5; s5 -= carry5 << 21;
195
+ carry7 = (s7 + (1<<20)) >> 21; s8 += carry7; s7 -= carry7 << 21;
196
+ carry9 = (s9 + (1<<20)) >> 21; s10 += carry9; s9 -= carry9 << 21;
197
+ carry11 = (s11 + (1<<20)) >> 21; s12 += carry11; s11 -= carry11 << 21;
198
+
199
+ s0 += s12 * 666643;
200
+ s1 += s12 * 470296;
201
+ s2 += s12 * 654183;
202
+ s3 -= s12 * 997805;
203
+ s4 += s12 * 136657;
204
+ s5 -= s12 * 683901;
205
+ s12 = 0;
206
+
207
+ carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 << 21;
208
+ carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 << 21;
209
+ carry2 = s2 >> 21; s3 += carry2; s2 -= carry2 << 21;
210
+ carry3 = s3 >> 21; s4 += carry3; s3 -= carry3 << 21;
211
+ carry4 = s4 >> 21; s5 += carry4; s4 -= carry4 << 21;
212
+ carry5 = s5 >> 21; s6 += carry5; s5 -= carry5 << 21;
213
+ carry6 = s6 >> 21; s7 += carry6; s6 -= carry6 << 21;
214
+ carry7 = s7 >> 21; s8 += carry7; s7 -= carry7 << 21;
215
+ carry8 = s8 >> 21; s9 += carry8; s8 -= carry8 << 21;
216
+ carry9 = s9 >> 21; s10 += carry9; s9 -= carry9 << 21;
217
+ carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 << 21;
218
+ carry11 = s11 >> 21; s12 += carry11; s11 -= carry11 << 21;
219
+
220
+ s0 += s12 * 666643;
221
+ s1 += s12 * 470296;
222
+ s2 += s12 * 654183;
223
+ s3 -= s12 * 997805;
224
+ s4 += s12 * 136657;
225
+ s5 -= s12 * 683901;
226
+ s12 = 0;
227
+
228
+ carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 << 21;
229
+ carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 << 21;
230
+ carry2 = s2 >> 21; s3 += carry2; s2 -= carry2 << 21;
231
+ carry3 = s3 >> 21; s4 += carry3; s3 -= carry3 << 21;
232
+ carry4 = s4 >> 21; s5 += carry4; s4 -= carry4 << 21;
233
+ carry5 = s5 >> 21; s6 += carry5; s5 -= carry5 << 21;
234
+ carry6 = s6 >> 21; s7 += carry6; s6 -= carry6 << 21;
235
+ carry7 = s7 >> 21; s8 += carry7; s7 -= carry7 << 21;
236
+ carry8 = s8 >> 21; s9 += carry8; s8 -= carry8 << 21;
237
+ carry9 = s9 >> 21; s10 += carry9; s9 -= carry9 << 21;
238
+ carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 << 21;
239
+
240
+ s[0] = s0 >> 0;
241
+ s[1] = s0 >> 8;
242
+ s[2] = (s0 >> 16) | (s1 << 5);
243
+ s[3] = s1 >> 3;
244
+ s[4] = s1 >> 11;
245
+ s[5] = (s1 >> 19) | (s2 << 2);
246
+ s[6] = s2 >> 6;
247
+ s[7] = (s2 >> 14) | (s3 << 7);
248
+ s[8] = s3 >> 1;
249
+ s[9] = s3 >> 9;
250
+ s[10] = (s3 >> 17) | (s4 << 4);
251
+ s[11] = s4 >> 4;
252
+ s[12] = s4 >> 12;
253
+ s[13] = (s4 >> 20) | (s5 << 1);
254
+ s[14] = s5 >> 7;
255
+ s[15] = (s5 >> 15) | (s6 << 6);
256
+ s[16] = s6 >> 2;
257
+ s[17] = s6 >> 10;
258
+ s[18] = (s6 >> 18) | (s7 << 3);
259
+ s[19] = s7 >> 5;
260
+ s[20] = s7 >> 13;
261
+ s[21] = s8 >> 0;
262
+ s[22] = s8 >> 8;
263
+ s[23] = (s8 >> 16) | (s9 << 5);
264
+ s[24] = s9 >> 3;
265
+ s[25] = s9 >> 11;
266
+ s[26] = (s9 >> 19) | (s10 << 2);
267
+ s[27] = s10 >> 6;
268
+ s[28] = (s10 >> 14) | (s11 << 7);
269
+ s[29] = s11 >> 1;
270
+ s[30] = s11 >> 9;
271
+ s[31] = s11 >> 17;
272
+ }
@@ -0,0 +1,304 @@
1
+ /*
2
+ 20080913
3
+ D. J. Bernstein
4
+ Public domain.
5
+ */
6
+
7
+ #include "sha512.h"
8
+
9
+ static void crypto_hashblocks_sha512(uint8_t *statebytes,const uint8_t *in,uint64_t inlen);
10
+
11
+ #define blocks crypto_hashblocks_sha512
12
+
13
+ static const uint8_t iv[64] = {
14
+ 0x6a,0x09,0xe6,0x67,0xf3,0xbc,0xc9,0x08,
15
+ 0xbb,0x67,0xae,0x85,0x84,0xca,0xa7,0x3b,
16
+ 0x3c,0x6e,0xf3,0x72,0xfe,0x94,0xf8,0x2b,
17
+ 0xa5,0x4f,0xf5,0x3a,0x5f,0x1d,0x36,0xf1,
18
+ 0x51,0x0e,0x52,0x7f,0xad,0xe6,0x82,0xd1,
19
+ 0x9b,0x05,0x68,0x8c,0x2b,0x3e,0x6c,0x1f,
20
+ 0x1f,0x83,0xd9,0xab,0xfb,0x41,0xbd,0x6b,
21
+ 0x5b,0xe0,0xcd,0x19,0x13,0x7e,0x21,0x79
22
+ };
23
+
24
+ int crypto_hash_sha512(uint8_t *out,const uint8_t *in,uint64_t inlen)
25
+ {
26
+ uint8_t h[64];
27
+ uint8_t padded[256];
28
+ uint64_t i;
29
+ uint64_t bytes = inlen;
30
+
31
+ for (i = 0;i < 64;++i) h[i] = iv[i];
32
+
33
+ blocks(h,in,inlen);
34
+ in += inlen;
35
+ inlen &= 127;
36
+ in -= inlen;
37
+
38
+ for (i = 0;i < inlen;++i) padded[i] = in[i];
39
+ padded[inlen] = 0x80;
40
+
41
+ if (inlen < 112) {
42
+ for (i = inlen + 1;i < 119;++i) padded[i] = 0;
43
+ padded[119] = bytes >> 61;
44
+ padded[120] = bytes >> 53;
45
+ padded[121] = bytes >> 45;
46
+ padded[122] = bytes >> 37;
47
+ padded[123] = bytes >> 29;
48
+ padded[124] = bytes >> 21;
49
+ padded[125] = bytes >> 13;
50
+ padded[126] = bytes >> 5;
51
+ padded[127] = bytes << 3;
52
+ blocks(h,padded,128);
53
+ } else {
54
+ for (i = inlen + 1;i < 247;++i) padded[i] = 0;
55
+ padded[247] = bytes >> 61;
56
+ padded[248] = bytes >> 53;
57
+ padded[249] = bytes >> 45;
58
+ padded[250] = bytes >> 37;
59
+ padded[251] = bytes >> 29;
60
+ padded[252] = bytes >> 21;
61
+ padded[253] = bytes >> 13;
62
+ padded[254] = bytes >> 5;
63
+ padded[255] = bytes << 3;
64
+ blocks(h,padded,256);
65
+ }
66
+
67
+ for (i = 0;i < 64;++i) out[i] = h[i];
68
+
69
+ return 0;
70
+ }
71
+
72
+ static uint64_t load_bigendian(const unsigned char *x)
73
+ {
74
+ return
75
+ (uint64_t) (x[7]) \
76
+ | (((uint64_t) (x[6])) << 8) \
77
+ | (((uint64_t) (x[5])) << 16) \
78
+ | (((uint64_t) (x[4])) << 24) \
79
+ | (((uint64_t) (x[3])) << 32) \
80
+ | (((uint64_t) (x[2])) << 40) \
81
+ | (((uint64_t) (x[1])) << 48) \
82
+ | (((uint64_t) (x[0])) << 56)
83
+ ;
84
+ }
85
+
86
+ static void store_bigendian(unsigned char *x,uint64_t u)
87
+ {
88
+ x[7] = u; u >>= 8;
89
+ x[6] = u; u >>= 8;
90
+ x[5] = u; u >>= 8;
91
+ x[4] = u; u >>= 8;
92
+ x[3] = u; u >>= 8;
93
+ x[2] = u; u >>= 8;
94
+ x[1] = u; u >>= 8;
95
+ x[0] = u;
96
+ }
97
+
98
+ #define SHR(x,c) ((x) >> (c))
99
+ #define ROTR(x,c) (((x) >> (c)) | ((x) << (64 - (c))))
100
+
101
+ #define Ch(x,y,z) ((x & y) ^ (~x & z))
102
+ #define Maj(x,y,z) ((x & y) ^ (x & z) ^ (y & z))
103
+ #define Sigma0(x) (ROTR(x,28) ^ ROTR(x,34) ^ ROTR(x,39))
104
+ #define Sigma1(x) (ROTR(x,14) ^ ROTR(x,18) ^ ROTR(x,41))
105
+ #define sigma0(x) (ROTR(x, 1) ^ ROTR(x, 8) ^ SHR(x,7))
106
+ #define sigma1(x) (ROTR(x,19) ^ ROTR(x,61) ^ SHR(x,6))
107
+
108
+ #define M(w0,w14,w9,w1) w0 = sigma1(w14) + w9 + sigma0(w1) + w0;
109
+
110
+ #define EXPAND \
111
+ M(w0 ,w14,w9 ,w1 ) \
112
+ M(w1 ,w15,w10,w2 ) \
113
+ M(w2 ,w0 ,w11,w3 ) \
114
+ M(w3 ,w1 ,w12,w4 ) \
115
+ M(w4 ,w2 ,w13,w5 ) \
116
+ M(w5 ,w3 ,w14,w6 ) \
117
+ M(w6 ,w4 ,w15,w7 ) \
118
+ M(w7 ,w5 ,w0 ,w8 ) \
119
+ M(w8 ,w6 ,w1 ,w9 ) \
120
+ M(w9 ,w7 ,w2 ,w10) \
121
+ M(w10,w8 ,w3 ,w11) \
122
+ M(w11,w9 ,w4 ,w12) \
123
+ M(w12,w10,w5 ,w13) \
124
+ M(w13,w11,w6 ,w14) \
125
+ M(w14,w12,w7 ,w15) \
126
+ M(w15,w13,w8 ,w0 )
127
+
128
+ #define F(w,k) \
129
+ T1 = h + Sigma1(e) + Ch(e,f,g) + k + w; \
130
+ T2 = Sigma0(a) + Maj(a,b,c); \
131
+ h = g; \
132
+ g = f; \
133
+ f = e; \
134
+ e = d + T1; \
135
+ d = c; \
136
+ c = b; \
137
+ b = a; \
138
+ a = T1 + T2;
139
+
140
+ static void crypto_hashblocks_sha512(uint8_t *statebytes,const uint8_t *in,uint64_t inlen)
141
+ {
142
+ uint64_t state[8];
143
+ uint64_t a;
144
+ uint64_t b;
145
+ uint64_t c;
146
+ uint64_t d;
147
+ uint64_t e;
148
+ uint64_t f;
149
+ uint64_t g;
150
+ uint64_t h;
151
+ uint64_t T1;
152
+ uint64_t T2;
153
+
154
+ a = load_bigendian(statebytes + 0); state[0] = a;
155
+ b = load_bigendian(statebytes + 8); state[1] = b;
156
+ c = load_bigendian(statebytes + 16); state[2] = c;
157
+ d = load_bigendian(statebytes + 24); state[3] = d;
158
+ e = load_bigendian(statebytes + 32); state[4] = e;
159
+ f = load_bigendian(statebytes + 40); state[5] = f;
160
+ g = load_bigendian(statebytes + 48); state[6] = g;
161
+ h = load_bigendian(statebytes + 56); state[7] = h;
162
+
163
+ while (inlen >= 128) {
164
+ uint64_t w0 = load_bigendian(in + 0);
165
+ uint64_t w1 = load_bigendian(in + 8);
166
+ uint64_t w2 = load_bigendian(in + 16);
167
+ uint64_t w3 = load_bigendian(in + 24);
168
+ uint64_t w4 = load_bigendian(in + 32);
169
+ uint64_t w5 = load_bigendian(in + 40);
170
+ uint64_t w6 = load_bigendian(in + 48);
171
+ uint64_t w7 = load_bigendian(in + 56);
172
+ uint64_t w8 = load_bigendian(in + 64);
173
+ uint64_t w9 = load_bigendian(in + 72);
174
+ uint64_t w10 = load_bigendian(in + 80);
175
+ uint64_t w11 = load_bigendian(in + 88);
176
+ uint64_t w12 = load_bigendian(in + 96);
177
+ uint64_t w13 = load_bigendian(in + 104);
178
+ uint64_t w14 = load_bigendian(in + 112);
179
+ uint64_t w15 = load_bigendian(in + 120);
180
+
181
+ F(w0 ,0x428a2f98d728ae22ULL)
182
+ F(w1 ,0x7137449123ef65cdULL)
183
+ F(w2 ,0xb5c0fbcfec4d3b2fULL)
184
+ F(w3 ,0xe9b5dba58189dbbcULL)
185
+ F(w4 ,0x3956c25bf348b538ULL)
186
+ F(w5 ,0x59f111f1b605d019ULL)
187
+ F(w6 ,0x923f82a4af194f9bULL)
188
+ F(w7 ,0xab1c5ed5da6d8118ULL)
189
+ F(w8 ,0xd807aa98a3030242ULL)
190
+ F(w9 ,0x12835b0145706fbeULL)
191
+ F(w10,0x243185be4ee4b28cULL)
192
+ F(w11,0x550c7dc3d5ffb4e2ULL)
193
+ F(w12,0x72be5d74f27b896fULL)
194
+ F(w13,0x80deb1fe3b1696b1ULL)
195
+ F(w14,0x9bdc06a725c71235ULL)
196
+ F(w15,0xc19bf174cf692694ULL)
197
+
198
+ EXPAND
199
+
200
+ F(w0 ,0xe49b69c19ef14ad2ULL)
201
+ F(w1 ,0xefbe4786384f25e3ULL)
202
+ F(w2 ,0x0fc19dc68b8cd5b5ULL)
203
+ F(w3 ,0x240ca1cc77ac9c65ULL)
204
+ F(w4 ,0x2de92c6f592b0275ULL)
205
+ F(w5 ,0x4a7484aa6ea6e483ULL)
206
+ F(w6 ,0x5cb0a9dcbd41fbd4ULL)
207
+ F(w7 ,0x76f988da831153b5ULL)
208
+ F(w8 ,0x983e5152ee66dfabULL)
209
+ F(w9 ,0xa831c66d2db43210ULL)
210
+ F(w10,0xb00327c898fb213fULL)
211
+ F(w11,0xbf597fc7beef0ee4ULL)
212
+ F(w12,0xc6e00bf33da88fc2ULL)
213
+ F(w13,0xd5a79147930aa725ULL)
214
+ F(w14,0x06ca6351e003826fULL)
215
+ F(w15,0x142929670a0e6e70ULL)
216
+
217
+ EXPAND
218
+
219
+ F(w0 ,0x27b70a8546d22ffcULL)
220
+ F(w1 ,0x2e1b21385c26c926ULL)
221
+ F(w2 ,0x4d2c6dfc5ac42aedULL)
222
+ F(w3 ,0x53380d139d95b3dfULL)
223
+ F(w4 ,0x650a73548baf63deULL)
224
+ F(w5 ,0x766a0abb3c77b2a8ULL)
225
+ F(w6 ,0x81c2c92e47edaee6ULL)
226
+ F(w7 ,0x92722c851482353bULL)
227
+ F(w8 ,0xa2bfe8a14cf10364ULL)
228
+ F(w9 ,0xa81a664bbc423001ULL)
229
+ F(w10,0xc24b8b70d0f89791ULL)
230
+ F(w11,0xc76c51a30654be30ULL)
231
+ F(w12,0xd192e819d6ef5218ULL)
232
+ F(w13,0xd69906245565a910ULL)
233
+ F(w14,0xf40e35855771202aULL)
234
+ F(w15,0x106aa07032bbd1b8ULL)
235
+
236
+ EXPAND
237
+
238
+ F(w0 ,0x19a4c116b8d2d0c8ULL)
239
+ F(w1 ,0x1e376c085141ab53ULL)
240
+ F(w2 ,0x2748774cdf8eeb99ULL)
241
+ F(w3 ,0x34b0bcb5e19b48a8ULL)
242
+ F(w4 ,0x391c0cb3c5c95a63ULL)
243
+ F(w5 ,0x4ed8aa4ae3418acbULL)
244
+ F(w6 ,0x5b9cca4f7763e373ULL)
245
+ F(w7 ,0x682e6ff3d6b2b8a3ULL)
246
+ F(w8 ,0x748f82ee5defb2fcULL)
247
+ F(w9 ,0x78a5636f43172f60ULL)
248
+ F(w10,0x84c87814a1f0ab72ULL)
249
+ F(w11,0x8cc702081a6439ecULL)
250
+ F(w12,0x90befffa23631e28ULL)
251
+ F(w13,0xa4506cebde82bde9ULL)
252
+ F(w14,0xbef9a3f7b2c67915ULL)
253
+ F(w15,0xc67178f2e372532bULL)
254
+
255
+ EXPAND
256
+
257
+ F(w0 ,0xca273eceea26619cULL)
258
+ F(w1 ,0xd186b8c721c0c207ULL)
259
+ F(w2 ,0xeada7dd6cde0eb1eULL)
260
+ F(w3 ,0xf57d4f7fee6ed178ULL)
261
+ F(w4 ,0x06f067aa72176fbaULL)
262
+ F(w5 ,0x0a637dc5a2c898a6ULL)
263
+ F(w6 ,0x113f9804bef90daeULL)
264
+ F(w7 ,0x1b710b35131c471bULL)
265
+ F(w8 ,0x28db77f523047d84ULL)
266
+ F(w9 ,0x32caab7b40c72493ULL)
267
+ F(w10,0x3c9ebe0a15c9bebcULL)
268
+ F(w11,0x431d67c49c100d4cULL)
269
+ F(w12,0x4cc5d4becb3e42b6ULL)
270
+ F(w13,0x597f299cfc657e2aULL)
271
+ F(w14,0x5fcb6fab3ad6faecULL)
272
+ F(w15,0x6c44198c4a475817ULL)
273
+
274
+ a += state[0];
275
+ b += state[1];
276
+ c += state[2];
277
+ d += state[3];
278
+ e += state[4];
279
+ f += state[5];
280
+ g += state[6];
281
+ h += state[7];
282
+
283
+ state[0] = a;
284
+ state[1] = b;
285
+ state[2] = c;
286
+ state[3] = d;
287
+ state[4] = e;
288
+ state[5] = f;
289
+ state[6] = g;
290
+ state[7] = h;
291
+
292
+ in += 128;
293
+ inlen -= 128;
294
+ }
295
+
296
+ store_bigendian(statebytes + 0,state[0]);
297
+ store_bigendian(statebytes + 8,state[1]);
298
+ store_bigendian(statebytes + 16,state[2]);
299
+ store_bigendian(statebytes + 24,state[3]);
300
+ store_bigendian(statebytes + 32,state[4]);
301
+ store_bigendian(statebytes + 40,state[5]);
302
+ store_bigendian(statebytes + 48,state[6]);
303
+ store_bigendian(statebytes + 56,state[7]);
304
+ }