bls_basic_policy.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2018-2020 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_PUBKEY_BLS_BASIC_POLICY_HPP
27 #define CRYPTO3_PUBKEY_BLS_BASIC_POLICY_HPP
28 
29 #include <cstddef>
30 
32 #include <nil/crypto3/hash/h2c.hpp>
33 
36 
37 namespace nil {
38  namespace crypto3 {
39  namespace pubkey {
40  namespace detail {
41  template<typename CurveType>
43  typedef CurveType curve_type;
44 
45  typedef typename curve_type::scalar_field_type scalar_field_type;
46  typedef typename scalar_field_type::value_type private_key_type;
47  typedef typename scalar_field_type::modular_type scalar_modular_type;
48  typedef typename curve_type::gt_type::value_type gt_value_type;
49 
50  constexpr static std::size_t private_key_bits = scalar_field_type::modulus_bits;
51  constexpr static scalar_modular_type r = curve_type::q;
52  };
53 
54  //
55  // Minimal-signature-size
56  // Random oracle version of hash-to-point
57  //
58  template<typename PublicParams, typename CurveType>
61 
65 
66  // TODO: pass template parameters for Coordinates and Form of the group
67  typedef typename curve_type::template g2_type<> public_key_group_type;
68  typedef typename curve_type::template g1_type<> signature_group_type;
69 
71  typedef typename public_key_group_type::value_type public_key_type;
72  typedef typename signature_group_type::value_type signature_type;
73 
75  typedef typename bls_serializer::compressed_g2_octets public_key_serialized_type;
76  typedef typename bls_serializer::compressed_g1_octets signature_serialized_type;
77 
78  constexpr static const std::size_t private_key_bits = basic_policy::private_key_bits;
79  constexpr static const std::size_t public_key_bits = public_key_type::value_bits;
80  constexpr static const std::size_t signature_bits = signature_type::value_bits;
81 
84 
85  static inline gt_value_type pairing(const signature_type &U, const public_key_type &V) {
86  return algebra::pair_reduced<curve_type>(U, V);
87  }
88  };
89 
90  //
91  // Minimal-pubkey-size
92  // Random oracle version of hash-to-point
93  //
94  template<typename PublicParams, typename CurveType>
97 
101 
102  // TODO: pass template parameters for Coordinates and Form of the group
103  typedef typename curve_type::template g1_type<> public_key_group_type;
104  typedef typename curve_type::template g2_type<> signature_group_type;
105 
107  typedef typename public_key_group_type::value_type public_key_type;
108  typedef typename signature_group_type::value_type signature_type;
109 
111  typedef typename bls_serializer::compressed_g1_octets public_key_serialized_type;
112  typedef typename bls_serializer::compressed_g2_octets signature_serialized_type;
113 
114  constexpr static const std::size_t private_key_bits = basic_policy::private_key_bits;
115  constexpr static const std::size_t public_key_bits = public_key_type::value_bits;
116  constexpr static const std::size_t signature_bits = signature_type::value_bits;
117 
120 
121  static inline gt_value_type pairing(const signature_type &U, const public_key_type &V) {
122  return algebra::pair_reduced<curve_type>(V, U);
123  }
124 
126  return bls_serializer::point_to_octets_compress(pubkey);
127  }
128 
130  return bls_serializer::point_to_octets_compress(sig);
131  }
132  };
133  } // namespace detail
134  } // namespace pubkey
135  } // namespace crypto3
136 } // namespace nil
137 
138 #endif // CRYPTO3_PUBKEY_BLS_BASIC_POLICY_HPP
boost::accumulators::accumulator_set< typename Hash::result_type, boost::accumulators::features< hashes::accumulators::tag::to_curve< Hash > >> hashing_to_curve_accumulator_set
Accumulator set with pre-defined hashing to curve accumulator params.
Definition: to_curve_state.hpp:46
boost::mpl::apply< AccumulatorSet, tag::pubkey< ProcessingMode > >::type::result_type pubkey(const AccumulatorSet &acc)
Definition: accumulators/pubkey.hpp:106
Definition: pair.hpp:31
Hashing to Elliptic Curves https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-11.
Definition: h2c.hpp:62
Definition: bls_basic_policy.hpp:42
scalar_field_type::modular_type scalar_modular_type
Definition: bls_basic_policy.hpp:47
curve_type::scalar_field_type scalar_field_type
Definition: bls_basic_policy.hpp:45
curve_type::gt_type::value_type gt_value_type
Definition: bls_basic_policy.hpp:48
scalar_field_type::value_type private_key_type
Definition: bls_basic_policy.hpp:46
constexpr static std::size_t private_key_bits
Definition: bls_basic_policy.hpp:50
CurveType curve_type
Definition: bls_basic_policy.hpp:43
constexpr static scalar_modular_type r
Definition: bls_basic_policy.hpp:51
Definition: bls_basic_policy.hpp:95
constexpr static const std::size_t public_key_bits
Definition: bls_basic_policy.hpp:115
signature_group_type::value_type signature_type
Definition: bls_basic_policy.hpp:108
bls_serializer::compressed_g2_octets signature_serialized_type
Definition: bls_basic_policy.hpp:112
nil::marshalling::curve_element_serializer< curve_type > bls_serializer
Definition: bls_basic_policy.hpp:110
bls_serializer::compressed_g1_octets public_key_serialized_type
Definition: bls_basic_policy.hpp:111
basic_policy::curve_type curve_type
Definition: bls_basic_policy.hpp:98
basic_policy::scalar_modular_type scalar_modular_type
Definition: bls_basic_policy.hpp:100
curve_type::template g1_type public_key_group_type
Definition: bls_basic_policy.hpp:103
static signature_serialized_type point_to_signature(const signature_type &sig)
Definition: bls_basic_policy.hpp:129
static public_key_serialized_type point_to_pubkey(const public_key_type &pubkey)
Definition: bls_basic_policy.hpp:125
hashes::h2c< signature_group_type, PublicParams > h2c_policy
Definition: bls_basic_policy.hpp:118
bls_basic_policy< CurveType > basic_policy
Definition: bls_basic_policy.hpp:96
curve_type::template g2_type signature_group_type
Definition: bls_basic_policy.hpp:104
basic_policy::private_key_type private_key_type
Definition: bls_basic_policy.hpp:106
static gt_value_type pairing(const signature_type &U, const public_key_type &V)
Definition: bls_basic_policy.hpp:121
public_key_group_type::value_type public_key_type
Definition: bls_basic_policy.hpp:107
constexpr static const std::size_t signature_bits
Definition: bls_basic_policy.hpp:116
basic_policy::gt_value_type gt_value_type
Definition: bls_basic_policy.hpp:99
hashing_to_curve_accumulator_set< h2c_policy > internal_accumulator_type
Definition: bls_basic_policy.hpp:119
constexpr static const std::size_t private_key_bits
Definition: bls_basic_policy.hpp:114
Definition: bls_basic_policy.hpp:59
bls_serializer::compressed_g2_octets public_key_serialized_type
Definition: bls_basic_policy.hpp:75
basic_policy::gt_value_type gt_value_type
Definition: bls_basic_policy.hpp:63
basic_policy::curve_type curve_type
Definition: bls_basic_policy.hpp:62
bls_basic_policy< CurveType > basic_policy
Definition: bls_basic_policy.hpp:60
hashes::h2c< signature_group_type, PublicParams > h2c_policy
Definition: bls_basic_policy.hpp:82
basic_policy::scalar_modular_type scalar_modular_type
Definition: bls_basic_policy.hpp:64
public_key_group_type::value_type public_key_type
Definition: bls_basic_policy.hpp:71
bls_serializer::compressed_g1_octets signature_serialized_type
Definition: bls_basic_policy.hpp:76
curve_type::template g1_type signature_group_type
Definition: bls_basic_policy.hpp:68
curve_type::template g2_type public_key_group_type
Definition: bls_basic_policy.hpp:67
constexpr static const std::size_t public_key_bits
Definition: bls_basic_policy.hpp:79
nil::marshalling::curve_element_serializer< curve_type > bls_serializer
Definition: bls_basic_policy.hpp:74
constexpr static const std::size_t signature_bits
Definition: bls_basic_policy.hpp:80
static gt_value_type pairing(const signature_type &U, const public_key_type &V)
Definition: bls_basic_policy.hpp:85
constexpr static const std::size_t private_key_bits
Definition: bls_basic_policy.hpp:78
signature_group_type::value_type signature_type
Definition: bls_basic_policy.hpp:72
basic_policy::private_key_type private_key_type
Definition: bls_basic_policy.hpp:70
hashing_to_curve_accumulator_set< h2c_policy > internal_accumulator_type
Definition: bls_basic_policy.hpp:83
Definition: algebra/include/nil/crypto3/algebra/curves/detail/marshalling.hpp:43