Skip to content

Commit 951a1fd

Browse files
authored
add biguint api (#20)
1 parent 99fba9c commit 951a1fd

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

crates/curves/src/utils.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ pub fn biguint_from_le_words(le_words: &[u32]) -> BigUint {
6565
BigUint::from_bytes_le(&bytes)
6666
}
6767

68+
#[inline]
69+
pub fn biguint_to_words(integer: &BigUint, num_words: usize) -> Vec<u32> {
70+
let mut bytes = integer.to_bytes_le();
71+
bytes.resize(num_words * 4, 0u8);
72+
let mut words = Vec::with_capacity(num_words);
73+
for i in 0..num_words {
74+
let word = u32::from_le_bytes([
75+
bytes[4 * i],
76+
bytes[4 * i + 1],
77+
bytes[4 * i + 2],
78+
bytes[4 * i + 3],
79+
]);
80+
words.push(word);
81+
}
82+
words
83+
}
84+
6885
#[inline]
6986
/// Converts a slice of words to a byte vector in little endian.
7087
pub fn words_to_bytes_le_vec(words: &[u32]) -> Vec<u8> {

0 commit comments

Comments
 (0)