From 1279ba492ffab3c4a57697e8856bd28372a300ef Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Mon, 18 Dec 2023 19:37:52 -0700 Subject: [PATCH] Make `Uint::gcd` a `const fn` All the prerequisites are there. It was simply an oversight not making it so in #472. --- src/modular/bernstein_yang.rs | 2 +- src/uint/gcd.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modular/bernstein_yang.rs b/src/modular/bernstein_yang.rs index 6486d0431..117b47a1c 100644 --- a/src/modular/bernstein_yang.rs +++ b/src/modular/bernstein_yang.rs @@ -99,7 +99,7 @@ impl /// /// This is defined on this type to piggyback on the definitions for `SAT_LIMBS` and `UNSAT_LIMBS` which are /// computed when defining `PrecomputeInverter::Inverter` for various `Uint` limb sizes. - pub(crate) fn gcd(f: &Uint, g: &Uint) -> Uint { + pub(crate) const fn gcd(f: &Uint, g: &Uint) -> Uint { let f_0 = Int62L::from_uint(f); let inverse = inv_mod2_62(f.as_words()); diff --git a/src/uint/gcd.rs b/src/uint/gcd.rs index bd9b0e2e8..99e032a32 100644 --- a/src/uint/gcd.rs +++ b/src/uint/gcd.rs @@ -10,8 +10,8 @@ where /// Compute the greatest common divisor (GCD) of this number and another. /// /// Panics if `self` is odd. - pub fn gcd(&self, rhs: &Self) -> Self { - debug_assert!(bool::from(self.is_odd())); + pub const fn gcd(&self, rhs: &Self) -> Self { + debug_assert!(self.is_odd().is_true_vartime()); ::Inverter::gcd(self, rhs) } }