Skip to content

Commit 32343a7

Browse files
authored
k256: use std::sync::LazyLock instead of once_cell (#1135)
When building with the `precomputed-tables` and `std` features, uses the built-in implementation of `LazyLock` in lieu of `once_cell::sync::Lazy` thus avoiding the extra crate dependency. The `critical-section` feature is retained and uses `once_cell::sync::Lazy`. When `precomputed-tables`, `critical-section`, and `std` are all enabled, uses `once_cell/critical-section` and enables `once_cell/std`, which should use a `std::sync::Mutex` for synchronization.
1 parent 2436c10 commit 32343a7

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

k256/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ hash2curve = ["arithmetic", "elliptic-curve/hash2curve"]
5858
jwk = ["elliptic-curve/jwk"]
5959
pem = ["ecdsa-core/pem", "elliptic-curve/pem", "pkcs8"]
6060
pkcs8 = ["ecdsa-core/pkcs8", "elliptic-curve/pkcs8"]
61-
precomputed-tables = ["arithmetic", "once_cell"]
61+
precomputed-tables = ["arithmetic"]
6262
schnorr = ["arithmetic", "sha256", "signature"]
6363
serde = ["ecdsa-core/serde", "elliptic-curve/serde", "serdect"]
6464
sha256 = ["digest", "sha2"]

k256/src/arithmetic/mul.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,13 @@ use elliptic_curve::{
5252
subtle::{Choice, ConditionallySelectable, ConstantTimeEq},
5353
};
5454

55-
#[cfg(feature = "precomputed-tables")]
56-
use once_cell::sync::Lazy;
55+
#[cfg(all(feature = "precomputed-tables", feature = "critical-section"))]
56+
use once_cell::sync::Lazy as LazyLock;
57+
#[cfg(all(
58+
feature = "precomputed-tables",
59+
all(feature = "std", not(feature = "critical-section"))
60+
))]
61+
use std::sync::LazyLock;
5762

5863
/// Lookup table containing precomputed values `[p, 2p, 3p, ..., 8p]`
5964
#[derive(Copy, Clone, Default)]
@@ -363,7 +368,7 @@ fn lincomb(
363368

364369
/// Lazily computed basepoint table.
365370
#[cfg(feature = "precomputed-tables")]
366-
static GEN_LOOKUP_TABLE: Lazy<[LookupTable; 33]> = Lazy::new(precompute_gen_lookup_table);
371+
static GEN_LOOKUP_TABLE: LazyLock<[LookupTable; 33]> = LazyLock::new(precompute_gen_lookup_table);
367372

368373
#[cfg(feature = "precomputed-tables")]
369374
fn precompute_gen_lookup_table() -> [LookupTable; 33] {

k256/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
#[macro_use]
3333
extern crate alloc;
3434

35+
#[cfg(feature = "std")]
36+
extern crate std;
37+
3538
#[cfg(feature = "arithmetic")]
3639
mod arithmetic;
3740

0 commit comments

Comments
 (0)