short_weierstrass/jacobian_with_a4_0/add_2007_bl.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2020-2021 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2020-2021 Nikita Kaskov <nbering@nil.foundation>
4 //
5 // MIT License
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in all
15 // copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // SOFTWARE.
24 //---------------------------------------------------------------------------//
25 
26 #ifndef CRYPTO3_ALGEBRA_CURVES_SHORT_WEIERSTRASS_G1_ELEMENT_JACOBIAN_WITH_A4_0_ADD_2007_BL_HPP
27 #define CRYPTO3_ALGEBRA_CURVES_SHORT_WEIERSTRASS_G1_ELEMENT_JACOBIAN_WITH_A4_0_ADD_2007_BL_HPP
28 
29 namespace nil {
30  namespace crypto3 {
31  namespace algebra {
32  namespace curves {
33  namespace detail {
34 
42 
43  template<typename ElementType>
44  constexpr static inline ElementType process(const ElementType &first,
45  const ElementType &second) {
46 
47  using field_value_type = typename ElementType::field_type::value_type;
48 
49  field_value_type Z1Z1 = (first.Z).squared(); // Z1Z1 = Z1^2
50  field_value_type Z2Z2 = (second.Z).squared(); // Z2Z2 = Z2^2
51  field_value_type U1 = (first.X) * Z2Z2; // U1 = X1 * Z2Z2
52  field_value_type U2 = (second.X) * Z1Z1; // U2 = X2 * Z1Z1
53  field_value_type S1 = (first.Y) * (second.Z) * Z2Z2; // S1 = Y1 * Z2 * Z2Z2
54  field_value_type S2 = (second.Y) * (first.Z) * Z1Z1; // S2 = Y2 * Z1 * Z1Z1
55  field_value_type H = U2 - U1; // H = U2-U1
56  field_value_type S2_minus_S1 = S2 - S1;
57  field_value_type I = (H + H).squared(); // I = (2 * H)^2
58  field_value_type J = H * I; // J = H * I
59  field_value_type r = S2_minus_S1 + S2_minus_S1; // r = 2 * (S2-S1)
60  field_value_type V = U1 * I; // V = U1 * I
61  field_value_type X3 = r.squared() - J - (V + V); // X3 = r^2 - J - 2 * V
62  field_value_type S1_J = S1 * J;
63  field_value_type Y3 = r * (V - X3) - (S1_J + S1_J); // Y3 = r * (V-X3)-2 S1 J
64  field_value_type Z3 =
65  ((first.Z + second.Z).squared() - Z1Z1 - Z2Z2) * H; // Z3 = ((Z1+Z2)^2-Z1Z1-Z2Z2) * H
66 
67  return ElementType(X3, Y3, Z3);
68  }
69  };
70 
71  } // namespace detail
72  } // namespace curves
73  } // namespace algebra
74  } // namespace crypto3
75 } // namespace nil
76 #endif // CRYPTO3_ALGEBRA_CURVES_SHORT_WEIERSTRASS_G1_ELEMENT_JACOBIAN_WITH_A4_0_ADD_2007_BL_HPP
Definition: pair.hpp:31
A struct representing element addition from the group G1 of short Weierstrass curve for jacobian_with...
Definition: short_weierstrass/jacobian_with_a4_0/add_2007_bl.hpp:41
constexpr static ElementType process(const ElementType &first, const ElementType &second)
Definition: short_weierstrass/jacobian_with_a4_0/add_2007_bl.hpp:44