ed25519 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +13 -0
  3. data/README.md +6 -3
  4. data/Rakefile +4 -4
  5. data/ed25519.gemspec +3 -3
  6. data/ext/{ed25519 → ed25519_java}/org/cryptosphere/ed25519.java +0 -0
  7. data/ext/{ed25519 → ed25519_ref10}/api.h +1 -1
  8. data/ext/ed25519_ref10/base.h +1344 -0
  9. data/ext/ed25519_ref10/base2.h +40 -0
  10. data/ext/ed25519_ref10/d.h +1 -0
  11. data/ext/ed25519_ref10/d2.h +1 -0
  12. data/ext/ed25519_ref10/ed25519_ref10.c +99 -0
  13. data/ext/ed25519_ref10/ed25519_ref10.h +33 -0
  14. data/ext/ed25519_ref10/extconf.rb +9 -0
  15. data/ext/ed25519_ref10/fe.h +56 -0
  16. data/ext/ed25519_ref10/fe_0.c +19 -0
  17. data/ext/ed25519_ref10/fe_1.c +19 -0
  18. data/ext/ed25519_ref10/fe_add.c +57 -0
  19. data/ext/ed25519_ref10/fe_cmov.c +63 -0
  20. data/ext/ed25519_ref10/fe_copy.c +29 -0
  21. data/ext/ed25519_ref10/fe_frombytes.c +71 -0
  22. data/ext/ed25519_ref10/fe_invert.c +14 -0
  23. data/ext/ed25519_ref10/fe_isnegative.c +16 -0
  24. data/ext/ed25519_ref10/fe_isnonzero.c +19 -0
  25. data/ext/ed25519_ref10/fe_mul.c +252 -0
  26. data/ext/ed25519_ref10/fe_neg.c +45 -0
  27. data/ext/ed25519_ref10/fe_pow22523.c +13 -0
  28. data/ext/ed25519_ref10/fe_sq.c +148 -0
  29. data/ext/ed25519_ref10/fe_sq2.c +159 -0
  30. data/ext/ed25519_ref10/fe_sub.c +57 -0
  31. data/ext/ed25519_ref10/fe_tobytes.c +119 -0
  32. data/ext/ed25519_ref10/ge.h +95 -0
  33. data/ext/ed25519_ref10/ge_add.c +11 -0
  34. data/ext/ed25519_ref10/ge_add.h +97 -0
  35. data/ext/ed25519_ref10/ge_double_scalarmult.c +96 -0
  36. data/ext/ed25519_ref10/ge_frombytes.c +50 -0
  37. data/ext/ed25519_ref10/ge_madd.c +11 -0
  38. data/ext/ed25519_ref10/ge_madd.h +88 -0
  39. data/ext/ed25519_ref10/ge_msub.c +11 -0
  40. data/ext/ed25519_ref10/ge_msub.h +88 -0
  41. data/ext/ed25519_ref10/ge_p1p1_to_p2.c +12 -0
  42. data/ext/ed25519_ref10/ge_p1p1_to_p3.c +13 -0
  43. data/ext/ed25519_ref10/ge_p2_0.c +8 -0
  44. data/ext/ed25519_ref10/ge_p2_dbl.c +11 -0
  45. data/ext/ed25519_ref10/ge_p2_dbl.h +73 -0
  46. data/ext/ed25519_ref10/ge_p3_0.c +9 -0
  47. data/ext/ed25519_ref10/ge_p3_dbl.c +12 -0
  48. data/ext/ed25519_ref10/ge_p3_to_cached.c +17 -0
  49. data/ext/ed25519_ref10/ge_p3_to_p2.c +12 -0
  50. data/ext/ed25519_ref10/ge_p3_tobytes.c +14 -0
  51. data/ext/ed25519_ref10/ge_precomp_0.c +8 -0
  52. data/ext/ed25519_ref10/ge_scalarmult_base.c +104 -0
  53. data/ext/ed25519_ref10/ge_sub.c +11 -0
  54. data/ext/ed25519_ref10/ge_sub.h +97 -0
  55. data/ext/ed25519_ref10/ge_tobytes.c +14 -0
  56. data/ext/ed25519_ref10/keypair.c +22 -0
  57. data/ext/ed25519_ref10/open.c +47 -0
  58. data/ext/ed25519_ref10/pow22523.h +160 -0
  59. data/ext/ed25519_ref10/pow225521.h +160 -0
  60. data/ext/ed25519_ref10/sc.h +17 -0
  61. data/ext/ed25519_ref10/sc_muladd.c +366 -0
  62. data/ext/ed25519_ref10/sc_reduce.c +272 -0
  63. data/ext/{ed25519/sha512-blocks.c → ed25519_ref10/sha512.c} +108 -43
  64. data/ext/ed25519_ref10/sha512.h +8 -0
  65. data/ext/ed25519_ref10/sign.c +41 -0
  66. data/ext/ed25519_ref10/sqrtm1.h +1 -0
  67. data/ext/{ed25519 → ed25519_ref10}/verify.c +2 -2
  68. data/lib/ed25519.rb +40 -9
  69. data/lib/ed25519/provider/jruby.rb +39 -0
  70. data/lib/ed25519/signing_key.rb +11 -7
  71. data/lib/ed25519/verify_key.rb +26 -10
  72. data/lib/ed25519/version.rb +1 -1
  73. metadata +66 -26
  74. data/ext/ed25519/crypto_int32.h +0 -6
  75. data/ext/ed25519/crypto_sign.h +0 -13
  76. data/ext/ed25519/crypto_uint32.h +0 -6
  77. data/ext/ed25519/crypto_verify_32.h +0 -7
  78. data/ext/ed25519/ed25519.c +0 -136
  79. data/ext/ed25519/ed25519_engine.c +0 -82
  80. data/ext/ed25519/extconf.rb +0 -6
  81. data/ext/ed25519/fe25519.c +0 -326
  82. data/ext/ed25519/fe25519.h +0 -63
  83. data/ext/ed25519/ge25519.c +0 -311
  84. data/ext/ed25519/ge25519.h +0 -35
  85. data/ext/ed25519/ge25519_base.data +0 -850
  86. data/ext/ed25519/sc25519.c +0 -298
  87. data/ext/ed25519/sc25519.h +0 -73
  88. data/ext/ed25519/sha512-hash.c +0 -72
  89. data/ext/ed25519/sha512.h +0 -4
  90. data/lib/ed25519/jruby_engine.rb +0 -30
  91. data/tasks/extension.rake +0 -14
  92. data/tasks/rspec.rake +0 -9
@@ -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
+ }
@@ -1,22 +1,89 @@
1
- //#include "crypto_hashblocks.h"
1
+ /*
2
+ 20080913
3
+ D. J. Bernstein
4
+ Public domain.
5
+ */
2
6
 
3
- typedef unsigned long long uint64;
7
+ #include "sha512.h"
4
8
 
5
- static uint64 load_bigendian(const unsigned char *x)
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)
6
73
  {
7
74
  return
8
- (uint64) (x[7]) \
9
- | (((uint64) (x[6])) << 8) \
10
- | (((uint64) (x[5])) << 16) \
11
- | (((uint64) (x[4])) << 24) \
12
- | (((uint64) (x[3])) << 32) \
13
- | (((uint64) (x[2])) << 40) \
14
- | (((uint64) (x[1])) << 48) \
15
- | (((uint64) (x[0])) << 56)
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)
16
83
  ;
17
84
  }
18
85
 
19
- static void store_bigendian(unsigned char *x,uint64 u)
86
+ static void store_bigendian(unsigned char *x,uint64_t u)
20
87
  {
21
88
  x[7] = u; u >>= 8;
22
89
  x[6] = u; u >>= 8;
@@ -70,19 +137,19 @@ static void store_bigendian(unsigned char *x,uint64 u)
70
137
  b = a; \
71
138
  a = T1 + T2;
72
139
 
73
- int crypto_hashblocks(unsigned char *statebytes,const unsigned char *in,unsigned long long inlen)
140
+ static void crypto_hashblocks_sha512(uint8_t *statebytes,const uint8_t *in,uint64_t inlen)
74
141
  {
75
- uint64 state[8];
76
- uint64 a;
77
- uint64 b;
78
- uint64 c;
79
- uint64 d;
80
- uint64 e;
81
- uint64 f;
82
- uint64 g;
83
- uint64 h;
84
- uint64 T1;
85
- uint64 T2;
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;
86
153
 
87
154
  a = load_bigendian(statebytes + 0); state[0] = a;
88
155
  b = load_bigendian(statebytes + 8); state[1] = b;
@@ -94,22 +161,22 @@ int crypto_hashblocks(unsigned char *statebytes,const unsigned char *in,unsigned
94
161
  h = load_bigendian(statebytes + 56); state[7] = h;
95
162
 
96
163
  while (inlen >= 128) {
97
- uint64 w0 = load_bigendian(in + 0);
98
- uint64 w1 = load_bigendian(in + 8);
99
- uint64 w2 = load_bigendian(in + 16);
100
- uint64 w3 = load_bigendian(in + 24);
101
- uint64 w4 = load_bigendian(in + 32);
102
- uint64 w5 = load_bigendian(in + 40);
103
- uint64 w6 = load_bigendian(in + 48);
104
- uint64 w7 = load_bigendian(in + 56);
105
- uint64 w8 = load_bigendian(in + 64);
106
- uint64 w9 = load_bigendian(in + 72);
107
- uint64 w10 = load_bigendian(in + 80);
108
- uint64 w11 = load_bigendian(in + 88);
109
- uint64 w12 = load_bigendian(in + 96);
110
- uint64 w13 = load_bigendian(in + 104);
111
- uint64 w14 = load_bigendian(in + 112);
112
- uint64 w15 = load_bigendian(in + 120);
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);
113
180
 
114
181
  F(w0 ,0x428a2f98d728ae22ULL)
115
182
  F(w1 ,0x7137449123ef65cdULL)
@@ -212,7 +279,7 @@ int crypto_hashblocks(unsigned char *statebytes,const unsigned char *in,unsigned
212
279
  f += state[5];
213
280
  g += state[6];
214
281
  h += state[7];
215
-
282
+
216
283
  state[0] = a;
217
284
  state[1] = b;
218
285
  state[2] = c;
@@ -234,6 +301,4 @@ int crypto_hashblocks(unsigned char *statebytes,const unsigned char *in,unsigned
234
301
  store_bigendian(statebytes + 40,state[5]);
235
302
  store_bigendian(statebytes + 48,state[6]);
236
303
  store_bigendian(statebytes + 56,state[7]);
237
-
238
- return inlen;
239
304
  }