use crypto_bigint::Uint;
pub fn from_u64_words<const BLOCK: usize>(words: &mut [u64; BLOCK]) -> Uint<BLOCK> {
words.reverse();
let res = Uint::<BLOCK>::from_words(*words);
*words = [0; BLOCK];
return res;
}
pub fn to_u64_words<const BLOCK: usize>(u: Uint<BLOCK>) -> [u64; BLOCK] {
let mut words = u.as_words().clone();
words.reverse();
return words;
}
pub fn from_u32_words<const BLOCK: usize>(words_vec: &Vec<u32>) -> Uint<BLOCK> {
if words_vec.len() != 2 * BLOCK {
panic!(
"Length of words_vec: {}\n is not 2 times the BLOCK length: {}",
words_vec.len(),
BLOCK
);
}
let mut words = [0u64; BLOCK];
for i in 0..BLOCK {
let upper = (words_vec[2 * i] as u64) << 32;
let lower = words_vec[2 * i + 1] as u64;
words[i] = upper + lower;
}
words.reverse();
let res = Uint::<BLOCK>::from_words(words);
return res;
}
pub fn to_u32_words<const BLOCK: usize>(u: Uint<BLOCK>) -> Vec<u32> {
let mut words = u.as_words().clone();
words.reverse();
let mut split = vec![0; BLOCK * 2];
for i in 0..BLOCK {
let upper: u32 = (words[i] >> 32) as u32;
let lower: u32 = words[i] as u32;
split[2 * i] = upper;
split[2 * i + 1] = lower;
}
return split.to_vec();
}