@@ -117,24 +117,20 @@ namespace boost {
117
117
};
118
118
119
119
template <typename CurveParams>
120
- struct print_log_value <curves::detail::curve_element<CurveParams,
121
- curves::forms::short_weierstrass,
120
+ struct print_log_value <curves::detail::curve_element<CurveParams, curves::forms::short_weierstrass,
122
121
curves::coordinates::jacobian_with_a4_0>> {
123
122
void operator ()(std::ostream &os,
124
- curves::detail::curve_element<CurveParams,
125
- curves::forms::short_weierstrass,
123
+ curves::detail::curve_element<CurveParams, curves::forms::short_weierstrass,
126
124
curves::coordinates::jacobian_with_a4_0> const &p) {
127
125
print_projective_curve_group_element (os, p);
128
126
}
129
127
};
130
128
131
129
template <typename CurveParams>
132
- struct print_log_value <curves::detail::curve_element<CurveParams,
133
- curves::forms::short_weierstrass,
130
+ struct print_log_value <curves::detail::curve_element<CurveParams, curves::forms::short_weierstrass,
134
131
curves::coordinates::affine>> {
135
132
void operator ()(std::ostream &os,
136
- curves::detail::curve_element<CurveParams,
137
- curves::forms::short_weierstrass,
133
+ curves::detail::curve_element<CurveParams, curves::forms::short_weierstrass,
138
134
curves::coordinates::affine> const &p) {
139
135
print_affine_curve_group_element (os, p);
140
136
}
@@ -213,100 +209,121 @@ BOOST_AUTO_TEST_CASE(threshold_bls_feldman_self_test) {
213
209
// threshold number of participants aggregate partial signatures
214
210
// TODO: add simplified call interface for aggregate and verify
215
211
typename pubkey_type::signature_type sig =
216
- nil::crypto3::aggregate<scheme_type, decltype (part_signatures. begin ( )), aggregation_processing_mode_type>(
217
- part_signatures. begin ( ), part_signatures. begin ( ) + t);
212
+ nil::crypto3::aggregate<scheme_type, decltype (std::cbegin (part_signatures )), aggregation_processing_mode_type>(
213
+ std::cbegin (part_signatures ), std::cbegin (part_signatures ) + t);
218
214
BOOST_CHECK (static_cast <bool >(
219
215
nil::crypto3::verify<scheme_type, decltype (msg), verification_processing_mode_type>(msg, sig, PK)));
220
216
221
217
// ===========================================================================
222
218
// less than threshold number of participants cannot aggregate partial signatures
223
219
// TODO: add simplified call interface for aggregate and verify
224
220
typename pubkey_type::signature_type wrong_sig =
225
- nil::crypto3::aggregate<scheme_type, decltype (part_signatures. begin ( )), aggregation_processing_mode_type>(
226
- part_signatures. begin ( ), part_signatures. begin ( ) + t - 1 );
221
+ nil::crypto3::aggregate<scheme_type, decltype (std::cbegin (part_signatures )), aggregation_processing_mode_type>(
222
+ std::cbegin (part_signatures ), std::cbegin (part_signatures ) + t - 1 );
227
223
BOOST_CHECK (!static_cast <bool >(
228
224
nil::crypto3::verify<scheme_type, decltype (msg), verification_processing_mode_type>(msg, wrong_sig, PK)));
229
225
}
230
226
231
- // BOOST_AUTO_TEST_CASE(threshold_bls_pedersen_self_test) {
232
- // using curve_type = curves::bls12_381;
233
- // using hash_type = sha2<256>;
234
- // using bls_variant = bls_mps_ro_variant<curve_type, hash_type>;
235
- // using base_scheme_type = bls<bls_variant, bls_basic_scheme>;
236
- // using mode_type = modes::threshold<base_scheme_type, pedersen_dkg, nop_padding>;
237
- // using scheme_type = typename mode_type::scheme_type;
238
- // using privkey_type = private_key<scheme_type>;
239
- // using pubkey_type = public_key<scheme_type>;
240
- // using no_key_type = no_key_ops<scheme_type>;
241
- // using sss_pubkey_group_type = typename privkey_type::sss_public_key_group_type;
242
- // using sss_pubkey_no_key_type = typename privkey_type::sss_public_key_no_key_ops_type;
243
- //
244
- // std::size_t n = 20;
245
- // std::size_t t = 10;
246
- //
247
- // //===========================================================================
248
- // // every participant generates polynomial
249
- //
250
- // std::vector<typename sss_pubkey_no_key_type::coeffs_type> P_polys;
251
- // std::generate_n(std::back_inserter(P_polys), n, [t, n]() { return sss_pubkey_no_key_type::get_poly(t, n); });
252
- //
253
- // //===========================================================================
254
- // // each participant calculates public values representing coefficients of its polynomial,
255
- // // then he broadcasts these values
256
- //
257
- // std::vector<typename sss_pubkey_no_key_type::public_coeffs_type> P_public_polys;
258
- // std::transform(P_polys.begin(), P_polys.end(), std::back_inserter(P_public_polys),
259
- // [](const auto &poly_i) { return sss_pubkey_no_key_type::get_public_coeffs(poly_i); });
260
- //
261
- // //===========================================================================
262
- // // every participant generates shares for each participant in group,
263
- // // which he then transmits to the intended parties
264
- //
265
- // std::vector<typename sss_pubkey_no_key_type::shares_type> P_generated_shares;
266
- // std::transform(P_polys.begin(), P_polys.end(), std::back_inserter(P_generated_shares), [n, t](const auto &poly_i)
267
- // {
268
- // return static_cast<typename sss_pubkey_no_key_type::shares_type>(
269
- // nil::crypto3::deal_shares<sss_pubkey_group_type>(poly_i, n));
270
- // });
271
- //
272
- // std::vector<std::vector<typename sss_pubkey_no_key_type::share_type>> P_received_shares(n);
273
- // for (auto &i_generated_shares : P_generated_shares) {
274
- // for (auto it = i_generated_shares.begin(); it != i_generated_shares.end(); it++) {
275
- // P_received_shares.at(it->first - 1).emplace_back(*it);
276
- // }
277
- // }
278
- //
279
- // //===========================================================================
280
- // // each participant check received share and create key
281
- //
282
- // std::vector<pubkey_type> PKs;
283
- // std::vector<privkey_type> privkeys;
284
- // for (auto &shares : P_received_shares) {
285
- // auto [PK_temp, privkey] = nil::crypto3::create_key<scheme_type>(P_public_polys, shares, n);
286
- // PKs.emplace_back(PK_temp);
287
- // privkeys.emplace_back(privkey);
288
- // }
289
- //
290
- // //===========================================================================
291
- // // participants sign messages and verify its signatures
292
- // std::vector<typename privkey_type::part_signature_type> part_signatures;
293
- // for (auto &sk : privkeys) {
294
- // part_signatures.emplace_back(nil::crypto3::sign<mode_type>(msg, sk));
295
- // BOOST_CHECK(static_cast<bool>(nil::crypto3::part_verify<mode_type>(msg, part_signatures.back(), sk)));
296
- // }
297
- //
298
- // //===========================================================================
299
- // // threshold number of participants aggregate partial signatures
300
- // typename no_key_type::signature_type sig =
301
- // nil::crypto3::aggregate<mode_type>(part_signatures.begin(), part_signatures.begin() + t);
302
- // BOOST_CHECK(static_cast<bool>(nil::crypto3::verify<mode_type>(msg, sig, PKs.back())));
303
- //
304
- // //===========================================================================
305
- // // less than threshold number of participants cannot aggregate partial signatures
306
- // typename no_key_type::signature_type wrong_sig =
307
- // nil::crypto3::aggregate<mode_type>(part_signatures.begin(), part_signatures.begin() + t - 1);
308
- // BOOST_CHECK(!static_cast<bool>(nil::crypto3::verify<mode_type>(msg, wrong_sig, PKs.back())));
309
- // }
227
+ BOOST_AUTO_TEST_CASE (threshold_bls_pedersen_self_test) {
228
+ using curve_type = algebra::curves::bls12_381;
229
+ using base_scheme_type = bls<bls_default_public_params<>, bls_mps_ro_version, bls_basic_scheme, curve_type>;
230
+
231
+ using mode_type = modes::threshold<base_scheme_type, pedersen_dkg>;
232
+ using scheme_type = typename mode_type::scheme_type;
233
+ using privkey_type = private_key<scheme_type>;
234
+ using pubkey_type = public_key<scheme_type>;
235
+
236
+ using sss_public_key_group_type = typename pubkey_type::sss_public_key_group_type;
237
+ using shares_dealing_processing_mode = typename pubkey::modes::isomorphic<sss_public_key_group_type>::template bind<
238
+ pubkey::shares_dealing_policy<sss_public_key_group_type>>::type;
239
+ using share_dealing_processing_mode = typename pubkey::modes::isomorphic<sss_public_key_group_type>::template bind<
240
+ pubkey::share_dealing_policy<sss_public_key_group_type>>::type;
241
+ using signing_processing_mode_type = typename mode_type::template bind<typename mode_type::signing_policy>::type;
242
+ using verification_processing_mode_type =
243
+ typename mode_type::template bind<typename mode_type::verification_policy>::type;
244
+ using aggregation_processing_mode_type =
245
+ typename mode_type::template bind<typename mode_type::aggregation_policy>::type;
246
+
247
+ std::size_t n = 20 ;
248
+ std::size_t t = 10 ;
249
+
250
+ // ===========================================================================
251
+ // every participant generates polynomial
252
+
253
+ // TODO: add public interface for get_poly and get_public_coeffs
254
+ std::vector<typename sss_public_key_group_type::coeffs_type> P_polys;
255
+ std::generate_n (std::back_inserter (P_polys), n, [t, n]() { return sss_public_key_group_type::get_poly (t, n); });
256
+
257
+ // ===========================================================================
258
+ // each participant calculates public values representing coefficients of its polynomial,
259
+ // then he broadcasts these values
260
+
261
+ std::vector<typename sss_public_key_group_type::public_coeffs_type> P_public_polys;
262
+ std::transform (P_polys.begin (), P_polys.end (), std::back_inserter (P_public_polys),
263
+ [](const auto &poly_i) { return sss_public_key_group_type::get_public_coeffs (poly_i); });
264
+
265
+ // ===========================================================================
266
+ // every participant generates shares for each participant in group,
267
+ // which he then transmits to the intended parties
268
+
269
+ std::vector<typename shares_dealing_processing_mode::result_type> P_generated_shares;
270
+ std::transform (std::cbegin (P_polys), std::cend (P_polys), std::back_inserter (P_generated_shares),
271
+ [n, t](const auto &poly_i) {
272
+ return static_cast <typename shares_dealing_processing_mode::result_type>(
273
+ nil::crypto3::deal_shares<sss_public_key_group_type>(poly_i, n));
274
+ });
275
+
276
+ std::vector<std::vector<share_sss<sss_public_key_group_type>>> P_received_shares (n);
277
+ for (auto &i_generated_shares : P_generated_shares) {
278
+ for (auto it = std::cbegin (i_generated_shares); it != std::cend (i_generated_shares); it++) {
279
+ P_received_shares.at (it->get_index () - 1 ).emplace_back (*it);
280
+ }
281
+ }
282
+
283
+ // ===========================================================================
284
+ // each participant check received share and create key
285
+
286
+ std::vector<pubkey_type> PKs;
287
+ std::vector<privkey_type> privkeys;
288
+ for (auto &shares : P_received_shares) {
289
+ auto [PK_i, privkey] = nil::crypto3::create_key<scheme_type>(P_public_polys, shares, n);
290
+ PKs.emplace_back (PK_i);
291
+ privkeys.emplace_back (privkey);
292
+ }
293
+
294
+ // ===========================================================================
295
+ // participants sign messages and verify its signatures
296
+
297
+ std::vector<typename privkey_type::part_signature_type> part_signatures;
298
+ for (auto &sk : privkeys) {
299
+ // TODO: add simplified call interface for sign
300
+ part_signatures.emplace_back (
301
+ nil::crypto3::sign<scheme_type, decltype (msg), signing_processing_mode_type>(msg, sk));
302
+ BOOST_CHECK (static_cast <bool >(nil::crypto3::part_verify<mode_type>(msg, part_signatures.back (), sk)));
303
+ BOOST_CHECK (!static_cast <bool >(nil::crypto3::part_verify<mode_type>(
304
+ msg, typename privkey_type::part_signature_type (part_signatures.back ().get_index ()), sk)));
305
+ }
306
+
307
+ // ===========================================================================
308
+ // threshold number of participants aggregate partial signatures
309
+
310
+ // TODO: add simplified call interface for aggregate and verify
311
+ typename pubkey_type::signature_type sig =
312
+ nil::crypto3::aggregate<scheme_type, decltype (std::cbegin (part_signatures)), aggregation_processing_mode_type>(
313
+ std::cbegin (part_signatures), std::cbegin (part_signatures) + t);
314
+ BOOST_CHECK (static_cast <bool >(
315
+ nil::crypto3::verify<scheme_type, decltype (msg), verification_processing_mode_type>(msg, sig, PKs.back ())));
316
+
317
+ // ===========================================================================
318
+ // less than threshold number of participants cannot aggregate partial signatures
319
+
320
+ // TODO: add simplified call interface for aggregate and verify
321
+ typename pubkey_type::signature_type wrong_sig =
322
+ nil::crypto3::aggregate<scheme_type, decltype (std::cbegin (part_signatures)), aggregation_processing_mode_type>(
323
+ std::cbegin (part_signatures), std::cbegin (part_signatures) + t - 1 );
324
+ BOOST_CHECK (!static_cast <bool >(nil::crypto3::verify<scheme_type, decltype (msg), verification_processing_mode_type>(
325
+ msg, wrong_sig, PKs.back ())));
326
+ }
310
327
311
328
// BOOST_AUTO_TEST_CASE(threshold_bls_weighted_shamir_test) {
312
329
// using curve_type = curves::bls12_381;
0 commit comments