Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl PublicKeyBytes {
}

/// A wrapper for Ed25519 signature bytes.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct SignatureBytes(pub [u8; SignatureBytes::SIZE]);
ic_crypto_internal_types::derive_serde!(SignatureBytes, SignatureBytes::SIZE);
impl SignatureBytes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::fmt;
#[cfg(test)]
mod tests;

// Note: This is needed because Rust doesn't support const generics yet.
impl fmt::Debug for SignatureBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "SignatureBytes({:?})", base64::encode(&self.0[..]))
Expand All @@ -22,10 +21,3 @@ impl fmt::Debug for PublicKeyBytes {
write!(f, "PublicKeyBytes({:?})", base64::encode(&self.0[..]))
}
}

impl PartialEq for SignatureBytes {
fn eq(&self, other: &Self) -> bool {
self.0[..] == other.0[..]
}
}
impl Eq for SignatureBytes {}
4 changes: 1 addition & 3 deletions rs/crypto/internal/crypto_lib/bls12_381/type/src/poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ use rand::{CryptoRng, RngCore};
///
/// The coefficients are stored in little-endian ordering, ie a_0 is
/// self.coefficients\[0\]
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Eq)]
pub struct Polynomial {
coefficients: Vec<Scalar>,
}

impl Eq for Polynomial {}

impl PartialEq for Polynomial {
fn eq(&self, other: &Self) -> bool {
// Accept leading zero elements
Expand Down
44 changes: 39 additions & 5 deletions rs/crypto/internal/crypto_lib/multi_sig/bls12_381/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
use ic_crypto_internal_bls12_381_type::{G1Affine, G2Affine, Scalar};
use ic_crypto_secrets_containers::SecretArray;
use serde::{Deserialize, Serialize};
use std::fmt;
use zeroize::{Zeroize, ZeroizeOnDrop};

#[cfg(test)]
pub mod arbitrary;

#[cfg(test)]
pub mod tests;

pub mod conversions;
mod generic_traits;

/// A BLS secret key is a field element.
pub type SecretKey = Scalar;
Expand Down Expand Up @@ -41,34 +44,65 @@ impl SecretKeyBytes {
}
}

// Note: This is needed to keep sensitive material from getting Debug logged.
impl fmt::Debug for SecretKeyBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "REDACTED")
}
}

/// Wrapper for a serialized individual signature.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct IndividualSignatureBytes(pub [u8; IndividualSignatureBytes::SIZE]);
ic_crypto_internal_types::derive_serde!(IndividualSignatureBytes, IndividualSignatureBytes::SIZE);
impl IndividualSignatureBytes {
pub const SIZE: usize = G1Affine::BYTES;
}

impl fmt::Debug for IndividualSignatureBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", base64::encode(&self.0[..]))
}
}

/// Wrapper for a serialized proof of possession.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct PopBytes(pub [u8; PopBytes::SIZE]);
ic_crypto_internal_types::derive_serde!(PopBytes, PopBytes::SIZE);
impl PopBytes {
pub const SIZE: usize = G1Affine::BYTES;
}

impl fmt::Debug for PopBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", &self.0[..])
}
}

/// Wrapper for a serialized combined signature.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct CombinedSignatureBytes(pub [u8; CombinedSignatureBytes::SIZE]);
ic_crypto_internal_types::derive_serde!(CombinedSignatureBytes, CombinedSignatureBytes::SIZE);
impl CombinedSignatureBytes {
pub const SIZE: usize = G1Affine::BYTES;
}

impl fmt::Debug for CombinedSignatureBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", base64::encode(&self.0[..]))
}
}

/// Wrapper for a serialized public key.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct PublicKeyBytes(pub [u8; PublicKeyBytes::SIZE]);
ic_crypto_internal_types::derive_serde!(PublicKeyBytes, PublicKeyBytes::SIZE);
impl PublicKeyBytes {
pub const SIZE: usize = G2Affine::BYTES;
}

impl fmt::Debug for PublicKeyBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", &self.0[..])
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub(super) type Signature = G1Affine;
pub(super) type IndividualSignature = Signature;

/// A serialized individual BLS signature.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct IndividualSignatureBytes(pub [u8; G1Affine::BYTES]);
ic_crypto_internal_types::derive_serde!(IndividualSignatureBytes, IndividualSignatureBytes::SIZE);
impl IndividualSignatureBytes {
Expand All @@ -37,7 +37,7 @@ impl IndividualSignatureBytes {
pub(super) type CombinedSignature = Signature;

/// A serialized combined (threshold-signed) BLS signature.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct CombinedSignatureBytes(pub [u8; G1Affine::BYTES]);
ic_crypto_internal_types::derive_serde!(CombinedSignatureBytes, CombinedSignatureBytes::SIZE);
impl CombinedSignatureBytes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,17 @@ use std::fmt;
#[cfg(test)]
mod tests;

// Note: This is needed because Rust doesn't support const generics yet.
impl fmt::Debug for IndividualSignatureBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", base64::encode(&self.0[..]))
}
}
impl PartialEq for IndividualSignatureBytes {
fn eq(&self, other: &Self) -> bool {
self.0[..] == other.0[..]
}
}
impl Eq for IndividualSignatureBytes {}

// Note: This is needed because Rust doesn't support const generics yet.
impl fmt::Debug for CombinedSignatureBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", base64::encode(&self.0[..]))
}
}
impl PartialEq for CombinedSignatureBytes {
fn eq(&self, other: &Self) -> bool {
self.0[..] == other.0[..]
}
}
impl Eq for CombinedSignatureBytes {}

// Note: This is needed to keep sensitive material from getting Debug logged.
impl fmt::Debug for SecretKeyBytes {
Expand Down
8 changes: 1 addition & 7 deletions rs/crypto/internal/crypto_lib/types/src/sign/eddsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub mod ed25519 {
}

/// An Ed25519 signature.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct Signature(pub [u8; Signature::SIZE]);
crate::derive_serde!(Signature, Signature::SIZE);

Expand All @@ -92,12 +92,6 @@ pub mod ed25519 {
write!(f, "Signature(0x{hex_sig})")
}
}
impl PartialEq for Signature {
fn eq(&self, other: &Self) -> bool {
self.0[..] == other.0[..]
}
}
impl Eq for Signature {}
impl Hash for Signature {
fn hash<H: Hasher>(&self, state: &mut H) {
self.0[..].hash(state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub mod bls12_381 {
use thiserror::Error;

/// A BLS12-381 public key as bytes.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct PublicKeyBytes(pub [u8; PublicKeyBytes::SIZE]);
crate::derive_serde!(PublicKeyBytes, PublicKeyBytes::SIZE);

Expand Down Expand Up @@ -100,14 +100,6 @@ pub mod bls12_381 {
}
}

impl PartialEq for PublicKeyBytes {
fn eq(&self, other: &Self) -> bool {
self.0[..] == other.0[..]
}
}

impl Eq for PublicKeyBytes {}

impl Ord for PublicKeyBytes {
fn cmp(&self, other: &Self) -> Ordering {
self.0.cmp(&other.0)
Expand Down
Loading