@@ -172,7 +172,6 @@ namespace nil {
172
172
auto it = adjusted_range.cbegin ();
173
173
marshalling_integral_value_be.template read (it, modulus_octets);
174
174
result = marshalling_integral_value_be.value ();
175
- std::cout << result << std::endl;
176
175
} else {
177
176
// TODO: check correctness of this case
178
177
marshalling_integral_value_le_type marshalling_integral_value_le;
@@ -184,79 +183,69 @@ namespace nil {
184
183
}
185
184
186
185
template <typename InputRange>
187
- static inline modulus_octets_container_type bits2octets (const InputRange &range) {
188
- field_value_type z2 (bits2int (range));
189
- return int2octets (z2);
186
+ static inline modulus_octets_container_type bits2octets (const InputRange& range) {
187
+ return int2octets (field_value_type (bits2int (range)));
190
188
}
191
189
192
190
inline void seed (const result_type& x, const digest_type& h1) {
193
191
// b.
194
192
std::fill (V.begin (), V.end (), 1 );
195
193
196
194
// c.
197
- digest_type K;
198
195
std::fill (K.begin (), K.end (), 0 );
199
- Key = key_type (K);
196
+ key_type Key (K);
200
197
201
198
// d.
202
199
internal_accumulator_type acc_d (Key);
200
+ auto int2octets_x = int2octets (x);
201
+ auto bits2octets_h1 = bits2octets (h1);
203
202
compute<hmac_policy>(V, acc_d);
204
203
compute<hmac_policy>(std::array<std::uint8_t , 1 > {0 }, acc_d);
205
- // int2octets(x)
206
- marshalling_field_element_be_type marshalling_field_element =
207
- ::nil::crypto3::marshalling::types::fill_field_element<field_type,
208
- ::nil::marshalling::option::big_endian>(
209
- x);
210
- modulus_octets_container_type modulus_octet_container;
211
- marshalling_field_element.template write (modulus_octet_container.begin (), modulus_octets);
212
- compute<hmac_policy>(modulus_octet_container, acc_d);
213
- compute<hmac_policy>(h1, acc_d);
214
- Key = key_type (
215
- ::nil::crypto3::accumulators::extract::mac<mac::computation_policy<hmac_policy>>(acc_d));
204
+ compute<hmac_policy>(int2octets_x, acc_d);
205
+ compute<hmac_policy>(bits2octets_h1, acc_d);
206
+ Key = key_type (::nil::crypto3::accumulators::extract::mac<mac::computation_policy<hmac_policy>>(acc_d));
216
207
217
208
// e.
218
- internal_accumulator_type acc_e (Key);
219
- compute<hmac_policy>(V, acc_e);
220
- V = ::nil::crypto3::accumulators::extract::mac<mac::computation_policy<hmac_policy>>(acc_e);
209
+ V = compute<hmac_policy>(V, Key);
221
210
222
211
// f.
223
212
internal_accumulator_type acc_f (Key);
224
213
compute<hmac_policy>(V, acc_f);
225
214
compute<hmac_policy>(std::array<std::uint8_t , 1 > {1 }, acc_f);
226
- compute<hmac_policy>(modulus_octet_container , acc_f);
227
- compute<hmac_policy>(h1 , acc_f);
228
- Key = key_type (
229
- ::nil::crypto3::accumulators::extract::mac<mac::computation_policy<hmac_policy>>(acc_f) );
215
+ compute<hmac_policy>(int2octets_x , acc_f);
216
+ compute<hmac_policy>(bits2octets_h1 , acc_f);
217
+ K = ::nil::crypto3::accumulators::extract::mac<mac::computation_policy<hmac_policy>>(acc_f);
218
+ Key = key_type (K );
230
219
231
220
// g.
232
- internal_accumulator_type acc_g (Key);
233
- compute<hmac_policy>(V, acc_g);
234
- V = ::nil::crypto3::accumulators::extract::mac<mac::computation_policy<hmac_policy>>(acc_g);
221
+ V = compute<hmac_policy>(V, Key);
235
222
}
236
223
237
224
inline result_type operator ()() {
238
225
// h.
239
226
do {
240
- std::vector <std::uint8_t > T;
227
+ std::array <std::uint8_t , digest_chunks * digest_octets > T;
241
228
242
229
// h.2.
230
+ key_type Key (K);
243
231
for (auto i = 0 ; i < digest_chunks; i++) {
244
- digest_type T_temp = compute<hmac_policy>(V, Key);
245
- std::copy (T_temp .cbegin (), T_temp .cend (), std::back_inserter (T) );
232
+ V = compute<hmac_policy>(V, Key);
233
+ std::copy (V .cbegin (), V .cend (), T. begin () + i * digest_octets );
246
234
}
247
235
248
236
// h.3.
249
- // TODO: use marshalling
250
- integral_type k;
251
- ::nil::crypto3::multiprecision::import_bits (k, T.begin(), T.begin() + modulus_octets, 8, false);
252
- if (1 < k && k < field_type::modulus) {
237
+ integral_type k = bits2int (T);
238
+ if (0 < k && k < field_type::modulus) {
253
239
return k;
254
240
}
255
241
256
- // marshalling_field_element_type marshalling_field_element;
257
- // marshalling_field_element.read(T.begin(), modulus_octets);
258
- // return crypto3::marshalling::types::construct_field_element<field_type, endianness>(
259
- // marshalling_field_element);
242
+ internal_accumulator_type acc_h3 (Key);
243
+ compute<hmac_policy>(V, acc_h3);
244
+ compute<hmac_policy>(std::array<std::uint8_t , 1 > {0 }, acc_h3);
245
+ K = ::nil::crypto3::accumulators::extract::mac<mac::computation_policy<hmac_policy>>(acc_h3);
246
+
247
+ Key = key_type (K);
248
+ V = compute<hmac_policy>(V, Key);
260
249
} while (true );
261
250
}
262
251
@@ -294,7 +283,7 @@ namespace nil {
294
283
295
284
protected:
296
285
digest_type V;
297
- key_type Key ;
286
+ digest_type K ;
298
287
};
299
288
} // namespace random
300
289
} // namespace crypto3
0 commit comments