crypto_bigint/uint/
split.rs1use crate::{Limb, Uint};
2
3#[inline]
6pub(crate) const fn split_mixed<const L: usize, const H: usize, const O: usize>(
7 n: &Uint<O>,
8) -> (Uint<H>, Uint<L>) {
9 let top = L + H;
10 let top = if top < O { top } else { O };
11 let mut lo = [Limb::ZERO; L];
12 let mut hi = [Limb::ZERO; H];
13 let mut i = 0;
14
15 while i < top {
16 if i < L {
17 lo[i] = n.limbs[i];
18 } else {
19 hi[i - L] = n.limbs[i];
20 }
21 i += 1;
22 }
23
24 (Uint { limbs: hi }, Uint { limbs: lo })
25}
26
27#[cfg(test)]
28mod tests {
29 use crate::{U128, U64};
30
31 #[test]
32 fn split() {
33 let (hi, lo) = U128::from_be_hex("00112233445566778899aabbccddeeff").split();
34 assert_eq!(hi, U64::from_u64(0x0011223344556677));
35 assert_eq!(lo, U64::from_u64(0x8899aabbccddeeff));
36 }
37}