From 951be44108bfbeb1028f02e48799b46eaee527ff Mon Sep 17 00:00:00 2001 From: "sm.wu" Date: Mon, 1 Dec 2025 12:52:49 +0800 Subject: [PATCH] add biguint api --- crates/curves/src/utils.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/curves/src/utils.rs b/crates/curves/src/utils.rs index 1337cb8..5cedd87 100644 --- a/crates/curves/src/utils.rs +++ b/crates/curves/src/utils.rs @@ -65,6 +65,23 @@ pub fn biguint_from_le_words(le_words: &[u32]) -> BigUint { BigUint::from_bytes_le(&bytes) } +#[inline] +pub fn biguint_to_words(integer: &BigUint, num_words: usize) -> Vec { + let mut bytes = integer.to_bytes_le(); + bytes.resize(num_words * 4, 0u8); + let mut words = Vec::with_capacity(num_words); + for i in 0..num_words { + let word = u32::from_le_bytes([ + bytes[4 * i], + bytes[4 * i + 1], + bytes[4 * i + 2], + bytes[4 * i + 3], + ]); + words.push(word); + } + words +} + #[inline] /// Converts a slice of words to a byte vector in little endian. pub fn words_to_bytes_le_vec(words: &[u32]) -> Vec {