h2c_sgn0.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2020-2021 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2020-2021 Ilias Khairullin <ilias@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_HASH_TO_CURVE_UTILS_HPP
27 #define CRYPTO3_ALGEBRA_CURVES_HASH_TO_CURVE_UTILS_HPP
28 
31 
32 namespace nil {
33  namespace crypto3 {
34  namespace algebra {
35  namespace curves {
36  namespace detail {
38 
39  template<typename FieldParams>
40  inline bool sgn0(const element_fp<FieldParams> &e) {
41  using modular_type = typename FieldParams::modular_type;
42 
43  static const modular_type two = modular_type(2, element_fp<FieldParams>::modulus);
44 
45  return static_cast<bool>(e.data % two);
46  }
47 
48  template<typename FieldParams>
49  inline bool sgn0(const element_fp2<FieldParams> &e) {
50  using underlying_type = typename element_fp2<FieldParams>::underlying_type;
51  using modular_type = typename FieldParams::modular_type;
52 
53  static const modular_type two = modular_type(2, underlying_type::modulus);
54 
55  modular_type sign_0 = e.data[0].data % two;
56  bool zero_0 = e.data[0].data.is_zero();
57  modular_type sign_1 = e.data[1].data % two;
58  return static_cast<bool>(sign_0) || (zero_0 && static_cast<bool>(sign_1));
59  }
60  } // namespace detail
61  } // namespace curves
62  } // namespace algebra
63  } // namespace crypto3
64 } // namespace nil
65 
66 #endif // CRYPTO3_ALGEBRA_CURVES_HASH_TO_CURVE_UTILS_HPP
Definition: detail/element/fp2.hpp:39
policy_type::underlying_type underlying_type
Definition: detail/element/fp2.hpp:52
data_type data
Definition: detail/element/fp2.hpp:56
bool sgn0(const element_fp< FieldParams > &e)
Definition: h2c_sgn0.hpp:40
Definition: pair.hpp:31