diff --git a/.github/workflows/k256.yml b/.github/workflows/k256.yml index d1c669c1..22648a9b 100644 --- a/.github/workflows/k256.yml +++ b/.github/workflows/k256.yml @@ -3,8 +3,8 @@ name: k256 on: pull_request: paths: - - "elliptic-curve-crate/**" - "k256/**" + - "tests/k256_no_std/**" - "Cargo.*" push: branches: master @@ -28,6 +28,9 @@ jobs: target: - thumbv7em-none-eabi - wasm32-unknown-unknown + defaults: + run: + working-directory: tests/k256_no_std steps: - uses: actions/checkout@v1 - uses: actions-rs/toolchain@v1 @@ -36,13 +39,14 @@ jobs: toolchain: ${{ matrix.rust }} target: ${{ matrix.target }} override: true - - run: cargo build --no-default-features --release --target ${{ matrix.target }} - - run: cargo build --no-default-features --features arithmetic --release --target ${{ matrix.target }} - - run: cargo build --no-default-features --features ecdsa-core --release --target ${{ matrix.target }} - # TODO(tarcieri): use new cargo resolver when stable: https://github.com/rust-lang/cargo/issues/7915 - #- run: cargo build --no-default-features --features ecdsa --release --target ${{ matrix.target }} - #- run: cargo build --no-default-features --features rand --release --target ${{ matrix.target }} - - run: cargo build --no-default-features --features sha256 --release --target ${{ matrix.target }} + - run: cargo build --release --target ${{ matrix.target }} + - run: cargo build --release --target ${{ matrix.target }} --features arithmetic + - run: cargo build --release --target ${{ matrix.target }} --features ecdh + - run: cargo build --release --target ${{ matrix.target }} --features ecdsa-core + - run: cargo build --release --target ${{ matrix.target }} --features ecdsa + - run: cargo build --release --target ${{ matrix.target }} --features keccak256 + - run: cargo build --release --target ${{ matrix.target }} --features sha256 + - run: cargo build --release --target ${{ matrix.target }} --all-features test: runs-on: ubuntu-latest strategy: @@ -60,6 +64,6 @@ jobs: - run: cargo test --no-default-features - run: cargo test - run: cargo test --all-features - - run: cargo test --features field-montgomery,rand - - run: cargo test --features force-32-bit,rand + - run: cargo test --features field-montgomery + - run: cargo test --features force-32-bit - run: cargo build --all-features --benches diff --git a/.github/workflows/p256.yml b/.github/workflows/p256.yml index 3479abd9..b1091908 100644 --- a/.github/workflows/p256.yml +++ b/.github/workflows/p256.yml @@ -3,8 +3,8 @@ name: p256 on: pull_request: paths: - - "elliptic-curve-crate/**" - "p256/**" + - "tests/p256_no_std/**" - "Cargo.*" push: branches: master @@ -28,6 +28,9 @@ jobs: target: - thumbv7em-none-eabi - wasm32-unknown-unknown + defaults: + run: + working-directory: tests/p256_no_std steps: - uses: actions/checkout@v1 - uses: actions-rs/toolchain@v1 @@ -36,13 +39,13 @@ jobs: toolchain: ${{ matrix.rust }} target: ${{ matrix.target }} override: true - - run: cargo build --no-default-features --release --target ${{ matrix.target }} - - run: cargo build --no-default-features --features arithmetic --release --target ${{ matrix.target }} - - run: cargo build --no-default-features --features ecdsa-core --release --target ${{ matrix.target }} - # TODO(tarcieri): use new cargo resolver when stable: https://github.com/rust-lang/cargo/issues/7915 - #- run: cargo build --no-default-features --features rand --release --target ${{ matrix.target }} - #- run: cargo build --no-default-features --features ecdsa --release --target ${{ matrix.target }} - - run: cargo build --no-default-features --features sha256 --release --target ${{ matrix.target }} + - run: cargo build --release --target ${{ matrix.target }} + - run: cargo build --release --target ${{ matrix.target }} --features arithmetic + - run: cargo build --release --target ${{ matrix.target }} --features ecdh + - run: cargo build --release --target ${{ matrix.target }} --features ecdsa-core + - run: cargo build --release --target ${{ matrix.target }} --features ecdsa + - run: cargo build --release --target ${{ matrix.target }} --features sha256 + - run: cargo build --release --target ${{ matrix.target }} --all-features test: runs-on: ubuntu-latest strategy: diff --git a/.github/workflows/p384.yml b/.github/workflows/p384.yml index aec6bc97..7f6d361f 100644 --- a/.github/workflows/p384.yml +++ b/.github/workflows/p384.yml @@ -3,8 +3,8 @@ name: p384 on: pull_request: paths: - - "elliptic-curve-crate/**" - "p384/**" + - "tests/p384_no_std/**" - "Cargo.*" push: branches: master @@ -28,6 +28,9 @@ jobs: target: - thumbv7em-none-eabi - wasm32-unknown-unknown + defaults: + run: + working-directory: tests/p384_no_std steps: - uses: actions/checkout@v1 - uses: actions-rs/toolchain@v1 @@ -36,7 +39,10 @@ jobs: toolchain: ${{ matrix.rust }} target: ${{ matrix.target }} override: true - - run: cargo build --no-default-features --release --target ${{ matrix.target }} + - run: cargo build --release --target ${{ matrix.target }} + - run: cargo build --release --target ${{ matrix.target }} --features ecdsa + - run: cargo build --release --target ${{ matrix.target }} --features sha384 + - run: cargo build --release --target ${{ matrix.target }} --all-features test: runs-on: ubuntu-latest strategy: diff --git a/.gitignore b/.gitignore index 7d0d0d09..c5cd1066 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ target +tests/Cargo.lock *.sw* diff --git a/Cargo.lock b/Cargo.lock index 99fab962..11b992ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -243,7 +243,7 @@ dependencies = [ [[package]] name = "ecdsa" version = "0.7.2" -source = "git+https://github.com/RustCrypto/signatures#5046c9244904a8a6f0200d1c89024199c17e7582" +source = "git+https://github.com/RustCrypto/signatures#1b54c722c4292222b5c603c657db7891785de226" dependencies = [ "elliptic-curve", "hmac", @@ -259,16 +259,29 @@ checksum = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f" [[package]] name = "elliptic-curve" version = "0.5.0" -source = "git+https://github.com/RustCrypto/traits#ab2598b62c35d8e9350937b2f632c54b84cbcb01" +source = "git+https://github.com/RustCrypto/traits#80abd0a2e92202915d853cf644ec8de50c2c3324" dependencies = [ "const-oid", "digest", + "ff", "generic-array", + "group", "rand_core", "subtle", "zeroize", ] +[[package]] +name = "ff" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11efdc125f2647dde5a0f5f88010a5b0f89b700f86052afa1d148c4696047" +dependencies = [ + "byteorder", + "rand_core", + "subtle", +] + [[package]] name = "fnv" version = "1.0.7" @@ -296,6 +309,17 @@ dependencies = [ "wasi", ] +[[package]] +name = "group" +version = "0.7.0" +source = "git+https://github.com/zkcrypto/group.git#2942324876cdbb5c94140ad39ae83da642c30374" +dependencies = [ + "byteorder", + "ff", + "rand_core", + "subtle", +] + [[package]] name = "half" version = "1.6.0" diff --git a/Cargo.toml b/Cargo.toml index 668b5fd1..abc31941 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,4 @@ members = [ [patch.crates-io] ecdsa = { git = "https://github.com/RustCrypto/signatures" } elliptic-curve = { git = "https://github.com/RustCrypto/traits" } +group = { git = "https://github.com/zkcrypto/group.git" } diff --git a/k256/Cargo.toml b/k256/Cargo.toml index b2661948..665535a5 100644 --- a/k256/Cargo.toml +++ b/k256/Cargo.toml @@ -18,7 +18,7 @@ keywords = ["bitcoin", "crypto", "ecc", "ethereum", "secp256k1"] [dependencies] cfg-if = "0.1" ecdsa-core = { version = "0.7", package = "ecdsa", optional = true, default-features = false } -elliptic-curve = { version = "0.5", default-features = false, features = ["weierstrass"] } +elliptic-curve = { version = "0.5", default-features = false } sha2 = { version = "0.9", optional = true, default-features = false } sha3 = { version = "0.9", optional = true, default-features = false } @@ -36,15 +36,14 @@ rand_core = { version = "0.5", features = ["getrandom"] } default = ["arithmetic", "oid", "std"] arithmetic = [] digest = ["elliptic-curve/digest", "ecdsa-core/digest"] -ecdh = ["elliptic-curve/ecdh", "rand", "zeroize"] -ecdsa = ["arithmetic", "digest", "ecdsa-core/rand", "ecdsa-core/sign", "ecdsa-core/verify", "rand", "zeroize"] +ecdh = ["elliptic-curve/ecdh", "zeroize"] +ecdsa = ["arithmetic", "digest", "ecdsa-core/sign", "ecdsa-core/verify", "zeroize"] endomorphism-mul = [] expose-field = ["arithmetic"] field-montgomery = [] force-32-bit = [] keccak256 = ["digest", "sha3"] oid = ["elliptic-curve/oid"] -rand = ["elliptic-curve/rand"] sha256 = ["digest", "sha2"] test-vectors = [] std = ["elliptic-curve/std"] diff --git a/k256/src/arithmetic.rs b/k256/src/arithmetic.rs index 46687316..a7541741 100644 --- a/k256/src/arithmetic.rs +++ b/k256/src/arithmetic.rs @@ -44,7 +44,6 @@ mod tests { assert_eq!(CURVE_EQUATION_B.to_bytes(), CURVE_EQUATION_B_BYTES.into()); } - #[cfg(feature = "rand")] #[test] fn generate_secret_key() { use crate::SecretKey; diff --git a/k256/src/arithmetic/scalar.rs b/k256/src/arithmetic/scalar.rs index 1cdc3fbe..1f1e19a1 100644 --- a/k256/src/arithmetic/scalar.rs +++ b/k256/src/arithmetic/scalar.rs @@ -6,12 +6,10 @@ cfg_if! { if #[cfg(any(target_pointer_width = "32", feature = "force-32-bit"))] { mod scalar_8x32; use scalar_8x32::Scalar8x32 as ScalarImpl; - #[cfg(feature = "rand")] use scalar_8x32::WideScalar16x32 as WideScalarImpl; } else if #[cfg(target_pointer_width = "64")] { mod scalar_4x64; use scalar_4x64::Scalar4x64 as ScalarImpl; - #[cfg(feature = "rand")] use scalar_4x64::WideScalar8x64 as WideScalarImpl; } } @@ -21,19 +19,14 @@ use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Shr, Sub, SubAssign}; use elliptic_curve::{ consts::U32, ops::Invert, + rand_core::{CryptoRng, RngCore}, subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}, - FromBytes, + FromBytes, Generate, }; #[cfg(feature = "digest")] use elliptic_curve::{Digest, FromDigest}; -#[cfg(feature = "rand")] -use elliptic_curve::{ - rand_core::{CryptoRng, RngCore}, - Generate, -}; - #[cfg(feature = "zeroize")] use elliptic_curve::zeroize::Zeroize; @@ -197,7 +190,6 @@ impl Scalar { } /// Returns a (nearly) uniformly-random scalar, generated in constant time. - #[cfg(feature = "rand")] pub fn generate_biased(mut rng: impl CryptoRng + RngCore) -> Self { // We reduce a random 512-bit value into a 256-bit field, which results in a // negligible bias from the uniform distribution, but the process is constant-time. @@ -207,7 +199,6 @@ impl Scalar { } /// Returns a uniformly-random scalar, generated using rejection sampling. - #[cfg(feature = "rand")] pub fn generate_vartime(mut rng: impl CryptoRng + RngCore) -> Self { let mut bytes = ElementBytes::default(); @@ -399,7 +390,6 @@ impl From for ElementBytes { } } -#[cfg(feature = "rand")] impl Generate for Scalar { fn generate(rng: impl CryptoRng + RngCore) -> Self { // Uses rejection sampling as the default random generation method, @@ -511,7 +501,6 @@ mod tests { assert_eq!(res, res_ref); } - #[cfg(feature = "rand")] #[test] fn generate_biased() { use elliptic_curve::rand_core::OsRng; @@ -520,7 +509,6 @@ mod tests { assert_eq!((a - &a).is_zero().unwrap_u8(), 1); } - #[cfg(feature = "rand")] #[test] fn generate_vartime() { use elliptic_curve::rand_core::OsRng; diff --git a/k256/src/arithmetic/scalar/scalar_4x64.rs b/k256/src/arithmetic/scalar/scalar_4x64.rs index 1a93c510..30daaf1b 100644 --- a/k256/src/arithmetic/scalar/scalar_4x64.rs +++ b/k256/src/arithmetic/scalar/scalar_4x64.rs @@ -413,7 +413,6 @@ impl ConstantTimeEq for Scalar4x64 { pub struct WideScalar8x64([u64; 8]); impl WideScalar8x64 { - #[cfg(feature = "rand")] pub fn from_bytes(bytes: &[u8; 64]) -> Self { let mut w = [0u64; 8]; for i in 0..8 { diff --git a/k256/src/arithmetic/scalar/scalar_8x32.rs b/k256/src/arithmetic/scalar/scalar_8x32.rs index fdf9ed8e..38859fd9 100644 --- a/k256/src/arithmetic/scalar/scalar_8x32.rs +++ b/k256/src/arithmetic/scalar/scalar_8x32.rs @@ -551,7 +551,6 @@ impl ConstantTimeEq for Scalar8x32 { pub struct WideScalar16x32([u32; 16]); impl WideScalar16x32 { - #[cfg(feature = "rand")] pub fn from_bytes(bytes: &[u8; 64]) -> Self { let mut w = [0u32; 16]; for i in 0..16 { diff --git a/k256/src/ecdsa/recoverable.rs b/k256/src/ecdsa/recoverable.rs index 9198a1e1..a97d03b4 100644 --- a/k256/src/ecdsa/recoverable.rs +++ b/k256/src/ecdsa/recoverable.rs @@ -47,7 +47,7 @@ use crate::{ AffinePoint, NonZeroScalar, ProjectivePoint, Scalar, }; -#[cfg(any(feature = "ecdsa", docsrs))] +#[cfg(any(all(feature = "ecdsa", feature = "keccak256"), docsrs))] use crate::EncodedPoint; #[cfg(feature = "keccak256")] @@ -94,8 +94,9 @@ impl Signature { /// Given a public key, message, and signature, use trial recovery for both /// possible recovery IDs in an attempt to determine if a suitable /// recovery ID exists, or return an error otherwise. - #[cfg(feature = "ecdsa")] + #[cfg(all(feature = "ecdsa", feature = "keccak256"))] #[cfg_attr(docsrs, doc(cfg(feature = "ecdsa")))] + #[cfg_attr(docsrs, doc(cfg(feature = "keccak256")))] pub fn from_trial_recovery( public_key: &EncodedPoint, msg: &[u8], @@ -120,7 +121,8 @@ impl Signature { /// Recover the public key used to create the given signature as an /// [`EncodedPoint`]. #[cfg(all(feature = "ecdsa", feature = "keccak256"))] - #[cfg_attr(docsrs, doc(cfg(feature = "ecdsa")), doc(cfg(feature = "keccak256")))] + #[cfg_attr(docsrs, doc(cfg(feature = "ecdsa")))] + #[cfg_attr(docsrs, doc(cfg(feature = "keccak256")))] pub fn recover_verify_key(&self, msg: &[u8]) -> Result { self.recover_verify_key_from_digest(Keccak256::new().chain(msg)) } diff --git a/k256/src/ecdsa/sign.rs b/k256/src/ecdsa/sign.rs index 3dc47428..f4da8a6a 100644 --- a/k256/src/ecdsa/sign.rs +++ b/k256/src/ecdsa/sign.rs @@ -17,7 +17,7 @@ use elliptic_curve::{ }; use signature::PrehashSignature; -#[cfg(any(feature = "sha256", feature = "keccak256"))] +#[cfg(feature = "digest")] use signature::digest::Digest; /// ECDSA/secp256k1 signing key diff --git a/p256/Cargo.toml b/p256/Cargo.toml index 3eabe7ee..fa83cb90 100644 --- a/p256/Cargo.toml +++ b/p256/Cargo.toml @@ -17,7 +17,7 @@ keywords = ["crypto", "ecc", "nist", "prime256v1", "secp256r1"] [dependencies] ecdsa-core = { version = "0.7", package = "ecdsa", optional = true, default-features = false } -elliptic-curve = { version = "0.5", default-features = false, features = ["weierstrass"] } +elliptic-curve = { version = "0.5", default-features = false } sha2 = { version = "0.9", optional = true, default-features = false } [dev-dependencies] @@ -31,10 +31,9 @@ rand_core = { version = "0.5", features = ["getrandom"] } default = ["arithmetic", "std"] arithmetic = [] digest = ["elliptic-curve/digest", "ecdsa-core/digest"] -ecdh = ["elliptic-curve/ecdh", "rand", "zeroize"] -ecdsa = ["arithmetic", "ecdsa-core/rand", "ecdsa-core/sign", "ecdsa-core/verify", "rand", "sha256", "zeroize"] +ecdh = ["elliptic-curve/ecdh", "zeroize"] +ecdsa = ["arithmetic", "ecdsa-core/sign", "ecdsa-core/verify", "sha256", "zeroize"] oid = ["elliptic-curve/oid"] -rand = ["elliptic-curve/rand"] sha256 = ["digest", "ecdsa-core/hazmat", "sha2"] test-vectors = [] std = ["elliptic-curve/std"] diff --git a/p256/src/arithmetic.rs b/p256/src/arithmetic.rs index f65e33ee..178bac50 100644 --- a/p256/src/arithmetic.rs +++ b/p256/src/arithmetic.rs @@ -53,7 +53,6 @@ mod tests { ); } - #[cfg(feature = "rand")] #[test] fn generate_secret_key() { use crate::SecretKey; diff --git a/p256/src/arithmetic/field.rs b/p256/src/arithmetic/field.rs index 9621b8e3..77345bc0 100644 --- a/p256/src/arithmetic/field.rs +++ b/p256/src/arithmetic/field.rs @@ -4,13 +4,11 @@ use crate::ElementBytes; use core::convert::TryInto; use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign}; use elliptic_curve::{ + rand_core::{CryptoRng, RngCore}, subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}, util::{adc64, mac64, sbb64}, }; -#[cfg(feature = "rand")] -use elliptic_curve::rand_core::{CryptoRng, RngCore}; - #[cfg(feature = "zeroize")] use elliptic_curve::zeroize::Zeroize; @@ -92,7 +90,6 @@ impl FieldElement { } /// Returns a uniformly-random element within the field. - #[cfg(feature = "rand")] pub fn generate(mut rng: impl CryptoRng + RngCore) -> Self { // We reduce a random 512-bit value into a 256-bit field, which results in a // negligible bias from the uniform distribution. @@ -101,7 +98,6 @@ impl FieldElement { FieldElement::from_bytes_wide(buf) } - #[cfg(feature = "rand")] fn from_bytes_wide(bytes: [u8; 64]) -> Self { FieldElement::montgomery_reduce( u64::from_be_bytes(bytes[0..8].try_into().unwrap()), diff --git a/p256/src/arithmetic/scalar.rs b/p256/src/arithmetic/scalar.rs index 179a1d32..5a207966 100644 --- a/p256/src/arithmetic/scalar.rs +++ b/p256/src/arithmetic/scalar.rs @@ -1,6 +1,5 @@ //! Scalar field arithmetic modulo n = 115792089210356248762697446949407573529996955224135760342422259061068512044369 -#[cfg(feature = "rand")] pub mod blinding; use crate::{ElementBytes, NistP256, SecretKey}; @@ -11,20 +10,15 @@ use core::{ use elliptic_curve::{ consts::U32, ops::Invert, + rand_core::{CryptoRng, RngCore}, subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}, util::{adc64, mac64, sbb64}, - FromBytes, + FromBytes, Generate, }; #[cfg(feature = "digest")] use elliptic_curve::{Digest, FromDigest}; -#[cfg(feature = "rand")] -use elliptic_curve::{ - rand_core::{CryptoRng, RngCore}, - Generate, -}; - #[cfg(feature = "zeroize")] use elliptic_curve::zeroize::Zeroize; @@ -700,7 +694,6 @@ impl From for ElementBytes { } } -#[cfg(feature = "rand")] impl Generate for Scalar { fn generate(mut rng: impl CryptoRng + RngCore) -> Self { let mut bytes = ElementBytes::default(); diff --git a/p256/src/arithmetic/scalar/blinding.rs b/p256/src/arithmetic/scalar/blinding.rs index 65771789..f4dea69f 100644 --- a/p256/src/arithmetic/scalar/blinding.rs +++ b/p256/src/arithmetic/scalar/blinding.rs @@ -20,7 +20,6 @@ use elliptic_curve::zeroize::Zeroize; /// This provides a randomly blinded impl of [`Invert`] which is useful for /// ECDSA ephemeral (`k`) scalars. #[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))] -#[cfg_attr(docsrs, doc(cfg(feature = "rand")))] pub struct BlindedScalar { /// Actual scalar value scalar: Scalar, diff --git a/p256/src/ecdsa.rs b/p256/src/ecdsa.rs index a5419d26..f2452da8 100644 --- a/p256/src/ecdsa.rs +++ b/p256/src/ecdsa.rs @@ -134,13 +134,11 @@ mod tests { use crate::{ ecdsa::{signature::Signer, SigningKey}, test_vectors::ecdsa::ECDSA_TEST_VECTORS, - NistP256, + BlindedScalar, NistP256, Scalar, }; + use elliptic_curve::rand_core::OsRng; use hex_literal::hex; - #[cfg(feature = "rand")] - use crate::{elliptic_curve::rand_core::OsRng, BlindedScalar, Scalar}; - ecdsa_core::new_signing_test!(NistP256, ECDSA_TEST_VECTORS); // Test vector from RFC 6979 Appendix 2.5 (NIST P-256 + SHA-256) @@ -159,7 +157,6 @@ mod tests { ); } - #[cfg(feature = "rand")] #[test] fn scalar_blinding() { let vector = &ECDSA_TEST_VECTORS[0]; diff --git a/p256/src/lib.rs b/p256/src/lib.rs index ce9b7b1f..aa9ef0f1 100644 --- a/p256/src/lib.rs +++ b/p256/src/lib.rs @@ -61,12 +61,10 @@ pub use elliptic_curve; pub use arithmetic::{ affine::AffinePoint, projective::ProjectivePoint, + scalar::blinding::BlindedScalar, scalar::{NonZeroScalar, Scalar}, }; -#[cfg(all(feature = "arithmetic", feature = "rand"))] -pub use arithmetic::scalar::blinding::BlindedScalar; - use elliptic_curve::consts::U32; #[cfg(feature = "oid")] diff --git a/p384/Cargo.toml b/p384/Cargo.toml index 18d8b0e3..9aa19563 100644 --- a/p384/Cargo.toml +++ b/p384/Cargo.toml @@ -13,10 +13,11 @@ keywords = ["crypto", "ecc", "nist", "secp384r1"] [dependencies] ecdsa = { version = "0.7", optional = true, default-features = false } -elliptic-curve = { version = "0.5", default-features = false, features = ["weierstrass"] } +elliptic-curve = { version = "0.5", default-features = false } sha2 = { version = "0.9", optional = true, default-features = false } [features] +default = ["oid", "std"] oid = ["elliptic-curve/oid"] sha384 = ["ecdsa/digest", "ecdsa/hazmat", "sha2"] std = ["elliptic-curve/std"] diff --git a/tests/Cargo.toml b/tests/Cargo.toml new file mode 100644 index 00000000..6014fa81 --- /dev/null +++ b/tests/Cargo.toml @@ -0,0 +1,11 @@ +[workspace] +members = [ + "k256_no_std", + "p256_no_std", + "p384_no_std", +] + +[patch.crates-io] +ecdsa = { git = "https://github.com/RustCrypto/signatures" } +elliptic-curve = { git = "https://github.com/RustCrypto/traits" } +group = { git = "https://github.com/zkcrypto/group.git" } diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 00000000..917ccb79 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,16 @@ +# no_std tests + +This directory and associated CI configs in `.github` is a workaround for +issues with the `cargo` resolver activating features from dev-dependencies +which cause `std` to get linked in a release target. + +It contains small test crates in their own isolated workspace which ensure that +these features are not activated when linking and therefore that the crates +will link in `no_std` environments when consumed as a dependency of another +`no_std`-compatible crate. + +Here are upstream issues tracking the problem: + +- [#7914: Tracking issue for `-Z features=itarget`](https://github.com/rust-lang/cargo/issues/7914) +- [#7915: Tracking issue for `-Z features=host_dep`](https://github.com/rust-lang/cargo/issues/7915) +- [#7916: Tracking issue for `-Z features=dev_dep`](https://github.com/rust-lang/cargo/issues/7916]) diff --git a/tests/k256_no_std/Cargo.toml b/tests/k256_no_std/Cargo.toml new file mode 100644 index 00000000..5b25115d --- /dev/null +++ b/tests/k256_no_std/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "k256_no_std" +version = "0.1.0" +authors = ["RustCrypto Developers"] +edition = "2018" + +[dependencies] +k256 = { path = "../../k256", default-features = false } + +[features] +arithmetic = ["k256/arithmetic"] +ecdh = ["k256/ecdh"] +ecdsa = ["k256/ecdsa"] +ecdsa-core = ["k256/ecdsa-core"] +keccak256 = ["k256/keccak256"] +sha256 = ["k256/sha256"] diff --git a/tests/k256_no_std/src/lib.rs b/tests/k256_no_std/src/lib.rs new file mode 100644 index 00000000..0c9ac1ac --- /dev/null +++ b/tests/k256_no_std/src/lib.rs @@ -0,0 +1 @@ +#![no_std] diff --git a/tests/p256_no_std/Cargo.toml b/tests/p256_no_std/Cargo.toml new file mode 100644 index 00000000..64f68238 --- /dev/null +++ b/tests/p256_no_std/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "p256_no_std" +version = "0.1.0" +authors = ["RustCrypto Developers"] +edition = "2018" + +[dependencies] +p256 = { path = "../../p256", default-features = false } + +[features] +arithmetic = ["p256/arithmetic"] +ecdh = ["p256/ecdh"] +ecdsa = ["p256/ecdsa"] +ecdsa-core = ["p256/ecdsa-core"] +sha256 = ["p256/sha256"] diff --git a/tests/p256_no_std/src/lib.rs b/tests/p256_no_std/src/lib.rs new file mode 100644 index 00000000..0c9ac1ac --- /dev/null +++ b/tests/p256_no_std/src/lib.rs @@ -0,0 +1 @@ +#![no_std] diff --git a/tests/p384_no_std/Cargo.toml b/tests/p384_no_std/Cargo.toml new file mode 100644 index 00000000..77f03610 --- /dev/null +++ b/tests/p384_no_std/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "p384_no_std" +version = "0.1.0" +authors = ["RustCrypto Developers"] +edition = "2018" + +[dependencies] +p384 = { path = "../../p384", default-features = false } + +[features] +ecdsa = ["p384/ecdsa"] +sha384 = ["p384/sha384"] diff --git a/tests/p384_no_std/src/lib.rs b/tests/p384_no_std/src/lib.rs new file mode 100644 index 00000000..0c9ac1ac --- /dev/null +++ b/tests/p384_no_std/src/lib.rs @@ -0,0 +1 @@ +#![no_std]