26 #ifndef CRYPTO3_ALGEBRA_CURVES_HASH_TO_CURVE_EXPAND_HPP
27 #define CRYPTO3_ALGEBRA_CURVES_HASH_TO_CURVE_EXPAND_HPP
39 #include <boost/assert.hpp>
40 #include <boost/static_assert.hpp>
41 #include <boost/concept/assert.hpp>
44 #include <type_traits>
53 template<std::size_t k,
typename HashType,
55 typename =
typename std::enable_if<
56 std::is_same<std::uint8_t, typename HashType::digest_type::value_type>::value>::type>
59 BOOST_STATIC_ASSERT_MSG(HashType::block_bits % 8 == 0,
"r_in_bytes is not a multiple of 8");
60 BOOST_STATIC_ASSERT_MSG(HashType::digest_bits % 8 == 0,
"b_in_bytes is not a multiple of 8");
61 BOOST_STATIC_ASSERT_MSG(HashType::digest_bits >= 2 * k,
62 "k-bit collision resistance is not fulfilled");
64 constexpr
static const std::size_t b_in_bytes = HashType::digest_bits / 8;
65 constexpr
static const std::size_t r_in_bytes = HashType::block_bits / 8;
67 constexpr
static const std::array<std::uint8_t, r_in_bytes> Z_pad {0};
70 template<
typename InputMsgType,
typename InputDstType,
typename OutputType,
71 typename =
typename std::enable_if<
72 std::is_same<std::uint8_t, typename InputMsgType::value_type>::value &&
73 std::is_same<std::uint8_t, typename InputDstType::value_type>::value &&
74 std::is_same<std::uint8_t, typename OutputType::value_type>::value>::type>
75 static inline void process(
const std::size_t len_in_bytes,
const InputMsgType &msg,
76 const InputDstType &dst, OutputType &uniform_bytes) {
77 BOOST_CONCEPT_ASSERT((boost::SinglePassRangeConcept<InputMsgType>));
78 BOOST_CONCEPT_ASSERT((boost::SinglePassRangeConcept<InputDstType>));
79 BOOST_CONCEPT_ASSERT((boost::SinglePassRangeConcept<OutputType>));
80 BOOST_CONCEPT_ASSERT((boost::WriteableRangeConcept<OutputType>));
83 BOOST_ASSERT(len_in_bytes < 0x10000);
84 BOOST_ASSERT(std::distance(dst.begin(), dst.end()) >= 16 &&
85 std::distance(dst.begin(), dst.end()) <= 255);
86 BOOST_ASSERT(std::distance(uniform_bytes.begin(), uniform_bytes.end()) >= len_in_bytes);
88 const std::array<std::uint8_t, 2> l_i_b_str = {
89 static_cast<std::uint8_t
>(len_in_bytes >> 8u),
90 static_cast<std::uint8_t
>(len_in_bytes % 0x100)};
91 const std::size_t ell =
static_cast<std::size_t
>(len_in_bytes / b_in_bytes) +
92 static_cast<std::size_t
>(len_in_bytes % b_in_bytes != 0);
95 BOOST_ASSERT(ell <= 255);
107 std::vector<std::uint8_t> msg_prime;
108 msg_prime.insert(msg_prime.end(), Z_pad.begin(), Z_pad.end());
109 msg_prime.insert(msg_prime.end(), msg.begin(), msg.end());
110 msg_prime.insert(msg_prime.end(), l_i_b_str.begin(), l_i_b_str.end());
111 msg_prime.insert(msg_prime.end(),
static_cast<std::uint8_t
>(0));
112 msg_prime.insert(msg_prime.end(), dst.begin(), dst.end());
113 msg_prime.insert(msg_prime.end(),
114 static_cast<std::uint8_t
>(std::distance(dst.begin(), dst.end())));
115 typename HashType::digest_type b0 = hash<HashType>(msg_prime);
126 std::vector<std::uint8_t> b_i_str;
127 b_i_str.insert(b_i_str.end(), b0.begin(), b0.end());
128 b_i_str.insert(b_i_str.end(),
static_cast<std::uint8_t
>(1));
129 b_i_str.insert(b_i_str.end(), dst.begin(), dst.end());
130 b_i_str.insert(b_i_str.end(),
131 static_cast<std::uint8_t
>(std::distance(dst.begin(), dst.end())));
132 typename HashType::digest_type bi = hash<HashType>(b_i_str);
133 std::copy(bi.begin(), bi.end(), uniform_bytes.begin());
135 typename HashType::digest_type xored_b;
136 for (std::size_t i = 2; i <= ell; i++) {
148 std::vector<std::uint8_t> b_i_str;
149 b_i_str.insert(b_i_str.end(), xored_b.begin(), xored_b.end());
150 b_i_str.insert(b_i_str.end(),
static_cast<std::uint8_t
>(i));
151 b_i_str.insert(b_i_str.end(), dst.begin(), dst.end());
152 b_i_str.insert(b_i_str.end(),
153 static_cast<std::uint8_t
>(std::distance(dst.begin(), dst.end())));
154 bi = hash<HashType>(b_i_str);
155 std::copy(bi.begin(), bi.end(), uniform_bytes.begin() + (i - 1) * b_in_bytes);
Definition: h2c_expand.hpp:57
static void process(const std::size_t len_in_bytes, const InputMsgType &msg, const InputDstType &dst, OutputType &uniform_bytes)
Definition: h2c_expand.hpp:75
constexpr std::enable_if< std::is_same< typename std::iterator_traits< InputIterator1 >::value_type, typename std::iterator_traits< InputIterator2 >::value_type >::value, OutputIterator >::type strxor(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator out)
Definition: algebra/include/nil/crypto3/algebra/algorithms/strxor.hpp:42
Definition: algebra/include/nil/crypto3/detail/make_array.hpp:33