Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
- Add that we treat BLAKE2b as a random oracle to the comment
- Avoid unnecessary array allocation
  • Loading branch information
moCello committed Dec 5, 2023
1 parent 721e1ec commit ba307b3
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/scalar/dusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ impl Scalar {
/// BLAKE2b into a 512-bits number, and then converting the number into its
/// `Scalar` representation by reducing it by the modulo.
///
/// This implementation follows the first conversion of
/// By treating the output of the BLAKE2b hash as a random oracle, this
/// implementation follows the first conversion of
/// https://hackmd.io/zV6qe1_oSU-kYU6Tt7pO7Q with concrete numbers:
/// ```text
/// p = 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001
Expand All @@ -285,10 +286,18 @@ impl Scalar {
.update(input)
.finalize();

let mut bytes = [0u8; 64];
bytes.copy_from_slice(&state.as_bytes()[..64]);

Self::from_bytes_wide(&bytes)
let bytes = state.as_bytes();

Scalar::from_u512([
u64::from_le_bytes(<[u8; 8]>::try_from(&bytes[0..8]).unwrap()),
u64::from_le_bytes(<[u8; 8]>::try_from(&bytes[8..16]).unwrap()),
u64::from_le_bytes(<[u8; 8]>::try_from(&bytes[16..24]).unwrap()),
u64::from_le_bytes(<[u8; 8]>::try_from(&bytes[24..32]).unwrap()),
u64::from_le_bytes(<[u8; 8]>::try_from(&bytes[32..40]).unwrap()),
u64::from_le_bytes(<[u8; 8]>::try_from(&bytes[40..48]).unwrap()),
u64::from_le_bytes(<[u8; 8]>::try_from(&bytes[48..56]).unwrap()),
u64::from_le_bytes(<[u8; 8]>::try_from(&bytes[56..64]).unwrap()),
])
}

/// SHR impl
Expand Down

0 comments on commit ba307b3

Please sign in to comment.