summaryrefslogtreecommitdiffstats
path: root/vendor/crypto-bigint/src/uint/add_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/add_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/add_mod.rs')
-rw-r--r--vendor/crypto-bigint/src/uint/add_mod.rs34
1 files changed, 17 insertions, 17 deletions
diff --git a/vendor/crypto-bigint/src/uint/add_mod.rs b/vendor/crypto-bigint/src/uint/add_mod.rs
index 3486a0a57..bfdda6ff5 100644
--- a/vendor/crypto-bigint/src/uint/add_mod.rs
+++ b/vendor/crypto-bigint/src/uint/add_mod.rs
@@ -1,12 +1,12 @@
-//! [`UInt`] addition modulus operations.
+//! [`Uint`] addition modulus operations.
-use crate::{AddMod, Limb, UInt};
+use crate::{AddMod, Limb, 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 integer is `< 2p`.
- pub const fn add_mod(&self, rhs: &UInt<LIMBS>, p: &UInt<LIMBS>) -> UInt<LIMBS> {
+ pub const fn add_mod(&self, rhs: &Uint<LIMBS>, p: &Uint<LIMBS>) -> Uint<LIMBS> {
let (w, carry) = self.adc(rhs, Limb::ZERO);
// Attempt to subtract the modulus, to ensure the result is in the field.
@@ -36,19 +36,19 @@ impl<const LIMBS: usize> UInt<LIMBS> {
///
/// Assumes `self + rhs` as unbounded integer is `< 2p`.
pub const fn add_mod_special(&self, rhs: &Self, c: Limb) -> Self {
- // `UInt::adc` also works with a carry greater than 1.
+ // `Uint::adc` also works with a carry greater than 1.
let (out, carry) = self.adc(rhs, c);
// If overflow occurred, then above addition of `c` already accounts
// for the overflow. Otherwise, we need to subtract `c` again, which
// in that case cannot underflow.
let l = carry.0.wrapping_sub(1) & 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> AddMod for UInt<LIMBS> {
+impl<const LIMBS: usize> AddMod for Uint<LIMBS> {
type Output = Self;
fn add_mod(&self, rhs: &Self, p: &Self) -> Self {
@@ -60,7 +60,7 @@ impl<const LIMBS: usize> AddMod for UInt<LIMBS> {
#[cfg(all(test, feature = "rand"))]
mod tests {
- use crate::{Limb, NonZero, Random, RandomMod, UInt, U256};
+ use crate::{Limb, NonZero, Random, RandomMod, Uint, U256};
use rand_core::SeedableRng;
// TODO(tarcieri): additional tests + proptests
@@ -92,17 +92,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, UInt::ONE),
- (minus_one, UInt::ONE, UInt::ZERO),
- (UInt::ONE, minus_one, UInt::ZERO),
+ (Uint::ZERO, Uint::ZERO, Uint::ZERO),
+ (Uint::ONE, Uint::ZERO, Uint::ONE),
+ (Uint::ZERO, Uint::ONE, Uint::ONE),
+ (minus_one, Uint::ONE, Uint::ZERO),
+ (Uint::ONE, minus_one, Uint::ZERO),
];
for (a, b, c) in &base_cases {
let x = a.add_mod_special(b, *special.as_ref());
@@ -110,8 +110,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.add_mod_special(&b, *special.as_ref());
assert!(c < **p, "not reduced: {} >= {} ", c, p);