mpvss_rs/lib.rs
1// Copyright 2020-2021 MathxH Chen.
2//
3// Code is licensed under MIT Apache Dual License
4
5//! # MPVSS - A Simple Publicly Verifiable Secret Sharing Library
6//!
7//! The library implements a simple PVSS scheme in Rust.
8//!
9//! ## What is PVSS?
10//!
11//! Secret sharing means a dealer can break a secret into secret shares among a group of participants which can reconstruct the secret only by collaboratively joining their parts of the secret. The library also implements threshold cryptography so that the dealer can decide whether all of the receiving participants need to collaborate or if a smaller subgroup of participants is sufficient to reconstruct the secret.
12//!
13//! In addition to the plain secret sharing scheme PVSS adds verifiability in the following way: All the parts the secret is split into are encrypted with the receivers' public keys respectively. The dealer publishes all the encrypted shares along with a non-interactive zero-knowledge proof that allows everbody (not only the receiving participants) to verify that the decrypted shares indeed can be used to reconstruct the secret. The participants then decrypt all their shares and exchange them along with another non-interactive zero-knowledge proof that allows the receiving participant to verify that the share is actually the result of the decryption.
14//!
15//! Thus PVSS can be used to share a secret among a group of participants so that either the secret can be reconstructed by the participants who all play fair or a participant that received a faked share can identify the malicious party.
16//!
17//! ## Documents
18//!
19//! See [Github README](https://github.com/AlexiaChen/mpvss-rs/blob/master/README.md)
20
21// Core modules
22pub mod dleq;
23pub mod mpvss;
24pub mod participant;
25pub mod polynomial;
26pub mod sharebox;
27mod util;
28
29// Group abstractions (new 1.0.0 API)
30pub mod group;
31pub mod groups;
32
33// Public API exports
34pub use dleq::DLEQ;
35pub use mpvss::PVSS;
36pub use participant::{ModpParticipant, Participant};
37pub use sharebox::{DistributionSharesBox, ShareBox};
38
39// Type aliases for convenience
40/// Type alias for Participant with Secp256k1Group (elliptic curve cryptography)
41pub type Secp256k1Participant = Participant<crate::groups::Secp256k1Group>;
42
43/// Type alias for Participant with Ristretto255Group (prime-order group over Curve25519)
44pub type Ristretto255Participant =
45 Participant<crate::groups::Ristretto255Group>;
46
47use num_bigint::{BigInt, BigUint, ToBigInt};
48
49pub fn string_to_secret(message: &str) -> BigInt {
50 BigUint::from_bytes_be(message.as_bytes())
51 .to_bigint()
52 .unwrap()
53}
54
55pub fn string_from_secret(secret: &BigInt) -> String {
56 String::from_utf8(secret.to_biguint().unwrap().to_bytes_be()).unwrap()
57}