fix: endian-ness

This commit is contained in:
Nicholas Ward 2021-07-21 14:12:33 -07:00
parent ff56486189
commit 3e00a5819f
3 changed files with 10 additions and 13 deletions

View File

@ -252,15 +252,14 @@ impl Field for CrandallField {
}
fn from_canonical_biguint(n: BigUint) -> Self {
let last_two: Vec<_> = n
let smallest_two: Vec<_> = n
.to_u32_digits()
.iter()
.rev()
.take(2)
.pad_using(2, |_| &0u32)
.map(|x| *x as u64)
.collect();
let n_u64 = last_two[0] + (1u64 << 32) * last_two[1];
let n_u64 = smallest_two[0] + (1u64 << 32) * smallest_two[1];
Self(n_u64)
}

View File

@ -98,16 +98,15 @@ impl Field for QuadraticCrandallField {
}
fn from_canonical_biguint(n: BigUint) -> Self {
let last_four: Vec<_> = n
let smallest_four: Vec<_> = n
.to_u32_digits()
.iter()
.rev()
.take(4)
.pad_using(4, |_| &0u32)
.map(|x| *x as u64)
.collect();
let last_u64 = last_four[0] + (1u64 << 32) * last_four[1];
let next_last_u64 = last_four[2] + (1u64 << 32) * last_four[3];
let last_u64 = smallest_four[0] + (1u64 << 32) * smallest_four[1];
let next_last_u64 = smallest_four[2] + (1u64 << 32) * smallest_four[3];
Self([
<Self as FieldExtension<2>>::BaseField::from_canonical_u64(last_u64),

View File

@ -138,18 +138,17 @@ impl Field for QuarticCrandallField {
}
fn from_canonical_biguint(n: BigUint) -> Self {
let last_eight: Vec<_> = n
let smallest_eight: Vec<_> = n
.to_u32_digits()
.iter()
.rev()
.take(8)
.pad_using(8, |_| &0u32)
.map(|x| *x as u64)
.collect();
let last_u64 = last_eight[0] + (1u64 << 32) * last_eight[1];
let next_last_u64 = last_eight[2] + (1u64 << 32) * last_eight[3];
let third_last_u64 = last_eight[4] + (1u64 << 32) * last_eight[5];
let fourth_last_u64 = last_eight[6] + (1u64 << 32) * last_eight[7];
let last_u64 = smallest_eight[0] + (1u64 << 32) * smallest_eight[1];
let next_last_u64 = smallest_eight[2] + (1u64 << 32) * smallest_eight[3];
let third_last_u64 = smallest_eight[4] + (1u64 << 32) * smallest_eight[5];
let fourth_last_u64 = smallest_eight[6] + (1u64 << 32) * smallest_eight[7];
Self([
<Self as FieldExtension<4>>::BaseField::from_canonical_u64(last_u64),