ed25519 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +13 -0
- data/README.md +6 -3
- data/Rakefile +4 -4
- data/ed25519.gemspec +3 -3
- data/ext/{ed25519 → ed25519_java}/org/cryptosphere/ed25519.java +0 -0
- data/ext/{ed25519 → ed25519_ref10}/api.h +1 -1
- data/ext/ed25519_ref10/base.h +1344 -0
- data/ext/ed25519_ref10/base2.h +40 -0
- data/ext/ed25519_ref10/d.h +1 -0
- data/ext/ed25519_ref10/d2.h +1 -0
- data/ext/ed25519_ref10/ed25519_ref10.c +99 -0
- data/ext/ed25519_ref10/ed25519_ref10.h +33 -0
- data/ext/ed25519_ref10/extconf.rb +9 -0
- data/ext/ed25519_ref10/fe.h +56 -0
- data/ext/ed25519_ref10/fe_0.c +19 -0
- data/ext/ed25519_ref10/fe_1.c +19 -0
- data/ext/ed25519_ref10/fe_add.c +57 -0
- data/ext/ed25519_ref10/fe_cmov.c +63 -0
- data/ext/ed25519_ref10/fe_copy.c +29 -0
- data/ext/ed25519_ref10/fe_frombytes.c +71 -0
- data/ext/ed25519_ref10/fe_invert.c +14 -0
- data/ext/ed25519_ref10/fe_isnegative.c +16 -0
- data/ext/ed25519_ref10/fe_isnonzero.c +19 -0
- data/ext/ed25519_ref10/fe_mul.c +252 -0
- data/ext/ed25519_ref10/fe_neg.c +45 -0
- data/ext/ed25519_ref10/fe_pow22523.c +13 -0
- data/ext/ed25519_ref10/fe_sq.c +148 -0
- data/ext/ed25519_ref10/fe_sq2.c +159 -0
- data/ext/ed25519_ref10/fe_sub.c +57 -0
- data/ext/ed25519_ref10/fe_tobytes.c +119 -0
- data/ext/ed25519_ref10/ge.h +95 -0
- data/ext/ed25519_ref10/ge_add.c +11 -0
- data/ext/ed25519_ref10/ge_add.h +97 -0
- data/ext/ed25519_ref10/ge_double_scalarmult.c +96 -0
- data/ext/ed25519_ref10/ge_frombytes.c +50 -0
- data/ext/ed25519_ref10/ge_madd.c +11 -0
- data/ext/ed25519_ref10/ge_madd.h +88 -0
- data/ext/ed25519_ref10/ge_msub.c +11 -0
- data/ext/ed25519_ref10/ge_msub.h +88 -0
- data/ext/ed25519_ref10/ge_p1p1_to_p2.c +12 -0
- data/ext/ed25519_ref10/ge_p1p1_to_p3.c +13 -0
- data/ext/ed25519_ref10/ge_p2_0.c +8 -0
- data/ext/ed25519_ref10/ge_p2_dbl.c +11 -0
- data/ext/ed25519_ref10/ge_p2_dbl.h +73 -0
- data/ext/ed25519_ref10/ge_p3_0.c +9 -0
- data/ext/ed25519_ref10/ge_p3_dbl.c +12 -0
- data/ext/ed25519_ref10/ge_p3_to_cached.c +17 -0
- data/ext/ed25519_ref10/ge_p3_to_p2.c +12 -0
- data/ext/ed25519_ref10/ge_p3_tobytes.c +14 -0
- data/ext/ed25519_ref10/ge_precomp_0.c +8 -0
- data/ext/ed25519_ref10/ge_scalarmult_base.c +104 -0
- data/ext/ed25519_ref10/ge_sub.c +11 -0
- data/ext/ed25519_ref10/ge_sub.h +97 -0
- data/ext/ed25519_ref10/ge_tobytes.c +14 -0
- data/ext/ed25519_ref10/keypair.c +22 -0
- data/ext/ed25519_ref10/open.c +47 -0
- data/ext/ed25519_ref10/pow22523.h +160 -0
- data/ext/ed25519_ref10/pow225521.h +160 -0
- data/ext/ed25519_ref10/sc.h +17 -0
- data/ext/ed25519_ref10/sc_muladd.c +366 -0
- data/ext/ed25519_ref10/sc_reduce.c +272 -0
- data/ext/{ed25519/sha512-blocks.c → ed25519_ref10/sha512.c} +108 -43
- data/ext/ed25519_ref10/sha512.h +8 -0
- data/ext/ed25519_ref10/sign.c +41 -0
- data/ext/ed25519_ref10/sqrtm1.h +1 -0
- data/ext/{ed25519 → ed25519_ref10}/verify.c +2 -2
- data/lib/ed25519.rb +40 -9
- data/lib/ed25519/provider/jruby.rb +39 -0
- data/lib/ed25519/signing_key.rb +11 -7
- data/lib/ed25519/verify_key.rb +26 -10
- data/lib/ed25519/version.rb +1 -1
- metadata +66 -26
- data/ext/ed25519/crypto_int32.h +0 -6
- data/ext/ed25519/crypto_sign.h +0 -13
- data/ext/ed25519/crypto_uint32.h +0 -6
- data/ext/ed25519/crypto_verify_32.h +0 -7
- data/ext/ed25519/ed25519.c +0 -136
- data/ext/ed25519/ed25519_engine.c +0 -82
- data/ext/ed25519/extconf.rb +0 -6
- data/ext/ed25519/fe25519.c +0 -326
- data/ext/ed25519/fe25519.h +0 -63
- data/ext/ed25519/ge25519.c +0 -311
- data/ext/ed25519/ge25519.h +0 -35
- data/ext/ed25519/ge25519_base.data +0 -850
- data/ext/ed25519/sc25519.c +0 -298
- data/ext/ed25519/sc25519.h +0 -73
- data/ext/ed25519/sha512-hash.c +0 -72
- data/ext/ed25519/sha512.h +0 -4
- data/lib/ed25519/jruby_engine.rb +0 -30
- data/tasks/extension.rake +0 -14
- data/tasks/rspec.rake +0 -9
@@ -1,82 +0,0 @@
|
|
1
|
-
#include "ruby.h"
|
2
|
-
#include "crypto_sign.h"
|
3
|
-
|
4
|
-
static VALUE mEd25519 = Qnil;
|
5
|
-
static VALUE mEd25519_Engine = Qnil;
|
6
|
-
|
7
|
-
static VALUE Ed25519_Engine_create_keypair(VALUE self, VALUE seed);
|
8
|
-
static VALUE Ed25519_Engine_sign(VALUE self, VALUE signing_key, VALUE msg);
|
9
|
-
static VALUE Ed25519_Engine_verify(VALUE self, VALUE verify_key, VALUE signature, VALUE msg);
|
10
|
-
|
11
|
-
void Init_ed25519_engine()
|
12
|
-
{
|
13
|
-
mEd25519 = rb_define_module("Ed25519");
|
14
|
-
mEd25519_Engine = rb_define_module_under(mEd25519, "Engine");
|
15
|
-
|
16
|
-
rb_define_singleton_method(mEd25519_Engine, "create_keypair", Ed25519_Engine_create_keypair, 1);
|
17
|
-
rb_define_singleton_method(mEd25519_Engine, "sign", Ed25519_Engine_sign, 2);
|
18
|
-
rb_define_singleton_method(mEd25519_Engine, "verify", Ed25519_Engine_verify, 3);
|
19
|
-
}
|
20
|
-
|
21
|
-
static VALUE Ed25519_Engine_create_keypair(VALUE self, VALUE seed)
|
22
|
-
{
|
23
|
-
unsigned char verify_key[PUBLICKEYBYTES], signing_key[SECRETKEYBYTES];
|
24
|
-
|
25
|
-
seed = rb_convert_type(seed, T_STRING, "String", "to_str");
|
26
|
-
|
27
|
-
if(RSTRING_LEN(seed) != SECRETKEYBYTES / 2)
|
28
|
-
rb_raise(rb_eArgError, "seed must be exactly %d bytes", SECRETKEYBYTES / 2);
|
29
|
-
|
30
|
-
crypto_sign_publickey(verify_key, signing_key, RSTRING_PTR(seed));
|
31
|
-
|
32
|
-
return rb_ary_new3(2,
|
33
|
-
rb_str_new(verify_key, PUBLICKEYBYTES),
|
34
|
-
rb_str_new(signing_key, SECRETKEYBYTES)
|
35
|
-
);
|
36
|
-
}
|
37
|
-
|
38
|
-
static VALUE Ed25519_Engine_sign(VALUE self, VALUE signing_key, VALUE msg)
|
39
|
-
{
|
40
|
-
unsigned char *sig_and_msg;
|
41
|
-
unsigned long long sig_and_msg_len;
|
42
|
-
VALUE result;
|
43
|
-
|
44
|
-
if(RSTRING_LEN(signing_key) != SECRETKEYBYTES)
|
45
|
-
rb_raise(rb_eArgError, "private signing keys must be %d bytes", SECRETKEYBYTES);
|
46
|
-
|
47
|
-
sig_and_msg = (unsigned char *)xmalloc(SIGNATUREBYTES + RSTRING_LEN(msg));
|
48
|
-
crypto_sign(sig_and_msg, &sig_and_msg_len, RSTRING_PTR(msg), RSTRING_LEN(msg), RSTRING_PTR(signing_key));
|
49
|
-
result = rb_str_new(sig_and_msg, SIGNATUREBYTES);
|
50
|
-
free(sig_and_msg);
|
51
|
-
|
52
|
-
return result;
|
53
|
-
}
|
54
|
-
|
55
|
-
static VALUE Ed25519_Engine_verify(VALUE self, VALUE verify_key, VALUE signature, VALUE msg)
|
56
|
-
{
|
57
|
-
unsigned char *sig_and_msg, *buffer;
|
58
|
-
unsigned long long sig_and_msg_len, buffer_len;
|
59
|
-
int result;
|
60
|
-
|
61
|
-
if(RSTRING_LEN(verify_key) != PUBLICKEYBYTES)
|
62
|
-
rb_raise(rb_eArgError, "public verify keys must be %d bytes", PUBLICKEYBYTES);
|
63
|
-
|
64
|
-
if(RSTRING_LEN(signature) != SIGNATUREBYTES)
|
65
|
-
rb_raise(rb_eArgError, "signatures must be %d bytes", SIGNATUREBYTES);
|
66
|
-
|
67
|
-
sig_and_msg_len = SIGNATUREBYTES + RSTRING_LEN(msg);
|
68
|
-
sig_and_msg = (unsigned char *)xmalloc(sig_and_msg_len);
|
69
|
-
buffer = (unsigned char *)xmalloc(sig_and_msg_len);
|
70
|
-
memcpy(sig_and_msg, RSTRING_PTR(signature), SIGNATUREBYTES);
|
71
|
-
memcpy(sig_and_msg + SIGNATUREBYTES, RSTRING_PTR(msg), RSTRING_LEN(msg));
|
72
|
-
|
73
|
-
result = crypto_sign_open(
|
74
|
-
buffer, &buffer_len,
|
75
|
-
sig_and_msg, sig_and_msg_len,
|
76
|
-
RSTRING_PTR(verify_key));
|
77
|
-
|
78
|
-
free(sig_and_msg);
|
79
|
-
free(buffer);
|
80
|
-
|
81
|
-
return result == 0 ? Qtrue : Qfalse;
|
82
|
-
}
|
data/ext/ed25519/extconf.rb
DELETED
data/ext/ed25519/fe25519.c
DELETED
@@ -1,326 +0,0 @@
|
|
1
|
-
#define WINDOWSIZE 1 /* Should be 1,2, or 4 */
|
2
|
-
#define WINDOWMASK ((1<<WINDOWSIZE)-1)
|
3
|
-
|
4
|
-
#include "fe25519.h"
|
5
|
-
|
6
|
-
static crypto_uint32 equal(crypto_uint32 a,crypto_uint32 b) /* 16-bit inputs */
|
7
|
-
{
|
8
|
-
crypto_uint32 x = a ^ b; /* 0: yes; 1..65535: no */
|
9
|
-
x -= 1; /* 4294967295: yes; 0..65534: no */
|
10
|
-
x >>= 31; /* 1: yes; 0: no */
|
11
|
-
return x;
|
12
|
-
}
|
13
|
-
|
14
|
-
static crypto_uint32 ge(crypto_uint32 a,crypto_uint32 b) /* 16-bit inputs */
|
15
|
-
{
|
16
|
-
unsigned int x = a;
|
17
|
-
x -= (unsigned int) b; /* 0..65535: yes; 4294901761..4294967295: no */
|
18
|
-
x >>= 31; /* 0: yes; 1: no */
|
19
|
-
x ^= 1; /* 1: yes; 0: no */
|
20
|
-
return x;
|
21
|
-
}
|
22
|
-
|
23
|
-
static crypto_uint32 times19(crypto_uint32 a)
|
24
|
-
{
|
25
|
-
return (a << 4) + (a << 1) + a;
|
26
|
-
}
|
27
|
-
|
28
|
-
static crypto_uint32 times38(crypto_uint32 a)
|
29
|
-
{
|
30
|
-
return (a << 5) + (a << 2) + (a << 1);
|
31
|
-
}
|
32
|
-
|
33
|
-
static void reduce_add_sub(fe25519 *r)
|
34
|
-
{
|
35
|
-
crypto_uint32 t;
|
36
|
-
int i,rep;
|
37
|
-
|
38
|
-
for(rep=0;rep<4;rep++)
|
39
|
-
{
|
40
|
-
t = r->v[31] >> 7;
|
41
|
-
r->v[31] &= 127;
|
42
|
-
t = times19(t);
|
43
|
-
r->v[0] += t;
|
44
|
-
for(i=0;i<31;i++)
|
45
|
-
{
|
46
|
-
t = r->v[i] >> 8;
|
47
|
-
r->v[i+1] += t;
|
48
|
-
r->v[i] &= 255;
|
49
|
-
}
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
static void reduce_mul(fe25519 *r)
|
54
|
-
{
|
55
|
-
crypto_uint32 t;
|
56
|
-
int i,rep;
|
57
|
-
|
58
|
-
for(rep=0;rep<2;rep++)
|
59
|
-
{
|
60
|
-
t = r->v[31] >> 7;
|
61
|
-
r->v[31] &= 127;
|
62
|
-
t = times19(t);
|
63
|
-
r->v[0] += t;
|
64
|
-
for(i=0;i<31;i++)
|
65
|
-
{
|
66
|
-
t = r->v[i] >> 8;
|
67
|
-
r->v[i+1] += t;
|
68
|
-
r->v[i] &= 255;
|
69
|
-
}
|
70
|
-
}
|
71
|
-
}
|
72
|
-
|
73
|
-
/* reduction modulo 2^255-19 */
|
74
|
-
void fe25519_freeze(fe25519 *r)
|
75
|
-
{
|
76
|
-
int i;
|
77
|
-
crypto_uint32 m = equal(r->v[31],127);
|
78
|
-
for(i=30;i>0;i--)
|
79
|
-
m &= equal(r->v[i],255);
|
80
|
-
m &= ge(r->v[0],237);
|
81
|
-
|
82
|
-
m = -m;
|
83
|
-
|
84
|
-
r->v[31] -= m&127;
|
85
|
-
for(i=30;i>0;i--)
|
86
|
-
r->v[i] -= m&255;
|
87
|
-
r->v[0] -= m&237;
|
88
|
-
}
|
89
|
-
|
90
|
-
void fe25519_unpack(fe25519 *r, const unsigned char x[32])
|
91
|
-
{
|
92
|
-
int i;
|
93
|
-
for(i=0;i<32;i++) r->v[i] = x[i];
|
94
|
-
r->v[31] &= 127;
|
95
|
-
}
|
96
|
-
|
97
|
-
/* Assumes input x being reduced below 2^255 */
|
98
|
-
void fe25519_pack(unsigned char r[32], const fe25519 *x)
|
99
|
-
{
|
100
|
-
int i;
|
101
|
-
fe25519 y = *x;
|
102
|
-
fe25519_freeze(&y);
|
103
|
-
for(i=0;i<32;i++)
|
104
|
-
r[i] = y.v[i];
|
105
|
-
}
|
106
|
-
|
107
|
-
int fe25519_iszero(const fe25519 *x)
|
108
|
-
{
|
109
|
-
int i, r;
|
110
|
-
fe25519 t = *x;
|
111
|
-
fe25519_freeze(&t);
|
112
|
-
r = equal(t.v[0],0);
|
113
|
-
for(i=1;i<32;i++)
|
114
|
-
r &= equal(t.v[i],0);
|
115
|
-
return r;
|
116
|
-
}
|
117
|
-
|
118
|
-
int fe25519_iseq_vartime(const fe25519 *x, const fe25519 *y)
|
119
|
-
{
|
120
|
-
int i;
|
121
|
-
fe25519 t1 = *x;
|
122
|
-
fe25519 t2 = *y;
|
123
|
-
fe25519_freeze(&t1);
|
124
|
-
fe25519_freeze(&t2);
|
125
|
-
for(i=0;i<32;i++)
|
126
|
-
if(t1.v[i] != t2.v[i]) return 0;
|
127
|
-
return 1;
|
128
|
-
}
|
129
|
-
|
130
|
-
void fe25519_cmov(fe25519 *r, const fe25519 *x, unsigned char b)
|
131
|
-
{
|
132
|
-
int i;
|
133
|
-
crypto_uint32 mask = b;
|
134
|
-
mask = -mask;
|
135
|
-
for(i=0;i<32;i++) r->v[i] ^= mask & (x->v[i] ^ r->v[i]);
|
136
|
-
}
|
137
|
-
|
138
|
-
unsigned char fe25519_getparity(const fe25519 *x)
|
139
|
-
{
|
140
|
-
fe25519 t = *x;
|
141
|
-
fe25519_freeze(&t);
|
142
|
-
return t.v[0] & 1;
|
143
|
-
}
|
144
|
-
|
145
|
-
void fe25519_setone(fe25519 *r)
|
146
|
-
{
|
147
|
-
int i;
|
148
|
-
r->v[0] = 1;
|
149
|
-
for(i=1;i<32;i++) r->v[i]=0;
|
150
|
-
}
|
151
|
-
|
152
|
-
void fe25519_setzero(fe25519 *r)
|
153
|
-
{
|
154
|
-
int i;
|
155
|
-
for(i=0;i<32;i++) r->v[i]=0;
|
156
|
-
}
|
157
|
-
|
158
|
-
void fe25519_neg(fe25519 *r, const fe25519 *x)
|
159
|
-
{
|
160
|
-
fe25519 t;
|
161
|
-
int i;
|
162
|
-
for(i=0;i<32;i++) t.v[i]=x->v[i];
|
163
|
-
fe25519_setzero(r);
|
164
|
-
fe25519_sub(r, r, &t);
|
165
|
-
}
|
166
|
-
|
167
|
-
void fe25519_add(fe25519 *r, const fe25519 *x, const fe25519 *y)
|
168
|
-
{
|
169
|
-
int i;
|
170
|
-
for(i=0;i<32;i++) r->v[i] = x->v[i] + y->v[i];
|
171
|
-
reduce_add_sub(r);
|
172
|
-
}
|
173
|
-
|
174
|
-
void fe25519_sub(fe25519 *r, const fe25519 *x, const fe25519 *y)
|
175
|
-
{
|
176
|
-
int i;
|
177
|
-
crypto_uint32 t[32];
|
178
|
-
t[0] = x->v[0] + 0x1da;
|
179
|
-
t[31] = x->v[31] + 0xfe;
|
180
|
-
for(i=1;i<31;i++) t[i] = x->v[i] + 0x1fe;
|
181
|
-
for(i=0;i<32;i++) r->v[i] = t[i] - y->v[i];
|
182
|
-
reduce_add_sub(r);
|
183
|
-
}
|
184
|
-
|
185
|
-
void fe25519_mul(fe25519 *r, const fe25519 *x, const fe25519 *y)
|
186
|
-
{
|
187
|
-
int i,j;
|
188
|
-
crypto_uint32 t[63];
|
189
|
-
for(i=0;i<63;i++)t[i] = 0;
|
190
|
-
|
191
|
-
for(i=0;i<32;i++)
|
192
|
-
for(j=0;j<32;j++)
|
193
|
-
t[i+j] += x->v[i] * y->v[j];
|
194
|
-
|
195
|
-
for(i=32;i<63;i++)
|
196
|
-
r->v[i-32] = t[i-32] + times38(t[i]);
|
197
|
-
r->v[31] = t[31]; /* result now in r[0]...r[31] */
|
198
|
-
|
199
|
-
reduce_mul(r);
|
200
|
-
}
|
201
|
-
|
202
|
-
void fe25519_square(fe25519 *r, const fe25519 *x)
|
203
|
-
{
|
204
|
-
fe25519_mul(r, x, x);
|
205
|
-
}
|
206
|
-
|
207
|
-
void fe25519_invert(fe25519 *r, const fe25519 *x)
|
208
|
-
{
|
209
|
-
fe25519 z2;
|
210
|
-
fe25519 z9;
|
211
|
-
fe25519 z11;
|
212
|
-
fe25519 z2_5_0;
|
213
|
-
fe25519 z2_10_0;
|
214
|
-
fe25519 z2_20_0;
|
215
|
-
fe25519 z2_50_0;
|
216
|
-
fe25519 z2_100_0;
|
217
|
-
fe25519 t0;
|
218
|
-
fe25519 t1;
|
219
|
-
int i;
|
220
|
-
|
221
|
-
/* 2 */ fe25519_square(&z2,x);
|
222
|
-
/* 4 */ fe25519_square(&t1,&z2);
|
223
|
-
/* 8 */ fe25519_square(&t0,&t1);
|
224
|
-
/* 9 */ fe25519_mul(&z9,&t0,x);
|
225
|
-
/* 11 */ fe25519_mul(&z11,&z9,&z2);
|
226
|
-
/* 22 */ fe25519_square(&t0,&z11);
|
227
|
-
/* 2^5 - 2^0 = 31 */ fe25519_mul(&z2_5_0,&t0,&z9);
|
228
|
-
|
229
|
-
/* 2^6 - 2^1 */ fe25519_square(&t0,&z2_5_0);
|
230
|
-
/* 2^7 - 2^2 */ fe25519_square(&t1,&t0);
|
231
|
-
/* 2^8 - 2^3 */ fe25519_square(&t0,&t1);
|
232
|
-
/* 2^9 - 2^4 */ fe25519_square(&t1,&t0);
|
233
|
-
/* 2^10 - 2^5 */ fe25519_square(&t0,&t1);
|
234
|
-
/* 2^10 - 2^0 */ fe25519_mul(&z2_10_0,&t0,&z2_5_0);
|
235
|
-
|
236
|
-
/* 2^11 - 2^1 */ fe25519_square(&t0,&z2_10_0);
|
237
|
-
/* 2^12 - 2^2 */ fe25519_square(&t1,&t0);
|
238
|
-
/* 2^20 - 2^10 */ for (i = 2;i < 10;i += 2) { fe25519_square(&t0,&t1); fe25519_square(&t1,&t0); }
|
239
|
-
/* 2^20 - 2^0 */ fe25519_mul(&z2_20_0,&t1,&z2_10_0);
|
240
|
-
|
241
|
-
/* 2^21 - 2^1 */ fe25519_square(&t0,&z2_20_0);
|
242
|
-
/* 2^22 - 2^2 */ fe25519_square(&t1,&t0);
|
243
|
-
/* 2^40 - 2^20 */ for (i = 2;i < 20;i += 2) { fe25519_square(&t0,&t1); fe25519_square(&t1,&t0); }
|
244
|
-
/* 2^40 - 2^0 */ fe25519_mul(&t0,&t1,&z2_20_0);
|
245
|
-
|
246
|
-
/* 2^41 - 2^1 */ fe25519_square(&t1,&t0);
|
247
|
-
/* 2^42 - 2^2 */ fe25519_square(&t0,&t1);
|
248
|
-
/* 2^50 - 2^10 */ for (i = 2;i < 10;i += 2) { fe25519_square(&t1,&t0); fe25519_square(&t0,&t1); }
|
249
|
-
/* 2^50 - 2^0 */ fe25519_mul(&z2_50_0,&t0,&z2_10_0);
|
250
|
-
|
251
|
-
/* 2^51 - 2^1 */ fe25519_square(&t0,&z2_50_0);
|
252
|
-
/* 2^52 - 2^2 */ fe25519_square(&t1,&t0);
|
253
|
-
/* 2^100 - 2^50 */ for (i = 2;i < 50;i += 2) { fe25519_square(&t0,&t1); fe25519_square(&t1,&t0); }
|
254
|
-
/* 2^100 - 2^0 */ fe25519_mul(&z2_100_0,&t1,&z2_50_0);
|
255
|
-
|
256
|
-
/* 2^101 - 2^1 */ fe25519_square(&t1,&z2_100_0);
|
257
|
-
/* 2^102 - 2^2 */ fe25519_square(&t0,&t1);
|
258
|
-
/* 2^200 - 2^100 */ for (i = 2;i < 100;i += 2) { fe25519_square(&t1,&t0); fe25519_square(&t0,&t1); }
|
259
|
-
/* 2^200 - 2^0 */ fe25519_mul(&t1,&t0,&z2_100_0);
|
260
|
-
|
261
|
-
/* 2^201 - 2^1 */ fe25519_square(&t0,&t1);
|
262
|
-
/* 2^202 - 2^2 */ fe25519_square(&t1,&t0);
|
263
|
-
/* 2^250 - 2^50 */ for (i = 2;i < 50;i += 2) { fe25519_square(&t0,&t1); fe25519_square(&t1,&t0); }
|
264
|
-
/* 2^250 - 2^0 */ fe25519_mul(&t0,&t1,&z2_50_0);
|
265
|
-
|
266
|
-
/* 2^251 - 2^1 */ fe25519_square(&t1,&t0);
|
267
|
-
/* 2^252 - 2^2 */ fe25519_square(&t0,&t1);
|
268
|
-
/* 2^253 - 2^3 */ fe25519_square(&t1,&t0);
|
269
|
-
/* 2^254 - 2^4 */ fe25519_square(&t0,&t1);
|
270
|
-
/* 2^255 - 2^5 */ fe25519_square(&t1,&t0);
|
271
|
-
/* 2^255 - 21 */ fe25519_mul(r,&t1,&z11);
|
272
|
-
}
|
273
|
-
|
274
|
-
void fe25519_pow2523(fe25519 *r, const fe25519 *x)
|
275
|
-
{
|
276
|
-
fe25519 z2;
|
277
|
-
fe25519 z9;
|
278
|
-
fe25519 z11;
|
279
|
-
fe25519 z2_5_0;
|
280
|
-
fe25519 z2_10_0;
|
281
|
-
fe25519 z2_20_0;
|
282
|
-
fe25519 z2_50_0;
|
283
|
-
fe25519 z2_100_0;
|
284
|
-
fe25519 t;
|
285
|
-
int i;
|
286
|
-
|
287
|
-
/* 2 */ fe25519_square(&z2,x);
|
288
|
-
/* 4 */ fe25519_square(&t,&z2);
|
289
|
-
/* 8 */ fe25519_square(&t,&t);
|
290
|
-
/* 9 */ fe25519_mul(&z9,&t,x);
|
291
|
-
/* 11 */ fe25519_mul(&z11,&z9,&z2);
|
292
|
-
/* 22 */ fe25519_square(&t,&z11);
|
293
|
-
/* 2^5 - 2^0 = 31 */ fe25519_mul(&z2_5_0,&t,&z9);
|
294
|
-
|
295
|
-
/* 2^6 - 2^1 */ fe25519_square(&t,&z2_5_0);
|
296
|
-
/* 2^10 - 2^5 */ for (i = 1;i < 5;i++) { fe25519_square(&t,&t); }
|
297
|
-
/* 2^10 - 2^0 */ fe25519_mul(&z2_10_0,&t,&z2_5_0);
|
298
|
-
|
299
|
-
/* 2^11 - 2^1 */ fe25519_square(&t,&z2_10_0);
|
300
|
-
/* 2^20 - 2^10 */ for (i = 1;i < 10;i++) { fe25519_square(&t,&t); }
|
301
|
-
/* 2^20 - 2^0 */ fe25519_mul(&z2_20_0,&t,&z2_10_0);
|
302
|
-
|
303
|
-
/* 2^21 - 2^1 */ fe25519_square(&t,&z2_20_0);
|
304
|
-
/* 2^40 - 2^20 */ for (i = 1;i < 20;i++) { fe25519_square(&t,&t); }
|
305
|
-
/* 2^40 - 2^0 */ fe25519_mul(&t,&t,&z2_20_0);
|
306
|
-
|
307
|
-
/* 2^41 - 2^1 */ fe25519_square(&t,&t);
|
308
|
-
/* 2^50 - 2^10 */ for (i = 1;i < 10;i++) { fe25519_square(&t,&t); }
|
309
|
-
/* 2^50 - 2^0 */ fe25519_mul(&z2_50_0,&t,&z2_10_0);
|
310
|
-
|
311
|
-
/* 2^51 - 2^1 */ fe25519_square(&t,&z2_50_0);
|
312
|
-
/* 2^100 - 2^50 */ for (i = 1;i < 50;i++) { fe25519_square(&t,&t); }
|
313
|
-
/* 2^100 - 2^0 */ fe25519_mul(&z2_100_0,&t,&z2_50_0);
|
314
|
-
|
315
|
-
/* 2^101 - 2^1 */ fe25519_square(&t,&z2_100_0);
|
316
|
-
/* 2^200 - 2^100 */ for (i = 1;i < 100;i++) { fe25519_square(&t,&t); }
|
317
|
-
/* 2^200 - 2^0 */ fe25519_mul(&t,&t,&z2_100_0);
|
318
|
-
|
319
|
-
/* 2^201 - 2^1 */ fe25519_square(&t,&t);
|
320
|
-
/* 2^250 - 2^50 */ for (i = 1;i < 50;i++) { fe25519_square(&t,&t); }
|
321
|
-
/* 2^250 - 2^0 */ fe25519_mul(&t,&t,&z2_50_0);
|
322
|
-
|
323
|
-
/* 2^251 - 2^1 */ fe25519_square(&t,&t);
|
324
|
-
/* 2^252 - 2^2 */ fe25519_square(&t,&t);
|
325
|
-
/* 2^252 - 3 */ fe25519_mul(r,&t,x);
|
326
|
-
}
|
data/ext/ed25519/fe25519.h
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
#ifndef FE25519_H
|
2
|
-
#define FE25519_H
|
3
|
-
|
4
|
-
#include "crypto_int32.h"
|
5
|
-
#include "crypto_uint32.h"
|
6
|
-
|
7
|
-
#define fe25519 crypto_sign_ed25519_ref_fe25519
|
8
|
-
#define fe25519_freeze crypto_sign_ed25519_ref_fe25519_freeze
|
9
|
-
#define fe25519_unpack crypto_sign_ed25519_ref_fe25519_unpack
|
10
|
-
#define fe25519_pack crypto_sign_ed25519_ref_fe25519_pack
|
11
|
-
#define fe25519_iszero crypto_sign_ed25519_ref_fe25519_iszero
|
12
|
-
#define fe25519_iseq_vartime crypto_sign_ed25519_ref_fe25519_iseq_vartime
|
13
|
-
#define fe25519_cmov crypto_sign_ed25519_ref_fe25519_cmov
|
14
|
-
#define fe25519_setone crypto_sign_ed25519_ref_fe25519_setone
|
15
|
-
#define fe25519_setzero crypto_sign_ed25519_ref_fe25519_setzero
|
16
|
-
#define fe25519_neg crypto_sign_ed25519_ref_fe25519_neg
|
17
|
-
#define fe25519_getparity crypto_sign_ed25519_ref_fe25519_getparity
|
18
|
-
#define fe25519_add crypto_sign_ed25519_ref_fe25519_add
|
19
|
-
#define fe25519_sub crypto_sign_ed25519_ref_fe25519_sub
|
20
|
-
#define fe25519_mul crypto_sign_ed25519_ref_fe25519_mul
|
21
|
-
#define fe25519_square crypto_sign_ed25519_ref_fe25519_square
|
22
|
-
#define fe25519_invert crypto_sign_ed25519_ref_fe25519_invert
|
23
|
-
#define fe25519_pow2523 crypto_sign_ed25519_ref_fe25519_pow2523
|
24
|
-
|
25
|
-
typedef struct
|
26
|
-
{
|
27
|
-
crypto_uint32 v[32];
|
28
|
-
}
|
29
|
-
fe25519;
|
30
|
-
|
31
|
-
void fe25519_freeze(fe25519 *r);
|
32
|
-
|
33
|
-
void fe25519_unpack(fe25519 *r, const unsigned char x[32]);
|
34
|
-
|
35
|
-
void fe25519_pack(unsigned char r[32], const fe25519 *x);
|
36
|
-
|
37
|
-
int fe25519_iszero(const fe25519 *x);
|
38
|
-
|
39
|
-
int fe25519_iseq_vartime(const fe25519 *x, const fe25519 *y);
|
40
|
-
|
41
|
-
void fe25519_cmov(fe25519 *r, const fe25519 *x, unsigned char b);
|
42
|
-
|
43
|
-
void fe25519_setone(fe25519 *r);
|
44
|
-
|
45
|
-
void fe25519_setzero(fe25519 *r);
|
46
|
-
|
47
|
-
void fe25519_neg(fe25519 *r, const fe25519 *x);
|
48
|
-
|
49
|
-
unsigned char fe25519_getparity(const fe25519 *x);
|
50
|
-
|
51
|
-
void fe25519_add(fe25519 *r, const fe25519 *x, const fe25519 *y);
|
52
|
-
|
53
|
-
void fe25519_sub(fe25519 *r, const fe25519 *x, const fe25519 *y);
|
54
|
-
|
55
|
-
void fe25519_mul(fe25519 *r, const fe25519 *x, const fe25519 *y);
|
56
|
-
|
57
|
-
void fe25519_square(fe25519 *r, const fe25519 *x);
|
58
|
-
|
59
|
-
void fe25519_invert(fe25519 *r, const fe25519 *x);
|
60
|
-
|
61
|
-
void fe25519_pow2523(fe25519 *r, const fe25519 *x);
|
62
|
-
|
63
|
-
#endif
|