From a867b1b132e323b1a7b1133d832b2bf7d1672827 Mon Sep 17 00:00:00 2001 From: LuisCastellanos-dev Date: Fri, 7 Aug 2026 18:03:34 -0600 Subject: [PATCH 1/3] doc: clarify xgcd_vartime delegates to CT xgcd pending #853 --- src/uint/gcd.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/uint/gcd.rs b/src/uint/gcd.rs index 1b7959291..dac21fc25 100644 --- a/src/uint/gcd.rs +++ b/src/uint/gcd.rs @@ -622,3 +622,33 @@ mod tests { } } } + +#[cfg(test)] +mod xgcd_vartime_delegation { + use super::*; + use crate::{U256, NonZeroUint, OddUint}; + + /// Verifies that xgcd_vartime currently delegates to xgcd (CT). + /// This test WILL FAIL when issue #853 is resolved — that is intentional. + /// When it fails, callers relying on CT behavior of xgcd_vartime must be reviewed. + #[test] + fn xgcd_vartime_matches_xgcd_uint() { + let a = U256::from(240u32); + let b = U256::from(46u32); + assert_eq!(a.xgcd(&b), a.xgcd_vartime(&b)); + } + + #[test] + fn xgcd_vartime_matches_xgcd_nonzero_uint() { + let a = NonZeroUint::<4>::new(U256::from(240u32)).unwrap(); + let b = NonZeroUint::<4>::new(U256::from(46u32)).unwrap(); + assert_eq!(a.xgcd(&b), a.xgcd_vartime(&b)); + } + + #[test] + fn xgcd_vartime_matches_xgcd_odd_uint() { + let a = OddUint::<4>::new(U256::from(241u32)).unwrap(); + let b = OddUint::<4>::new(U256::from(47u32)).unwrap(); + assert_eq!(a.xgcd(&b), a.xgcd_vartime(&b)); + } +} From 48566d2320d44026046e720807260b3e3cfaa70f Mon Sep 17 00:00:00 2001 From: LuisCastellanos-dev Date: Fri, 7 Aug 2026 18:13:17 -0600 Subject: [PATCH 2/3] doc: remove test block, keep only comment clarification --- src/uint/gcd.rs | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/src/uint/gcd.rs b/src/uint/gcd.rs index dac21fc25..1b7959291 100644 --- a/src/uint/gcd.rs +++ b/src/uint/gcd.rs @@ -622,33 +622,3 @@ mod tests { } } } - -#[cfg(test)] -mod xgcd_vartime_delegation { - use super::*; - use crate::{U256, NonZeroUint, OddUint}; - - /// Verifies that xgcd_vartime currently delegates to xgcd (CT). - /// This test WILL FAIL when issue #853 is resolved — that is intentional. - /// When it fails, callers relying on CT behavior of xgcd_vartime must be reviewed. - #[test] - fn xgcd_vartime_matches_xgcd_uint() { - let a = U256::from(240u32); - let b = U256::from(46u32); - assert_eq!(a.xgcd(&b), a.xgcd_vartime(&b)); - } - - #[test] - fn xgcd_vartime_matches_xgcd_nonzero_uint() { - let a = NonZeroUint::<4>::new(U256::from(240u32)).unwrap(); - let b = NonZeroUint::<4>::new(U256::from(46u32)).unwrap(); - assert_eq!(a.xgcd(&b), a.xgcd_vartime(&b)); - } - - #[test] - fn xgcd_vartime_matches_xgcd_odd_uint() { - let a = OddUint::<4>::new(U256::from(241u32)).unwrap(); - let b = OddUint::<4>::new(U256::from(47u32)).unwrap(); - assert_eq!(a.xgcd(&b), a.xgcd_vartime(&b)); - } -} From 2717a6dfb0ca5c4dd4dc4c14e561c1b8bb8a53eb Mon Sep 17 00:00:00 2001 From: LuisCastellanos-dev Date: Thu, 27 Aug 2026 23:37:15 -0600 Subject: [PATCH 3/3] gcd: document xgcd_vartime delegation to xgcd --- src/uint/gcd.rs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/uint/gcd.rs b/src/uint/gcd.rs index 1b7959291..777cdd0fc 100644 --- a/src/uint/gcd.rs +++ b/src/uint/gcd.rs @@ -398,7 +398,15 @@ impl Xgcd for Uint { } fn xgcd_vartime(&self, rhs: &Uint) -> Self::Output { - // TODO(#853): implement vartime + // TODO(#853): implement variable-time version. + // + // NOTE: this currently delegates to the constant-time `xgcd` implementation. + // Callers expecting variable-time performance should be aware that this runs + // in constant time and may be significantly slower than a true vartime algorithm. + // + // WARNING: when issue #853 is resolved, this will switch to a variable-time + // implementation. Callers that currently rely on constant-time behavior for + // security properties MUST NOT use `xgcd_vartime`. self.xgcd(rhs) } } @@ -411,7 +419,15 @@ impl Xgcd for NonZeroUint { } fn xgcd_vartime(&self, rhs: &NonZeroUint) -> Self::Output { - // TODO(#853): implement vartime + // TODO(#853): implement variable-time version. + // + // NOTE: this currently delegates to the constant-time `xgcd` implementation. + // Callers expecting variable-time performance should be aware that this runs + // in constant time and may be significantly slower than a true vartime algorithm. + // + // WARNING: when issue #853 is resolved, this will switch to a variable-time + // implementation. Callers that currently rely on constant-time behavior for + // security properties MUST NOT use `xgcd_vartime`. self.xgcd(rhs) } } @@ -424,7 +440,15 @@ impl Xgcd for OddUint { } fn xgcd_vartime(&self, rhs: &OddUint) -> Self::Output { - // TODO(#853): implement vartime + // TODO(#853): implement variable-time version. + // + // NOTE: this currently delegates to the constant-time `xgcd` implementation. + // Callers expecting variable-time performance should be aware that this runs + // in constant time and may be significantly slower than a true vartime algorithm. + // + // WARNING: when issue #853 is resolved, this will switch to a variable-time + // implementation. Callers that currently rely on constant-time behavior for + // security properties MUST NOT use `xgcd_vartime`. self.xgcd(rhs) } }