dbl_2009_l.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_DBL_2009_L_HPP
27 #define CRYPTO3_ALGEBRA_CURVES_SHORT_WEIERSTRASS_G1_ELEMENT_JACOBIAN_WITH_A4_0_DBL_2009_L_HPP
28 
29 namespace nil {
30  namespace crypto3 {
31  namespace algebra {
32  namespace curves {
33  namespace detail {
34 
41 
42  template<typename ElementType>
43  constexpr static inline ElementType process(const ElementType &first) {
44 
45  using field_value_type = typename ElementType::field_type::value_type;
46 
47  // handle point at infinity
48  if (first.is_zero()) {
49  return (first);
50  }
51 
52  field_value_type A = (first.X).squared(); // A = X1^2
53  field_value_type B = (first.Y).squared(); // B = Y1^2
54  field_value_type C = B.squared(); // C = B^2
55  field_value_type D = (first.X + B).squared() - A - C;
56  D = D + D; // D = 2 * ((X1 + B)^2 - A - C)
57  field_value_type E = A + A + A; // E = 3 * A
58  field_value_type F = E.squared(); // F = E^2
59  field_value_type X3 = F - (D + D); // X3 = F - 2 D
60  field_value_type eightC = C + C;
61  eightC = eightC + eightC;
62  eightC = eightC + eightC;
63  field_value_type Y3 = E * (D - X3) - eightC; // Y3 = E * (D - X3) - 8 * C
64  field_value_type Y1Z1 = (first.Y) * (first.Z);
65  field_value_type Z3 = Y1Z1 + Y1Z1; // Z3 = 2 * Y1 * Z1
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_DBL_2009_L_HPP
Definition: pair.hpp:31
A struct representing element doubling from the group G1 of short Weierstrass curve for jacobian_with...
Definition: dbl_2009_l.hpp:40
constexpr static ElementType process(const ElementType &first)
Definition: dbl_2009_l.hpp:43