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,159 @@
|
|
1
|
+
#include "fe.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
h = 2 * 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_sq2(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
|
+
h0 += h0;
|
120
|
+
h1 += h1;
|
121
|
+
h2 += h2;
|
122
|
+
h3 += h3;
|
123
|
+
h4 += h4;
|
124
|
+
h5 += h5;
|
125
|
+
h6 += h6;
|
126
|
+
h7 += h7;
|
127
|
+
h8 += h8;
|
128
|
+
h9 += h9;
|
129
|
+
|
130
|
+
carry0 = (h0 + (int64_t) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
|
131
|
+
carry4 = (h4 + (int64_t) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
|
132
|
+
|
133
|
+
carry1 = (h1 + (int64_t) (1<<24)) >> 25; h2 += carry1; h1 -= carry1 << 25;
|
134
|
+
carry5 = (h5 + (int64_t) (1<<24)) >> 25; h6 += carry5; h5 -= carry5 << 25;
|
135
|
+
|
136
|
+
carry2 = (h2 + (int64_t) (1<<25)) >> 26; h3 += carry2; h2 -= carry2 << 26;
|
137
|
+
carry6 = (h6 + (int64_t) (1<<25)) >> 26; h7 += carry6; h6 -= carry6 << 26;
|
138
|
+
|
139
|
+
carry3 = (h3 + (int64_t) (1<<24)) >> 25; h4 += carry3; h3 -= carry3 << 25;
|
140
|
+
carry7 = (h7 + (int64_t) (1<<24)) >> 25; h8 += carry7; h7 -= carry7 << 25;
|
141
|
+
|
142
|
+
carry4 = (h4 + (int64_t) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
|
143
|
+
carry8 = (h8 + (int64_t) (1<<25)) >> 26; h9 += carry8; h8 -= carry8 << 26;
|
144
|
+
|
145
|
+
carry9 = (h9 + (int64_t) (1<<24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25;
|
146
|
+
|
147
|
+
carry0 = (h0 + (int64_t) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
|
148
|
+
|
149
|
+
h[0] = (int32_t)h0;
|
150
|
+
h[1] = (int32_t)h1;
|
151
|
+
h[2] = (int32_t)h2;
|
152
|
+
h[3] = (int32_t)h3;
|
153
|
+
h[4] = (int32_t)h4;
|
154
|
+
h[5] = (int32_t)h5;
|
155
|
+
h[6] = (int32_t)h6;
|
156
|
+
h[7] = (int32_t)h7;
|
157
|
+
h[8] = (int32_t)h8;
|
158
|
+
h[9] = (int32_t)h9;
|
159
|
+
}
|
@@ -0,0 +1,57 @@
|
|
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.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
|
9
|
+
|g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
|
10
|
+
|
11
|
+
Postconditions:
|
12
|
+
|h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
|
13
|
+
*/
|
14
|
+
|
15
|
+
void fe_sub(fe h,const fe f,const fe g)
|
16
|
+
{
|
17
|
+
int32_t f0 = f[0];
|
18
|
+
int32_t f1 = f[1];
|
19
|
+
int32_t f2 = f[2];
|
20
|
+
int32_t f3 = f[3];
|
21
|
+
int32_t f4 = f[4];
|
22
|
+
int32_t f5 = f[5];
|
23
|
+
int32_t f6 = f[6];
|
24
|
+
int32_t f7 = f[7];
|
25
|
+
int32_t f8 = f[8];
|
26
|
+
int32_t f9 = f[9];
|
27
|
+
int32_t g0 = g[0];
|
28
|
+
int32_t g1 = g[1];
|
29
|
+
int32_t g2 = g[2];
|
30
|
+
int32_t g3 = g[3];
|
31
|
+
int32_t g4 = g[4];
|
32
|
+
int32_t g5 = g[5];
|
33
|
+
int32_t g6 = g[6];
|
34
|
+
int32_t g7 = g[7];
|
35
|
+
int32_t g8 = g[8];
|
36
|
+
int32_t g9 = g[9];
|
37
|
+
int32_t h0 = f0 - g0;
|
38
|
+
int32_t h1 = f1 - g1;
|
39
|
+
int32_t h2 = f2 - g2;
|
40
|
+
int32_t h3 = f3 - g3;
|
41
|
+
int32_t h4 = f4 - g4;
|
42
|
+
int32_t h5 = f5 - g5;
|
43
|
+
int32_t h6 = f6 - g6;
|
44
|
+
int32_t h7 = f7 - g7;
|
45
|
+
int32_t h8 = f8 - g8;
|
46
|
+
int32_t h9 = f9 - g9;
|
47
|
+
h[0] = h0;
|
48
|
+
h[1] = h1;
|
49
|
+
h[2] = h2;
|
50
|
+
h[3] = h3;
|
51
|
+
h[4] = h4;
|
52
|
+
h[5] = h5;
|
53
|
+
h[6] = h6;
|
54
|
+
h[7] = h7;
|
55
|
+
h[8] = h8;
|
56
|
+
h[9] = h9;
|
57
|
+
}
|
@@ -0,0 +1,119 @@
|
|
1
|
+
#include "fe.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
Preconditions:
|
5
|
+
|h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
|
6
|
+
|
7
|
+
Write p=2^255-19; q=floor(h/p).
|
8
|
+
Basic claim: q = floor(2^(-255)(h + 19 2^(-25)h9 + 2^(-1))).
|
9
|
+
|
10
|
+
Proof:
|
11
|
+
Have |h|<=p so |q|<=1 so |19^2 2^(-255) q|<1/4.
|
12
|
+
Also have |h-2^230 h9|<2^231 so |19 2^(-255)(h-2^230 h9)|<1/4.
|
13
|
+
|
14
|
+
Write y=2^(-1)-19^2 2^(-255)q-19 2^(-255)(h-2^230 h9).
|
15
|
+
Then 0<y<1.
|
16
|
+
|
17
|
+
Write r=h-pq.
|
18
|
+
Have 0<=r<=p-1=2^255-20.
|
19
|
+
Thus 0<=r+19(2^-255)r<r+19(2^-255)2^255<=2^255-1.
|
20
|
+
|
21
|
+
Write x=r+19(2^-255)r+y.
|
22
|
+
Then 0<x<2^255 so floor(2^(-255)x) = 0 so floor(q+2^(-255)x) = q.
|
23
|
+
|
24
|
+
Have q+2^(-255)x = 2^(-255)(h + 19 2^(-25) h9 + 2^(-1))
|
25
|
+
so floor(2^(-255)(h + 19 2^(-25) h9 + 2^(-1))) = q.
|
26
|
+
*/
|
27
|
+
|
28
|
+
void fe_tobytes(unsigned char *s,const fe h)
|
29
|
+
{
|
30
|
+
int32_t h0 = h[0];
|
31
|
+
int32_t h1 = h[1];
|
32
|
+
int32_t h2 = h[2];
|
33
|
+
int32_t h3 = h[3];
|
34
|
+
int32_t h4 = h[4];
|
35
|
+
int32_t h5 = h[5];
|
36
|
+
int32_t h6 = h[6];
|
37
|
+
int32_t h7 = h[7];
|
38
|
+
int32_t h8 = h[8];
|
39
|
+
int32_t h9 = h[9];
|
40
|
+
int32_t q;
|
41
|
+
int32_t carry0;
|
42
|
+
int32_t carry1;
|
43
|
+
int32_t carry2;
|
44
|
+
int32_t carry3;
|
45
|
+
int32_t carry4;
|
46
|
+
int32_t carry5;
|
47
|
+
int32_t carry6;
|
48
|
+
int32_t carry7;
|
49
|
+
int32_t carry8;
|
50
|
+
int32_t carry9;
|
51
|
+
|
52
|
+
q = (19 * h9 + (((int32_t) 1) << 24)) >> 25;
|
53
|
+
q = (h0 + q) >> 26;
|
54
|
+
q = (h1 + q) >> 25;
|
55
|
+
q = (h2 + q) >> 26;
|
56
|
+
q = (h3 + q) >> 25;
|
57
|
+
q = (h4 + q) >> 26;
|
58
|
+
q = (h5 + q) >> 25;
|
59
|
+
q = (h6 + q) >> 26;
|
60
|
+
q = (h7 + q) >> 25;
|
61
|
+
q = (h8 + q) >> 26;
|
62
|
+
q = (h9 + q) >> 25;
|
63
|
+
|
64
|
+
/* Goal: Output h-(2^255-19)q, which is between 0 and 2^255-20. */
|
65
|
+
h0 += 19 * q;
|
66
|
+
/* Goal: Output h-2^255 q, which is between 0 and 2^255-20. */
|
67
|
+
|
68
|
+
carry0 = h0 >> 26; h1 += carry0; h0 -= carry0 << 26;
|
69
|
+
carry1 = h1 >> 25; h2 += carry1; h1 -= carry1 << 25;
|
70
|
+
carry2 = h2 >> 26; h3 += carry2; h2 -= carry2 << 26;
|
71
|
+
carry3 = h3 >> 25; h4 += carry3; h3 -= carry3 << 25;
|
72
|
+
carry4 = h4 >> 26; h5 += carry4; h4 -= carry4 << 26;
|
73
|
+
carry5 = h5 >> 25; h6 += carry5; h5 -= carry5 << 25;
|
74
|
+
carry6 = h6 >> 26; h7 += carry6; h6 -= carry6 << 26;
|
75
|
+
carry7 = h7 >> 25; h8 += carry7; h7 -= carry7 << 25;
|
76
|
+
carry8 = h8 >> 26; h9 += carry8; h8 -= carry8 << 26;
|
77
|
+
carry9 = h9 >> 25; h9 -= carry9 << 25;
|
78
|
+
/* h10 = carry9 */
|
79
|
+
|
80
|
+
/*
|
81
|
+
Goal: Output h0+...+2^255 h10-2^255 q, which is between 0 and 2^255-20.
|
82
|
+
Have h0+...+2^230 h9 between 0 and 2^255-1;
|
83
|
+
evidently 2^255 h10-2^255 q = 0.
|
84
|
+
Goal: Output h0+...+2^230 h9.
|
85
|
+
*/
|
86
|
+
|
87
|
+
s[0] = h0 >> 0;
|
88
|
+
s[1] = h0 >> 8;
|
89
|
+
s[2] = h0 >> 16;
|
90
|
+
s[3] = (h0 >> 24) | (h1 << 2);
|
91
|
+
s[4] = h1 >> 6;
|
92
|
+
s[5] = h1 >> 14;
|
93
|
+
s[6] = (h1 >> 22) | (h2 << 3);
|
94
|
+
s[7] = h2 >> 5;
|
95
|
+
s[8] = h2 >> 13;
|
96
|
+
s[9] = (h2 >> 21) | (h3 << 5);
|
97
|
+
s[10] = h3 >> 3;
|
98
|
+
s[11] = h3 >> 11;
|
99
|
+
s[12] = (h3 >> 19) | (h4 << 6);
|
100
|
+
s[13] = h4 >> 2;
|
101
|
+
s[14] = h4 >> 10;
|
102
|
+
s[15] = h4 >> 18;
|
103
|
+
s[16] = h5 >> 0;
|
104
|
+
s[17] = h5 >> 8;
|
105
|
+
s[18] = h5 >> 16;
|
106
|
+
s[19] = (h5 >> 24) | (h6 << 1);
|
107
|
+
s[20] = h6 >> 7;
|
108
|
+
s[21] = h6 >> 15;
|
109
|
+
s[22] = (h6 >> 23) | (h7 << 3);
|
110
|
+
s[23] = h7 >> 5;
|
111
|
+
s[24] = h7 >> 13;
|
112
|
+
s[25] = (h7 >> 21) | (h8 << 4);
|
113
|
+
s[26] = h8 >> 4;
|
114
|
+
s[27] = h8 >> 12;
|
115
|
+
s[28] = (h8 >> 20) | (h9 << 6);
|
116
|
+
s[29] = h9 >> 2;
|
117
|
+
s[30] = h9 >> 10;
|
118
|
+
s[31] = h9 >> 18;
|
119
|
+
}
|
@@ -0,0 +1,95 @@
|
|
1
|
+
#ifndef GE_H
|
2
|
+
#define GE_H
|
3
|
+
|
4
|
+
/*
|
5
|
+
ge means group element.
|
6
|
+
|
7
|
+
Here the group is the set of pairs (x,y) of field elements (see fe.h)
|
8
|
+
satisfying -x^2 + y^2 = 1 + d x^2y^2
|
9
|
+
where d = -121665/121666.
|
10
|
+
|
11
|
+
Representations:
|
12
|
+
ge_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
|
13
|
+
ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
|
14
|
+
ge_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
|
15
|
+
ge_precomp (Duif): (y+x,y-x,2dxy)
|
16
|
+
*/
|
17
|
+
|
18
|
+
#include "fe.h"
|
19
|
+
|
20
|
+
typedef struct {
|
21
|
+
fe X;
|
22
|
+
fe Y;
|
23
|
+
fe Z;
|
24
|
+
} ge_p2;
|
25
|
+
|
26
|
+
typedef struct {
|
27
|
+
fe X;
|
28
|
+
fe Y;
|
29
|
+
fe Z;
|
30
|
+
fe T;
|
31
|
+
} ge_p3;
|
32
|
+
|
33
|
+
typedef struct {
|
34
|
+
fe X;
|
35
|
+
fe Y;
|
36
|
+
fe Z;
|
37
|
+
fe T;
|
38
|
+
} ge_p1p1;
|
39
|
+
|
40
|
+
typedef struct {
|
41
|
+
fe yplusx;
|
42
|
+
fe yminusx;
|
43
|
+
fe xy2d;
|
44
|
+
} ge_precomp;
|
45
|
+
|
46
|
+
typedef struct {
|
47
|
+
fe YplusX;
|
48
|
+
fe YminusX;
|
49
|
+
fe Z;
|
50
|
+
fe T2d;
|
51
|
+
} ge_cached;
|
52
|
+
|
53
|
+
#define ge_frombytes_negate_vartime crypto_sign_ed25519_ref10_ge_frombytes_negate_vartime
|
54
|
+
#define ge_tobytes crypto_sign_ed25519_ref10_ge_tobytes
|
55
|
+
#define ge_p3_tobytes crypto_sign_ed25519_ref10_ge_p3_tobytes
|
56
|
+
|
57
|
+
#define ge_p2_0 crypto_sign_ed25519_ref10_ge_p2_0
|
58
|
+
#define ge_p3_0 crypto_sign_ed25519_ref10_ge_p3_0
|
59
|
+
#define ge_precomp_0 crypto_sign_ed25519_ref10_ge_precomp_0
|
60
|
+
#define ge_p3_to_p2 crypto_sign_ed25519_ref10_ge_p3_to_p2
|
61
|
+
#define ge_p3_to_cached crypto_sign_ed25519_ref10_ge_p3_to_cached
|
62
|
+
#define ge_p1p1_to_p2 crypto_sign_ed25519_ref10_ge_p1p1_to_p2
|
63
|
+
#define ge_p1p1_to_p3 crypto_sign_ed25519_ref10_ge_p1p1_to_p3
|
64
|
+
#define ge_p2_dbl crypto_sign_ed25519_ref10_ge_p2_dbl
|
65
|
+
#define ge_p3_dbl crypto_sign_ed25519_ref10_ge_p3_dbl
|
66
|
+
|
67
|
+
#define ge_madd crypto_sign_ed25519_ref10_ge_madd
|
68
|
+
#define ge_msub crypto_sign_ed25519_ref10_ge_msub
|
69
|
+
#define ge_add crypto_sign_ed25519_ref10_ge_add
|
70
|
+
#define ge_sub crypto_sign_ed25519_ref10_ge_sub
|
71
|
+
#define ge_scalarmult_base crypto_sign_ed25519_ref10_ge_scalarmult_base
|
72
|
+
#define ge_double_scalarmult_vartime crypto_sign_ed25519_ref10_ge_double_scalarmult_vartime
|
73
|
+
|
74
|
+
extern void ge_tobytes(unsigned char *,const ge_p2 *);
|
75
|
+
extern void ge_p3_tobytes(unsigned char *,const ge_p3 *);
|
76
|
+
extern int ge_frombytes_negate_vartime(ge_p3 *,const unsigned char *);
|
77
|
+
|
78
|
+
extern void ge_p2_0(ge_p2 *);
|
79
|
+
extern void ge_p3_0(ge_p3 *);
|
80
|
+
extern void ge_precomp_0(ge_precomp *);
|
81
|
+
extern void ge_p3_to_p2(ge_p2 *,const ge_p3 *);
|
82
|
+
extern void ge_p3_to_cached(ge_cached *,const ge_p3 *);
|
83
|
+
extern void ge_p1p1_to_p2(ge_p2 *,const ge_p1p1 *);
|
84
|
+
extern void ge_p1p1_to_p3(ge_p3 *,const ge_p1p1 *);
|
85
|
+
extern void ge_p2_dbl(ge_p1p1 *,const ge_p2 *);
|
86
|
+
extern void ge_p3_dbl(ge_p1p1 *,const ge_p3 *);
|
87
|
+
|
88
|
+
extern void ge_madd(ge_p1p1 *,const ge_p3 *,const ge_precomp *);
|
89
|
+
extern void ge_msub(ge_p1p1 *,const ge_p3 *,const ge_precomp *);
|
90
|
+
extern void ge_add(ge_p1p1 *,const ge_p3 *,const ge_cached *);
|
91
|
+
extern void ge_sub(ge_p1p1 *,const ge_p3 *,const ge_cached *);
|
92
|
+
extern void ge_scalarmult_base(ge_p3 *,const unsigned char *);
|
93
|
+
extern void ge_double_scalarmult_vartime(ge_p2 *,const unsigned char *,const ge_p3 *,const unsigned char *);
|
94
|
+
|
95
|
+
#endif
|
@@ -0,0 +1,97 @@
|
|
1
|
+
|
2
|
+
/* qhasm: enter ge_add */
|
3
|
+
|
4
|
+
/* qhasm: fe X1 */
|
5
|
+
|
6
|
+
/* qhasm: fe Y1 */
|
7
|
+
|
8
|
+
/* qhasm: fe Z1 */
|
9
|
+
|
10
|
+
/* qhasm: fe Z2 */
|
11
|
+
|
12
|
+
/* qhasm: fe T1 */
|
13
|
+
|
14
|
+
/* qhasm: fe ZZ */
|
15
|
+
|
16
|
+
/* qhasm: fe YpX2 */
|
17
|
+
|
18
|
+
/* qhasm: fe YmX2 */
|
19
|
+
|
20
|
+
/* qhasm: fe T2d2 */
|
21
|
+
|
22
|
+
/* qhasm: fe X3 */
|
23
|
+
|
24
|
+
/* qhasm: fe Y3 */
|
25
|
+
|
26
|
+
/* qhasm: fe Z3 */
|
27
|
+
|
28
|
+
/* qhasm: fe T3 */
|
29
|
+
|
30
|
+
/* qhasm: fe YpX1 */
|
31
|
+
|
32
|
+
/* qhasm: fe YmX1 */
|
33
|
+
|
34
|
+
/* qhasm: fe A */
|
35
|
+
|
36
|
+
/* qhasm: fe B */
|
37
|
+
|
38
|
+
/* qhasm: fe C */
|
39
|
+
|
40
|
+
/* qhasm: fe D */
|
41
|
+
|
42
|
+
/* qhasm: YpX1 = Y1+X1 */
|
43
|
+
/* asm 1: fe_add(>YpX1=fe#1,<Y1=fe#12,<X1=fe#11); */
|
44
|
+
/* asm 2: fe_add(>YpX1=r->X,<Y1=p->Y,<X1=p->X); */
|
45
|
+
fe_add(r->X,p->Y,p->X);
|
46
|
+
|
47
|
+
/* qhasm: YmX1 = Y1-X1 */
|
48
|
+
/* asm 1: fe_sub(>YmX1=fe#2,<Y1=fe#12,<X1=fe#11); */
|
49
|
+
/* asm 2: fe_sub(>YmX1=r->Y,<Y1=p->Y,<X1=p->X); */
|
50
|
+
fe_sub(r->Y,p->Y,p->X);
|
51
|
+
|
52
|
+
/* qhasm: A = YpX1*YpX2 */
|
53
|
+
/* asm 1: fe_mul(>A=fe#3,<YpX1=fe#1,<YpX2=fe#15); */
|
54
|
+
/* asm 2: fe_mul(>A=r->Z,<YpX1=r->X,<YpX2=q->YplusX); */
|
55
|
+
fe_mul(r->Z,r->X,q->YplusX);
|
56
|
+
|
57
|
+
/* qhasm: B = YmX1*YmX2 */
|
58
|
+
/* asm 1: fe_mul(>B=fe#2,<YmX1=fe#2,<YmX2=fe#16); */
|
59
|
+
/* asm 2: fe_mul(>B=r->Y,<YmX1=r->Y,<YmX2=q->YminusX); */
|
60
|
+
fe_mul(r->Y,r->Y,q->YminusX);
|
61
|
+
|
62
|
+
/* qhasm: C = T2d2*T1 */
|
63
|
+
/* asm 1: fe_mul(>C=fe#4,<T2d2=fe#18,<T1=fe#14); */
|
64
|
+
/* asm 2: fe_mul(>C=r->T,<T2d2=q->T2d,<T1=p->T); */
|
65
|
+
fe_mul(r->T,q->T2d,p->T);
|
66
|
+
|
67
|
+
/* qhasm: ZZ = Z1*Z2 */
|
68
|
+
/* asm 1: fe_mul(>ZZ=fe#1,<Z1=fe#13,<Z2=fe#17); */
|
69
|
+
/* asm 2: fe_mul(>ZZ=r->X,<Z1=p->Z,<Z2=q->Z); */
|
70
|
+
fe_mul(r->X,p->Z,q->Z);
|
71
|
+
|
72
|
+
/* qhasm: D = 2*ZZ */
|
73
|
+
/* asm 1: fe_add(>D=fe#5,<ZZ=fe#1,<ZZ=fe#1); */
|
74
|
+
/* asm 2: fe_add(>D=t0,<ZZ=r->X,<ZZ=r->X); */
|
75
|
+
fe_add(t0,r->X,r->X);
|
76
|
+
|
77
|
+
/* qhasm: X3 = A-B */
|
78
|
+
/* asm 1: fe_sub(>X3=fe#1,<A=fe#3,<B=fe#2); */
|
79
|
+
/* asm 2: fe_sub(>X3=r->X,<A=r->Z,<B=r->Y); */
|
80
|
+
fe_sub(r->X,r->Z,r->Y);
|
81
|
+
|
82
|
+
/* qhasm: Y3 = A+B */
|
83
|
+
/* asm 1: fe_add(>Y3=fe#2,<A=fe#3,<B=fe#2); */
|
84
|
+
/* asm 2: fe_add(>Y3=r->Y,<A=r->Z,<B=r->Y); */
|
85
|
+
fe_add(r->Y,r->Z,r->Y);
|
86
|
+
|
87
|
+
/* qhasm: Z3 = D+C */
|
88
|
+
/* asm 1: fe_add(>Z3=fe#3,<D=fe#5,<C=fe#4); */
|
89
|
+
/* asm 2: fe_add(>Z3=r->Z,<D=t0,<C=r->T); */
|
90
|
+
fe_add(r->Z,t0,r->T);
|
91
|
+
|
92
|
+
/* qhasm: T3 = D-C */
|
93
|
+
/* asm 1: fe_sub(>T3=fe#4,<D=fe#5,<C=fe#4); */
|
94
|
+
/* asm 2: fe_sub(>T3=r->T,<D=t0,<C=r->T); */
|
95
|
+
fe_sub(r->T,t0,r->T);
|
96
|
+
|
97
|
+
/* qhasm: return */
|