Skip to content

Commit

Permalink
Impl DefaultIsZeros for every type that uses jubjub::Fr/Scalar
Browse files Browse the repository at this point in the history
This requires Copy and Clone along with Default. If we do not want to include those, we can impl
Zeroize and Drop directly.
  • Loading branch information
dconnolly committed Mar 18, 2021
1 parent 360be24 commit 2745d37
Showing 1 changed file with 8 additions and 25 deletions.
33 changes: 8 additions & 25 deletions src/frost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use std::{collections::HashMap, convert::TryFrom, marker::PhantomData};

use rand_core::{CryptoRng, RngCore};
use zeroize::Zeroize;
use zeroize::DefaultIsZeroes;

use crate::private::Sealed;
use crate::{HStar, Scalar, Signature, SpendAuth, VerificationKey};
Expand All @@ -34,17 +34,7 @@ use crate::{HStar, Scalar, Signature, SpendAuth, VerificationKey};
#[derive(Clone, Default)]
pub struct Secret(Scalar);

impl Zeroize for Secret {
fn zeroize(&mut self) {
self.0 = Scalar::zero();
}
}

impl Drop for Secret {
fn drop(&mut self) {
self.zeroize();
}
}
impl DefaultIsZeroes for Secret {}

impl From<Scalar> for Secret {
fn from(source: Scalar) -> Secret {
Expand Down Expand Up @@ -316,24 +306,13 @@ fn generate_shares<R: RngCore + CryptoRng>(
/// Note that [`SigningNonces`] must be used *only once* for a signing
/// operation; re-using nonces will result in leakage of a signer's long-lived
/// signing key.
#[derive(Clone)]
#[derive(Clone, Copy, Default)]
pub struct SigningNonces {
hiding: Scalar,
binding: Scalar,
}

impl Drop for SigningNonces {
fn drop(&mut self) {
self.zeroize();
}
}

impl Zeroize for SigningNonces {
fn zeroize(&mut self) {
self.hiding = Scalar::zero();
self.binding = Scalar::zero();
}
}
impl DefaultIsZeroes for SigningNonces {}

impl SigningNonces {
/// Generates a new signing nonce.
Expand Down Expand Up @@ -390,12 +369,16 @@ pub struct SigningPackage {

/// A participant's signature share, which the coordinator will use to aggregate
/// with all other signer's shares into the joint signature.
#[derive(Clone, Copy, Default)]
pub struct SignatureShare {
/// Represents the participant index.
pub(crate) index: u32,
/// This participant's signature over the message.
pub(crate) signature: Scalar,
}

impl DefaultIsZeroes for SignatureShare {}

impl SignatureShare {
/// Tests if a signature share issued by a participant is valid before
/// aggregating it into a final joint signature to publish.
Expand Down

0 comments on commit 2745d37

Please sign in to comment.