curves/detail/curve25519/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_CURVE25519_PARAMS_HPP
27 #define CRYPTO3_ALGEBRA_CURVES_CURVE25519_PARAMS_HPP
28 
31 
33 
34 namespace nil {
35  namespace crypto3 {
36  namespace algebra {
37  namespace curves {
38  namespace detail {
42  template<>
43  struct curve25519_params<forms::montgomery> {
46 
47  constexpr static typename curve25519_types::integral_type a =
49  0x76d06);
50  constexpr static typename curve25519_types::integral_type b =
52  0x01);
53  };
54 
55  template<>
56  struct curve25519_g1_params<forms::montgomery> : public curve25519_params<forms::montgomery> {
58 
59  template<typename Coordinates>
61 
62  constexpr static std::array<typename field_type::value_type, 2> zero_fill = {
63  field_type::value_type::zero(), field_type::value_type::one()};
64 
65  constexpr static std::array<typename field_type::value_type, 2> one_fill = {
66  typename field_type::value_type(0x09),
67  typename field_type::value_type(
68  0x20ae19a1b8a086b4e01edd2c7748d14c923d4d7e6d7c61b229e9c5a27eced3d9_cppui254)};
69  };
70 
74  template<>
75  struct curve25519_params<forms::twisted_edwards> {
78 
79  constexpr static typename curve25519_types::integral_type a = typename curve25519_types::integral_type(
80  0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec_cppui255);
86  constexpr static typename curve25519_types::integral_type d = typename curve25519_types::integral_type(
87  0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3_cppui255);
93  };
94 
95  template<>
96  struct curve25519_g1_params<forms::twisted_edwards>
97  : public curve25519_params<forms::twisted_edwards> {
99 
100  template<typename Coordinates>
102 
103  constexpr static std::array<typename field_type::value_type, 2> zero_fill = {
104  field_type::value_type::zero(), field_type::value_type::one()};
105 
106  constexpr static std::array<typename field_type::value_type, 2> one_fill = {
107  typename field_type::value_type(
108  0x216936D3CD6E53FEC0A4E231FDD6DC5C692CC7609525A7B2C9562D608F25D51A_cppui254),
109  typename field_type::value_type(
110  0x6666666666666666666666666666666666666666666666666666666666666658_cppui255)};
111  };
112 
115 
116  constexpr std::array<typename curve25519_g1_params<forms::montgomery>::field_type::value_type, 2>
118  constexpr std::array<typename curve25519_g1_params<forms::montgomery>::field_type::value_type, 2>
120 
123 
124  constexpr std::array<typename curve25519_g1_params<forms::twisted_edwards>::field_type::value_type,
125  2>
127  constexpr std::array<typename curve25519_g1_params<forms::twisted_edwards>::field_type::value_type,
128  2>
130  } // namespace detail
131  } // namespace curves
132  } // namespace algebra
133  } // namespace crypto3
134 } // namespace nil
135 
136 #endif // CRYPTO3_ALGEBRA_CURVES_CURVE25519_PARAMS_HPP
Definition: pair.hpp:31
typename curve25519_types::g1_field_type field_type
Definition: curves/detail/curve25519/params.hpp:57
constexpr static std::array< typename field_type::value_type, 2 > one_fill
Definition: curves/detail/curve25519/params.hpp:65
constexpr static std::array< typename field_type::value_type, 2 > zero_fill
Definition: curves/detail/curve25519/params.hpp:62
constexpr static std::array< typename field_type::value_type, 2 > one_fill
Definition: curves/detail/curve25519/params.hpp:106
constexpr static std::array< typename field_type::value_type, 2 > zero_fill
Definition: curves/detail/curve25519/params.hpp:103
typename curve25519_types::g1_field_type field_type
Definition: curves/detail/curve25519/params.hpp:98
Definition: curves/detail/curve25519/types.hpp:45
A struct representing a group G1 of curve25519 curve.
Definition: curve25519/g1.hpp:46
typename curve25519_types::scalar_field_type scalar_field_type
Definition: curves/detail/curve25519/params.hpp:45
typename curve25519_types::base_field_type base_field_type
Definition: curves/detail/curve25519/params.hpp:44
constexpr static curve25519_types::integral_type a
coefficient of Montgomery curve $b*y^2=x^3+a*x^2+x$
Definition: curves/detail/curve25519/params.hpp:47
constexpr static curve25519_types::integral_type b
coefficient of Montgomery curve $b*y^2=x^3+a*x^2+x$
Definition: curves/detail/curve25519/params.hpp:50
typename curve25519_types::base_field_type base_field_type
Definition: curves/detail/curve25519/params.hpp:76
constexpr static curve25519_types::integral_type a
Definition: curves/detail/curve25519/params.hpp:79
typename curve25519_types::scalar_field_type scalar_field_type
Definition: curves/detail/curve25519/params.hpp:77
constexpr static curve25519_types::integral_type d
Definition: curves/detail/curve25519/params.hpp:86
Definition: curves/detail/curve25519/types.hpp:42
fields::curve25519_scalar_field scalar_field_type
Definition: curves/detail/curve25519/types.hpp:51
fields::curve25519_base_field base_field_type
Definition: curves/detail/curve25519/types.hpp:50
typename base_field_type::integral_type integral_type
Definition: curves/detail/curve25519/types.hpp:55
base_field_type g1_field_type
Definition: curves/detail/curve25519/types.hpp:53
Definition: forms.hpp:34