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
@@ -1,298 +0,0 @@
1
- #include "sc25519.h"
2
-
3
- /*Arithmetic modulo the group order m = 2^252 + 27742317777372353535851937790883648493 = 7237005577332262213973186563042994240857116359379907606001950938285454250989 */
4
-
5
- static const crypto_uint32 m[32] = {0xED, 0xD3, 0xF5, 0x5C, 0x1A, 0x63, 0x12, 0x58, 0xD6, 0x9C, 0xF7, 0xA2, 0xDE, 0xF9, 0xDE, 0x14,
6
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10};
7
-
8
- static const crypto_uint32 mu[33] = {0x1B, 0x13, 0x2C, 0x0A, 0xA3, 0xE5, 0x9C, 0xED, 0xA7, 0x29, 0x63, 0x08, 0x5D, 0x21, 0x06, 0x21,
9
- 0xEB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F};
10
-
11
- static crypto_uint32 lt(crypto_uint32 a,crypto_uint32 b) /* 16-bit inputs */
12
- {
13
- unsigned int x = a;
14
- x -= (unsigned int) b; /* 0..65535: no; 4294901761..4294967295: yes */
15
- x >>= 31; /* 0: no; 1: yes */
16
- return x;
17
- }
18
-
19
- /* Reduce coefficients of r before calling reduce_add_sub */
20
- static void reduce_add_sub(sc25519 *r)
21
- {
22
- crypto_uint32 pb = 0;
23
- crypto_uint32 b;
24
- crypto_uint32 mask;
25
- int i;
26
- unsigned char t[32];
27
-
28
- for(i=0;i<32;i++)
29
- {
30
- pb += m[i];
31
- b = lt(r->v[i],pb);
32
- t[i] = r->v[i]-pb+(b<<8);
33
- pb = b;
34
- }
35
- mask = b - 1;
36
- for(i=0;i<32;i++)
37
- r->v[i] ^= mask & (r->v[i] ^ t[i]);
38
- }
39
-
40
- /* Reduce coefficients of x before calling barrett_reduce */
41
- static void barrett_reduce(sc25519 *r, const crypto_uint32 x[64])
42
- {
43
- /* See HAC, Alg. 14.42 */
44
- int i,j;
45
- crypto_uint32 q2[66];
46
- crypto_uint32 *q3 = q2 + 33;
47
- crypto_uint32 r1[33];
48
- crypto_uint32 r2[33];
49
- crypto_uint32 carry;
50
- crypto_uint32 pb = 0;
51
- crypto_uint32 b;
52
-
53
- for (i = 0;i < 66;++i) q2[i] = 0;
54
- for (i = 0;i < 33;++i) r2[i] = 0;
55
-
56
- for(i=0;i<33;i++)
57
- for(j=0;j<33;j++)
58
- if(i+j >= 31) q2[i+j] += mu[i]*x[j+31];
59
- carry = q2[31] >> 8;
60
- q2[32] += carry;
61
- carry = q2[32] >> 8;
62
- q2[33] += carry;
63
-
64
- for(i=0;i<33;i++)r1[i] = x[i];
65
- for(i=0;i<32;i++)
66
- for(j=0;j<33;j++)
67
- if(i+j < 33) r2[i+j] += m[i]*q3[j];
68
-
69
- for(i=0;i<32;i++)
70
- {
71
- carry = r2[i] >> 8;
72
- r2[i+1] += carry;
73
- r2[i] &= 0xff;
74
- }
75
-
76
- for(i=0;i<32;i++)
77
- {
78
- pb += r2[i];
79
- b = lt(r1[i],pb);
80
- r->v[i] = r1[i]-pb+(b<<8);
81
- pb = b;
82
- }
83
-
84
- /* XXX: Can it really happen that r<0?, See HAC, Alg 14.42, Step 3
85
- * If so: Handle it here!
86
- */
87
-
88
- reduce_add_sub(r);
89
- reduce_add_sub(r);
90
- }
91
-
92
- void sc25519_from32bytes(sc25519 *r, const unsigned char x[32])
93
- {
94
- int i;
95
- crypto_uint32 t[64];
96
- for(i=0;i<32;i++) t[i] = x[i];
97
- for(i=32;i<64;++i) t[i] = 0;
98
- barrett_reduce(r, t);
99
- }
100
-
101
- void shortsc25519_from16bytes(shortsc25519 *r, const unsigned char x[16])
102
- {
103
- int i;
104
- for(i=0;i<16;i++) r->v[i] = x[i];
105
- }
106
-
107
- void sc25519_from64bytes(sc25519 *r, const unsigned char x[64])
108
- {
109
- int i;
110
- crypto_uint32 t[64];
111
- for(i=0;i<64;i++) t[i] = x[i];
112
- barrett_reduce(r, t);
113
- }
114
-
115
- void sc25519_from_shortsc(sc25519 *r, const shortsc25519 *x)
116
- {
117
- int i;
118
- for(i=0;i<16;i++)
119
- r->v[i] = x->v[i];
120
- for(i=0;i<16;i++)
121
- r->v[16+i] = 0;
122
- }
123
-
124
- void sc25519_to32bytes(unsigned char r[32], const sc25519 *x)
125
- {
126
- int i;
127
- for(i=0;i<32;i++) r[i] = x->v[i];
128
- }
129
-
130
- int sc25519_iszero_vartime(const sc25519 *x)
131
- {
132
- int i;
133
- for(i=0;i<32;i++)
134
- if(x->v[i] != 0) return 0;
135
- return 1;
136
- }
137
-
138
- int sc25519_isshort_vartime(const sc25519 *x)
139
- {
140
- int i;
141
- for(i=31;i>15;i--)
142
- if(x->v[i] != 0) return 0;
143
- return 1;
144
- }
145
-
146
- int sc25519_lt_vartime(const sc25519 *x, const sc25519 *y)
147
- {
148
- int i;
149
- for(i=31;i>=0;i--)
150
- {
151
- if(x->v[i] < y->v[i]) return 1;
152
- if(x->v[i] > y->v[i]) return 0;
153
- }
154
- return 0;
155
- }
156
-
157
- void sc25519_add(sc25519 *r, const sc25519 *x, const sc25519 *y)
158
- {
159
- int i, carry;
160
- for(i=0;i<32;i++) r->v[i] = x->v[i] + y->v[i];
161
- for(i=0;i<31;i++)
162
- {
163
- carry = r->v[i] >> 8;
164
- r->v[i+1] += carry;
165
- r->v[i] &= 0xff;
166
- }
167
- reduce_add_sub(r);
168
- }
169
-
170
- void sc25519_sub_nored(sc25519 *r, const sc25519 *x, const sc25519 *y)
171
- {
172
- crypto_uint32 b = 0;
173
- crypto_uint32 t;
174
- int i;
175
- for(i=0;i<32;i++)
176
- {
177
- t = x->v[i] - y->v[i] - b;
178
- r->v[i] = t & 255;
179
- b = (t >> 8) & 1;
180
- }
181
- }
182
-
183
- void sc25519_mul(sc25519 *r, const sc25519 *x, const sc25519 *y)
184
- {
185
- int i,j,carry;
186
- crypto_uint32 t[64];
187
- for(i=0;i<64;i++)t[i] = 0;
188
-
189
- for(i=0;i<32;i++)
190
- for(j=0;j<32;j++)
191
- t[i+j] += x->v[i] * y->v[j];
192
-
193
- /* Reduce coefficients */
194
- for(i=0;i<63;i++)
195
- {
196
- carry = t[i] >> 8;
197
- t[i+1] += carry;
198
- t[i] &= 0xff;
199
- }
200
-
201
- barrett_reduce(r, t);
202
- }
203
-
204
- void sc25519_mul_shortsc(sc25519 *r, const sc25519 *x, const shortsc25519 *y)
205
- {
206
- sc25519 t;
207
- sc25519_from_shortsc(&t, y);
208
- sc25519_mul(r, x, &t);
209
- }
210
-
211
- void sc25519_window3(signed char r[85], const sc25519 *s)
212
- {
213
- char carry;
214
- int i;
215
- for(i=0;i<10;i++)
216
- {
217
- r[8*i+0] = s->v[3*i+0] & 7;
218
- r[8*i+1] = (s->v[3*i+0] >> 3) & 7;
219
- r[8*i+2] = (s->v[3*i+0] >> 6) & 7;
220
- r[8*i+2] ^= (s->v[3*i+1] << 2) & 7;
221
- r[8*i+3] = (s->v[3*i+1] >> 1) & 7;
222
- r[8*i+4] = (s->v[3*i+1] >> 4) & 7;
223
- r[8*i+5] = (s->v[3*i+1] >> 7) & 7;
224
- r[8*i+5] ^= (s->v[3*i+2] << 1) & 7;
225
- r[8*i+6] = (s->v[3*i+2] >> 2) & 7;
226
- r[8*i+7] = (s->v[3*i+2] >> 5) & 7;
227
- }
228
- r[8*i+0] = s->v[3*i+0] & 7;
229
- r[8*i+1] = (s->v[3*i+0] >> 3) & 7;
230
- r[8*i+2] = (s->v[3*i+0] >> 6) & 7;
231
- r[8*i+2] ^= (s->v[3*i+1] << 2) & 7;
232
- r[8*i+3] = (s->v[3*i+1] >> 1) & 7;
233
- r[8*i+4] = (s->v[3*i+1] >> 4) & 7;
234
-
235
- /* Making it signed */
236
- carry = 0;
237
- for(i=0;i<84;i++)
238
- {
239
- r[i] += carry;
240
- r[i+1] += r[i] >> 3;
241
- r[i] &= 7;
242
- carry = r[i] >> 2;
243
- r[i] -= carry<<3;
244
- }
245
- r[84] += carry;
246
- }
247
-
248
- void sc25519_window5(signed char r[51], const sc25519 *s)
249
- {
250
- char carry;
251
- int i;
252
- for(i=0;i<6;i++)
253
- {
254
- r[8*i+0] = s->v[5*i+0] & 31;
255
- r[8*i+1] = (s->v[5*i+0] >> 5) & 31;
256
- r[8*i+1] ^= (s->v[5*i+1] << 3) & 31;
257
- r[8*i+2] = (s->v[5*i+1] >> 2) & 31;
258
- r[8*i+3] = (s->v[5*i+1] >> 7) & 31;
259
- r[8*i+3] ^= (s->v[5*i+2] << 1) & 31;
260
- r[8*i+4] = (s->v[5*i+2] >> 4) & 31;
261
- r[8*i+4] ^= (s->v[5*i+3] << 4) & 31;
262
- r[8*i+5] = (s->v[5*i+3] >> 1) & 31;
263
- r[8*i+6] = (s->v[5*i+3] >> 6) & 31;
264
- r[8*i+6] ^= (s->v[5*i+4] << 2) & 31;
265
- r[8*i+7] = (s->v[5*i+4] >> 3) & 31;
266
- }
267
- r[8*i+0] = s->v[5*i+0] & 31;
268
- r[8*i+1] = (s->v[5*i+0] >> 5) & 31;
269
- r[8*i+1] ^= (s->v[5*i+1] << 3) & 31;
270
- r[8*i+2] = (s->v[5*i+1] >> 2) & 31;
271
-
272
- /* Making it signed */
273
- carry = 0;
274
- for(i=0;i<50;i++)
275
- {
276
- r[i] += carry;
277
- r[i+1] += r[i] >> 5;
278
- r[i] &= 31;
279
- carry = r[i] >> 4;
280
- r[i] -= carry<<5;
281
- }
282
- r[50] += carry;
283
- }
284
-
285
- void sc25519_2interleave2(unsigned char r[127], const sc25519 *s1, const sc25519 *s2)
286
- {
287
- int i;
288
- for(i=0;i<31;i++)
289
- {
290
- r[4*i] = ( s1->v[i] & 3) ^ (( s2->v[i] & 3) << 2);
291
- r[4*i+1] = ((s1->v[i] >> 2) & 3) ^ (((s2->v[i] >> 2) & 3) << 2);
292
- r[4*i+2] = ((s1->v[i] >> 4) & 3) ^ (((s2->v[i] >> 4) & 3) << 2);
293
- r[4*i+3] = ((s1->v[i] >> 6) & 3) ^ (((s2->v[i] >> 6) & 3) << 2);
294
- }
295
- r[124] = ( s1->v[31] & 3) ^ (( s2->v[31] & 3) << 2);
296
- r[125] = ((s1->v[31] >> 2) & 3) ^ (((s2->v[31] >> 2) & 3) << 2);
297
- r[126] = ((s1->v[31] >> 4) & 3) ^ (((s2->v[31] >> 4) & 3) << 2);
298
- }
@@ -1,73 +0,0 @@
1
- #ifndef SC25519_H
2
- #define SC25519_H
3
-
4
- #include "crypto_int32.h"
5
- #include "crypto_uint32.h"
6
-
7
- #define sc25519 crypto_sign_ed25519_ref_sc25519
8
- #define shortsc25519 crypto_sign_ed25519_ref_shortsc25519
9
- #define sc25519_from32bytes crypto_sign_ed25519_ref_sc25519_from32bytes
10
- #define shortsc25519_from16bytes crypto_sign_ed25519_ref_shortsc25519_from16bytes
11
- #define sc25519_from64bytes crypto_sign_ed25519_ref_sc25519_from64bytes
12
- #define sc25519_from_shortsc crypto_sign_ed25519_ref_sc25519_from_shortsc
13
- #define sc25519_to32bytes crypto_sign_ed25519_ref_sc25519_to32bytes
14
- #define sc25519_iszero_vartime crypto_sign_ed25519_ref_sc25519_iszero_vartime
15
- #define sc25519_isshort_vartime crypto_sign_ed25519_ref_sc25519_isshort_vartime
16
- #define sc25519_lt_vartime crypto_sign_ed25519_ref_sc25519_lt_vartime
17
- #define sc25519_add crypto_sign_ed25519_ref_sc25519_add
18
- #define sc25519_sub_nored crypto_sign_ed25519_ref_sc25519_sub_nored
19
- #define sc25519_mul crypto_sign_ed25519_ref_sc25519_mul
20
- #define sc25519_mul_shortsc crypto_sign_ed25519_ref_sc25519_mul_shortsc
21
- #define sc25519_window3 crypto_sign_ed25519_ref_sc25519_window3
22
- #define sc25519_window5 crypto_sign_ed25519_ref_sc25519_window5
23
- #define sc25519_2interleave2 crypto_sign_ed25519_ref_sc25519_2interleave2
24
-
25
- typedef struct
26
- {
27
- crypto_uint32 v[32];
28
- }
29
- sc25519;
30
-
31
- typedef struct
32
- {
33
- crypto_uint32 v[16];
34
- }
35
- shortsc25519;
36
-
37
- void sc25519_from32bytes(sc25519 *r, const unsigned char x[32]);
38
-
39
- void shortsc25519_from16bytes(shortsc25519 *r, const unsigned char x[16]);
40
-
41
- void sc25519_from64bytes(sc25519 *r, const unsigned char x[64]);
42
-
43
- void sc25519_from_shortsc(sc25519 *r, const shortsc25519 *x);
44
-
45
- void sc25519_to32bytes(unsigned char r[32], const sc25519 *x);
46
-
47
- int sc25519_iszero_vartime(const sc25519 *x);
48
-
49
- int sc25519_isshort_vartime(const sc25519 *x);
50
-
51
- int sc25519_lt_vartime(const sc25519 *x, const sc25519 *y);
52
-
53
- void sc25519_add(sc25519 *r, const sc25519 *x, const sc25519 *y);
54
-
55
- void sc25519_sub_nored(sc25519 *r, const sc25519 *x, const sc25519 *y);
56
-
57
- void sc25519_mul(sc25519 *r, const sc25519 *x, const sc25519 *y);
58
-
59
- void sc25519_mul_shortsc(sc25519 *r, const sc25519 *x, const shortsc25519 *y);
60
-
61
- /* Convert s into a representation of the form \sum_{i=0}^{84}r[i]2^3
62
- * with r[i] in {-4,...,3}
63
- */
64
- void sc25519_window3(signed char r[85], const sc25519 *s);
65
-
66
- /* Convert s into a representation of the form \sum_{i=0}^{50}r[i]2^5
67
- * with r[i] in {-16,...,15}
68
- */
69
- void sc25519_window5(signed char r[51], const sc25519 *s);
70
-
71
- void sc25519_2interleave2(unsigned char r[127], const sc25519 *s1, const sc25519 *s2);
72
-
73
- #endif
@@ -1,72 +0,0 @@
1
- /*
2
- 20080913
3
- D. J. Bernstein
4
- Public domain.
5
- */
6
-
7
- #include "sha512.h"
8
-
9
- extern int crypto_hashblocks(unsigned char *statebytes,const unsigned char *in,unsigned long long inlen);
10
-
11
- #define blocks crypto_hashblocks
12
-
13
- static const unsigned char 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
- typedef unsigned long long uint64;
25
-
26
- int crypto_hash_sha512(unsigned char *out,const unsigned char *in,unsigned long long inlen)
27
- {
28
- unsigned char h[64];
29
- unsigned char padded[256];
30
- int i;
31
- unsigned long long bytes = inlen;
32
-
33
- for (i = 0;i < 64;++i) h[i] = iv[i];
34
-
35
- blocks(h,in,inlen);
36
- in += inlen;
37
- inlen &= 127;
38
- in -= inlen;
39
-
40
- for (i = 0;i < inlen;++i) padded[i] = in[i];
41
- padded[inlen] = 0x80;
42
-
43
- if (inlen < 112) {
44
- for (i = inlen + 1;i < 119;++i) padded[i] = 0;
45
- padded[119] = bytes >> 61;
46
- padded[120] = bytes >> 53;
47
- padded[121] = bytes >> 45;
48
- padded[122] = bytes >> 37;
49
- padded[123] = bytes >> 29;
50
- padded[124] = bytes >> 21;
51
- padded[125] = bytes >> 13;
52
- padded[126] = bytes >> 5;
53
- padded[127] = bytes << 3;
54
- blocks(h,padded,128);
55
- } else {
56
- for (i = inlen + 1;i < 247;++i) padded[i] = 0;
57
- padded[247] = bytes >> 61;
58
- padded[248] = bytes >> 53;
59
- padded[249] = bytes >> 45;
60
- padded[250] = bytes >> 37;
61
- padded[251] = bytes >> 29;
62
- padded[252] = bytes >> 21;
63
- padded[253] = bytes >> 13;
64
- padded[254] = bytes >> 5;
65
- padded[255] = bytes << 3;
66
- blocks(h,padded,256);
67
- }
68
-
69
- for (i = 0;i < 64;++i) out[i] = h[i];
70
-
71
- return 0;
72
- }
@@ -1,4 +0,0 @@
1
- extern int crypto_hashblocks(unsigned char *statebytes,const unsigned char *in,unsigned long long inlen);
2
- extern int crypto_hash_sha512(unsigned char *out,const unsigned char *in,unsigned long long inlen);
3
-
4
- #define crypto_hash_sha512_BYTES 64