mirror of https://github.com/zcash/orchard.git
spec.rs: Add lebs2ip function bounded on const generic L.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
This commit is contained in:
parent
b299a51b31
commit
b7b8126ccf
|
@ -14,7 +14,7 @@ mod constants;
|
|||
mod sinsemilla_s;
|
||||
pub use constants::*;
|
||||
|
||||
pub fn lebs2ip_k(bits: &[bool]) -> u32 {
|
||||
fn lebs2ip_k(bits: &[bool]) -> u32 {
|
||||
assert!(bits.len() == K);
|
||||
bits.iter()
|
||||
.enumerate()
|
||||
|
|
12
src/spec.rs
12
src/spec.rs
|
@ -179,6 +179,18 @@ pub(crate) fn extract_p_bottom(point: CtOption<pallas::Point>) -> CtOption<palla
|
|||
point.map(|p| extract_p(&p))
|
||||
}
|
||||
|
||||
/// The u64 integer represented by an L-bit little-endian bitstring.
|
||||
///
|
||||
/// Panics
|
||||
///
|
||||
/// Panics if the bitstring is longer than 64 bits.
|
||||
pub fn lebs2ip<const L: usize>(bits: &[bool; L]) -> u64 {
|
||||
assert!(L <= 64);
|
||||
bits.iter()
|
||||
.enumerate()
|
||||
.fold(0u64, |acc, (i, b)| acc + if *b { 1 << i } else { 0 })
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use group::Group;
|
||||
|
|
Loading…
Reference in New Issue