Skip to content

Commit

Permalink
Merge pull request #36 from teleconsys/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Revanee authored May 16, 2023
2 parents 65ff0be + 32f65ab commit dab82ce
Show file tree
Hide file tree
Showing 11 changed files with 473 additions and 159 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kyber-rs"
version = "0.1.0-alpha.6"
version = "0.1.0-alpha.7"
edition = "2021"
description = "A toolbox of advanced cryptographic primitives for Rust"
license = "MPL-2.0"
Expand Down
2 changes: 1 addition & 1 deletion src/group/edwards25519/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl PartialEq for Point {

impl Display for Point {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "Ed25519Point( {self:#x} )")
write!(f, "Ed25519Point({self:#x})")
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/group/edwards25519/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl PartialEq for Scalar {

impl Display for Scalar {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "Ed25519Scalar( {self:#x} )")
write!(f, "Ed25519Scalar({self:#x})")
}
}

Expand Down
83 changes: 68 additions & 15 deletions src/share/dkg/pedersen/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,54 @@ impl<SUITE: Suite, READ: Read + Clone> Debug for Config<SUITE, READ> {

impl<SUITE: Suite, READ: Read + Clone> Display for Config<SUITE, READ> {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write! {f, "Config( suite: {}, old_nodes: {:?}, public_coefficients: {:?}, new_nodes: {:?},
share: {:?}, threshold: {}, old_threshold: {}, reader: {}, user_reader_only: {} )",
self.suite,
self.old_nodes.iter().map(|n| n.to_string()).collect::<Vec<_>>(),
self.public_coeffs.as_ref().map(|f| f.iter().map(|p| p.to_string()).collect::<Vec<_>>()),
self.new_nodes.iter().map(|n| n.to_string()).collect::<Vec<_>>(),
self.share.as_ref().map(|s| s.to_string()),
write!(f, "Config( suite: {},", self.suite,)?;

write!(f, " old_nodes: [")?;
let old_nodes = self
.old_nodes
.iter()
.map(|c| c.to_string())
.collect::<Vec<_>>()
.join(",");
write!(f, "{}],", old_nodes)?;

match self.public_coeffs {
Some(ref p) => {
write!(f, "Some([")?;
let coeffs = p
.iter()
.map(|c| c.to_string())
.collect::<Vec<_>>()
.join(",");
write!(f, "{}]),", coeffs)?;
}
None => write!(f, "None,")?,
};

write!(f, " new_nodes: [")?;
let new_nodes = self
.new_nodes
.iter()
.map(|c| c.to_string())
.collect::<Vec<_>>()
.join(",");
write!(f, "{}],", new_nodes)?;

write!(f, " share: ")?;
match self.share {
Some(ref s) => write!(f, "Some({})", s),
None => write!(f, "None"),
}?;
write!(f, ",")?;

write!(
f,
"threshold: {}, old_threshold: {}, reader: {}, user_reader_only: {} )",
self.threshold,
self.old_threshold,
self.reader.is_some(),
self.user_reader_only
}
)
}
}

Expand Down Expand Up @@ -196,17 +232,34 @@ impl<SUITE: Suite, READ: Read + Clone> Debug for DistKeyGenerator<SUITE, READ> {

impl<SUITE: Suite, READ: Read + Clone> Display for DistKeyGenerator<SUITE, READ> {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write! {f, "DistKeyGenerator( config: {}, suite: {:?}, public_key: {:?}, distributed_public_key: {:?},
dealer: {:?}, verifiers: {:?}, old_aggregators: {:?}, old_index: {}, new_index: {}, old_threshold: {},
new_threshold: {}, is_resharing: {}, can_issue: {}, can_receive: {}, new_present: {}, old_present: {},
processed: {}, timeout: {} )",
write! {f, "DistKeyGenerator( config: {}, suite: {}, public_key: {}, distributed_public_key: {},
dealer: {},",
self.c,
self.suite,
self.pubb,
self.dpub,
self.dealer,
self.verifiers,
self.old_aggregators,
}?;

write!(f, " verifiers: [")?;
let verifiers = self
.verifiers
.iter()
.map(|c| "(".to_string() + &c.0.to_string() + ", " + &c.1.to_string() + ")")
.collect::<Vec<_>>()
.join(", ");
write!(f, "{}],", verifiers)?;

write!(f, " old_aggregators: [")?;
let old_aggregators = self
.old_aggregators
.iter()
.map(|c| "(".to_string() + &c.0.to_string() + ", " + &c.1.to_string() + ")")
.collect::<Vec<_>>()
.join(", ");
write!(f, "{}],", old_aggregators)?;

write!(f, " old_index: {}, new_index: {}, old_threshold: {}, new_threshold: {}, is_resharing: {}, can_issue: {}, can_receive: {}, new_present: {}, old_present: {}, processed: {}, timeout: {} )",
self.oidx,
self.nidx,
self.old_t,
Expand All @@ -218,7 +271,7 @@ impl<SUITE: Suite, READ: Read + Clone> Display for DistKeyGenerator<SUITE, READ>
self.old_present,
self.processed,
self.timeout
}
)
}
}

Expand Down
17 changes: 14 additions & 3 deletions src/share/dkg/pedersen/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ impl<SUITE: Suite> Debug for DistKeyShare<SUITE> {

impl<SUITE: Suite> Display for DistKeyShare<SUITE> {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "DistKeyShare( commits: {:?} )", self.commits)
write!(f, "DistKeyShare(")?;

write!(f, " commits: [")?;
let commits = self
.commits
.iter()
.map(|c| c.to_string())
.collect::<Vec<_>>()
.join(",");
write!(f, "{}] )", commits)
}
}

Expand Down Expand Up @@ -79,8 +88,10 @@ impl<POINT: Point> Display for Deal<POINT> {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(
f,
"Deal( index: {}, deal: {}, signature: {:?} )",
self.index, self.deal, self.signature
"Deal( index: {}, deal: {}, signature: 0x{} )",
self.index,
self.deal,
hex::encode(&self.signature)
)
}
}
Expand Down
122 changes: 91 additions & 31 deletions src/share/dkg/rabin/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
/// must be broadcasted to all the QUAL participant.
/// 7. At this point, every QUAL participant can issue the distributed key by
/// calling [`dist_key_share()`].

extern crate alloc;
use core::fmt::{Debug, Display, Formatter};
use std::collections::HashMap;
Expand Down Expand Up @@ -76,7 +75,16 @@ impl<SUITE: Suite> Debug for DistKeyShare<SUITE> {

impl<SUITE: Suite> Display for DistKeyShare<SUITE> {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "DistKeyShare( commits: {:?} )", self.commits)
write!(f, "DistKeyShare(")?;

write!(f, " commits: [")?;
let commits = self
.commits
.iter()
.map(|c| c.to_string())
.collect::<Vec<_>>()
.join(",");
write!(f, "{}] )", commits)
}
}

Expand Down Expand Up @@ -176,16 +184,22 @@ pub struct SecretCommits<SUITE: Suite> {

impl<SUITE: Suite> Display for SecretCommits<SUITE> {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "SecretCommits( index: {},", self.index,)?;

write!(f, " commitments: [")?;
let commitments = self
.commitments
.iter()
.map(|c| c.to_string())
.collect::<Vec<_>>()
.join(",");
write!(f, "{}],", commitments)?;

write!(
f,
"SecretCommits( index: {}, commitments: {:?}, session_id: {:?}, signature: {:?} )",
self.index,
self.commitments
.iter()
.map(|c| c.to_string())
.collect::<Vec<_>>(),
self.session_id,
self.signature
" session_id: 0x{}, signature: 0x{} )",
hex::encode(&self.session_id),
hex::encode(&self.signature)
)
}
}
Expand Down Expand Up @@ -222,8 +236,11 @@ impl<SUITE: Suite> Display for ComplaintCommits<SUITE> {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(
f,
"ComplaintCommits( index: {}, commitments: {}, session_id: {}, signature: {:?} )",
self.index, self.dealer_index, self.deal, self.signature
"ComplaintCommits( index: {}, dealer_index: {}, deal: {}, signature: 0x{} )",
self.index,
self.dealer_index,
self.deal,
hex::encode(&self.signature)
)
}
}
Expand Down Expand Up @@ -272,8 +289,11 @@ impl<SUITE: Suite> Display for ReconstructCommits<SUITE> {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(
f,
"ReconstructCommits( session_id: {:?}, index: {}, dealer_index: {}, signature: {:?} )",
self.session_id, self.index, self.dealer_index, self.signature
"ReconstructCommits( session_id: 0x{}, index: {}, dealer_index: {}, signature: 0x{} )",
hex::encode(&self.session_id),
self.index,
self.dealer_index,
hex::encode(&self.signature)
)
}
}
Expand Down Expand Up @@ -339,23 +359,63 @@ impl<T: Suite> Display for DistKeyGenerator<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(
f,
"DistKeyGenerator( suite: {}, public: {}, index: {}, threshold: {}, dealer: {},
verifiers: {:?}, commitments: {:?}, pending_reconstruct: {:?},
reconstructed: {:?}, participants: {:?} )",
self.suite,
self.pubb,
self.index,
self.t,
self.dealer,
self.verifiers,
self.commitments,
self.pending_reconstruct,
self.reconstructed,
self.participants
.iter()
.map(|p| p.to_string())
.collect::<Vec<_>>(),
)
"DistKeyGenerator( suite: {}, index: {}, public: {},",
self.suite, self.index, self.pubb,
)?;

write!(f, " participants: [")?;
let participants = self
.participants
.iter()
.map(|c| c.to_string())
.collect::<Vec<_>>()
.join(",");
write!(f, "{}],", participants)?;

write!(f, " threshold: {}, dealer: {},", self.t, self.dealer,)?;

write!(f, " verifiers: [")?;
let verifiers = self
.verifiers
.iter()
.map(|c| "(".to_string() + &c.0.to_string() + ", " + &c.1.to_string() + ")")
.collect::<Vec<_>>()
.join(", ");
write!(f, "{}],", verifiers)?;

write!(f, " commitments: [")?;
let commitments = self
.commitments
.iter()
.map(|c| "(".to_string() + &c.0.to_string() + ", " + &c.1.to_string() + ")")
.collect::<Vec<_>>()
.join(", ");
write!(f, "{}],", commitments)?;

write!(f, " pending_reconstruct: [")?;
let pending_reconstruct = self
.pending_reconstruct
.iter()
.map(|c| {
let vec_str =
c.1.iter()
.map(|c| c.to_string())
.collect::<Vec<_>>()
.join(", ");
"(".to_string() + &c.0.to_string() + ", [" + &vec_str + "])"
})
.collect::<Vec<_>>()
.join(", ");
write!(f, "{}],", pending_reconstruct)?;

write!(f, " reconstructed: [")?;
let reconstructed = self
.reconstructed
.iter()
.map(|c| "(".to_string() + &c.0.to_string() + ", " + &c.1.to_string() + ")")
.collect::<Vec<_>>()
.join(", ");
write!(f, "{}] )", reconstructed)
}
}

Expand Down
26 changes: 16 additions & 10 deletions src/share/poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,22 @@ pub struct PubPoly<GROUP: Group> {

impl<GROUP: Group> Display for PubPoly<GROUP> {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(
f,
"PubPoly( group: {}, base_point: {:?}, commits: {:?} )",
self.g,
self.b.as_ref().map(|b| b.to_string()),
self.commits
.iter()
.map(|c| c.to_string())
.collect::<Vec<_>>()
)
write!(f, "PubPoly( group: {},", self.g,)?;

write!(f, " base_point:")?;
match self.b {
Some(ref base) => write!(f, " Some({}),", base),
None => write!(f, " None,"),
}?;

write!(f, " commits: [")?;
let commits = self
.commits
.iter()
.map(|c| c.to_string())
.collect::<Vec<_>>()
.join(", ");
write!(f, "{}] )", commits)
}
}

Expand Down
Loading

0 comments on commit dab82ce

Please sign in to comment.