@@ -124,7 +124,6 @@ namespace nil {
124
124
// TODO: local_char_bits is supposed to equal chunk_size from import_bits call in marshalling
125
125
constexpr std::size_t local_char_bits = 8 ;
126
126
constexpr std::size_t adjustment_shift = modulus_octets * local_char_bits - modulus_bits;
127
- constexpr std::size_t bits_remain = local_char_bits - adjustment_shift;
128
127
constexpr std::size_t chunk_size = std::numeric_limits<ValueType>::digits;
129
128
using bitset_repr_type = std::bitset<chunk_size>;
130
129
@@ -158,12 +157,9 @@ namespace nil {
158
157
return result;
159
158
}
160
159
161
- template <
162
- typename InputRange,
163
- typename std::enable_if<
164
- std::is_same<std::uint8_t ,
165
- typename std::iterator_traits<typename InputRange::iterator>::value_type>::value,
166
- bool >::type = true >
160
+ template <typename InputRange,
161
+ typename ValueType = typename std::iterator_traits<typename InputRange::iterator>::value_type,
162
+ typename std::enable_if<std::is_same<std::uint8_t , ValueType>::value, bool >::type = true >
167
163
static inline integral_type bits2int (const InputRange& range) {
168
164
integral_type result;
169
165
if (modulus_bits < range.size () * 8 ) {
@@ -173,11 +169,17 @@ namespace nil {
173
169
marshalling_integral_value_be.template read (it, modulus_octets);
174
170
result = marshalling_integral_value_be.value ();
175
171
} else {
176
- // TODO: check correctness of this case
177
- marshalling_integral_value_le_type marshalling_integral_value_le;
178
- auto it = range.crbegin ();
179
- marshalling_integral_value_le.template read (it, range.size ());
180
- result = marshalling_integral_value_le.value ();
172
+ // TODO: creating copy of input range of modulus_octets size is a bottleneck:
173
+ // extend marshaling interface by function supporting initialization from container which
174
+ // length is less than modulus_octets
175
+ // TODO: check need for adjust_bitstring call
176
+ modulus_octets_container_type range_padded;
177
+ range_padded.fill (0 );
178
+ std::copy (std::crbegin (range), std::crend (range), std::rbegin (range_padded));
179
+ marshalling_integral_value_be_type marshalling_integral_value_be;
180
+ auto it = std::cbegin (range_padded);
181
+ marshalling_integral_value_be.template read (it, range_padded.size ());
182
+ result = marshalling_integral_value_be.value ();
181
183
}
182
184
return result;
183
185
}
@@ -203,7 +205,8 @@ namespace nil {
203
205
compute<hmac_policy>(std::array<std::uint8_t , 1 > {0 }, acc_d);
204
206
compute<hmac_policy>(int2octets_x, acc_d);
205
207
compute<hmac_policy>(bits2octets_h1, acc_d);
206
- Key = key_type (::nil::crypto3::accumulators::extract::mac<mac::computation_policy<hmac_policy>>(acc_d));
208
+ Key = key_type (
209
+ ::nil::crypto3::accumulators::extract::mac<mac::computation_policy<hmac_policy>>(acc_d));
207
210
208
211
// e.
209
212
V = compute<hmac_policy>(V, Key);
@@ -249,38 +252,6 @@ namespace nil {
249
252
} while (true );
250
253
}
251
254
252
- // inline void discard(std::size_t n) {
253
- // if (n > 0 && !cached) {
254
- // operator()();
255
- // }
256
- // }
257
- //
258
- // inline bool operator==(const hash& other) const {
259
- // return state == other.state;
260
- // }
261
- //
262
- // inline bool operator!=(const hash& other) const {
263
- // return !(*this == other);
264
- // }
265
- //
266
- // /** Writes a rfc6979 to a @c std::ostream */
267
- // template<class CharT, class Traits>
268
- // friend std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os,
269
- // const algebraic_engine& e) {
270
- // os << e.state;
271
- // return os;
272
- // }
273
- //
274
- // /** Reads a rfc6979 from a @c std::istream */
275
- // template<class CharT, class Traits>
276
- // friend std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is,
277
- // algebraic_engine& e) {
278
- // input_type x;
279
- // is >> x;
280
- // e.seed(x);
281
- // return is;
282
- // }
283
-
284
255
protected:
285
256
digest_type V;
286
257
digest_type K;
0 commit comments