Skip to content

Commit

Permalink
k256: rename precomputed-tables feature (#707)
Browse files Browse the repository at this point in the history
Originally introduced as `basepoint-tables` in #705
  • Loading branch information
tarcieri authored Jan 9, 2023
1 parent 84871c3 commit e82a44c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/k256.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ jobs:
- run: cargo build --target ${{ matrix.target }} --release --no-default-features
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features alloc
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features arithmetic
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features basepoint-tables
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features bits
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features ecdh
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features ecdsa-core
Expand All @@ -49,12 +48,13 @@ jobs:
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features jwk
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features pem
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features pkcs8
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features precomputed-tables
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features schnorr
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features serde
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features sha256
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features ecdsa
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features ecdsa,sha256
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features basepoint-tables,bits,ecdh,ecdsa,hash2curve,jwk,pem,pkcs8,schnorr,serde,sha256
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features bits,ecdh,ecdsa,hash2curve,jwk,pem,pkcs8,precomputed-tables,schnorr,serde,sha256

benches:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions k256/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ rand_core = { version = "0.6", features = ["getrandom"] }
sha3 = { version = "0.10", default-features = false }

[features]
default = ["arithmetic", "basepoint-tables", "ecdsa", "pkcs8", "schnorr", "std"]
default = ["arithmetic", "ecdsa", "pkcs8", "precomputed-tables", "schnorr", "std"]
alloc = ["ecdsa-core?/alloc", "elliptic-curve/alloc"]
std = ["alloc", "ecdsa-core?/std", "elliptic-curve/std"]

arithmetic = ["elliptic-curve/arithmetic"]
basepoint-tables = ["arithmetic", "once_cell"]
bits = ["arithmetic", "elliptic-curve/bits"]
digest = ["ecdsa-core/digest", "ecdsa-core/hazmat"]
ecdh = ["arithmetic", "elliptic-curve/ecdh"]
Expand All @@ -56,6 +55,7 @@ hash2curve = ["arithmetic", "elliptic-curve/hash2curve"]
jwk = ["elliptic-curve/jwk"]
pem = ["ecdsa-core/pem", "elliptic-curve/pem", "pkcs8"]
pkcs8 = ["ecdsa-core/pkcs8", "elliptic-curve/pkcs8"]
precomputed-tables = ["arithmetic", "once_cell"]
schnorr = ["arithmetic", "sha256", "signature"]
serde = ["ecdsa-core/serde", "elliptic-curve/serde", "serdect"]
sha256 = ["digest", "sha2"]
Expand Down
10 changes: 5 additions & 5 deletions k256/src/arithmetic/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use elliptic_curve::{
IsHigh,
};

#[cfg(feature = "basepoint-tables")]
#[cfg(feature = "precomputed-tables")]
use once_cell::sync::Lazy;

/// Lookup table containing precomputed values `[p, 2p, 3p, ..., 8p]`
Expand Down Expand Up @@ -375,10 +375,10 @@ fn lincomb_generic<const N: usize>(xs: &[ProjectivePoint; N], ks: &[Scalar; N])
}

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

#[cfg(feature = "basepoint-tables")]
#[cfg(feature = "precomputed-tables")]
fn precompute_gen_lookup_table() -> [LookupTable; 33] {
let mut gen = ProjectivePoint::GENERATOR;
let mut res = [LookupTable::default(); 33];
Expand All @@ -396,13 +396,13 @@ fn precompute_gen_lookup_table() -> [LookupTable; 33] {

impl ProjectivePoint {
/// Calculates `k * G`, where `G` is the generator.
#[cfg(not(feature = "basepoint-tables"))]
#[cfg(not(feature = "precomputed-tables"))]
pub fn mul_by_generator(k: &Scalar) -> ProjectivePoint {
ProjectivePoint::GENERATOR * k
}

/// Calculates `k * G`, where `G` is the generator.
#[cfg(feature = "basepoint-tables")]
#[cfg(feature = "precomputed-tables")]
pub fn mul_by_generator(k: &Scalar) -> ProjectivePoint {
let digits = Radix16Decomposition::<65>::new(k);
let table = *GEN_LOOKUP_TABLE;
Expand Down

0 comments on commit e82a44c

Please sign in to comment.