summaryrefslogtreecommitdiffstats
path: root/vendor/crypto-bigint/src/uint/split.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:47:55 +0000
commit2aadc03ef15cb5ca5cc2af8a7c08e070742f0ac4 (patch)
tree033cc839730fda84ff08db877037977be94e5e3a /vendor/crypto-bigint/src/uint/split.rs
parentInitial commit. (diff)
downloadcargo-2aadc03ef15cb5ca5cc2af8a7c08e070742f0ac4.tar.xz
cargo-2aadc03ef15cb5ca5cc2af8a7c08e070742f0ac4.zip
Adding upstream version 0.70.1+ds1.upstream/0.70.1+ds1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/crypto-bigint/src/uint/split.rs')
-rw-r--r--vendor/crypto-bigint/src/uint/split.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/vendor/crypto-bigint/src/uint/split.rs b/vendor/crypto-bigint/src/uint/split.rs
new file mode 100644
index 0000000..e690974
--- /dev/null
+++ b/vendor/crypto-bigint/src/uint/split.rs
@@ -0,0 +1,37 @@
+use crate::{Limb, Uint};
+
+/// Split this number in half, returning its high and low components
+/// respectively.
+#[inline]
+pub(crate) const fn split_mixed<const L: usize, const H: usize, const O: usize>(
+ n: &Uint<O>,
+) -> (Uint<H>, Uint<L>) {
+ let top = L + H;
+ let top = if top < O { top } else { O };
+ let mut lo = [Limb::ZERO; L];
+ let mut hi = [Limb::ZERO; H];
+ let mut i = 0;
+
+ while i < top {
+ if i < L {
+ lo[i] = n.limbs[i];
+ } else {
+ hi[i - L] = n.limbs[i];
+ }
+ i += 1;
+ }
+
+ (Uint { limbs: hi }, Uint { limbs: lo })
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::{U128, U64};
+
+ #[test]
+ fn split() {
+ let (hi, lo) = U128::from_be_hex("00112233445566778899aabbccddeeff").split();
+ assert_eq!(hi, U64::from_u64(0x0011223344556677));
+ assert_eq!(lo, U64::from_u64(0x8899aabbccddeeff));
+ }
+}