Skip to content

Commit 93799b8

Browse files
authored
Merge pull request #35 from fjarri/bump-crypto-bigint
Bump `crypto-bigint` to 0.5.4
2 parents 6b069b6 + c8a0996 commit 93799b8

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
44
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

66

7+
## [0.5.1] - Unreleased
8+
9+
### Fixed
10+
11+
- Bumped `crypto-bigint` to 0.5.4. ([#35])
12+
13+
14+
[#35]: https://github.com/nucypher/rust-umbral/pull/35
15+
16+
717
## [0.5.0] - 2023-08-20
818

919
### Changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ categories = ["cryptography", "no-std"]
1010
rust-version = "1.65"
1111

1212
[dependencies]
13-
crypto-bigint = { version = "0.5.2", default-features = false, features = ["rand_core"] }
13+
crypto-bigint = { version = "0.5.4", default-features = false, features = ["rand_core"] }
1414
rand_core = { version = "0.6.4", default-features = false }
1515
openssl = { version = "0.10.39", optional = true, features = ["vendored"] }
1616
rug = { version = "1.18", default-features = false, features = ["integer"], optional = true }

src/hazmat/lucas.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl LucasBase for SelfridgeBase {
6060
}
6161

6262
if attempts >= ATTEMPTS_BEFORE_SQRT {
63-
let sqrt_n = n.sqrt();
63+
let sqrt_n = n.sqrt_vartime();
6464
if &sqrt_n.wrapping_mul(&sqrt_n) == n {
6565
return Err(Primality::Composite);
6666
}
@@ -137,7 +137,7 @@ impl LucasBase for BruteForceBase {
137137
}
138138

139139
if attempts >= ATTEMPTS_BEFORE_SQRT {
140-
let sqrt_n = n.sqrt();
140+
let sqrt_n = n.sqrt_vartime();
141141
if &sqrt_n.wrapping_mul(&sqrt_n) == n {
142142
return Err(Primality::Composite);
143143
}
@@ -172,25 +172,17 @@ impl LucasBase for BruteForceBase {
172172
}
173173

174174
/// For the given odd `n`, finds `s` and odd `d` such that `n + 1 == 2^s * d`.
175-
fn decompose<const L: usize>(n: &Uint<L>) -> (u32, Uint<L>) {
175+
fn decompose<const L: usize>(n: &Uint<L>) -> (usize, Uint<L>) {
176176
debug_assert!(bool::from(n.is_odd()));
177177

178178
// Need to be careful here since `n + 1` can overflow.
179179
// Instead of adding 1 and counting trailing 0s, we count trailing ones on the original `n`.
180180

181-
let mut n = *n;
182-
let mut s = 0;
183-
184-
while n.is_odd().into() {
185-
n >>= 1;
186-
s += 1;
187-
}
188-
181+
let s = n.trailing_ones();
189182
// This won't overflow since the original `n` was odd, so we right-shifted at least once.
190-
(
191-
s,
192-
Option::from(n.checked_add(&Uint::<L>::ONE)).expect("Integer overflow"),
193-
)
183+
let d = Option::from((n >> s).checked_add(&Uint::<L>::ONE)).expect("Integer overflow");
184+
185+
(s, d)
194186
}
195187

196188
/// The checks to perform in the Lucas test.
@@ -317,7 +309,8 @@ pub fn lucas_test<const L: usize>(
317309
return Primality::Composite;
318310
}
319311

320-
// Find d and s, such that d is odd and d * 2^s = (n - (D/n)).
312+
// Find `d` and `s`, such that `d` is odd and `d * 2^s = n - (D/n)`.
313+
// Since `(D/n) == -1` by construction, we're looking for `d * 2^s = n + 1`.
321314
let (s, d) = decompose(candidate);
322315

323316
// Some constants in Montgomery form

0 commit comments

Comments
 (0)