26 #ifndef CRYPTO3_ALGEBRA_PAIRING_EDWARDS_183_TATE_PRECOMPUTE_G1_HPP
27 #define CRYPTO3_ALGEBRA_PAIRING_EDWARDS_183_TATE_PRECOMPUTE_G1_HPP
29 #include <nil/crypto3/multiprecision/number.hpp>
30 #include <nil/crypto3/multiprecision/cpp_int.hpp>
41 template<std::
size_t Version = 183>
42 class edwards_ate_precompute_g1;
45 class edwards_ate_precompute_g1<183> {
46 using curve_type = curves::edwards<183>;
48 using params_type = detail::pairing_params<curve_type>;
49 typedef detail::types_policy<curve_type> policy_type;
51 using base_field_type =
typename curve_type::base_field_type;
52 using g1_type =
typename curve_type::template g1_type<>;
53 using g1_affine_type =
typename curve_type::template g1_type<curves::coordinates::affine>;
55 using g1_field_type_value =
typename g1_type::field_type::value_type;
57 struct extended_g1_projective {
58 g1_field_type_value X;
59 g1_field_type_value Y;
60 g1_field_type_value Z;
61 g1_field_type_value T;
64 static void doubling_step_for_miller_loop(extended_g1_projective ¤t,
65 typename policy_type::Fq_conic_coefficients &cc) {
67 const g1_field_type_value &X = current.X, &Y = current.Y, &Z = current.Z, &T = current.T;
68 const g1_field_type_value A = X.squared();
69 const g1_field_type_value B = Y.squared();
70 const g1_field_type_value C = Z.squared();
71 const g1_field_type_value D = (X + Y).squared();
72 const g1_field_type_value E = (Y + Z).squared();
73 const g1_field_type_value F = D - (A + B);
74 const g1_field_type_value G = E - (B + C);
75 const g1_field_type_value &H = A;
76 const g1_field_type_value I = H + B;
77 const g1_field_type_value J = C - I;
78 const g1_field_type_value K = J + C;
80 cc.c_ZZ = Y * (T - X);
81 cc.c_ZZ = cc.c_ZZ + cc.c_ZZ;
85 cc.c_XZ = cc.c_XZ + cc.c_XZ;
88 current.Y = I * (B - H);
90 current.T = F * (B - H);
93 static void full_addition_step_for_miller_loop(
const extended_g1_projective &base,
94 extended_g1_projective ¤t,
95 typename policy_type::Fq_conic_coefficients &cc) {
97 const g1_field_type_value &X1 = current.X, &Y1 = current.Y, &Z1 = current.Z, &T1 = current.T;
98 const g1_field_type_value &X2 = base.X, &Y2 = base.Y, &Z2 = base.Z, &T2 = base.T;
100 const g1_field_type_value A = X1 * X2;
101 const g1_field_type_value B = Y1 * Y2;
102 const g1_field_type_value C = Z1 * T2;
103 const g1_field_type_value D = T1 * Z2;
104 const g1_field_type_value E = D + C;
105 const g1_field_type_value F = (X1 - Y1) * (X2 + Y2) + B - A;
106 const g1_field_type_value G = B + A;
107 const g1_field_type_value H = D - C;
108 const g1_field_type_value I = T1 * T2;
110 cc.c_ZZ = (T1 - X1) * (T2 + X2) - I + A;
111 cc.c_XY = X1 * Z2 - X2 * Z1 + F;
112 cc.c_XZ = (Y1 - T1) * (Y2 + T2) - B + I - H;
119 static void mixed_addition_step_for_miller_loop(
const extended_g1_projective &base,
120 extended_g1_projective ¤t,
121 typename policy_type::Fq_conic_coefficients &cc) {
123 const g1_field_type_value &X1 = current.X, &Y1 = current.Y, &Z1 = current.Z, &T1 = current.T;
124 const g1_field_type_value &X2 = base.X, &Y2 = base.Y, &T2 = base.T;
126 const g1_field_type_value A = X1 * X2;
127 const g1_field_type_value B = Y1 * Y2;
128 const g1_field_type_value C = Z1 * T2;
129 const g1_field_type_value D = T1;
130 const g1_field_type_value E = D + C;
131 const g1_field_type_value F = (X1 - Y1) * (X2 + Y2) + B - A;
132 const g1_field_type_value G = B + A;
133 const g1_field_type_value H = D - C;
134 const g1_field_type_value I = T1 * T2;
136 cc.c_ZZ = (T1 - X1) * (T2 + X2) - I + A;
137 cc.c_XY = X1 - X2 * Z1 + F;
138 cc.c_XZ = (Y1 - T1) * (Y2 + T2) - B + I - H;
148 static typename policy_type::tate_g1_precomp
process(
const typename g1_type::value_type &P) {
150 typename policy_type::tate_g1_precomp result;
152 typename g1_affine_type::value_type Pcopy = P.to_affine();
154 extended_g1_projective P_ext;
158 P_ext.T = Pcopy.X * Pcopy.Y;
160 extended_g1_projective R = P_ext;
162 bool found_one =
false;
163 for (
long i = params_type::scalar_field_bits; i >= 0; --i) {
165 nil::crypto3::multiprecision::bit_test(params_type::scalar_field_modulus, i);
175 policy_type::Fq_conic_coefficients cc;
177 doubling_step_for_miller_loop(R, cc);
178 result.push_back(cc);
181 mixed_addition_step_for_miller_loop(P_ext, R, cc);
182 result.push_back(cc);
static policy_type::tate_g1_precomp process(const typename g1_type::value_type &P)
Definition: tate_precompute_g1.hpp:148
typename policy_type::ate_g1_precomputed_type g1_precomputed_type
Definition: edwards/183/ate_precompute_g1.hpp:50