curves/detail/jubjub/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_JUBJUB_PARAMS_HPP
27 #define CRYPTO3_ALGEBRA_CURVES_JUBJUB_PARAMS_HPP
28 
31 
33 
34 namespace nil {
35  namespace crypto3 {
36  namespace algebra {
37  namespace curves {
38  namespace detail {
39  template<>
40  struct jubjub_params<forms::twisted_edwards> {
43 
44  // Edwards representation constants a and d
45  constexpr static const typename jubjub_types::integral_type
46  a =
47  0x73EDA753299D7D483339D80809A1D80553BDA402FFFE5BFEFFFFFFFF00000000_cppui255;
54  constexpr static const typename jubjub_types::integral_type
55  d =
56  0x2A9318E74BFA2B48F5FD9207E6BD7FD4292D7F6D37579D2601065FD6D6343EB1_cppui254;
63  static constexpr std::size_t cofactor = 8;
64  };
65 
68 
69  template<>
70  struct jubjub_params<forms::montgomery> {
73 
74  // Montgomery representation constants A and B
75  constexpr static const typename jubjub_types::integral_type
76  A =
77  0xA002_cppui16;
78  constexpr static const typename jubjub_types::integral_type
79  B =
80  0x01;
81  static constexpr std::size_t cofactor = 8;
82  };
83 
86 
87  template<>
88  struct jubjub_g1_params<forms::twisted_edwards> : public jubjub_params<forms::twisted_edwards> {
90 
91  template<typename Coordinates>
93 
94  constexpr static const std::array<typename field_type::value_type, 2> zero_fill = {
95  field_type::value_type::zero(), field_type::value_type::one()};
96 
97  // according to https://neuromancer.sk/std/other/JubJub
98  constexpr static const std::array<typename field_type::value_type, 2> one_fill = {
99  typename field_type::value_type(
100  0x11dafe5d23e1218086a365b99fbf3d3be72f6afd7d1f72623e6b071492d1122b_cppui253),
101  typename field_type::value_type(
102  0x1d523cf1ddab1a1793132e78c866c0c33e26ba5cc220fed7cc3f870e59d292aa_cppui253)};
103  };
104 
105  constexpr std::array<typename jubjub_g1_params<forms::twisted_edwards>::base_field_type::value_type,
107  constexpr std::array<typename jubjub_g1_params<forms::twisted_edwards>::base_field_type::value_type,
109 
110  template<>
111  struct jubjub_g1_params<forms::montgomery> : public jubjub_params<forms::montgomery> {
113 
114  template<typename Coordinates>
116 
117  // TODO: check correctness of the base point coordinates
118  constexpr static const std::array<typename field_type::value_type, 2> one_fill = {
119  typename field_type::value_type(
120  0x52a47af6ec47deb77d663b6a45b148d1ccdaa4e2299ecfbd5504c409b3ea62c0_cppui255),
121  typename field_type::value_type(
122  0x399b020832f6a499ba9d5334ca932dc9faaeea860e9a49a8f8854f55f3b676d4_cppui254)};
123  };
124 
125  constexpr std::array<typename jubjub_g1_params<forms::montgomery>::base_field_type::value_type,
127  } // namespace detail
128  } // namespace curves
129  } // namespace algebra
130  } // namespace crypto3
131 } // namespace nil
132 
133 #endif // CRYPTO3_ALGEBRA_CURVES_JUBJUB_PARAMS_HPP
Definition: pair.hpp:31
typename jubjub_params< forms::twisted_edwards >::base_field_type field_type
Definition: curves/detail/jubjub/params.hpp:112
constexpr static const std::array< typename field_type::value_type, 2 > one_fill
Definition: curves/detail/jubjub/params.hpp:118
constexpr static const std::array< typename field_type::value_type, 2 > zero_fill
Definition: curves/detail/jubjub/params.hpp:94
constexpr static const std::array< typename field_type::value_type, 2 > one_fill
Definition: curves/detail/jubjub/params.hpp:98
typename jubjub_params< forms::twisted_edwards >::base_field_type field_type
Definition: curves/detail/jubjub/params.hpp:89
Definition: curves/detail/jubjub/types.hpp:45
A struct representing a group G1 of JubJub curve.
Definition: jubjub/g1.hpp:47
typename jubjub_types::scalar_field_type scalar_field_type
Definition: curves/detail/jubjub/params.hpp:72
typename jubjub_types::base_field_type base_field_type
Definition: curves/detail/jubjub/params.hpp:71
typename jubjub_types::base_field_type base_field_type
Definition: curves/detail/jubjub/params.hpp:41
typename jubjub_types::scalar_field_type scalar_field_type
Definition: curves/detail/jubjub/params.hpp:42
Definition: curves/detail/jubjub/types.hpp:42
fields::jubjub_scalar_field scalar_field_type
Definition: curves/detail/jubjub/types.hpp:56
fields::jubjub_base_field base_field_type
Definition: curves/detail/jubjub/types.hpp:55
typename base_field_type::integral_type integral_type
Definition: curves/detail/jubjub/types.hpp:60
Definition: forms.hpp:34