short_weierstrass/jacobian_with_a4_0/madd_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_MADD_2007_BL_HPP
27 #define CRYPTO3_ALGEBRA_CURVES_SHORT_WEIERSTRASS_G1_ELEMENT_JACOBIAN_WITH_A4_0_MADD_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  // Because for some reasons it's not so
50  // assert(second.Z == field_value_type::one());
51 
52  const field_value_type Z1Z1 = (first.Z).squared(); // Z1Z1 = Z1^2
53  const field_value_type U2 = second.X * Z1Z1; // X2*Z1Z1
54  const field_value_type S2 = second.Y * first.Z * Z1Z1; // S2 = Y2 * Z1 * Z1Z1
55  const field_value_type H = U2 - (first.X); // H = U2-X1
56  const field_value_type HH = H.squared(); // HH = H^2
57  const field_value_type I = HH.doubled().doubled(); // I = 4*HH
58  const field_value_type J = H * I; // J = H*I
59  const field_value_type r = (S2 - (first.Y)).doubled(); // r = 2*(S2-Y1)
60  const field_value_type V = first.X * I; // V = X1*I
61  const field_value_type X3 = r.squared() - J - V.doubled(); // X3 = r^2-J-2*V
62  const field_value_type Y3 =
63  r * (V - X3) - (first.Y * J).doubled(); // Y3 = r*(V-X3)-2*Y1*J
64  const field_value_type Z3 = (first.Z + H).squared() - Z1Z1 - HH; // Z3 = (Z1+H)^2-Z1Z1-HH
65 
66  return ElementType(X3, Y3, Z3);
67  }
68  };
69 
70  } // namespace detail
71  } // namespace curves
72  } // namespace algebra
73  } // namespace crypto3
74 } // namespace nil
75 #endif // CRYPTO3_ALGEBRA_CURVES_SHORT_WEIERSTRASS_G1_ELEMENT_JACOBIAN_WITH_A4_0_MADD_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/madd_2007_bl.hpp:41
constexpr static ElementType process(const ElementType &first, const ElementType &second)
Definition: short_weierstrass/jacobian_with_a4_0/madd_2007_bl.hpp:44