x25519 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rubocop.yml +3 -0
  4. data/CHANGES.md +3 -0
  5. data/Gemfile +3 -2
  6. data/README.md +205 -14
  7. data/Rakefile +9 -1
  8. data/ext/x25519/cputest.c +68 -0
  9. data/ext/x25519/extconf.rb +31 -0
  10. data/ext/x25519/ref10/api.h +2 -0
  11. data/ext/x25519/ref10/base.c +12 -0
  12. data/ext/x25519/ref10/fe.h +44 -0
  13. data/ext/x25519/ref10/fe_0.c +19 -0
  14. data/ext/x25519/ref10/fe_1.c +19 -0
  15. data/ext/x25519/ref10/fe_add.c +57 -0
  16. data/ext/x25519/ref10/fe_copy.c +29 -0
  17. data/ext/x25519/ref10/fe_cswap.c +73 -0
  18. data/ext/x25519/ref10/fe_frombytes.c +67 -0
  19. data/ext/x25519/ref10/fe_invert.c +14 -0
  20. data/ext/x25519/ref10/fe_mul.c +252 -0
  21. data/ext/x25519/ref10/fe_mul121666.c +69 -0
  22. data/ext/x25519/ref10/fe_sq.c +148 -0
  23. data/ext/x25519/ref10/fe_sub.c +57 -0
  24. data/ext/x25519/ref10/fe_tobytes.c +119 -0
  25. data/ext/x25519/ref10/montgomery.h +140 -0
  26. data/ext/x25519/ref10/pow225521.h +160 -0
  27. data/ext/x25519/ref10/scalarmult.c +46 -0
  28. data/ext/x25519/{fp25519_x64.c → rfc7748_precomputed/fp25519_x64.c} +14 -16
  29. data/ext/x25519/{fp25519_x64.h → rfc7748_precomputed/fp25519_x64.h} +6 -10
  30. data/ext/x25519/{bytes.h → rfc7748_precomputed/rfc7748_precomputed.h} +13 -5
  31. data/ext/x25519/{table_ladder_x25519.h → rfc7748_precomputed/table_ladder_x25519.h} +0 -0
  32. data/ext/x25519/{x25519_x64.c → rfc7748_precomputed/x25519_x64.c} +16 -29
  33. data/ext/x25519/x25519.c +325 -0
  34. data/ext/x25519/x25519.h +24 -0
  35. data/x25519.gemspec +3 -6
  36. metadata +32 -15
  37. data/ext/x25519/bytes.c +0 -42
  38. data/ext/x25519/random.c +0 -51
  39. data/ext/x25519/random.h +0 -24
  40. data/ext/x25519/rfc7748_precompted.h +0 -49
  41. data/ext/x25519/rfc7748_precomputed.c +0 -20
  42. data/lib/x25519.rb +0 -7
  43. data/lib/x25519/version.rb +0 -5
@@ -0,0 +1,69 @@
1
+ #include "fe.h"
2
+
3
+ /*
4
+ h = f * 121666
5
+ Can overlap h with f.
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
+ Postconditions:
11
+ |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
12
+ */
13
+
14
+ void fe_mul121666(fe h,fe f)
15
+ {
16
+ int32_t f0 = f[0];
17
+ int32_t f1 = f[1];
18
+ int32_t f2 = f[2];
19
+ int32_t f3 = f[3];
20
+ int32_t f4 = f[4];
21
+ int32_t f5 = f[5];
22
+ int32_t f6 = f[6];
23
+ int32_t f7 = f[7];
24
+ int32_t f8 = f[8];
25
+ int32_t f9 = f[9];
26
+ int64_t h0 = f0 * (int64_t) 121666;
27
+ int64_t h1 = f1 * (int64_t) 121666;
28
+ int64_t h2 = f2 * (int64_t) 121666;
29
+ int64_t h3 = f3 * (int64_t) 121666;
30
+ int64_t h4 = f4 * (int64_t) 121666;
31
+ int64_t h5 = f5 * (int64_t) 121666;
32
+ int64_t h6 = f6 * (int64_t) 121666;
33
+ int64_t h7 = f7 * (int64_t) 121666;
34
+ int64_t h8 = f8 * (int64_t) 121666;
35
+ int64_t h9 = f9 * (int64_t) 121666;
36
+ int64_t carry0;
37
+ int64_t carry1;
38
+ int64_t carry2;
39
+ int64_t carry3;
40
+ int64_t carry4;
41
+ int64_t carry5;
42
+ int64_t carry6;
43
+ int64_t carry7;
44
+ int64_t carry8;
45
+ int64_t carry9;
46
+
47
+ carry9 = (h9 + (int64_t) (1<<24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25;
48
+ carry1 = (h1 + (int64_t) (1<<24)) >> 25; h2 += carry1; h1 -= carry1 << 25;
49
+ carry3 = (h3 + (int64_t) (1<<24)) >> 25; h4 += carry3; h3 -= carry3 << 25;
50
+ carry5 = (h5 + (int64_t) (1<<24)) >> 25; h6 += carry5; h5 -= carry5 << 25;
51
+ carry7 = (h7 + (int64_t) (1<<24)) >> 25; h8 += carry7; h7 -= carry7 << 25;
52
+
53
+ carry0 = (h0 + (int64_t) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
54
+ carry2 = (h2 + (int64_t) (1<<25)) >> 26; h3 += carry2; h2 -= carry2 << 26;
55
+ carry4 = (h4 + (int64_t) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
56
+ carry6 = (h6 + (int64_t) (1<<25)) >> 26; h7 += carry6; h6 -= carry6 << 26;
57
+ carry8 = (h8 + (int64_t) (1<<25)) >> 26; h9 += carry8; h8 -= carry8 << 26;
58
+
59
+ h[0] = (int32_t)h0;
60
+ h[1] = (int32_t)h1;
61
+ h[2] = (int32_t)h2;
62
+ h[3] = (int32_t)h3;
63
+ h[4] = (int32_t)h4;
64
+ h[5] = (int32_t)h5;
65
+ h[6] = (int32_t)h6;
66
+ h[7] = (int32_t)h7;
67
+ h[8] = (int32_t)h8;
68
+ h[9] = (int32_t)h9;
69
+ }
@@ -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.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
9
+
10
+ Postconditions:
11
+ |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
12
+ */
13
+
14
+ /*
15
+ See fe_mul.c for discussion of implementation strategy.
16
+ */
17
+
18
+ void fe_sq(fe h,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.31*2^30 */
39
+ int32_t f6_19 = 19 * f6; /* 1.31*2^30 */
40
+ int32_t f7_38 = 38 * f7; /* 1.31*2^30 */
41
+ int32_t f8_19 = 19 * f8; /* 1.31*2^30 */
42
+ int32_t f9_38 = 38 * f9; /* 1.31*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
+ }
@@ -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,fe f,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^25,1.1*2^24,1.1*2^25,1.1*2^24,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^230 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,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,140 @@
1
+
2
+ /* qhasm: fe X2 */
3
+
4
+ /* qhasm: fe Z2 */
5
+
6
+ /* qhasm: fe X3 */
7
+
8
+ /* qhasm: fe Z3 */
9
+
10
+ /* qhasm: fe X4 */
11
+
12
+ /* qhasm: fe Z4 */
13
+
14
+ /* qhasm: fe X5 */
15
+
16
+ /* qhasm: fe Z5 */
17
+
18
+ /* qhasm: fe A */
19
+
20
+ /* qhasm: fe B */
21
+
22
+ /* qhasm: fe C */
23
+
24
+ /* qhasm: fe D */
25
+
26
+ /* qhasm: fe E */
27
+
28
+ /* qhasm: fe AA */
29
+
30
+ /* qhasm: fe BB */
31
+
32
+ /* qhasm: fe DA */
33
+
34
+ /* qhasm: fe CB */
35
+
36
+ /* qhasm: fe t0 */
37
+
38
+ /* qhasm: fe t1 */
39
+
40
+ /* qhasm: fe t2 */
41
+
42
+ /* qhasm: fe t3 */
43
+
44
+ /* qhasm: fe t4 */
45
+
46
+ /* qhasm: enter ladder */
47
+
48
+ /* qhasm: D = X3-Z3 */
49
+ /* asm 1: fe_sub(>D=fe#5,<X3=fe#3,<Z3=fe#4); */
50
+ /* asm 2: fe_sub(>D=tmp0,<X3=x3,<Z3=z3); */
51
+ fe_sub(tmp0,x3,z3);
52
+
53
+ /* qhasm: B = X2-Z2 */
54
+ /* asm 1: fe_sub(>B=fe#6,<X2=fe#1,<Z2=fe#2); */
55
+ /* asm 2: fe_sub(>B=tmp1,<X2=x2,<Z2=z2); */
56
+ fe_sub(tmp1,x2,z2);
57
+
58
+ /* qhasm: A = X2+Z2 */
59
+ /* asm 1: fe_add(>A=fe#1,<X2=fe#1,<Z2=fe#2); */
60
+ /* asm 2: fe_add(>A=x2,<X2=x2,<Z2=z2); */
61
+ fe_add(x2,x2,z2);
62
+
63
+ /* qhasm: C = X3+Z3 */
64
+ /* asm 1: fe_add(>C=fe#2,<X3=fe#3,<Z3=fe#4); */
65
+ /* asm 2: fe_add(>C=z2,<X3=x3,<Z3=z3); */
66
+ fe_add(z2,x3,z3);
67
+
68
+ /* qhasm: DA = D*A */
69
+ /* asm 1: fe_mul(>DA=fe#4,<D=fe#5,<A=fe#1); */
70
+ /* asm 2: fe_mul(>DA=z3,<D=tmp0,<A=x2); */
71
+ fe_mul(z3,tmp0,x2);
72
+
73
+ /* qhasm: CB = C*B */
74
+ /* asm 1: fe_mul(>CB=fe#2,<C=fe#2,<B=fe#6); */
75
+ /* asm 2: fe_mul(>CB=z2,<C=z2,<B=tmp1); */
76
+ fe_mul(z2,z2,tmp1);
77
+
78
+ /* qhasm: BB = B^2 */
79
+ /* asm 1: fe_sq(>BB=fe#5,<B=fe#6); */
80
+ /* asm 2: fe_sq(>BB=tmp0,<B=tmp1); */
81
+ fe_sq(tmp0,tmp1);
82
+
83
+ /* qhasm: AA = A^2 */
84
+ /* asm 1: fe_sq(>AA=fe#6,<A=fe#1); */
85
+ /* asm 2: fe_sq(>AA=tmp1,<A=x2); */
86
+ fe_sq(tmp1,x2);
87
+
88
+ /* qhasm: t0 = DA+CB */
89
+ /* asm 1: fe_add(>t0=fe#3,<DA=fe#4,<CB=fe#2); */
90
+ /* asm 2: fe_add(>t0=x3,<DA=z3,<CB=z2); */
91
+ fe_add(x3,z3,z2);
92
+
93
+ /* qhasm: assign x3 to t0 */
94
+
95
+ /* qhasm: t1 = DA-CB */
96
+ /* asm 1: fe_sub(>t1=fe#2,<DA=fe#4,<CB=fe#2); */
97
+ /* asm 2: fe_sub(>t1=z2,<DA=z3,<CB=z2); */
98
+ fe_sub(z2,z3,z2);
99
+
100
+ /* qhasm: X4 = AA*BB */
101
+ /* asm 1: fe_mul(>X4=fe#1,<AA=fe#6,<BB=fe#5); */
102
+ /* asm 2: fe_mul(>X4=x2,<AA=tmp1,<BB=tmp0); */
103
+ fe_mul(x2,tmp1,tmp0);
104
+
105
+ /* qhasm: E = AA-BB */
106
+ /* asm 1: fe_sub(>E=fe#6,<AA=fe#6,<BB=fe#5); */
107
+ /* asm 2: fe_sub(>E=tmp1,<AA=tmp1,<BB=tmp0); */
108
+ fe_sub(tmp1,tmp1,tmp0);
109
+
110
+ /* qhasm: t2 = t1^2 */
111
+ /* asm 1: fe_sq(>t2=fe#2,<t1=fe#2); */
112
+ /* asm 2: fe_sq(>t2=z2,<t1=z2); */
113
+ fe_sq(z2,z2);
114
+
115
+ /* qhasm: t3 = a24*E */
116
+ /* asm 1: fe_mul121666(>t3=fe#4,<E=fe#6); */
117
+ /* asm 2: fe_mul121666(>t3=z3,<E=tmp1); */
118
+ fe_mul121666(z3,tmp1);
119
+
120
+ /* qhasm: X5 = t0^2 */
121
+ /* asm 1: fe_sq(>X5=fe#3,<t0=fe#3); */
122
+ /* asm 2: fe_sq(>X5=x3,<t0=x3); */
123
+ fe_sq(x3,x3);
124
+
125
+ /* qhasm: t4 = BB+t3 */
126
+ /* asm 1: fe_add(>t4=fe#5,<BB=fe#5,<t3=fe#4); */
127
+ /* asm 2: fe_add(>t4=tmp0,<BB=tmp0,<t3=z3); */
128
+ fe_add(tmp0,tmp0,z3);
129
+
130
+ /* qhasm: Z5 = X1*t2 */
131
+ /* asm 1: fe_mul(>Z5=fe#4,x1,<t2=fe#2); */
132
+ /* asm 2: fe_mul(>Z5=z3,x1,<t2=z2); */
133
+ fe_mul(z3,x1,z2);
134
+
135
+ /* qhasm: Z4 = E*t4 */
136
+ /* asm 1: fe_mul(>Z4=fe#2,<E=fe#6,<t4=fe#5); */
137
+ /* asm 2: fe_mul(>Z4=z2,<E=tmp1,<t4=tmp0); */
138
+ fe_mul(z2,tmp1,tmp0);
139
+
140
+ /* qhasm: return */