summaryrefslogtreecommitdiffstats
path: root/vendor/crypto-bigint/src/uint/sub_mod.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/crypto-bigint/src/uint/sub_mod.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/crypto-bigint/src/uint/sub_mod.rs')
-rw-r--r--vendor/crypto-bigint/src/uint/sub_mod.rs48
1 files changed, 24 insertions, 24 deletions
diff --git a/vendor/crypto-bigint/src/uint/sub_mod.rs b/vendor/crypto-bigint/src/uint/sub_mod.rs
index f699f66eb..728a92760 100644
--- a/vendor/crypto-bigint/src/uint/sub_mod.rs
+++ b/vendor/crypto-bigint/src/uint/sub_mod.rs
@@ -1,12 +1,12 @@
-//! [`UInt`] subtraction modulus operations.
+//! [`Uint`] subtraction modulus operations.
-use crate::{Limb, SubMod, UInt};
+use crate::{Limb, SubMod, Uint};
-impl<const LIMBS: usize> UInt<LIMBS> {
+impl<const LIMBS: usize> Uint<LIMBS> {
/// Computes `self - rhs mod p` in constant time.
///
/// Assumes `self - rhs` as unbounded signed integer is in `[-p, p)`.
- pub const fn sub_mod(&self, rhs: &UInt<LIMBS>, p: &UInt<LIMBS>) -> UInt<LIMBS> {
+ pub const fn sub_mod(&self, rhs: &Uint<LIMBS>, p: &Uint<LIMBS>) -> Uint<LIMBS> {
let (mut out, borrow) = self.sbb(rhs, Limb::ZERO);
// If underflow occurred on the final limb, borrow = 0xfff...fff, otherwise
@@ -35,12 +35,12 @@ impl<const LIMBS: usize> UInt<LIMBS> {
// the underflow. This cannot underflow due to the assumption
// `self - rhs >= -p`.
let l = borrow.0 & c.0;
- let (out, _) = out.sbb(&UInt::from_word(l), Limb::ZERO);
+ let (out, _) = out.sbb(&Uint::from_word(l), Limb::ZERO);
out
}
}
-impl<const LIMBS: usize> SubMod for UInt<LIMBS> {
+impl<const LIMBS: usize> SubMod for Uint<LIMBS> {
type Output = Self;
fn sub_mod(&self, rhs: &Self, p: &Self) -> Self {
@@ -52,7 +52,7 @@ impl<const LIMBS: usize> SubMod for UInt<LIMBS> {
#[cfg(all(test, feature = "rand"))]
mod tests {
- use crate::{Limb, NonZero, Random, RandomMod, UInt};
+ use crate::{Limb, NonZero, Random, RandomMod, Uint};
use rand_core::SeedableRng;
macro_rules! test_sub_mod {
@@ -61,8 +61,8 @@ mod tests {
fn $test_name() {
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(1);
let moduli = [
- NonZero::<UInt<$size>>::random(&mut rng),
- NonZero::<UInt<$size>>::random(&mut rng),
+ NonZero::<Uint<$size>>::random(&mut rng),
+ NonZero::<Uint<$size>>::random(&mut rng),
];
for p in &moduli {
@@ -72,8 +72,8 @@ mod tests {
(0, 0, 0u64.into()),
];
for (a, b, c) in &base_cases {
- let a: UInt<$size> = (*a).into();
- let b: UInt<$size> = (*b).into();
+ let a: Uint<$size> = (*a).into();
+ let b: Uint<$size> = (*b).into();
let x = a.sub_mod(&b, p);
assert_eq!(*c, x, "{} - {} mod {} = {} != {}", a, b, p, x, c);
@@ -81,8 +81,8 @@ mod tests {
if $size > 1 {
for _i in 0..100 {
- let a: UInt<$size> = Limb::random(&mut rng).into();
- let b: UInt<$size> = Limb::random(&mut rng).into();
+ let a: Uint<$size> = Limb::random(&mut rng).into();
+ let b: Uint<$size> = Limb::random(&mut rng).into();
let (a, b) = if a < b { (b, a) } else { (a, b) };
let c = a.sub_mod(&b, p);
@@ -92,8 +92,8 @@ mod tests {
}
for _i in 0..100 {
- let a = UInt::<$size>::random_mod(&mut rng, p);
- let b = UInt::<$size>::random_mod(&mut rng, p);
+ let a = Uint::<$size>::random_mod(&mut rng, p);
+ let b = Uint::<$size>::random_mod(&mut rng, p);
let c = a.sub_mod(&b, p);
assert!(c < **p, "not reduced: {} >= {} ", c, p);
@@ -119,17 +119,17 @@ mod tests {
];
for special in &moduli {
- let p = &NonZero::new(UInt::ZERO.wrapping_sub(&UInt::from_word(special.0)))
+ let p = &NonZero::new(Uint::ZERO.wrapping_sub(&Uint::from_word(special.0)))
.unwrap();
- let minus_one = p.wrapping_sub(&UInt::ONE);
+ let minus_one = p.wrapping_sub(&Uint::ONE);
let base_cases = [
- (UInt::ZERO, UInt::ZERO, UInt::ZERO),
- (UInt::ONE, UInt::ZERO, UInt::ONE),
- (UInt::ZERO, UInt::ONE, minus_one),
- (minus_one, minus_one, UInt::ZERO),
- (UInt::ZERO, minus_one, UInt::ONE),
+ (Uint::ZERO, Uint::ZERO, Uint::ZERO),
+ (Uint::ONE, Uint::ZERO, Uint::ONE),
+ (Uint::ZERO, Uint::ONE, minus_one),
+ (minus_one, minus_one, Uint::ZERO),
+ (Uint::ZERO, minus_one, Uint::ONE),
];
for (a, b, c) in &base_cases {
let x = a.sub_mod_special(&b, *special.as_ref());
@@ -137,8 +137,8 @@ mod tests {
}
for _i in 0..100 {
- let a = UInt::<$size>::random_mod(&mut rng, p);
- let b = UInt::<$size>::random_mod(&mut rng, p);
+ let a = Uint::<$size>::random_mod(&mut rng, p);
+ let b = Uint::<$size>::random_mod(&mut rng, p);
let c = a.sub_mod_special(&b, *special.as_ref());
assert!(c < **p, "not reduced: {} >= {} ", c, p);