Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into remove-identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
conradoplg committed Jul 3, 2023
2 parents c7d5636 + 31913f4 commit 47652a5
Show file tree
Hide file tree
Showing 26 changed files with 147 additions and 175 deletions.
1 change: 1 addition & 0 deletions frost-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Entries are listed in reverse chronological order.
* `commit()` and `preprocess()` no longer take an identifier as input
* `SignatureResponse` was removed. `SignatureShare` can now be encoded directly with
`from/to_bytes()`.
* rename all `to_bytes()`/`from_bytes()` to `serialize()`/`deserialize()`

## Released

Expand Down
2 changes: 1 addition & 1 deletion frost-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ serdect = { version = "0.2.0", optional = true }
thiserror = "1.0"
visibility = "0.0.1"
zeroize = { version = "1.5.4", default-features = false, features = ["derive"] }
itertools = "0.10.5"
itertools = "0.11.0"

# Test dependencies used with the test-impl feature
proptest = { version = "1.0", optional = true }
Expand Down
16 changes: 4 additions & 12 deletions frost-core/src/frost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ where
C: Ciphersuite,
{
/// Deserializes [`BindingFactor`] from bytes.
pub fn from_bytes(
pub fn deserialize(
bytes: <<C::Group as Group>::Field as Field>::Serialization,
) -> Result<Self, Error<C>> {
<<C::Group as Group>::Field>::deserialize(&bytes)
Expand All @@ -54,7 +54,7 @@ where
}

/// Serializes [`BindingFactor`] to bytes.
pub fn to_bytes(&self) -> <<C::Group as Group>::Field as Field>::Serialization {
pub fn serialize(&self) -> <<C::Group as Group>::Field as Field>::Serialization {
<<C::Group as Group>::Field>::serialize(&self.0)
}
}
Expand All @@ -65,7 +65,7 @@ where
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("BindingFactor")
.field(&hex::encode(self.to_bytes()))
.field(&hex::encode(self.serialize()))
.finish()
}
}
Expand Down Expand Up @@ -140,7 +140,7 @@ where
fn from_hex<T: AsRef<[u8]>>(hex: T) -> Result<Self, Self::Error> {
let v: Vec<u8> = FromHex::from_hex(hex).map_err(|_| "invalid hex")?;
match v.try_into() {
Ok(bytes) => Self::from_bytes(bytes).map_err(|_| "malformed scalar encoding"),
Ok(bytes) => Self::deserialize(bytes).map_err(|_| "malformed scalar encoding"),
Err(_) => Err("malformed scalar encoding"),
}
}
Expand Down Expand Up @@ -286,14 +286,6 @@ where
}
}

// impl<C> Debug for GroupCommitment<C> where C: Ciphersuite {
// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// f.debug_tuple("GroupCommitment")
// .field(&hex::encode(self.0.compress().to_bytes()))
// .finish()
// }
// }

/// Generates the group commitment which is published as part of the joint
/// Schnorr signature.
///
Expand Down
25 changes: 14 additions & 11 deletions frost-core/src/frost/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ where
C: Ciphersuite,
{
/// Deserialize from bytes
pub fn from_bytes(
pub fn deserialize(
bytes: <<C::Group as Group>::Field as Field>::Serialization,
) -> Result<Self, Error<C>> {
<<C::Group as Group>::Field>::deserialize(&bytes)
Expand All @@ -64,7 +64,7 @@ where
}

/// Serialize to bytes
pub fn to_bytes(&self) -> <<C::Group as Group>::Field as Field>::Serialization {
pub fn serialize(&self) -> <<C::Group as Group>::Field as Field>::Serialization {
<<C::Group as Group>::Field>::serialize(&self.0)
}
}
Expand Down Expand Up @@ -100,7 +100,7 @@ where
fn from_hex<T: AsRef<[u8]>>(hex: T) -> Result<Self, Self::Error> {
let v: Vec<u8> = FromHex::from_hex(hex).map_err(|_| "invalid hex")?;
match v.try_into() {
Ok(bytes) => Self::from_bytes(bytes).map_err(|_| "malformed secret encoding"),
Ok(bytes) => Self::deserialize(bytes).map_err(|_| "malformed secret encoding"),
Err(_) => Err("malformed secret encoding"),
}
}
Expand All @@ -114,7 +114,7 @@ where
type Error = Error<C>;

fn try_from(value: ScalarSerialization<C>) -> Result<Self, Self::Error> {
Self::from_bytes(value.0)
Self::deserialize(value.0)
}
}

Expand All @@ -124,7 +124,7 @@ where
C: Ciphersuite,
{
fn from(value: SigningShare<C>) -> Self {
Self(value.to_bytes())
Self(value.serialize())
}
}

Expand All @@ -142,14 +142,14 @@ where
C: Ciphersuite,
{
/// Deserialize from bytes
pub fn from_bytes(bytes: <C::Group as Group>::Serialization) -> Result<Self, Error<C>> {
pub fn deserialize(bytes: <C::Group as Group>::Serialization) -> Result<Self, Error<C>> {
<C::Group as Group>::deserialize(&bytes)
.map(|element| Self(element))
.map_err(|e| e.into())
}

/// Serialize to bytes
pub fn to_bytes(&self) -> <C::Group as Group>::Serialization {
pub fn serialize(&self) -> <C::Group as Group>::Serialization {
<C::Group as Group>::serialize(&self.0)
}
}
Expand All @@ -160,7 +160,7 @@ where
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("VerifyingShare")
.field(&hex::encode(self.to_bytes()))
.field(&hex::encode(self.serialize()))
.finish()
}
}
Expand All @@ -182,7 +182,7 @@ where
type Error = Error<C>;

fn try_from(value: ElementSerialization<C>) -> Result<Self, Self::Error> {
Self::from_bytes(value.0)
Self::deserialize(value.0)
}
}

Expand All @@ -192,7 +192,7 @@ where
C: Ciphersuite,
{
fn from(value: VerifyingShare<C>) -> Self {
Self(value.to_bytes())
Self(value.serialize())
}
}

Expand Down Expand Up @@ -518,17 +518,20 @@ fn evaluate_vss<C: Ciphersuite>(
/// When using a central dealer, [`SecretShare`]s are distributed to
/// participants, who then perform verification, before deriving
/// [`KeyPackage`]s, which they store to later use during signing.
#[derive(Clone, Debug, PartialEq, Eq, Getters)]
#[derive(Clone, Debug, PartialEq, Eq, Getters, Zeroize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
pub struct KeyPackage<C: Ciphersuite> {
/// Denotes the participant identifier each secret share key package is owned by.
#[zeroize(skip)]
pub(crate) identifier: Identifier<C>,
/// This participant's secret share.
pub(crate) secret_share: SigningShare<C>,
/// This participant's public key.
#[zeroize(skip)]
pub(crate) public: VerifyingShare<C>,
/// The public signing key that represents the entire group.
#[zeroize(skip)]
pub(crate) group_public: VerifyingKey<C>,
/// Ciphersuite ID for serialization
#[cfg_attr(
Expand Down
22 changes: 22 additions & 0 deletions frost-core/src/frost/keys/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ use super::{
/// DKG Round 1 structures.
pub mod round1 {
use derive_getters::Getters;
use zeroize::Zeroize;

use super::*;

Expand Down Expand Up @@ -123,11 +124,23 @@ pub mod round1 {
.finish()
}
}

impl<C> Zeroize for SecretPackage<C>
where
C: Ciphersuite,
{
fn zeroize(&mut self) {
for i in 0..self.coefficients.len() {
self.coefficients[i] = <<C::Group as Group>::Field>::zero();
}
}
}
}

/// DKG Round 2 structures.
pub mod round2 {
use derive_getters::Getters;
use zeroize::Zeroize;

use super::*;

Expand Down Expand Up @@ -201,6 +214,15 @@ pub mod round2 {
.finish()
}
}

impl<C> Zeroize for SecretPackage<C>
where
C: Ciphersuite,
{
fn zeroize(&mut self) {
self.secret_share = <<C::Group as Group>::Field>::zero();
}
}
}

/// Performs the first part of the distributed key generation protocol
Expand Down
29 changes: 11 additions & 18 deletions frost-core/src/frost/round1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ where
}

/// Deserialize [`Nonce`] from bytes
pub fn from_bytes(
pub fn deserialize(
bytes: <<C::Group as Group>::Field as Field>::Serialization,
) -> Result<Self, Error<C>> {
<<C::Group as Group>::Field>::deserialize(&bytes)
Expand All @@ -73,7 +73,7 @@ where
}

/// Serialize [`Nonce`] to bytes
pub fn to_bytes(&self) -> <<C::Group as Group>::Field as Field>::Serialization {
pub fn serialize(&self) -> <<C::Group as Group>::Field as Field>::Serialization {
<<C::Group as Group>::Field>::serialize(&self.0)
}
}
Expand All @@ -87,15 +87,6 @@ where
}
}

// impl<C> Drop for Nonce<C>
// where
// C: Ciphersuite,
// {
// fn drop(&mut self) {
// self.zeroize()
// }
// }

#[cfg(any(test, feature = "test-impl"))]
impl<C> FromHex for Nonce<C>
where
Expand All @@ -106,7 +97,7 @@ where
fn from_hex<T: AsRef<[u8]>>(hex: T) -> Result<Self, Self::Error> {
let v: Vec<u8> = FromHex::from_hex(hex).map_err(|_| "invalid hex")?;
match v.try_into() {
Ok(bytes) => Self::from_bytes(bytes).map_err(|_| "malformed nonce encoding"),
Ok(bytes) => Self::deserialize(bytes).map_err(|_| "malformed nonce encoding"),
Err(_) => Err("malformed nonce encoding"),
}
}
Expand All @@ -124,14 +115,14 @@ where
C: Ciphersuite,
{
/// Deserialize [`NonceCommitment`] from bytes
pub fn from_bytes(bytes: <C::Group as Group>::Serialization) -> Result<Self, Error<C>> {
pub fn deserialize(bytes: <C::Group as Group>::Serialization) -> Result<Self, Error<C>> {
<C::Group>::deserialize(&bytes)
.map(|element| Self(element))
.map_err(|e| e.into())
}

/// Serialize [`NonceCommitment`] to bytes
pub fn to_bytes(&self) -> <C::Group as Group>::Serialization {
pub fn serialize(&self) -> <C::Group as Group>::Serialization {
<C::Group>::serialize(&self.0)
}
}
Expand All @@ -144,7 +135,7 @@ where
type Error = Error<C>;

fn try_from(value: ElementSerialization<C>) -> Result<Self, Self::Error> {
Self::from_bytes(value.0)
Self::deserialize(value.0)
}
}

Expand All @@ -154,7 +145,7 @@ where
C: Ciphersuite,
{
fn from(value: NonceCommitment<C>) -> Self {
Self(value.to_bytes())
Self(value.serialize())
}
}

Expand All @@ -164,7 +155,7 @@ where
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("NonceCommitment")
.field(&hex::encode(self.to_bytes()))
.field(&hex::encode(self.serialize()))
.finish()
}
}
Expand Down Expand Up @@ -197,7 +188,9 @@ where
fn from_hex<T: AsRef<[u8]>>(hex: T) -> Result<Self, Self::Error> {
let v: Vec<u8> = FromHex::from_hex(hex).map_err(|_| "invalid hex")?;
match v.try_into() {
Ok(bytes) => Self::from_bytes(bytes).map_err(|_| "malformed nonce commitment encoding"),
Ok(bytes) => {
Self::deserialize(bytes).map_err(|_| "malformed nonce commitment encoding")
}
Err(_) => Err("malformed nonce commitment encoding"),
}
}
Expand Down
13 changes: 4 additions & 9 deletions frost-core/src/frost/round2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ where
}
}

/// A participant's signature share, which the coordinator will aggregate with all other signer's
/// shares into the joint signature.
#[derive(Clone, Copy, Eq, PartialEq, Getters)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand All @@ -60,7 +61,7 @@ where
C: Ciphersuite,
{
/// Deserialize [`SignatureShare`] from bytes
pub fn from_bytes(
pub fn deserialize(
bytes: <<C::Group as Group>::Field as Field>::Serialization,
) -> Result<Self, Error<C>> {
<<C::Group as Group>::Field>::deserialize(&bytes)
Expand All @@ -69,7 +70,7 @@ where
}

/// Serialize [`SignatureShare`] to bytes
pub fn to_bytes(&self) -> <<C::Group as Group>::Field as Field>::Serialization {
pub fn serialize(&self) -> <<C::Group as Group>::Field as Field>::Serialization {
<<C::Group as Group>::Field>::serialize(&self.share)
}

Expand Down Expand Up @@ -148,7 +149,7 @@ where
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("SignatureShare")
.field("share", &hex::encode(self.to_bytes()))
.field("share", &hex::encode(self.serialize()))
.finish()
}
}
Expand All @@ -169,12 +170,6 @@ fn compute_signature_share<C: Ciphersuite>(
SignatureShare::<C> { share: z_share }
}

// // Zeroizes `SignatureShare` to be the `Default` value on drop (when it goes out
// // of scope). Luckily the derived `Default` includes the `Default` impl of
// // Scalar, which is four 0u64's under the hood, and u16, which is
// // 0u16.
// impl DefaultIsZeroes for SignatureShare {}

/// Performed once by each participant selected for the signing operation.
///
/// Implements [`sign`] from the spec.
Expand Down
Loading

0 comments on commit 47652a5

Please sign in to comment.