26 #ifndef CRYPTO3_ALGEBRA_PAIRING_BLS12_ATE_PRECOMPUTE_G2_HPP
27 #define CRYPTO3_ALGEBRA_PAIRING_BLS12_ATE_PRECOMPUTE_G2_HPP
29 #include <nil/crypto3/multiprecision/number.hpp>
30 #include <nil/crypto3/multiprecision/cpp_int.hpp>
41 template<std::
size_t Version = 183>
52 using g2_type =
typename curve_type::template g2_type<>;
53 using g2_affine_type =
typename curve_type::template g2_type<curves::coordinates::affine>;
55 using g2_field_type_value =
typename g2_type::field_type::value_type;
57 struct extended_g2_projective {
58 g2_field_type_value X;
59 g2_field_type_value Y;
60 g2_field_type_value Z;
61 g2_field_type_value T;
65 doubling_step_for_flipped_miller_loop(extended_g2_projective ¤t,
66 typename policy_type::Fq3_conic_coefficients &cc) {
68 const g2_field_type_value &X = current.X, &Y = current.Y, &Z = current.Z, &T = current.T;
69 const g2_field_type_value A = X.squared();
70 const g2_field_type_value B = Y.squared();
71 const g2_field_type_value C = Z.squared();
72 const g2_field_type_value D = (X + Y).squared();
73 const g2_field_type_value E = (Y + Z).squared();
74 const g2_field_type_value F = D - (A + B);
75 const g2_field_type_value G = E - (B + C);
76 const g2_field_type_value H =
77 g2_type::value_type::mul_by_a(A);
79 const g2_field_type_value I = H + B;
80 const g2_field_type_value J = C - I;
81 const g2_field_type_value K = J + C;
83 cc.c_ZZ = Y * (T - X);
84 cc.c_ZZ = cc.c_ZZ + cc.c_ZZ;
86 cc.c_XY = C - g2_type::value_type::mul_by_a(A) - B;
87 cc.c_XY = cc.c_XY + cc.c_XY + G;
89 cc.c_XZ = g2_type::value_type::mul_by_a(X * T) - B;
90 cc.c_XZ = cc.c_XZ + cc.c_XZ;
93 current.Y = I * (B - H);
95 current.T = F * (B - H);
99 full_addition_step_for_flipped_miller_loop(
const extended_g2_projective &base,
100 extended_g2_projective ¤t,
101 typename policy_type::Fq3_conic_coefficients &cc) {
103 const g2_field_type_value &X1 = current.X, &Y1 = current.Y, &Z1 = current.Z, &T1 = current.T;
104 const g2_field_type_value &X2 = base.X, &Y2 = base.Y, &Z2 = base.Z, &T2 = base.T;
106 const g2_field_type_value A = X1 * X2;
107 const g2_field_type_value B = Y1 * Y2;
108 const g2_field_type_value C = Z1 * T2;
109 const g2_field_type_value D = T1 * Z2;
110 const g2_field_type_value E = D + C;
111 const g2_field_type_value F = (X1 - Y1) * (X2 + Y2) + B - A;
113 const g2_field_type_value G =
114 B + g2_type::value_type::mul_by_a(A);
116 const g2_field_type_value H = D - C;
117 const g2_field_type_value I = T1 * T2;
120 cc.c_ZZ = g2_type::value_type::mul_by_a((T1 - X1) * (T2 + X2) - I +
123 cc.c_XY = X1 * Z2 - X2 * Z1 + F;
124 cc.c_XZ = (Y1 - T1) * (Y2 + T2) - B + I - H;
132 mixed_addition_step_for_flipped_miller_loop(
const extended_g2_projective &base,
133 extended_g2_projective ¤t,
134 typename policy_type::Fq3_conic_coefficients &cc) {
136 const g2_field_type_value &X1 = current.X, &Y1 = current.Y, &Z1 = current.Z, &T1 = current.T;
137 const g2_field_type_value &X2 = base.X, &Y2 = base.Y, &T2 = base.T;
139 const g2_field_type_value A = X1 * X2;
140 const g2_field_type_value B = Y1 * Y2;
141 const g2_field_type_value C = Z1 * T2;
142 const g2_field_type_value E = T1 + C;
143 const g2_field_type_value F = (X1 - Y1) * (X2 + Y2) + B - A;
145 const g2_field_type_value G =
146 B + g2_type::value_type::mul_by_a(A);
147 const g2_field_type_value H = T1 - C;
148 const g2_field_type_value I = T1 * T2;
151 cc.c_ZZ = g2_type::value_type::mul_by_a((T1 - X1) * (T2 + X2) - I +
154 cc.c_XY = X1 - X2 * Z1 + F;
155 cc.c_XZ = (Y1 - T1) * (Y2 + T2) - B + I - H;
168 typename g2_affine_type::value_type Qcopy = Q.to_affine();
169 extended_g2_projective Q_ext;
173 Q_ext.T = Qcopy.X * Qcopy.Y;
175 extended_g2_projective R = Q_ext;
177 const typename policy_type::integral_type &loop_count = params_type::ate_loop_count;
179 bool found_one =
false;
180 for (
long i = params_type::integral_type_max_bits - 1; i >= 0; --i) {
181 const bool bit = nil::crypto3::multiprecision::bit_test(loop_count, i);
188 typename policy_type::Fq3_conic_coefficients cc;
189 doubling_step_for_flipped_miller_loop(R, cc);
190 result.push_back(cc);
192 mixed_addition_step_for_flipped_miller_loop(Q_ext, R, cc);
193 result.push_back(cc);
Definition: pairing/detail/alt_bn128/params.hpp:38
Definition: pairing/detail/edwards/183/types.hpp:38
typename policy_type::ate_g2_precomputed_type g2_precomputed_type
Definition: edwards/183/ate_precompute_g2.hpp:163
static g2_precomputed_type process(const typename g2_type::value_type &Q)
Definition: edwards/183/ate_precompute_g2.hpp:165
Definition: edwards/183/ate_precompute_g2.hpp:42
A struct representing a Edwards curve, providing 128 bits of security.
Definition: curves/edwards.hpp:51
IETF IPsec groups.
Definition: edwards/base_field.hpp:46