ed25519 1.2.2-jruby → 1.2.3-jruby

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +12 -5
  3. data/README.md +2 -2
  4. data/ext/ed25519_ref10/fe.c +1085 -0
  5. data/ext/ed25519_ref10/ge.c +407 -0
  6. data/lib/ed25519/version.rb +1 -1
  7. metadata +4 -36
  8. data/ext/ed25519_ref10/fe_0.c +0 -19
  9. data/ext/ed25519_ref10/fe_1.c +0 -19
  10. data/ext/ed25519_ref10/fe_add.c +0 -57
  11. data/ext/ed25519_ref10/fe_cmov.c +0 -63
  12. data/ext/ed25519_ref10/fe_copy.c +0 -29
  13. data/ext/ed25519_ref10/fe_frombytes.c +0 -71
  14. data/ext/ed25519_ref10/fe_invert.c +0 -14
  15. data/ext/ed25519_ref10/fe_isnegative.c +0 -16
  16. data/ext/ed25519_ref10/fe_isnonzero.c +0 -19
  17. data/ext/ed25519_ref10/fe_mul.c +0 -252
  18. data/ext/ed25519_ref10/fe_neg.c +0 -45
  19. data/ext/ed25519_ref10/fe_pow22523.c +0 -13
  20. data/ext/ed25519_ref10/fe_sq.c +0 -148
  21. data/ext/ed25519_ref10/fe_sq2.c +0 -159
  22. data/ext/ed25519_ref10/fe_sub.c +0 -57
  23. data/ext/ed25519_ref10/fe_tobytes.c +0 -119
  24. data/ext/ed25519_ref10/ge_add.c +0 -11
  25. data/ext/ed25519_ref10/ge_double_scalarmult.c +0 -96
  26. data/ext/ed25519_ref10/ge_frombytes.c +0 -50
  27. data/ext/ed25519_ref10/ge_madd.c +0 -11
  28. data/ext/ed25519_ref10/ge_msub.c +0 -11
  29. data/ext/ed25519_ref10/ge_p1p1_to_p2.c +0 -12
  30. data/ext/ed25519_ref10/ge_p1p1_to_p3.c +0 -13
  31. data/ext/ed25519_ref10/ge_p2_0.c +0 -8
  32. data/ext/ed25519_ref10/ge_p2_dbl.c +0 -11
  33. data/ext/ed25519_ref10/ge_p3_0.c +0 -9
  34. data/ext/ed25519_ref10/ge_p3_dbl.c +0 -12
  35. data/ext/ed25519_ref10/ge_p3_to_cached.c +0 -17
  36. data/ext/ed25519_ref10/ge_p3_to_p2.c +0 -12
  37. data/ext/ed25519_ref10/ge_p3_tobytes.c +0 -14
  38. data/ext/ed25519_ref10/ge_precomp_0.c +0 -8
  39. data/ext/ed25519_ref10/ge_scalarmult_base.c +0 -104
  40. data/ext/ed25519_ref10/ge_sub.c +0 -11
  41. data/ext/ed25519_ref10/ge_tobytes.c +0 -14
@@ -1,45 +0,0 @@
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
- }
@@ -1,13 +0,0 @@
1
- #include "fe.h"
2
-
3
- void fe_pow22523(fe out,const fe z)
4
- {
5
- fe t0;
6
- fe t1;
7
- fe t2;
8
- int i;
9
-
10
- #include "pow22523.h"
11
-
12
- return;
13
- }
@@ -1,148 +0,0 @@
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
- }
@@ -1,159 +0,0 @@
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
- }
@@ -1,57 +0,0 @@
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
- }
@@ -1,119 +0,0 @@
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
- }