Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure library #72

Merged
merged 10 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ jobs:
with:
cache-on-failure: "true"
- name: Run clippy
run: cargo clippy --all --lib --exclude cggmp21-tests -- --no-deps -D clippy::all -D clippy::unwrap_used -D clippy::expect_used
run: cargo clippy --all --all-features --lib --exclude cggmp21-tests -- --no-deps -D clippy::all -D clippy::unwrap_used -D clippy::expect_used
- name: Run clippy tests
run: cargo clippy --tests --lib -- -D clippy::all
run: cargo clippy --tests --all-features --lib -- -D clippy::all
bench:
runs-on: ubuntu-latest
permissions:
Expand Down
42 changes: 37 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@
resolver = "2"
members = [
"cggmp21",
"cggmp21-keygen",
"key-share",
"tests",
]

[patch.crates-io.generic-ec]
git = "https://github.com/dfns/generic-ec"
branch = "small-impos"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ let aux_info = cggmp21::aux_info_gen(eid, i, n, pregenerated_primes)

After keygen and aux info gen are done, you can make a “complete” key share that can be used for signing:
```rust
let key_share = cggmp21::KeyShare::make(incomplete_key_share, aux_info)?;
let key_share = cggmp21::KeyShare::from_parts((incomplete_key_share, aux_info))?;
```

### Signing
Expand Down
35 changes: 35 additions & 0 deletions cggmp21-keygen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "cggmp21-keygen"
version = "0.1.0"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "UC-secure DKG implementation based on CGGMP21 paper"
repository = "https://github.com/dfns/cggmp21"
categories = ["algorithms", "cryptography"]
keywords = ["mpc", "dkg", "threshold-signatures", "tss", "ecdsa", "t-ecdsa"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
key-share = { path = "../key-share", features = ["serde"] }
slip-10 = { git = "https://github.com/dfns/slip-10", branch = "m", optional = true }

generic-ec = { version = "0.1", features = ["serde", "udigest"] }
generic-ec-zkp = { version = "0.1", features = ["serde", "udigest"] }
udigest = { version = "0.1", features = ["std", "derive"]}

round-based = { version = "0.2", features = ["derive"] }
futures = "0.3"

sha2 = "0.10"
digest = "0.10"
rand_core = "0.6"

serde = { version = "1", features = ["derive"] }
serde_with = { version = "2" }
hex = { version = "0.4", default-features = false, features = ["serde"] }

thiserror = "1"

[features]
hd-wallets = ["slip-10", "key-share/hd-wallets"]
57 changes: 57 additions & 0 deletions cggmp21-keygen/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use std::convert::Infallible;

use round_based::rounds_router::{
errors::{self as router_error, CompleteRoundError},
simple_store::RoundInputError,
};
use thiserror::Error;

pub type BoxedError = Box<dyn std::error::Error + Send + Sync>;

#[derive(Debug, Error)]
pub enum IoError {
#[error("send message")]
SendMessage(#[source] BoxedError),
#[error("receive message")]
ReceiveMessage(#[source] BoxedError),
#[error("got eof while recieving messages")]
ReceiveMessageEof,
#[error("route received message (possibly malicious behavior)")]
RouteReceivedError(router_error::CompleteRoundError<RoundInputError, Infallible>),
}

impl IoError {
pub fn send_message<E: std::error::Error + Send + Sync + 'static>(err: E) -> Self {
Self::SendMessage(Box::new(err))
}

pub fn receive_message<E: std::error::Error + Send + Sync + 'static>(
err: CompleteRoundError<RoundInputError, E>,
) -> Self {
match err {
CompleteRoundError::Io(router_error::IoError::Io(e)) => {
Self::ReceiveMessage(Box::new(e))
}
CompleteRoundError::Io(router_error::IoError::UnexpectedEof) => Self::ReceiveMessageEof,

CompleteRoundError::ProcessMessage(e) => {
Self::RouteReceivedError(CompleteRoundError::ProcessMessage(e))
}
CompleteRoundError::Other(e) => Self::RouteReceivedError(CompleteRoundError::Other(e)),
}
}
}

macro_rules! impl_from {
(impl From for $target:ty {
$($var:ident: $ty:ty => $new:expr),+,
}) => {$(
impl From<$ty> for $target {
fn from($var: $ty) -> Self {
$new
}
}
)+}
}

pub(crate) use impl_from;
21 changes: 21 additions & 0 deletions cggmp21-keygen/src/execution_id.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// Protocol execution ID
///
/// Each protocol execution must have unique execution ID. All signers taking part in the protocol
/// (keygen/signing/etc.) must share the same execution ID, otherwise protocol will abort with
/// unverbose error.
#[derive(Clone, Copy)]
pub struct ExecutionId<'id> {
id: &'id [u8],
}

impl<'id> ExecutionId<'id> {
/// Constructs an execution ID from bytes
pub fn new(eid: &'id [u8]) -> Self {
Self { id: eid }
}

/// Returns bytes that represent an execution ID
pub fn as_bytes(&self) -> &'id [u8] {
self.id
}
}
Loading
Loading