1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! Operations over the BLS12-381 scalar field.
//!
//! # Acknowledgements
//!
//! _The following crates were used as a reference when implementing this crate. If code is very similar
//! to the reference, it is accompanied by a comment and link._
//!
//! * <https://github.com/celo-org/celo-threshold-bls-rs>: Operations over the BLS12-381 scalar field, GJKR99, and Desmedt97.
//! * <https://github.com/filecoin-project/blstrs> + <https://github.com/MystenLabs/fastcrypto>: Implementing operations over
//! the BLS12-381 scalar field with <https://github.com/supranational/blst>.
//! * <https://github.com/supranational/blst/blob/v0.3.13/bindings/rust/src/pippenger.rs>: Parallel MSM using tile-based Pippenger.
//!
//! # Example
//!
//! ```rust
//! use commonware_cryptography::bls12381::{
//! primitives::{ops::{self, threshold}, variant::MinSig, sharing::Mode},
//! dkg,
//! };
//! use commonware_utils::{NZU32, N3f1};
//! use rand::rngs::OsRng;
//!
//! // Configure number of players
//! let n = NZU32!(5);
//!
//! // Generate commitment and shares
//! let (sharing, shares) = dkg::deal_anonymous::<MinSig, N3f1>(&mut OsRng, Mode::default(), n);
//!
//! // Generate partial signatures from shares
//! let namespace = b"demo";
//! let message = b"hello world";
//! let partials: Vec<_> = shares.iter().map(|s| threshold::sign_message::<MinSig>(s, namespace, message)).collect();
//!
//! // Verify partial signatures
//! for p in &partials {
//! threshold::verify_message::<MinSig>(&sharing, namespace, message, p).expect("signature should be valid");
//! }
//!
//! // Aggregate partial signatures
//! let threshold_sig = threshold::recover::<MinSig, _, N3f1>(&sharing, &partials, &commonware_parallel::Sequential).unwrap();
//!
//! // Verify threshold signature
//! let threshold_pub = sharing.public();
//! ops::verify_message::<MinSig>(threshold_pub, namespace, message, &threshold_sig).expect("signature should be valid");
//! ```
use Error;
/// Errors that can occur when working with BLS12-381 primitives.