curves/detail/babyjubjub/params.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_BABYJUBJUB_PARAMS_HPP
27 #define CRYPTO3_ALGEBRA_CURVES_BABYJUBJUB_PARAMS_HPP
28 
31 
33 
34 namespace nil {
35  namespace crypto3 {
36  namespace algebra {
37  namespace curves {
38  namespace detail {
39  template<>
40  struct babyjubjub_params<forms::twisted_edwards> {
43 
44  // Edwards representation constants a and d
45  constexpr static const typename babyjubjub_types::integral_type
46  a =
47  0x292FC_cppui18;
48  constexpr static const typename babyjubjub_types::integral_type
49  d =
50  0x292F8_cppui18;
51  };
52 
53  constexpr
55  constexpr
57 
58  template<>
59  struct babyjubjub_params<forms::montgomery> {
62 
63  // Montgomery representation constants A and B
64  constexpr static const typename babyjubjub_types::integral_type
65  A =
66  0x292FA_cppui18;
67  constexpr static const typename babyjubjub_types::integral_type
68  B =
69  0x01;
70  };
71 
74 
75  template<>
76  struct babyjubjub_g1_params<forms::twisted_edwards>
77  : public babyjubjub_params<forms::twisted_edwards> {
79 
80  template<typename Coordinates>
82 
83  constexpr static const std::array<typename base_field_type::value_type, 2> zero_fill = {
84  base_field_type::value_type::zero(), base_field_type::value_type::one()};
85 
86  constexpr static const std::array<typename base_field_type::value_type, 2> one_fill = {
87  typename base_field_type::value_type(
88  0xBB77A6AD63E739B4EACB2E09D6277C12AB8D8010534E0B62893F3F6BB957051_cppui252),
89  typename base_field_type::value_type(
90  0x25797203F7A0B24925572E1CD16BF9EDFCE0051FB9E133774B3C257A872D7D8B_cppui254)};
91  };
92 
93  constexpr std::array<
94  typename babyjubjub_g1_params<forms::twisted_edwards>::base_field_type::value_type, 2> const
96  constexpr std::array<
97  typename babyjubjub_g1_params<forms::twisted_edwards>::base_field_type::value_type, 2> const
99 
100  template<>
101  struct babyjubjub_g1_params<forms::montgomery> : public babyjubjub_params<forms::montgomery> {
103 
104  template<typename Coordinates>
106 
107  constexpr static const std::array<typename base_field_type::value_type, 2> one_fill = {
108  typename base_field_type::value_type(
109  0xfbc9ac10c16d45d4eacdd6489fa006480b17a811cdba46922896085f89faaf6_cppui252),
110  typename base_field_type::value_type(
111  0x203a710160811d5c07ebaeb8fe1d9ce201c66b970d66f18d0d2b264c195309aa_cppui254)};
112  };
113 
114  constexpr std::array<typename babyjubjub_g1_params<forms::montgomery>::base_field_type::value_type,
116  } // namespace detail
117  } // namespace curves
118  } // namespace algebra
119  } // namespace crypto3
120 } // namespace nil
121 
122 #endif // CRYPTO3_ALGEBRA_CURVES_BABYJUBJUB_PARAMS_HPP
Definition: pair.hpp:31
typename babyjubjub_params< forms::montgomery >::base_field_type field_type
Definition: curves/detail/babyjubjub/params.hpp:102
constexpr static const std::array< typename base_field_type::value_type, 2 > one_fill
Definition: curves/detail/babyjubjub/params.hpp:107
typename babyjubjub_params< forms::twisted_edwards >::base_field_type field_type
Definition: curves/detail/babyjubjub/params.hpp:78
constexpr static const std::array< typename base_field_type::value_type, 2 > one_fill
Definition: curves/detail/babyjubjub/params.hpp:86
constexpr static const std::array< typename base_field_type::value_type, 2 > zero_fill
Definition: curves/detail/babyjubjub/params.hpp:83
Definition: curves/detail/babyjubjub/types.hpp:45
A struct representing a group G1 of BabyJubJub curve.
Definition: babyjubjub/g1.hpp:47
typename babyjubjub_types::base_field_type base_field_type
Definition: curves/detail/babyjubjub/params.hpp:60
typename babyjubjub_types::scalar_field_type scalar_field_type
Definition: curves/detail/babyjubjub/params.hpp:61
typename babyjubjub_types::scalar_field_type scalar_field_type
Definition: curves/detail/babyjubjub/params.hpp:42
typename babyjubjub_types::base_field_type base_field_type
Definition: curves/detail/babyjubjub/params.hpp:41
Definition: curves/detail/babyjubjub/types.hpp:42
fields::babyjubjub_scalar_field scalar_field_type
Definition: curves/detail/babyjubjub/types.hpp:55
fields::babyjubjub_base_field base_field_type
Definition: curves/detail/babyjubjub/types.hpp:54
typename base_field_type::integral_type integral_type
Definition: curves/detail/babyjubjub/types.hpp:59
Definition: forms.hpp:34