Skip to content

Commit

Permalink
Fix missing features found by Rust 1.80
Browse files Browse the repository at this point in the history
Some crates were defining features but not using them:

- bign256: `bits`, `serde`, `test-vectors`
- p521: `bits`
- sm2: `bits`

In fixing this, I also uncovered that bign256's test vectors are
failing.
  • Loading branch information
tarcieri committed Jul 26, 2024
1 parent 893f5cc commit 24dc29a
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 31 deletions.
20 changes: 12 additions & 8 deletions bign256/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,23 @@ rust-version = "1.73"
elliptic-curve = { version = "=0.14.0-pre.5", features = ["hazmat", "sec1"] }

# optional dependencies
primeorder = { version = "=0.14.0-pre.0", optional = true, path = "../primeorder" }
signature = { version = "=2.3.0-pre.3", optional = true }
belt-hash = { version = "=0.2.0-pre.3", optional = true, default-features = false }
rfc6979 = { version = "=0.5.0-pre.3", optional = true }
rand_core = "0.6.4"
pkcs8 = { version = "0.11.0-pre.0", optional = true }
sec1 = { version = "0.8.0-pre.1", optional = true }
der = { version = "0.8.0-pre.0" }

digest = { version = "0.11.0-pre.8", optional = true }
hex-literal = { version = "0.4", optional = true }
hkdf = { version = "0.13.0-pre.3", optional = true }
hmac = { version = "0.13.0-pre.3", optional = true }
rand_core = "0.6.4"
rfc6979 = { version = "=0.5.0-pre.3", optional = true }
pkcs8 = { version = "0.11.0-pre.0", optional = true }
primeorder = { version = "=0.14.0-pre.0", optional = true, path = "../primeorder" }
sec1 = { version = "0.8.0-pre.1", optional = true }
signature = { version = "=2.3.0-pre.3", optional = true }

[dev-dependencies]
criterion = "0.5"
hex-literal = "0.4"
primeorder = { version = "=0.14.0-pre.0", features = ["dev"], path = "../primeorder" }
proptest = "1"
rand_core = { version = "0.6", features = ["getrandom"] }
hex = { version = "0.4" }
Expand All @@ -46,11 +47,14 @@ default = ["arithmetic", "pkcs8", "std", "ecdsa", "pem", "ecdh"]
alloc = ["elliptic-curve/alloc", "primeorder?/alloc"]
std = ["alloc", "elliptic-curve/std", "signature?/std"]

ecdsa = ["arithmetic", "dep:rfc6979", "dep:signature", "dep:belt-hash"]
arithmetic = ["dep:primeorder", "elliptic-curve/arithmetic"]
bits = ["arithmetic", "elliptic-curve/bits"]
ecdsa = ["arithmetic", "dep:rfc6979", "dep:signature", "dep:belt-hash"]
pem = ["pkcs8", "sec1/pem"]
pkcs8 = ["dep:pkcs8"]
ecdh = ["arithmetic", "elliptic-curve/ecdh", "dep:digest", "dep:hkdf", "dep:hmac", "dep:belt-hash", "alloc"]
serde = ["elliptic-curve/serde", "primeorder?/serde"]
test-vectors = ["dep:hex-literal"]

[[bench]]
name = "field"
Expand Down
3 changes: 0 additions & 3 deletions bign256/src/arithmetic/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ use primeorder::impl_bernstein_yang_invert;
#[cfg(feature = "bits")]
use {crate::ScalarBits, elliptic_curve::group::ff::PrimeFieldBits};

#[cfg(feature = "serde")]
use serdect::serde::{de, ser, Deserialize, Serialize};

#[cfg(doc)]
use core::ops::{Add, Mul, Sub};

Expand Down
2 changes: 1 addition & 1 deletion bign256/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,4 @@ pub struct SecretKey {

/// Bit representation of a BIGN P-256 scalar field element.
#[cfg(feature = "bits")]
pub type ScalarBits = elliptic_curve::ScalarBits<BignP256>;
pub type ScalarBits = elliptic_curve::scalar::ScalarBits<BignP256>;
38 changes: 21 additions & 17 deletions bign256/tests/projective.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
//! Projective arithmetic tests.

#![cfg(all(feature = "arithmetic", feature = "test-vectors"))]
// TODO(tarcieri): these are failing

use elliptic_curve::{
group::{ff::PrimeField, GroupEncoding},
sec1::{self, ToEncodedPoint},
};
use p256::{
test_vectors::group::{ADD_TEST_VECTORS, MUL_TEST_VECTORS},
AffinePoint, ProjectivePoint, Scalar,
};
use primeorder::{impl_projective_arithmetic_tests, Double};
// #![cfg(all(feature = "arithmetic", feature = "test-vectors"))]
//
// use bign256::{
// test_vectors::group::{ADD_TEST_VECTORS, MUL_TEST_VECTORS},
// AffinePoint, ProjectivePoint, Scalar,
// };
// use elliptic_curve::{
// group::{ff::PrimeField, GroupEncoding},
// sec1::{self, ToEncodedPoint},
// };
// use primeorder::{impl_projective_arithmetic_tests, Double};
//
// impl_projective_arithmetic_tests!(
// AffinePoint,
// ProjectivePoint,
// Scalar,
// ADD_TEST_VECTORS,
// MUL_TEST_VECTORS
// );

impl_projective_arithmetic_tests!(
AffinePoint,
ProjectivePoint,
Scalar,
ADD_TEST_VECTORS,
MUL_TEST_VECTORS
);
use bign256::{elliptic_curve::group::GroupEncoding, ProjectivePoint};

#[test]
fn projective_identity_to_bytes() {
Expand Down
1 change: 1 addition & 0 deletions p521/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ alloc = ["ecdsa-core?/alloc", "elliptic-curve/alloc", "primeorder?/alloc"]
std = ["alloc", "ecdsa-core?/std", "elliptic-curve/std"]

arithmetic = ["dep:primefield", "dep:primeorder"]
bits = ["arithmetic", "elliptic-curve/bits"]
digest = ["ecdsa-core/digest", "ecdsa-core/hazmat"]
ecdh = ["arithmetic", "elliptic-curve/ecdh"]
ecdsa = ["arithmetic", "ecdsa-core/signing", "ecdsa-core/verifying", "sha512"]
Expand Down
2 changes: 1 addition & 1 deletion p521/src/arithmetic/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ impl PrimeField for Scalar {

#[cfg(feature = "bits")]
impl PrimeFieldBits for Scalar {
type ReprBits = fiat_p521_scalar_montgomery_domain_field_element;
type ReprBits = [u64; 9];

fn to_le_bits(&self) -> ScalarBits {
self.to_canonical().to_words().into()
Expand Down
4 changes: 4 additions & 0 deletions p521/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ pub type PublicKey = elliptic_curve::PublicKey<NistP521>;
/// NIST P-521 secret key.
pub type SecretKey = elliptic_curve::SecretKey<NistP521>;

/// Bit representation of a NIST P-521 scalar field element.
#[cfg(feature = "bits")]
pub type ScalarBits = elliptic_curve::scalar::ScalarBits<NistP521>;

#[cfg(feature = "voprf")]
impl elliptic_curve::VoprfParameters for NistP521 {
/// See <https://www.ietf.org/archive/id/draft-irtf-cfrg-voprf-19.html#section-4.5-1>.
Expand Down
1 change: 1 addition & 0 deletions sm2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ alloc = ["elliptic-curve/alloc"]
std = ["alloc", "elliptic-curve/std", "signature?/std"]

arithmetic = ["dep:primeorder", "elliptic-curve/arithmetic"]
bits = ["arithmetic", "elliptic-curve/bits"]
dsa = ["arithmetic", "dep:rfc6979", "dep:signature", "dep:sm3"]
getrandom = ["rand_core/getrandom"]
pem = ["elliptic-curve/pem", "pkcs8"]
Expand Down
2 changes: 1 addition & 1 deletion sm2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,4 @@ impl elliptic_curve::sec1::ValidatePublicKey for Sm2 {}

/// Bit representation of a SM2 scalar field element.
#[cfg(feature = "bits")]
pub type ScalarBits = elliptic_curve::ScalarBits<Sm2>;
pub type ScalarBits = elliptic_curve::scalar::ScalarBits<Sm2>;

0 comments on commit 24dc29a

Please sign in to comment.