algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.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 // Copyright (c) 2020-2021 Ilias Khairullin <ilias@nil.foundation>
5 //
6 // MIT License
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 //---------------------------------------------------------------------------//
26 
27 #ifndef CRYPTO3_ALGEBRA_CURVES_EDWARDS_G1_ELEMENT_INVERTED_HPP
28 #define CRYPTO3_ALGEBRA_CURVES_EDWARDS_G1_ELEMENT_INVERTED_HPP
29 
32 
37 #include <nil/crypto3/algebra/curves/detail/forms/edwards/element_g1_affine.hpp>
38 
39 namespace nil {
40  namespace crypto3 {
41  namespace algebra {
42  namespace curves {
43  namespace detail {
49  template<typename CurveParams, typename Form, typename Coordinates>
50  struct curve_element;
51 
57  template<typename CurveParams>
58  struct curve_element<CurveParams, forms::edwards, coordinates::inverted> {
59 
60  using params_type = CurveParams;
61  using field_type = typename params_type::field_type;
62 
63  private:
64  using field_value_type = typename field_type::value_type;
65 
69 
70  public:
71  using group_type = typename params_type::group_type;
72 
74  using coordinates = coordinates::inverted;
75 
76  field_value_type X;
77  field_value_type Y;
78  field_value_type Z;
79 
80  /************************* Constructors and zero/one ***********************************/
81 
86  constexpr curve_element() :
87  curve_element(params_type::zero_fill[0],
88  params_type::zero_fill[1],
89  params_type::zero_fill[2]) {};
90 
95  constexpr curve_element(field_value_type X, field_value_type Y, field_value_type Z) {
96  this->X = X;
97  this->Y = Y;
98  this->Z = Z;
99  };
100 
104  constexpr static curve_element zero() {
105  return curve_element();
106  }
107 
111  constexpr static curve_element one() {
112  return curve_element(params_type::one_fill[0], params_type::one_fill[1],
113  params_type::one_fill[2]);
114  }
115 
116  /************************* Comparison operations ***********************************/
117 
118  constexpr bool operator==(const curve_element &other) const {
119  if (this->is_zero()) {
120  return other.is_zero();
121  }
122 
123  if (other.is_zero()) {
124  return false;
125  }
126 
127  /* now neither is O */
128 
129  // X1/Z1 = X2/Z2 <=> X1*Z2 = X2*Z1
130  if ((this->X * other.Z) != (other.X * this->Z)) {
131  return false;
132  }
133 
134  // Y1/Z1 = Y2/Z2 <=> Y1*Z2 = Y2*Z1
135  if ((this->Y * other.Z) != (other.Y * this->Z)) {
136  return false;
137  }
138 
139  return true;
140  }
141 
142  constexpr bool operator!=(const curve_element &other) const {
143  return !(operator==(other));
144  }
149  constexpr bool is_zero() const {
150  return (this->Y.is_zero() && this->Z.is_zero());
151  }
152 
157  constexpr bool is_well_formed() const {
158  assert(false && "Not implemented yet.");
159  }
160 
161  /************************* Reducing operations ***********************************/
162 
168  constexpr curve_element<typename params_type::affine_params, form,
170  to_affine() const {
171 
172  using result_type = curve_element<typename params_type::affine_params, form,
173  typename curves::coordinates::affine>;
174 
175  if (is_zero()) {
176  return result_type::zero();
177  }
178 
179  return result_type(Z / X, Z / Y); // x=Z/X, y=Z/Y
180  }
181 
182  /************************* Arithmetic operations ***********************************/
183 
184  constexpr curve_element operator=(const curve_element &other) {
185  // handle special cases having to do with O
186  this->X = other.X;
187  this->Y = other.Y;
188  this->Z = other.Z;
189 
190  return *this;
191  }
192 
193  constexpr curve_element operator+(const curve_element &other) const {
194  // handle special cases having to do with O
195  if (this->is_zero()) {
196  return other;
197  }
198 
199  if (other.is_zero()) {
200  return (*this);
201  }
202 
203  if (*this == other) {
204  return this->doubled();
205  }
206 
207  return common_addition_processor::process(*this, other);
208  }
209 
210  constexpr curve_element operator-() const {
211  return curve_element(-(this->X), this->Y, this->Z);
212  }
213 
214  constexpr curve_element operator-(const curve_element &other) const {
215  return (*this) + (-other);
216  }
217 
222  constexpr curve_element doubled() const {
223  return common_doubling_processor::process(*this);
224  }
225 
231  curve_element mixed_add(const curve_element &other) const {
232 
233  // handle special cases having to do with O
234  if (this->is_zero()) {
235  return other;
236  }
237 
238  if (other.is_zero()) {
239  return *this;
240  }
241 
242  return mixed_addition_processor::process(*this, other);
243  }
244  };
245 
246  } // namespace detail
247  } // namespace curves
248  } // namespace algebra
249  } // namespace crypto3
250 } // namespace nil
251 #endif // CRYPTO3_ALGEBRA_CURVES_EDWARDS_G1_ELEMENT_INVERTED_HPP
constexpr bool operator==(const matrix< T, N, M > &a, const matrix< T, N, M > &b)
checks equality of two matrices
Definition: matrix/operators.hpp:48
edwards_base_field< Version > edwards
Definition: edwards/base_field.hpp:86
bool is_zero(const Range &a)
Definition: basic_operations.hpp:43
Definition: pair.hpp:31
Jacobi quatrics curve group element coordinates representation. Description: https://hyperelliptic....
Definition: jacobi_quartics/coordinates.hpp:40
typename params_type::field_type field_type
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:61
typename params_type::group_type group_type
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:71
constexpr curve_element operator+(const curve_element &other) const
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:193
constexpr bool is_well_formed() const
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:157
curve_element mixed_add(const curve_element &other) const
“Mixed addition” refers to the case Z2 known to be 1.
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:231
constexpr curve_element< typename params_type::affine_params, form, typename curves::coordinates::affine > to_affine() const
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:170
constexpr curve_element operator=(const curve_element &other)
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:184
constexpr bool operator==(const curve_element &other) const
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:118
CurveParams params_type
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:60
constexpr curve_element operator-(const curve_element &other) const
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:214
constexpr static curve_element one()
Get the generator of group G1.
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:111
field_value_type Z
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:78
constexpr bool operator!=(const curve_element &other) const
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:142
constexpr curve_element operator-() const
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:210
constexpr static curve_element zero()
Get the point at infinity.
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:104
constexpr curve_element(field_value_type X, field_value_type Y, field_value_type Z)
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:95
field_value_type X
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:76
field_value_type Y
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:77
coordinates::inverted coordinates
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:74
constexpr bool is_zero() const
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:149
constexpr curve_element doubled() const
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:222
constexpr curve_element()
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:86
A struct representing a group G1 of elliptic curve.
Definition: algebra/include/nil/crypto3/algebra/curves/detail/forms/edwards/inverted/element_g1.hpp:50
A struct representing element addition from the group G1 of Edwards curve for inversed coordinates re...
Definition: edwards/inverted/add_2007_bl.hpp:41
A struct representing element doubling from the group G1 of Edwards curve for inversed coordinates re...
Definition: edwards/inverted/dbl_2007_bl.hpp:41
A struct representing element addition from the group G1 of Edwards curve for inversed coordinates re...
Definition: edwards/inverted/madd_2007_bl.hpp:41
A struct representing a Edwards curve, providing 128 bits of security.
Definition: curves/edwards.hpp:51
Definition: forms.hpp:34