Correctly interpret BLAKE2s inputs and outputs as little endian.

This commit is contained in:
Sean Bowe 2018-05-17 00:05:32 -06:00
parent 87c62e2248
commit f491e02b56
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
2 changed files with 5 additions and 11 deletions

View File

@ -343,7 +343,7 @@ mod test {
let mut out = out.into_iter();
for b in expected.into_iter() {
for i in (0..8).rev() {
for i in 0..8 {
let c = out.next().unwrap().get_value().unwrap();
assert_eq!(c, (b >> i) & 1u8 == 1u8);
@ -405,7 +405,7 @@ mod test {
let mut input_bits = vec![];
for (byte_i, input_byte) in data.into_iter().enumerate() {
for bit_i in (0..8).rev() {
for bit_i in 0..8 {
let cs = cs.namespace(|| format!("input bit {} {}", byte_i, bit_i));
input_bits.push(AllocatedBit::alloc(cs, Some((input_byte >> bit_i) & 1u8 == 1u8)).unwrap().into());
@ -417,7 +417,7 @@ mod test {
assert!(cs.is_satisfied());
let mut s = hash_result.as_ref().iter()
.flat_map(|&byte| (0..8).rev().map(move |i| (byte >> i) & 1u8 == 1u8));
.flat_map(|&byte| (0..8).map(move |i| (byte >> i) & 1u8 == 1u8));
for b in r {
match b {

View File

@ -114,10 +114,7 @@ impl UInt32 {
/// Turns this `UInt32` into its little-endian byte order representation.
pub fn into_bits(&self) -> Vec<Boolean> {
self.bits.chunks(8)
.flat_map(|v| v.iter().rev())
.cloned()
.collect()
self.bits.clone()
}
/// Converts a little-endian byte order representation of bits into a
@ -126,10 +123,7 @@ impl UInt32 {
{
assert_eq!(bits.len(), 32);
let new_bits = bits.chunks(8)
.flat_map(|v| v.iter().rev())
.cloned()
.collect::<Vec<_>>();
let new_bits = bits.to_vec();
let mut value = Some(0u32);
for b in new_bits.iter().rev() {