Skip to content

Commit

Permalink
Reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Fiono11 committed Apr 29, 2024
1 parent 1aa608f commit e1d0c11
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 177 deletions.
82 changes: 28 additions & 54 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,49 +97,33 @@ pub trait SigningTranscript {
/// alternative implementations.
#[rustfmt::skip]
impl<T> SigningTranscript for &mut T
where
T: SigningTranscript + ?Sized,
where T: SigningTranscript + ?Sized,
{
#[inline(always)]
fn commit_bytes(&mut self, label: &'static [u8], bytes: &[u8]) {
(**self).commit_bytes(label, bytes)
}
fn commit_bytes(&mut self, label: &'static [u8], bytes: &[u8])
{ (**self).commit_bytes(label,bytes) }
#[inline(always)]
fn proto_name(&mut self, label: &'static [u8]) {
(**self).proto_name(label)
}
fn proto_name(&mut self, label: &'static [u8])
{ (**self).proto_name(label) }
#[inline(always)]
fn commit_point(&mut self, label: &'static [u8], compressed: &CompressedRistretto) {
(**self).commit_point(label, compressed)
}
fn commit_point(&mut self, label: &'static [u8], compressed: &CompressedRistretto)
{ (**self).commit_point(label, compressed) }
#[inline(always)]
fn challenge_bytes(&mut self, label: &'static [u8], dest: &mut [u8]) {
(**self).challenge_bytes(label, dest)
}
fn challenge_bytes(&mut self, label: &'static [u8], dest: &mut [u8])
{ (**self).challenge_bytes(label,dest) }
#[inline(always)]
fn challenge_scalar(&mut self, label: &'static [u8]) -> Scalar {
(**self).challenge_scalar(label)
}
fn challenge_scalar(&mut self, label: &'static [u8]) -> Scalar
{ (**self).challenge_scalar(label) }
#[inline(always)]
fn witness_scalar(&self, label: &'static [u8], nonce_seeds: &[&[u8]]) -> Scalar {
(**self).witness_scalar(label, nonce_seeds)
}
fn witness_scalar(&self, label: &'static [u8], nonce_seeds: &[&[u8]]) -> Scalar
{ (**self).witness_scalar(label,nonce_seeds) }
#[inline(always)]
fn witness_bytes(&self, label: &'static [u8], dest: &mut [u8], nonce_seeds: &[&[u8]]) {
(**self).witness_bytes(label, dest, nonce_seeds)
}
fn witness_bytes(&self, label: &'static [u8], dest: &mut [u8], nonce_seeds: &[&[u8]])
{ (**self).witness_bytes(label,dest,nonce_seeds) }
#[inline(always)]
fn witness_bytes_rng<R>(
&self,
label: &'static [u8],
dest: &mut [u8],
nonce_seeds: &[&[u8]],
rng: R,
) where
R: RngCore + CryptoRng,
{
(**self).witness_bytes_rng(label, dest, nonce_seeds, rng)
}
fn witness_bytes_rng<R>(&self, label: &'static [u8], dest: &mut [u8], nonce_seeds: &[&[u8]], rng: R)
where R: RngCore+CryptoRng
{ (**self).witness_bytes_rng(label,dest,nonce_seeds,rng) }
}

/// We delegate `SigningTranscript` methods to the corresponding
Expand Down Expand Up @@ -385,29 +369,19 @@ where
impl<T,R> SigningTranscript for SigningTranscriptWithRng<T,R>
where T: SigningTranscript, R: RngCore+CryptoRng
{
fn commit_bytes(&mut self, label: &'static [u8], bytes: &[u8]) {
self.t.commit_bytes(label, bytes)
}
fn commit_bytes(&mut self, label: &'static [u8], bytes: &[u8])
{ self.t.commit_bytes(label, bytes) }

fn challenge_bytes(&mut self, label: &'static [u8], dest: &mut [u8]) {
self.t.challenge_bytes(label, dest)
}
fn challenge_bytes(&mut self, label: &'static [u8], dest: &mut [u8])
{ self.t.challenge_bytes(label, dest) }

fn witness_bytes(&self, label: &'static [u8], dest: &mut [u8], nonce_seeds: &[&[u8]]) {
self.witness_bytes_rng(label, dest, nonce_seeds, &mut *self.rng.borrow_mut())
}
fn witness_bytes(&self, label: &'static [u8], dest: &mut [u8], nonce_seeds: &[&[u8]])
{ self.witness_bytes_rng(label, dest, nonce_seeds, &mut *self.rng.borrow_mut()) }

fn witness_bytes_rng<RR>(&self, label: &'static [u8], dest: &mut [u8], nonce_seeds: &[&[u8]], rng: RR)
where RR: RngCore+CryptoRng
{ self.t.witness_bytes_rng(label,dest,nonce_seeds,rng) }

fn witness_bytes_rng<RR>(
&self,
label: &'static [u8],
dest: &mut [u8],
nonce_seeds: &[&[u8]],
rng: RR,
) where
RR: RngCore + CryptoRng,
{
self.t.witness_bytes_rng(label, dest, nonce_seeds, rng)
}
}

/// Attach a `CryptoRng` to a `SigningTranscript` to replace the default `ThreadRng`.
Expand Down
20 changes: 6 additions & 14 deletions src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,29 +630,21 @@ impl PublicKey {
const DESCRIPTION: &'static str = "A Ristretto Schnorr public key represented as a 32-byte Ristretto compressed point";

/// Access the compressed Ristretto form
pub fn as_compressed(&self) -> &CompressedRistretto {
self.0.as_compressed()
}
pub fn as_compressed(&self) -> &CompressedRistretto { self.0.as_compressed() }

/// Extract the compressed Ristretto form
pub fn into_compressed(self) -> CompressedRistretto {
self.0.into_compressed()
}
pub fn into_compressed(self) -> CompressedRistretto { self.0.into_compressed() }

/// Access the point form
pub fn as_point(&self) -> &RistrettoPoint {
self.0.as_point()
}
pub fn as_point(&self) -> &RistrettoPoint { self.0.as_point() }

/// Extract the point form
pub fn into_point(self) -> RistrettoPoint {
self.0.into_point()
}
pub fn into_point(self) -> RistrettoPoint { self.0.into_point() }

/// Decompress into the `PublicKey` format that also retains the
/// compressed form.
pub fn from_compressed(compressed: CompressedRistretto) -> SignatureResult<PublicKey> {
Ok(PublicKey(RistrettoBoth::from_compressed(compressed)?))
Ok(PublicKey(RistrettoBoth::from_compressed(compressed) ?))
}

/// Compress into the `PublicKey` format that also retains the
Expand Down Expand Up @@ -703,7 +695,7 @@ impl PublicKey {
/// is an `SignatureError` describing the error that occurred.
#[inline]
pub fn from_bytes(bytes: &[u8]) -> SignatureResult<PublicKey> {
Ok(PublicKey(RistrettoBoth::from_bytes_ser("PublicKey", PublicKey::DESCRIPTION, bytes)?))
Ok(PublicKey(RistrettoBoth::from_bytes_ser("PublicKey",PublicKey::DESCRIPTION,bytes) ?))
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,16 @@ use curve25519_dalek::scalar::Scalar;
#[macro_use]
mod serdey;

pub mod keys;
pub mod points;
mod scalars;
pub mod keys;

pub mod cert;
pub mod context;
pub mod derive;
pub mod errors;
pub mod sign;
pub mod vrf;
pub mod derive;
pub mod cert;
pub mod errors;

#[cfg(all(feature = "alloc", feature = "aead"))]
pub mod olaf;
Expand Down
37 changes: 13 additions & 24 deletions src/points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,38 +59,33 @@ impl RistrettoBoth {
// equality comparisons.

/// Access the compressed Ristretto form
pub fn as_compressed(&self) -> &CompressedRistretto {
&self.compressed
}
pub fn as_compressed(&self) -> &CompressedRistretto { &self.compressed }

/// Extract the compressed Ristretto form
pub fn into_compressed(self) -> CompressedRistretto {
self.compressed
}
pub fn into_compressed(self) -> CompressedRistretto { self.compressed }

/// Access the point form
pub fn as_point(&self) -> &RistrettoPoint {
&self.point
}
pub fn as_point(&self) -> &RistrettoPoint { &self.point }

/// Extract the point form
pub fn into_point(self) -> RistrettoPoint {
self.point
}
pub fn into_point(self) -> RistrettoPoint { self.point }

/// Decompress into the `RistrettoBoth` format that also retains the
/// compressed form.
pub fn from_compressed(compressed: CompressedRistretto) -> SignatureResult<RistrettoBoth> {
Ok(RistrettoBoth {
point: compressed.decompress().ok_or(SignatureError::PointDecompressionError)?,
point: compressed.decompress().ok_or(SignatureError::PointDecompressionError) ?,
compressed,
})
}

/// Compress into the `RistrettoBoth` format that also retains the
/// uncompressed form.
pub fn from_point(point: RistrettoPoint) -> RistrettoBoth {
RistrettoBoth { compressed: point.compress(), point }
RistrettoBoth {
compressed: point.compress(),
point,
}
}

/// Convert this public key to a byte array.
Expand Down Expand Up @@ -129,21 +124,15 @@ impl RistrettoBoth {
/// is an `SignatureError` describing the error that occurred.
#[inline]
pub fn from_bytes(bytes: &[u8]) -> SignatureResult<RistrettoBoth> {
RistrettoBoth::from_bytes_ser("RistrettoPoint", RistrettoBoth::DESCRIPTION, bytes)
RistrettoBoth::from_bytes_ser("RistrettoPoint",RistrettoBoth::DESCRIPTION,bytes)
}

/// Variant of `RistrettoBoth::from_bytes` that propagates more informative errors.
#[inline]
pub fn from_bytes_ser(
name: &'static str,
description: &'static str,
bytes: &[u8],
) -> SignatureResult<RistrettoBoth> {
pub fn from_bytes_ser(name: &'static str, description: &'static str, bytes: &[u8]) -> SignatureResult<RistrettoBoth> {
if bytes.len() != RISTRETTO_POINT_LENGTH {
return Err(SignatureError::BytesLengthError {
name,
description,
length: RISTRETTO_POINT_LENGTH,
return Err(SignatureError::BytesLengthError{
name, description, length: RISTRETTO_POINT_LENGTH,
});
}
let mut compressed = CompressedRistretto([0u8; RISTRETTO_POINT_LENGTH]);
Expand Down
3 changes: 1 addition & 2 deletions src/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use curve25519_dalek::ristretto::{CompressedRistretto, RistrettoPoint};
use curve25519_dalek::scalar::Scalar;

use super::*;

use crate::context::{SigningTranscript, SigningContext};

// === Actual signature type === //
Expand Down Expand Up @@ -429,8 +428,8 @@ impl Keypair {

#[cfg(test)]
mod test {
use curve25519_dalek::digest::Update;
use sha3::Shake128;
use curve25519_dalek::digest::{Update};

use super::super::*;

Expand Down
Loading

0 comments on commit e1d0c11

Please sign in to comment.