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
@@ -0,0 +1,16 @@
|
|
1
|
+
#include "fe.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
return 1 if f is in {1,3,5,...,q-2}
|
5
|
+
return 0 if f is in {0,2,4,...,q-1}
|
6
|
+
|
7
|
+
Preconditions:
|
8
|
+
|f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
|
9
|
+
*/
|
10
|
+
|
11
|
+
int fe_isnegative(const fe f)
|
12
|
+
{
|
13
|
+
unsigned char s[32];
|
14
|
+
fe_tobytes(s,f);
|
15
|
+
return s[0] & 1;
|
16
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#include "fe.h"
|
2
|
+
#include "ed25519_ref10.h"
|
3
|
+
|
4
|
+
/*
|
5
|
+
return 1 if f == 0
|
6
|
+
return 0 if f != 0
|
7
|
+
|
8
|
+
Preconditions:
|
9
|
+
|f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
|
10
|
+
*/
|
11
|
+
|
12
|
+
static const unsigned char zero[32];
|
13
|
+
|
14
|
+
int fe_isnonzero(const fe f)
|
15
|
+
{
|
16
|
+
unsigned char s[32];
|
17
|
+
fe_tobytes(s,f);
|
18
|
+
return crypto_verify_32(s,zero);
|
19
|
+
}
|
@@ -0,0 +1,252 @@
|
|
1
|
+
#include "fe.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
h = f * g
|
5
|
+
Can overlap h with f or g.
|
6
|
+
|
7
|
+
Preconditions:
|
8
|
+
|f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
|
9
|
+
|g| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
|
10
|
+
|
11
|
+
Postconditions:
|
12
|
+
|h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc.
|
13
|
+
*/
|
14
|
+
|
15
|
+
/*
|
16
|
+
Notes on implementation strategy:
|
17
|
+
|
18
|
+
Using schoolbook multiplication.
|
19
|
+
Karatsuba would save a little in some cost models.
|
20
|
+
|
21
|
+
Most multiplications by 2 and 19 are 32-bit precomputations;
|
22
|
+
cheaper than 64-bit postcomputations.
|
23
|
+
|
24
|
+
There is one remaining multiplication by 19 in the carry chain;
|
25
|
+
one *19 precomputation can be merged into this,
|
26
|
+
but the resulting data flow is considerably less clean.
|
27
|
+
|
28
|
+
There are 12 carries below.
|
29
|
+
10 of them are 2-way parallelizable and vectorizable.
|
30
|
+
Can get away with 11 carries, but then data flow is much deeper.
|
31
|
+
|
32
|
+
With tighter constraints on inputs can squeeze carries into int32.
|
33
|
+
*/
|
34
|
+
|
35
|
+
void fe_mul(fe h,const fe f,const fe g)
|
36
|
+
{
|
37
|
+
int32_t f0 = f[0];
|
38
|
+
int32_t f1 = f[1];
|
39
|
+
int32_t f2 = f[2];
|
40
|
+
int32_t f3 = f[3];
|
41
|
+
int32_t f4 = f[4];
|
42
|
+
int32_t f5 = f[5];
|
43
|
+
int32_t f6 = f[6];
|
44
|
+
int32_t f7 = f[7];
|
45
|
+
int32_t f8 = f[8];
|
46
|
+
int32_t f9 = f[9];
|
47
|
+
int32_t g0 = g[0];
|
48
|
+
int32_t g1 = g[1];
|
49
|
+
int32_t g2 = g[2];
|
50
|
+
int32_t g3 = g[3];
|
51
|
+
int32_t g4 = g[4];
|
52
|
+
int32_t g5 = g[5];
|
53
|
+
int32_t g6 = g[6];
|
54
|
+
int32_t g7 = g[7];
|
55
|
+
int32_t g8 = g[8];
|
56
|
+
int32_t g9 = g[9];
|
57
|
+
int32_t g1_19 = 19 * g1; /* 1.959375*2^29 */
|
58
|
+
int32_t g2_19 = 19 * g2; /* 1.959375*2^30; still ok */
|
59
|
+
int32_t g3_19 = 19 * g3;
|
60
|
+
int32_t g4_19 = 19 * g4;
|
61
|
+
int32_t g5_19 = 19 * g5;
|
62
|
+
int32_t g6_19 = 19 * g6;
|
63
|
+
int32_t g7_19 = 19 * g7;
|
64
|
+
int32_t g8_19 = 19 * g8;
|
65
|
+
int32_t g9_19 = 19 * g9;
|
66
|
+
int32_t f1_2 = 2 * f1;
|
67
|
+
int32_t f3_2 = 2 * f3;
|
68
|
+
int32_t f5_2 = 2 * f5;
|
69
|
+
int32_t f7_2 = 2 * f7;
|
70
|
+
int32_t f9_2 = 2 * f9;
|
71
|
+
int64_t f0g0 = f0 * (int64_t) g0;
|
72
|
+
int64_t f0g1 = f0 * (int64_t) g1;
|
73
|
+
int64_t f0g2 = f0 * (int64_t) g2;
|
74
|
+
int64_t f0g3 = f0 * (int64_t) g3;
|
75
|
+
int64_t f0g4 = f0 * (int64_t) g4;
|
76
|
+
int64_t f0g5 = f0 * (int64_t) g5;
|
77
|
+
int64_t f0g6 = f0 * (int64_t) g6;
|
78
|
+
int64_t f0g7 = f0 * (int64_t) g7;
|
79
|
+
int64_t f0g8 = f0 * (int64_t) g8;
|
80
|
+
int64_t f0g9 = f0 * (int64_t) g9;
|
81
|
+
int64_t f1g0 = f1 * (int64_t) g0;
|
82
|
+
int64_t f1g1_2 = f1_2 * (int64_t) g1;
|
83
|
+
int64_t f1g2 = f1 * (int64_t) g2;
|
84
|
+
int64_t f1g3_2 = f1_2 * (int64_t) g3;
|
85
|
+
int64_t f1g4 = f1 * (int64_t) g4;
|
86
|
+
int64_t f1g5_2 = f1_2 * (int64_t) g5;
|
87
|
+
int64_t f1g6 = f1 * (int64_t) g6;
|
88
|
+
int64_t f1g7_2 = f1_2 * (int64_t) g7;
|
89
|
+
int64_t f1g8 = f1 * (int64_t) g8;
|
90
|
+
int64_t f1g9_38 = f1_2 * (int64_t) g9_19;
|
91
|
+
int64_t f2g0 = f2 * (int64_t) g0;
|
92
|
+
int64_t f2g1 = f2 * (int64_t) g1;
|
93
|
+
int64_t f2g2 = f2 * (int64_t) g2;
|
94
|
+
int64_t f2g3 = f2 * (int64_t) g3;
|
95
|
+
int64_t f2g4 = f2 * (int64_t) g4;
|
96
|
+
int64_t f2g5 = f2 * (int64_t) g5;
|
97
|
+
int64_t f2g6 = f2 * (int64_t) g6;
|
98
|
+
int64_t f2g7 = f2 * (int64_t) g7;
|
99
|
+
int64_t f2g8_19 = f2 * (int64_t) g8_19;
|
100
|
+
int64_t f2g9_19 = f2 * (int64_t) g9_19;
|
101
|
+
int64_t f3g0 = f3 * (int64_t) g0;
|
102
|
+
int64_t f3g1_2 = f3_2 * (int64_t) g1;
|
103
|
+
int64_t f3g2 = f3 * (int64_t) g2;
|
104
|
+
int64_t f3g3_2 = f3_2 * (int64_t) g3;
|
105
|
+
int64_t f3g4 = f3 * (int64_t) g4;
|
106
|
+
int64_t f3g5_2 = f3_2 * (int64_t) g5;
|
107
|
+
int64_t f3g6 = f3 * (int64_t) g6;
|
108
|
+
int64_t f3g7_38 = f3_2 * (int64_t) g7_19;
|
109
|
+
int64_t f3g8_19 = f3 * (int64_t) g8_19;
|
110
|
+
int64_t f3g9_38 = f3_2 * (int64_t) g9_19;
|
111
|
+
int64_t f4g0 = f4 * (int64_t) g0;
|
112
|
+
int64_t f4g1 = f4 * (int64_t) g1;
|
113
|
+
int64_t f4g2 = f4 * (int64_t) g2;
|
114
|
+
int64_t f4g3 = f4 * (int64_t) g3;
|
115
|
+
int64_t f4g4 = f4 * (int64_t) g4;
|
116
|
+
int64_t f4g5 = f4 * (int64_t) g5;
|
117
|
+
int64_t f4g6_19 = f4 * (int64_t) g6_19;
|
118
|
+
int64_t f4g7_19 = f4 * (int64_t) g7_19;
|
119
|
+
int64_t f4g8_19 = f4 * (int64_t) g8_19;
|
120
|
+
int64_t f4g9_19 = f4 * (int64_t) g9_19;
|
121
|
+
int64_t f5g0 = f5 * (int64_t) g0;
|
122
|
+
int64_t f5g1_2 = f5_2 * (int64_t) g1;
|
123
|
+
int64_t f5g2 = f5 * (int64_t) g2;
|
124
|
+
int64_t f5g3_2 = f5_2 * (int64_t) g3;
|
125
|
+
int64_t f5g4 = f5 * (int64_t) g4;
|
126
|
+
int64_t f5g5_38 = f5_2 * (int64_t) g5_19;
|
127
|
+
int64_t f5g6_19 = f5 * (int64_t) g6_19;
|
128
|
+
int64_t f5g7_38 = f5_2 * (int64_t) g7_19;
|
129
|
+
int64_t f5g8_19 = f5 * (int64_t) g8_19;
|
130
|
+
int64_t f5g9_38 = f5_2 * (int64_t) g9_19;
|
131
|
+
int64_t f6g0 = f6 * (int64_t) g0;
|
132
|
+
int64_t f6g1 = f6 * (int64_t) g1;
|
133
|
+
int64_t f6g2 = f6 * (int64_t) g2;
|
134
|
+
int64_t f6g3 = f6 * (int64_t) g3;
|
135
|
+
int64_t f6g4_19 = f6 * (int64_t) g4_19;
|
136
|
+
int64_t f6g5_19 = f6 * (int64_t) g5_19;
|
137
|
+
int64_t f6g6_19 = f6 * (int64_t) g6_19;
|
138
|
+
int64_t f6g7_19 = f6 * (int64_t) g7_19;
|
139
|
+
int64_t f6g8_19 = f6 * (int64_t) g8_19;
|
140
|
+
int64_t f6g9_19 = f6 * (int64_t) g9_19;
|
141
|
+
int64_t f7g0 = f7 * (int64_t) g0;
|
142
|
+
int64_t f7g1_2 = f7_2 * (int64_t) g1;
|
143
|
+
int64_t f7g2 = f7 * (int64_t) g2;
|
144
|
+
int64_t f7g3_38 = f7_2 * (int64_t) g3_19;
|
145
|
+
int64_t f7g4_19 = f7 * (int64_t) g4_19;
|
146
|
+
int64_t f7g5_38 = f7_2 * (int64_t) g5_19;
|
147
|
+
int64_t f7g6_19 = f7 * (int64_t) g6_19;
|
148
|
+
int64_t f7g7_38 = f7_2 * (int64_t) g7_19;
|
149
|
+
int64_t f7g8_19 = f7 * (int64_t) g8_19;
|
150
|
+
int64_t f7g9_38 = f7_2 * (int64_t) g9_19;
|
151
|
+
int64_t f8g0 = f8 * (int64_t) g0;
|
152
|
+
int64_t f8g1 = f8 * (int64_t) g1;
|
153
|
+
int64_t f8g2_19 = f8 * (int64_t) g2_19;
|
154
|
+
int64_t f8g3_19 = f8 * (int64_t) g3_19;
|
155
|
+
int64_t f8g4_19 = f8 * (int64_t) g4_19;
|
156
|
+
int64_t f8g5_19 = f8 * (int64_t) g5_19;
|
157
|
+
int64_t f8g6_19 = f8 * (int64_t) g6_19;
|
158
|
+
int64_t f8g7_19 = f8 * (int64_t) g7_19;
|
159
|
+
int64_t f8g8_19 = f8 * (int64_t) g8_19;
|
160
|
+
int64_t f8g9_19 = f8 * (int64_t) g9_19;
|
161
|
+
int64_t f9g0 = f9 * (int64_t) g0;
|
162
|
+
int64_t f9g1_38 = f9_2 * (int64_t) g1_19;
|
163
|
+
int64_t f9g2_19 = f9 * (int64_t) g2_19;
|
164
|
+
int64_t f9g3_38 = f9_2 * (int64_t) g3_19;
|
165
|
+
int64_t f9g4_19 = f9 * (int64_t) g4_19;
|
166
|
+
int64_t f9g5_38 = f9_2 * (int64_t) g5_19;
|
167
|
+
int64_t f9g6_19 = f9 * (int64_t) g6_19;
|
168
|
+
int64_t f9g7_38 = f9_2 * (int64_t) g7_19;
|
169
|
+
int64_t f9g8_19 = f9 * (int64_t) g8_19;
|
170
|
+
int64_t f9g9_38 = f9_2 * (int64_t) g9_19;
|
171
|
+
int64_t h0 = f0g0+f1g9_38+f2g8_19+f3g7_38+f4g6_19+f5g5_38+f6g4_19+f7g3_38+f8g2_19+f9g1_38;
|
172
|
+
int64_t h1 = f0g1+f1g0 +f2g9_19+f3g8_19+f4g7_19+f5g6_19+f6g5_19+f7g4_19+f8g3_19+f9g2_19;
|
173
|
+
int64_t h2 = f0g2+f1g1_2 +f2g0 +f3g9_38+f4g8_19+f5g7_38+f6g6_19+f7g5_38+f8g4_19+f9g3_38;
|
174
|
+
int64_t h3 = f0g3+f1g2 +f2g1 +f3g0 +f4g9_19+f5g8_19+f6g7_19+f7g6_19+f8g5_19+f9g4_19;
|
175
|
+
int64_t h4 = f0g4+f1g3_2 +f2g2 +f3g1_2 +f4g0 +f5g9_38+f6g8_19+f7g7_38+f8g6_19+f9g5_38;
|
176
|
+
int64_t h5 = f0g5+f1g4 +f2g3 +f3g2 +f4g1 +f5g0 +f6g9_19+f7g8_19+f8g7_19+f9g6_19;
|
177
|
+
int64_t h6 = f0g6+f1g5_2 +f2g4 +f3g3_2 +f4g2 +f5g1_2 +f6g0 +f7g9_38+f8g8_19+f9g7_38;
|
178
|
+
int64_t h7 = f0g7+f1g6 +f2g5 +f3g4 +f4g3 +f5g2 +f6g1 +f7g0 +f8g9_19+f9g8_19;
|
179
|
+
int64_t h8 = f0g8+f1g7_2 +f2g6 +f3g5_2 +f4g4 +f5g3_2 +f6g2 +f7g1_2 +f8g0 +f9g9_38;
|
180
|
+
int64_t h9 = f0g9+f1g8 +f2g7 +f3g6 +f4g5 +f5g4 +f6g3 +f7g2 +f8g1 +f9g0 ;
|
181
|
+
int64_t carry0;
|
182
|
+
int64_t carry1;
|
183
|
+
int64_t carry2;
|
184
|
+
int64_t carry3;
|
185
|
+
int64_t carry4;
|
186
|
+
int64_t carry5;
|
187
|
+
int64_t carry6;
|
188
|
+
int64_t carry7;
|
189
|
+
int64_t carry8;
|
190
|
+
int64_t carry9;
|
191
|
+
|
192
|
+
/*
|
193
|
+
|h0| <= (1.65*1.65*2^52*(1+19+19+19+19)+1.65*1.65*2^50*(38+38+38+38+38))
|
194
|
+
i.e. |h0| <= 1.4*2^60; narrower ranges for h2, h4, h6, h8
|
195
|
+
|h1| <= (1.65*1.65*2^51*(1+1+19+19+19+19+19+19+19+19))
|
196
|
+
i.e. |h1| <= 1.7*2^59; narrower ranges for h3, h5, h7, h9
|
197
|
+
*/
|
198
|
+
|
199
|
+
carry0 = (h0 + (int64_t) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
|
200
|
+
carry4 = (h4 + (int64_t) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
|
201
|
+
/* |h0| <= 2^25 */
|
202
|
+
/* |h4| <= 2^25 */
|
203
|
+
/* |h1| <= 1.71*2^59 */
|
204
|
+
/* |h5| <= 1.71*2^59 */
|
205
|
+
|
206
|
+
carry1 = (h1 + (int64_t) (1<<24)) >> 25; h2 += carry1; h1 -= carry1 << 25;
|
207
|
+
carry5 = (h5 + (int64_t) (1<<24)) >> 25; h6 += carry5; h5 -= carry5 << 25;
|
208
|
+
/* |h1| <= 2^24; from now on fits into int32 */
|
209
|
+
/* |h5| <= 2^24; from now on fits into int32 */
|
210
|
+
/* |h2| <= 1.41*2^60 */
|
211
|
+
/* |h6| <= 1.41*2^60 */
|
212
|
+
|
213
|
+
carry2 = (h2 + (int64_t) (1<<25)) >> 26; h3 += carry2; h2 -= carry2 << 26;
|
214
|
+
carry6 = (h6 + (int64_t) (1<<25)) >> 26; h7 += carry6; h6 -= carry6 << 26;
|
215
|
+
/* |h2| <= 2^25; from now on fits into int32 unchanged */
|
216
|
+
/* |h6| <= 2^25; from now on fits into int32 unchanged */
|
217
|
+
/* |h3| <= 1.71*2^59 */
|
218
|
+
/* |h7| <= 1.71*2^59 */
|
219
|
+
|
220
|
+
carry3 = (h3 + (int64_t) (1<<24)) >> 25; h4 += carry3; h3 -= carry3 << 25;
|
221
|
+
carry7 = (h7 + (int64_t) (1<<24)) >> 25; h8 += carry7; h7 -= carry7 << 25;
|
222
|
+
/* |h3| <= 2^24; from now on fits into int32 unchanged */
|
223
|
+
/* |h7| <= 2^24; from now on fits into int32 unchanged */
|
224
|
+
/* |h4| <= 1.72*2^34 */
|
225
|
+
/* |h8| <= 1.41*2^60 */
|
226
|
+
|
227
|
+
carry4 = (h4 + (int64_t) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
|
228
|
+
carry8 = (h8 + (int64_t) (1<<25)) >> 26; h9 += carry8; h8 -= carry8 << 26;
|
229
|
+
/* |h4| <= 2^25; from now on fits into int32 unchanged */
|
230
|
+
/* |h8| <= 2^25; from now on fits into int32 unchanged */
|
231
|
+
/* |h5| <= 1.01*2^24 */
|
232
|
+
/* |h9| <= 1.71*2^59 */
|
233
|
+
|
234
|
+
carry9 = (h9 + (int64_t) (1<<24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25;
|
235
|
+
/* |h9| <= 2^24; from now on fits into int32 unchanged */
|
236
|
+
/* |h0| <= 1.1*2^39 */
|
237
|
+
|
238
|
+
carry0 = (h0 + (int64_t) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
|
239
|
+
/* |h0| <= 2^25; from now on fits into int32 unchanged */
|
240
|
+
/* |h1| <= 1.01*2^24 */
|
241
|
+
|
242
|
+
h[0] = (int32_t)h0;
|
243
|
+
h[1] = (int32_t)h1;
|
244
|
+
h[2] = (int32_t)h2;
|
245
|
+
h[3] = (int32_t)h3;
|
246
|
+
h[4] = (int32_t)h4;
|
247
|
+
h[5] = (int32_t)h5;
|
248
|
+
h[6] = (int32_t)h6;
|
249
|
+
h[7] = (int32_t)h7;
|
250
|
+
h[8] = (int32_t)h8;
|
251
|
+
h[9] = (int32_t)h9;
|
252
|
+
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#include "fe.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
h = -f
|
5
|
+
|
6
|
+
Preconditions:
|
7
|
+
|f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
|
8
|
+
|
9
|
+
Postconditions:
|
10
|
+
|h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
|
11
|
+
*/
|
12
|
+
|
13
|
+
void fe_neg(fe h,const fe f)
|
14
|
+
{
|
15
|
+
int32_t f0 = f[0];
|
16
|
+
int32_t f1 = f[1];
|
17
|
+
int32_t f2 = f[2];
|
18
|
+
int32_t f3 = f[3];
|
19
|
+
int32_t f4 = f[4];
|
20
|
+
int32_t f5 = f[5];
|
21
|
+
int32_t f6 = f[6];
|
22
|
+
int32_t f7 = f[7];
|
23
|
+
int32_t f8 = f[8];
|
24
|
+
int32_t f9 = f[9];
|
25
|
+
int32_t h0 = -f0;
|
26
|
+
int32_t h1 = -f1;
|
27
|
+
int32_t h2 = -f2;
|
28
|
+
int32_t h3 = -f3;
|
29
|
+
int32_t h4 = -f4;
|
30
|
+
int32_t h5 = -f5;
|
31
|
+
int32_t h6 = -f6;
|
32
|
+
int32_t h7 = -f7;
|
33
|
+
int32_t h8 = -f8;
|
34
|
+
int32_t h9 = -f9;
|
35
|
+
h[0] = h0;
|
36
|
+
h[1] = h1;
|
37
|
+
h[2] = h2;
|
38
|
+
h[3] = h3;
|
39
|
+
h[4] = h4;
|
40
|
+
h[5] = h5;
|
41
|
+
h[6] = h6;
|
42
|
+
h[7] = h7;
|
43
|
+
h[8] = h8;
|
44
|
+
h[9] = h9;
|
45
|
+
}
|
@@ -0,0 +1,148 @@
|
|
1
|
+
#include "fe.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
h = f * f
|
5
|
+
Can overlap h with f.
|
6
|
+
|
7
|
+
Preconditions:
|
8
|
+
|f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
|
9
|
+
|
10
|
+
Postconditions:
|
11
|
+
|h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc.
|
12
|
+
*/
|
13
|
+
|
14
|
+
/*
|
15
|
+
See fe_mul.c for discussion of implementation strategy.
|
16
|
+
*/
|
17
|
+
|
18
|
+
void fe_sq(fe h,const fe f)
|
19
|
+
{
|
20
|
+
int32_t f0 = f[0];
|
21
|
+
int32_t f1 = f[1];
|
22
|
+
int32_t f2 = f[2];
|
23
|
+
int32_t f3 = f[3];
|
24
|
+
int32_t f4 = f[4];
|
25
|
+
int32_t f5 = f[5];
|
26
|
+
int32_t f6 = f[6];
|
27
|
+
int32_t f7 = f[7];
|
28
|
+
int32_t f8 = f[8];
|
29
|
+
int32_t f9 = f[9];
|
30
|
+
int32_t f0_2 = 2 * f0;
|
31
|
+
int32_t f1_2 = 2 * f1;
|
32
|
+
int32_t f2_2 = 2 * f2;
|
33
|
+
int32_t f3_2 = 2 * f3;
|
34
|
+
int32_t f4_2 = 2 * f4;
|
35
|
+
int32_t f5_2 = 2 * f5;
|
36
|
+
int32_t f6_2 = 2 * f6;
|
37
|
+
int32_t f7_2 = 2 * f7;
|
38
|
+
int32_t f5_38 = 38 * f5; /* 1.959375*2^30 */
|
39
|
+
int32_t f6_19 = 19 * f6; /* 1.959375*2^30 */
|
40
|
+
int32_t f7_38 = 38 * f7; /* 1.959375*2^30 */
|
41
|
+
int32_t f8_19 = 19 * f8; /* 1.959375*2^30 */
|
42
|
+
int32_t f9_38 = 38 * f9; /* 1.959375*2^30 */
|
43
|
+
int64_t f0f0 = f0 * (int64_t) f0;
|
44
|
+
int64_t f0f1_2 = f0_2 * (int64_t) f1;
|
45
|
+
int64_t f0f2_2 = f0_2 * (int64_t) f2;
|
46
|
+
int64_t f0f3_2 = f0_2 * (int64_t) f3;
|
47
|
+
int64_t f0f4_2 = f0_2 * (int64_t) f4;
|
48
|
+
int64_t f0f5_2 = f0_2 * (int64_t) f5;
|
49
|
+
int64_t f0f6_2 = f0_2 * (int64_t) f6;
|
50
|
+
int64_t f0f7_2 = f0_2 * (int64_t) f7;
|
51
|
+
int64_t f0f8_2 = f0_2 * (int64_t) f8;
|
52
|
+
int64_t f0f9_2 = f0_2 * (int64_t) f9;
|
53
|
+
int64_t f1f1_2 = f1_2 * (int64_t) f1;
|
54
|
+
int64_t f1f2_2 = f1_2 * (int64_t) f2;
|
55
|
+
int64_t f1f3_4 = f1_2 * (int64_t) f3_2;
|
56
|
+
int64_t f1f4_2 = f1_2 * (int64_t) f4;
|
57
|
+
int64_t f1f5_4 = f1_2 * (int64_t) f5_2;
|
58
|
+
int64_t f1f6_2 = f1_2 * (int64_t) f6;
|
59
|
+
int64_t f1f7_4 = f1_2 * (int64_t) f7_2;
|
60
|
+
int64_t f1f8_2 = f1_2 * (int64_t) f8;
|
61
|
+
int64_t f1f9_76 = f1_2 * (int64_t) f9_38;
|
62
|
+
int64_t f2f2 = f2 * (int64_t) f2;
|
63
|
+
int64_t f2f3_2 = f2_2 * (int64_t) f3;
|
64
|
+
int64_t f2f4_2 = f2_2 * (int64_t) f4;
|
65
|
+
int64_t f2f5_2 = f2_2 * (int64_t) f5;
|
66
|
+
int64_t f2f6_2 = f2_2 * (int64_t) f6;
|
67
|
+
int64_t f2f7_2 = f2_2 * (int64_t) f7;
|
68
|
+
int64_t f2f8_38 = f2_2 * (int64_t) f8_19;
|
69
|
+
int64_t f2f9_38 = f2 * (int64_t) f9_38;
|
70
|
+
int64_t f3f3_2 = f3_2 * (int64_t) f3;
|
71
|
+
int64_t f3f4_2 = f3_2 * (int64_t) f4;
|
72
|
+
int64_t f3f5_4 = f3_2 * (int64_t) f5_2;
|
73
|
+
int64_t f3f6_2 = f3_2 * (int64_t) f6;
|
74
|
+
int64_t f3f7_76 = f3_2 * (int64_t) f7_38;
|
75
|
+
int64_t f3f8_38 = f3_2 * (int64_t) f8_19;
|
76
|
+
int64_t f3f9_76 = f3_2 * (int64_t) f9_38;
|
77
|
+
int64_t f4f4 = f4 * (int64_t) f4;
|
78
|
+
int64_t f4f5_2 = f4_2 * (int64_t) f5;
|
79
|
+
int64_t f4f6_38 = f4_2 * (int64_t) f6_19;
|
80
|
+
int64_t f4f7_38 = f4 * (int64_t) f7_38;
|
81
|
+
int64_t f4f8_38 = f4_2 * (int64_t) f8_19;
|
82
|
+
int64_t f4f9_38 = f4 * (int64_t) f9_38;
|
83
|
+
int64_t f5f5_38 = f5 * (int64_t) f5_38;
|
84
|
+
int64_t f5f6_38 = f5_2 * (int64_t) f6_19;
|
85
|
+
int64_t f5f7_76 = f5_2 * (int64_t) f7_38;
|
86
|
+
int64_t f5f8_38 = f5_2 * (int64_t) f8_19;
|
87
|
+
int64_t f5f9_76 = f5_2 * (int64_t) f9_38;
|
88
|
+
int64_t f6f6_19 = f6 * (int64_t) f6_19;
|
89
|
+
int64_t f6f7_38 = f6 * (int64_t) f7_38;
|
90
|
+
int64_t f6f8_38 = f6_2 * (int64_t) f8_19;
|
91
|
+
int64_t f6f9_38 = f6 * (int64_t) f9_38;
|
92
|
+
int64_t f7f7_38 = f7 * (int64_t) f7_38;
|
93
|
+
int64_t f7f8_38 = f7_2 * (int64_t) f8_19;
|
94
|
+
int64_t f7f9_76 = f7_2 * (int64_t) f9_38;
|
95
|
+
int64_t f8f8_19 = f8 * (int64_t) f8_19;
|
96
|
+
int64_t f8f9_38 = f8 * (int64_t) f9_38;
|
97
|
+
int64_t f9f9_38 = f9 * (int64_t) f9_38;
|
98
|
+
int64_t h0 = f0f0 +f1f9_76+f2f8_38+f3f7_76+f4f6_38+f5f5_38;
|
99
|
+
int64_t h1 = f0f1_2+f2f9_38+f3f8_38+f4f7_38+f5f6_38;
|
100
|
+
int64_t h2 = f0f2_2+f1f1_2 +f3f9_76+f4f8_38+f5f7_76+f6f6_19;
|
101
|
+
int64_t h3 = f0f3_2+f1f2_2 +f4f9_38+f5f8_38+f6f7_38;
|
102
|
+
int64_t h4 = f0f4_2+f1f3_4 +f2f2 +f5f9_76+f6f8_38+f7f7_38;
|
103
|
+
int64_t h5 = f0f5_2+f1f4_2 +f2f3_2 +f6f9_38+f7f8_38;
|
104
|
+
int64_t h6 = f0f6_2+f1f5_4 +f2f4_2 +f3f3_2 +f7f9_76+f8f8_19;
|
105
|
+
int64_t h7 = f0f7_2+f1f6_2 +f2f5_2 +f3f4_2 +f8f9_38;
|
106
|
+
int64_t h8 = f0f8_2+f1f7_4 +f2f6_2 +f3f5_4 +f4f4 +f9f9_38;
|
107
|
+
int64_t h9 = f0f9_2+f1f8_2 +f2f7_2 +f3f6_2 +f4f5_2;
|
108
|
+
int64_t carry0;
|
109
|
+
int64_t carry1;
|
110
|
+
int64_t carry2;
|
111
|
+
int64_t carry3;
|
112
|
+
int64_t carry4;
|
113
|
+
int64_t carry5;
|
114
|
+
int64_t carry6;
|
115
|
+
int64_t carry7;
|
116
|
+
int64_t carry8;
|
117
|
+
int64_t carry9;
|
118
|
+
|
119
|
+
carry0 = (h0 + (int64_t) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
|
120
|
+
carry4 = (h4 + (int64_t) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
|
121
|
+
|
122
|
+
carry1 = (h1 + (int64_t) (1<<24)) >> 25; h2 += carry1; h1 -= carry1 << 25;
|
123
|
+
carry5 = (h5 + (int64_t) (1<<24)) >> 25; h6 += carry5; h5 -= carry5 << 25;
|
124
|
+
|
125
|
+
carry2 = (h2 + (int64_t) (1<<25)) >> 26; h3 += carry2; h2 -= carry2 << 26;
|
126
|
+
carry6 = (h6 + (int64_t) (1<<25)) >> 26; h7 += carry6; h6 -= carry6 << 26;
|
127
|
+
|
128
|
+
carry3 = (h3 + (int64_t) (1<<24)) >> 25; h4 += carry3; h3 -= carry3 << 25;
|
129
|
+
carry7 = (h7 + (int64_t) (1<<24)) >> 25; h8 += carry7; h7 -= carry7 << 25;
|
130
|
+
|
131
|
+
carry4 = (h4 + (int64_t) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
|
132
|
+
carry8 = (h8 + (int64_t) (1<<25)) >> 26; h9 += carry8; h8 -= carry8 << 26;
|
133
|
+
|
134
|
+
carry9 = (h9 + (int64_t) (1<<24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25;
|
135
|
+
|
136
|
+
carry0 = (h0 + (int64_t) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
|
137
|
+
|
138
|
+
h[0] = (int32_t)h0;
|
139
|
+
h[1] = (int32_t)h1;
|
140
|
+
h[2] = (int32_t)h2;
|
141
|
+
h[3] = (int32_t)h3;
|
142
|
+
h[4] = (int32_t)h4;
|
143
|
+
h[5] = (int32_t)h5;
|
144
|
+
h[6] = (int32_t)h6;
|
145
|
+
h[7] = (int32_t)h7;
|
146
|
+
h[8] = (int32_t)h8;
|
147
|
+
h[9] = (int32_t)h9;
|
148
|
+
}
|