Skip to content

Commit 100c0b5

Browse files
committed
Separate key-share and cggmp21-keygen libs
1 parent c1ce66c commit 100c0b5

24 files changed

+2714
-117
lines changed

Cargo.lock

+35-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,11 @@
22
resolver = "2"
33
members = [
44
"cggmp21",
5+
"cggmp21-keygen",
6+
"key-share",
57
"tests",
68
]
9+
10+
[patch.crates-io.generic-ec]
11+
git = "https://github.com/dfns/generic-ec"
12+
branch = "small-impos"

cggmp21-keygen/Cargo.toml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[package]
2+
name = "cggmp21-keygen"
3+
version = "0.1.0"
4+
edition = "2021"
5+
license = "MIT OR Apache-2.0"
6+
description = "UC-secure DKG implementation based on CGGMP21 paper"
7+
repository = "https://github.com/dfns/cggmp21"
8+
categories = ["algorithms", "cryptography"]
9+
keywords = ["mpc", "dkg", "threshold-signatures", "tss", "ecdsa", "t-ecdsa"]
10+
11+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
12+
13+
[dependencies]
14+
key-share = { path = "../key-share" }
15+
slip-10 = { git = "https://github.com/dfns/slip-10", branch = "m", optional = true }
16+
17+
generic-ec = { version = "0.1", features = ["serde", "udigest"] }
18+
generic-ec-zkp = { version = "0.1", features = ["serde", "udigest"] }
19+
udigest = { version = "0.1", features = ["std", "derive"]}
20+
21+
round-based = { version = "0.2", features = ["derive"] }
22+
futures = "0.3"
23+
24+
sha2 = "0.10"
25+
digest = "0.10"
26+
rand_core = "0.6"
27+
28+
serde = { version = "1", features = ["derive"] }
29+
serde_with = { version = "2" }
30+
hex = { version = "0.4", default-features = false, features = ["serde"] }
31+
32+
thiserror = "1"
33+
34+
[features]
35+
hd-wallets = ["slip-10", "key-share/hd-wallets"]

cggmp21-keygen/src/errors.rs

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
use std::convert::Infallible;
2+
3+
use round_based::rounds_router::{
4+
errors::{self as router_error, CompleteRoundError},
5+
simple_store::RoundInputError,
6+
};
7+
use thiserror::Error;
8+
9+
pub type BoxedError = Box<dyn std::error::Error + Send + Sync>;
10+
11+
#[derive(Debug, Error)]
12+
pub enum IoError {
13+
#[error("send message")]
14+
SendMessage(#[source] BoxedError),
15+
#[error("receive message")]
16+
ReceiveMessage(#[source] BoxedError),
17+
#[error("got eof while recieving messages")]
18+
ReceiveMessageEof,
19+
#[error("route received message (possibly malicious behavior)")]
20+
RouteReceivedError(router_error::CompleteRoundError<RoundInputError, Infallible>),
21+
}
22+
23+
impl IoError {
24+
pub fn send_message<E: std::error::Error + Send + Sync + 'static>(err: E) -> Self {
25+
Self::SendMessage(Box::new(err))
26+
}
27+
28+
pub fn receive_message<E: std::error::Error + Send + Sync + 'static>(
29+
err: CompleteRoundError<RoundInputError, E>,
30+
) -> Self {
31+
match err {
32+
CompleteRoundError::Io(router_error::IoError::Io(e)) => {
33+
Self::ReceiveMessage(Box::new(e))
34+
}
35+
CompleteRoundError::Io(router_error::IoError::UnexpectedEof) => Self::ReceiveMessageEof,
36+
37+
CompleteRoundError::ProcessMessage(e) => {
38+
Self::RouteReceivedError(CompleteRoundError::ProcessMessage(e))
39+
}
40+
CompleteRoundError::Other(e) => Self::RouteReceivedError(CompleteRoundError::Other(e)),
41+
}
42+
}
43+
}
44+
45+
macro_rules! impl_from {
46+
(impl From for $target:ty {
47+
$($var:ident: $ty:ty => $new:expr),+,
48+
}) => {$(
49+
impl From<$ty> for $target {
50+
fn from($var: $ty) -> Self {
51+
$new
52+
}
53+
}
54+
)+}
55+
}
56+
57+
pub(crate) use impl_from;

cggmp21-keygen/src/execution_id.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// Protocol execution ID
2+
///
3+
/// Each protocol execution must have unique execution ID. All signers taking part in the protocol
4+
/// (keygen/signing/etc.) must share the same execution ID, otherwise protocol will abort with
5+
/// unverbose error.
6+
#[derive(Clone, Copy)]
7+
pub struct ExecutionId<'id> {
8+
id: &'id [u8],
9+
}
10+
11+
impl<'id> ExecutionId<'id> {
12+
/// Constructs an execution ID from bytes
13+
pub fn new(eid: &'id [u8]) -> Self {
14+
Self { id: eid }
15+
}
16+
17+
/// Returns bytes that represent an execution ID
18+
pub fn as_bytes(&self) -> &'id [u8] {
19+
self.id
20+
}
21+
}

0 commit comments

Comments
 (0)