Skip to content

Commit

Permalink
chore: minor formatting updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbinth committed Mar 15, 2024
1 parent 5d4e166 commit 8f9a489
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/dsa/rpo_falcon512/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ const SIGMA: f64 = 165.7366171829776;
// TYPE ALIASES
// ================================================================================================

type NonceBytes = [u8; SIG_NONCE_LEN];
type NonceElements = [Felt; NONCE_ELEMENTS];
type ShortLatticeBasis = [Polynomial<i16>; 4];

// NONCE
Expand All @@ -64,25 +62,26 @@ pub struct Nonce([u8; SIG_NONCE_LEN]);

impl Nonce {
/// Returns a new [Nonce] instantiated from the provided bytes.
pub fn new(bytes: NonceBytes) -> Self {
pub fn new(bytes: [u8; SIG_NONCE_LEN]) -> Self {
Self(bytes)
}

pub fn as_bytes(&self) -> &NonceBytes {
/// Returns the underlying bytes of this nonce.
pub fn as_bytes(&self) -> &[u8; SIG_NONCE_LEN] {
&self.0
}

/// Converts byte representation of the nonce into field element representation.
///
/// Nonce bytes are converted to field elements by taking consecutive 5 byte chunks
/// of the nonce and interpreting them as field elements.
pub fn to_elements(&self) -> NonceElements {
pub fn to_elements(&self) -> [Felt; NONCE_ELEMENTS] {
let mut buffer = [0_u8; 8];
let mut result = [ZERO; 8];
for (i, bytes) in self.0.chunks(5).enumerate() {
buffer[..5].copy_from_slice(bytes);
// we can safely (without overflow) create a new Felt from u64 value here since this value
// contains at most 5 bytes
// we can safely (without overflow) create a new Felt from u64 value here since this
// value contains at most 5 bytes
result[i] = Felt::new(u64::from_le_bytes(buffer));
}

Expand Down

0 comments on commit 8f9a489

Please sign in to comment.