diff --git a/.github/workflows/k256.yml b/.github/workflows/k256.yml index 441d1bc56..8480e786e 100644 --- a/.github/workflows/k256.yml +++ b/.github/workflows/k256.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: rust: - - 1.41.0 # MSRV + - 1.44.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -53,7 +53,7 @@ jobs: strategy: matrix: rust: - - 1.41.0 # MSRV + - 1.44.0 # MSRV - stable steps: - uses: actions/checkout@v1 diff --git a/.github/workflows/p256.yml b/.github/workflows/p256.yml index 8eb0774a7..a53bebaa0 100644 --- a/.github/workflows/p256.yml +++ b/.github/workflows/p256.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: rust: - - 1.41.0 # MSRV + - 1.44.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -52,7 +52,7 @@ jobs: strategy: matrix: rust: - - 1.41.0 # MSRV + - 1.44.0 # MSRV - stable steps: - uses: actions/checkout@v1 diff --git a/.github/workflows/p384.yml b/.github/workflows/p384.yml index 920eb1522..b2badbefc 100644 --- a/.github/workflows/p384.yml +++ b/.github/workflows/p384.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: rust: - - 1.41.0 # MSRV + - 1.44.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -49,7 +49,7 @@ jobs: strategy: matrix: rust: - - 1.41.0 # MSRV + - 1.44.0 # MSRV - stable steps: - uses: actions/checkout@v1 diff --git a/.github/workflows/workspace.yml b/.github/workflows/workspace.yml index b2d952000..4163786b3 100644 --- a/.github/workflows/workspace.yml +++ b/.github/workflows/workspace.yml @@ -21,7 +21,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.41.0 + toolchain: 1.44.0 # MSRV components: clippy - run: cargo clippy --all --all-features -- -D warnings diff --git a/Cargo.lock b/Cargo.lock index aac4b9c58..0c8b96556 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,6 +38,17 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "bitvec" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c1f0df4bb4c441080e98d6ea2dc3281fc19bb440e69ce03075e3d705894f1cb" +dependencies = [ + "funty", + "radium", + "wyz", +] + [[package]] name = "block-buffer" version = "0.9.0" @@ -243,7 +254,7 @@ dependencies = [ [[package]] name = "ecdsa" version = "0.7.2" -source = "git+https://github.com/RustCrypto/signatures#d1a8f0812db4f09e75e5171b182e4b9b002d9d1d" +source = "git+https://github.com/RustCrypto/signatures#e6151cdfaf003fa350bc1a1d5146d31b6c311518" dependencies = [ "elliptic-curve", "hmac", @@ -259,8 +270,9 @@ checksum = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f" [[package]] name = "elliptic-curve" version = "0.5.0" -source = "git+https://github.com/RustCrypto/traits#88d462bd5c94a1b1dbf3f2f5375fdfc406b35293" +source = "git+https://github.com/RustCrypto/traits#548e11779ea85d411daa39214afcd7cc6c72c2b8" dependencies = [ + "bitvec", "const-oid", "digest", "ff", @@ -273,11 +285,11 @@ dependencies = [ [[package]] name = "ff" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01d11efdc125f2647dde5a0f5f88010a5b0f89b700f86052afa1d148c4696047" +checksum = "01646e077d4ebda82b73f1bca002ea1e91561a77df2431a9e79729bcc31950ef" dependencies = [ - "byteorder", + "bitvec", "rand_core", "subtle", ] @@ -288,6 +300,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "funty" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ba62103ce691c2fd80fbae2213dfdda9ce60804973ac6b6e97de818ea7f52c8" + [[package]] name = "generic-array" version = "0.14.4" @@ -311,10 +329,10 @@ dependencies = [ [[package]] name = "group" -version = "0.7.0" -source = "git+https://github.com/zkcrypto/group.git#2942324876cdbb5c94140ad39ae83da642c30374" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc11f9f5fbf1943b48ae7c2bf6846e7d827a512d1be4f23af708f5ca5d01dde1" dependencies = [ - "byteorder", "ff", "rand_core", "subtle", @@ -374,9 +392,9 @@ checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" [[package]] name = "js-sys" -version = "0.3.44" +version = "0.3.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85a7e2c92a4804dd459b86c339278d0fe87cf93757fae222c3fa3ae75458bc73" +checksum = "ca059e81d9486668f12d455a4ea6daa600bd408134cd17e3d3fb5a32d1f016f8" dependencies = [ "wasm-bindgen", ] @@ -385,7 +403,6 @@ dependencies = [ name = "k256" version = "0.4.2" dependencies = [ - "byteorder", "cfg-if", "criterion", "ecdsa", @@ -504,7 +521,6 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" name = "p256" version = "0.4.1" dependencies = [ - "byteorder", "ecdsa", "elliptic-curve", "hex", @@ -585,6 +601,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "def50a86306165861203e7f84ecffbbdfdea79f0e51039b33de1e952358c47ac" + [[package]] name = "rand" version = "0.7.3" @@ -931,9 +953,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasm-bindgen" -version = "0.2.67" +version = "0.2.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0563a9a4b071746dd5aedbc3a28c6fe9be4586fb3fbadb67c400d4f53c6b16c" +checksum = "1ac64ead5ea5f05873d7c12b545865ca2b8d28adfc50a49b84770a3a97265d42" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -941,9 +963,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.67" +version = "0.2.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc71e4c5efa60fb9e74160e89b93353bc24059999c0ae0fb03affc39770310b0" +checksum = "f22b422e2a757c35a73774860af8e112bff612ce6cb604224e8e47641a9e4f68" dependencies = [ "bumpalo", "lazy_static", @@ -956,9 +978,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.67" +version = "0.2.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97c57cefa5fa80e2ba15641578b44d36e7a64279bc5ed43c6dbaf329457a2ed2" +checksum = "6b13312a745c08c469f0b292dd2fcd6411dba5f7160f593da6ef69b64e407038" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -966,9 +988,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.67" +version = "0.2.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841a6d1c35c6f596ccea1f82504a192a60378f64b3bb0261904ad8f2f5657556" +checksum = "f249f06ef7ee334cc3b8ff031bfc11ec99d00f34d86da7498396dc1e3b1498fe" dependencies = [ "proc-macro2", "quote", @@ -979,15 +1001,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.67" +version = "0.2.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93b162580e34310e5931c4b792560108b10fd14d64915d7fff8ff00180e70092" +checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307" [[package]] name = "web-sys" -version = "0.3.44" +version = "0.3.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dda38f4e5ca63eda02c059d243aa25b5f35ab98451e518c51612cd0f1bd19a47" +checksum = "4bf6ef87ad7ae8008e15a355ce696bed26012b7caa21605188cfd8214ab51e2d" dependencies = [ "js-sys", "wasm-bindgen", @@ -1024,6 +1046,12 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "wyz" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" + [[package]] name = "zeroize" version = "1.1.0" diff --git a/Cargo.toml b/Cargo.toml index abc31941e..668b5fd12 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,3 @@ 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/README.md b/README.md index 6c384e966..bc1c26ec8 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,10 @@ if you are interested in curves beyond the ones listed here. ## Minimum Supported Rust Version -All crates in this repository support Rust **1.41** or higher. In future minimum -supported Rust version can be changed, but it will be done with the minor -version bump. +All crates in this repository support Rust **1.44** or higher. + +Minimum supported Rust version can be changed in the future, but it will be +done with a minor version bump. ## License @@ -47,7 +48,7 @@ dual licensed as above, without any additional terms or conditions. [//]: # (badges) -[rustc-image]: https://img.shields.io/badge/rustc-1.41+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.44+-blue.svg [//]: # (crates) diff --git a/k256/Cargo.toml b/k256/Cargo.toml index 970ee79b4..5e5d645de 100644 --- a/k256/Cargo.toml +++ b/k256/Cargo.toml @@ -16,7 +16,6 @@ categories = ["cryptography", "cryptography::cryptocurrencies", "no-std"] keywords = ["bitcoin", "crypto", "ecc", "ethereum", "secp256k1"] [dependencies] -byteorder = { version = "1", default-features = false } cfg-if = "0.1" ecdsa-core = { version = "0.7", package = "ecdsa", optional = true, default-features = false } elliptic-curve = { version = "0.5", default-features = false } @@ -35,7 +34,7 @@ rand_core = { version = "0.5", features = ["getrandom"] } [features] default = ["arithmetic", "oid", "std"] -arithmetic = [] +arithmetic = ["elliptic-curve/arithmetic"] digest = ["elliptic-curve/digest", "ecdsa-core/digest"] ecdh = ["elliptic-curve/ecdh", "zeroize"] ecdsa = ["arithmetic", "digest", "ecdsa-core/sign", "ecdsa-core/verify", "zeroize"] diff --git a/k256/README.md b/k256/README.md index 7f4880d19..c9b09ac7f 100644 --- a/k256/README.md +++ b/k256/README.md @@ -52,7 +52,7 @@ particularly in conjunction with the ## Minimum Supported Rust Version -Rust **1.41** or higher. +Rust **1.44** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -84,7 +84,7 @@ dual licensed as above, without any additional terms or conditions. [docs-image]: https://docs.rs/k256/badge.svg [docs-link]: https://docs.rs/k256/ [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.41+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.44+-blue.svg [build-image]: https://github.com/RustCrypto/elliptic-curves/workflows/k256/badge.svg?branch=master&event=push [build-link]: https://github.com/RustCrypto/elliptic-curves/actions?query=workflow%3Ak256 diff --git a/k256/src/arithmetic.rs b/k256/src/arithmetic.rs index a75417416..418b279bb 100644 --- a/k256/src/arithmetic.rs +++ b/k256/src/arithmetic.rs @@ -29,6 +29,7 @@ pub(crate) const CURVE_EQUATION_B: FieldElement = FieldElement::from_bytes_unche impl elliptic_curve::Arithmetic for Secp256k1 { type Scalar = Scalar; type AffinePoint = AffinePoint; + type ProjectivePoint = ProjectivePoint; } #[cfg(test)] diff --git a/k256/src/arithmetic/scalar.rs b/k256/src/arithmetic/scalar.rs index 6b76c7698..5d64d5412 100644 --- a/k256/src/arithmetic/scalar.rs +++ b/k256/src/arithmetic/scalar.rs @@ -5,10 +5,12 @@ use cfg_if::cfg_if; cfg_if! { if #[cfg(any(target_pointer_width = "32", feature = "force-32-bit"))] { mod scalar_8x32; + use scalar_8x32::MODULUS; use scalar_8x32::Scalar8x32 as ScalarImpl; use scalar_8x32::WideScalar16x32 as WideScalarImpl; } else if #[cfg(target_pointer_width = "64")] { mod scalar_4x64; + use scalar_4x64::MODULUS; use scalar_4x64::Scalar4x64 as ScalarImpl; use scalar_4x64::WideScalar8x64 as WideScalarImpl; } @@ -40,13 +42,16 @@ use num_bigint::{BigUint, ToBigUint}; /// Non-zero scalar value. pub type NonZeroScalar = elliptic_curve::scalar::NonZeroScalar; +/// secp256k1 field element serialized as bits. +pub type ScalarBits = elliptic_curve::scalar::ScalarBits; + /// An element in the finite field modulo curve order. #[derive(Clone, Copy, Debug, Default)] #[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))] pub struct Scalar(ScalarImpl); impl Field for Scalar { - fn random(rng: &mut R) -> Self { + fn random(rng: impl RngCore) -> Self { Scalar::generate_vartime(rng) } @@ -84,7 +89,14 @@ impl Field for Scalar { impl PrimeField for Scalar { type Repr = ElementBytes; - type ReprEndianness = byteorder::BigEndian; + + cfg_if! { + if #[cfg(any(target_pointer_width = "32", feature = "force-32-bit"))] { + type ReprBits = [u32; 8]; + } else if #[cfg(target_pointer_width = "64")] { + type ReprBits = [u64; 4]; + } + } const NUM_BITS: u32 = 256; const CAPACITY: u32 = 255; @@ -98,12 +110,16 @@ impl PrimeField for Scalar { self.to_bytes() } + fn to_le_bits(&self) -> ScalarBits { + self.into() + } + fn is_odd(&self) -> bool { self.0.is_odd().into() } - fn char() -> Self::Repr { - unimplemented!(); // removed in newer versions of `ff` + fn char_le_bits() -> ScalarBits { + MODULUS.into() } fn multiplicative_generator() -> Self { @@ -517,6 +533,12 @@ impl Invert for Scalar { } } +impl From<&Scalar> for ScalarBits { + fn from(scalar: &Scalar) -> ScalarBits { + scalar.0.into() + } +} + impl From for ElementBytes { fn from(scalar: Scalar) -> Self { scalar.to_bytes() diff --git a/k256/src/arithmetic/scalar/scalar_4x64.rs b/k256/src/arithmetic/scalar/scalar_4x64.rs index 3ce872a96..c4d608d02 100644 --- a/k256/src/arithmetic/scalar/scalar_4x64.rs +++ b/k256/src/arithmetic/scalar/scalar_4x64.rs @@ -4,9 +4,9 @@ use core::convert::TryInto; use elliptic_curve::{ subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}, - util::{adc64, sbb64} + util::{adc64, sbb64}, }; -use crate::ElementBytes; +use crate::{ScalarBits, ElementBytes}; #[cfg(feature = "zeroize")] use elliptic_curve::zeroize::Zeroize; @@ -421,6 +421,12 @@ impl ConstantTimeEq for Scalar4x64 { } } +impl From for ScalarBits { + fn from(scalar: Scalar4x64) -> ScalarBits { + scalar.0.into() + } +} + #[derive(Clone, Copy, Debug, Default)] pub struct WideScalar8x64([u64; 8]); diff --git a/k256/src/arithmetic/scalar/scalar_8x32.rs b/k256/src/arithmetic/scalar/scalar_8x32.rs index 3305f341b..bcdc43b14 100644 --- a/k256/src/arithmetic/scalar/scalar_8x32.rs +++ b/k256/src/arithmetic/scalar/scalar_8x32.rs @@ -6,7 +6,7 @@ use elliptic_curve::{ util::{adc32, sbb32} }; use core::convert::TryInto; -use crate::{ElementBytes}; +use crate::{ElementBytes, ScalarBits}; #[cfg(feature = "zeroize")] use elliptic_curve::zeroize::Zeroize; @@ -559,6 +559,12 @@ impl ConstantTimeEq for Scalar8x32 { } } +impl From for ScalarBits { + fn from(scalar: Scalar8x32) -> ScalarBits { + scalar.0.into() + } +} + #[derive(Clone, Copy, Debug, Default)] pub struct WideScalar16x32([u32; 16]); diff --git a/k256/src/lib.rs b/k256/src/lib.rs index 505566868..bec55e8e6 100644 --- a/k256/src/lib.rs +++ b/k256/src/lib.rs @@ -27,7 +27,7 @@ //! //! ## Minimum Supported Rust Version //! -//! Rust **1.41** or higher. +//! Rust **1.44** or higher. //! //! Minimum supported Rust version can be changed in the future, but it will be //! done with a minor version bump. @@ -65,7 +65,7 @@ pub use elliptic_curve; pub use arithmetic::{ affine::AffinePoint, projective::ProjectivePoint, - scalar::{NonZeroScalar, Scalar}, + scalar::{NonZeroScalar, Scalar, ScalarBits}, }; #[cfg(feature = "expose-field")] @@ -110,7 +110,7 @@ impl elliptic_curve::Identifier for Secp256k1 { /// Compressed SEC1-encoded secp256k1 (K-256) point (i.e. public key) pub type CompressedPoint = [u8; 33]; -/// secp256k1 (K-256) serialized field element. +/// secp256k1 (K-256) field element serialized as bytes. /// /// Byte array containing a serialized field element value (base field or scalar). pub type ElementBytes = elliptic_curve::ElementBytes; diff --git a/p256/Cargo.toml b/p256/Cargo.toml index dadb7233d..6973dbd9e 100644 --- a/p256/Cargo.toml +++ b/p256/Cargo.toml @@ -16,7 +16,6 @@ categories = ["cryptography", "no-std"] keywords = ["crypto", "ecc", "nist", "prime256v1", "secp256r1"] [dependencies] -byteorder = { version = "1", default-features = false } ecdsa-core = { version = "0.7", package = "ecdsa", optional = true, default-features = false } elliptic-curve = { version = "0.5", default-features = false } sha2 = { version = "0.9", optional = true, default-features = false } @@ -30,7 +29,7 @@ rand_core = { version = "0.5", features = ["getrandom"] } [features] default = ["arithmetic", "std"] -arithmetic = [] +arithmetic = ["elliptic-curve/arithmetic"] digest = ["elliptic-curve/digest", "ecdsa-core/digest"] ecdh = ["elliptic-curve/ecdh", "zeroize"] ecdsa = ["arithmetic", "ecdsa-core/sign", "ecdsa-core/verify", "sha256", "zeroize"] diff --git a/p256/README.md b/p256/README.md index b33612e1e..313a27360 100644 --- a/p256/README.md +++ b/p256/README.md @@ -46,7 +46,7 @@ like TLS and the associated X.509 PKI. ## Minimum Supported Rust Version -Rust **1.41** or higher. +Rust **1.44** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -78,7 +78,7 @@ dual licensed as above, without any additional terms or conditions. [docs-image]: https://docs.rs/p256/badge.svg [docs-link]: https://docs.rs/p256/ [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.41+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.44+-blue.svg [build-image]: https://github.com/RustCrypto/elliptic-curves/workflows/p256/badge.svg?branch=master&event=push [build-link]: https://github.com/RustCrypto/elliptic-curves/actions?query=workflow%3Ap256 diff --git a/p256/src/arithmetic.rs b/p256/src/arithmetic.rs index 178bac509..740295b9d 100644 --- a/p256/src/arithmetic.rs +++ b/p256/src/arithmetic.rs @@ -28,6 +28,7 @@ const CURVE_EQUATION_B: FieldElement = FieldElement([ impl elliptic_curve::Arithmetic for NistP256 { type Scalar = Scalar; type AffinePoint = AffinePoint; + type ProjectivePoint = ProjectivePoint; } #[cfg(test)] diff --git a/p256/src/arithmetic/scalar.rs b/p256/src/arithmetic/scalar.rs index ff05f0800..9725e91db 100644 --- a/p256/src/arithmetic/scalar.rs +++ b/p256/src/arithmetic/scalar.rs @@ -69,6 +69,9 @@ pub const MU: [u64; 5] = [ /// Non-zero scalar value. pub type NonZeroScalar = elliptic_curve::scalar::NonZeroScalar; +/// NIST P-256 field element serialized as bits. +pub type ScalarBits = elliptic_curve::scalar::ScalarBits; + /// An element in the finite field modulo n. // The internal representation is as little-endian ordered u64 words. #[derive(Clone, Copy, Debug, Default)] @@ -76,7 +79,7 @@ pub type NonZeroScalar = elliptic_curve::scalar::NonZeroScalar; pub struct Scalar(pub(crate) [u64; LIMBS]); impl Field for Scalar { - fn random(rng: &mut R) -> Self { + fn random(mut rng: impl RngCore) -> Self { let mut bytes = ElementBytes::default(); // Generate a uniformly random scalar using rejection sampling, @@ -133,7 +136,12 @@ impl Field for Scalar { impl PrimeField for Scalar { type Repr = ElementBytes; - type ReprEndianness = byteorder::BigEndian; + + #[cfg(target_pointer_width = "32")] + type ReprBits = [u32; 8]; + + #[cfg(target_pointer_width = "64")] + type ReprBits = [u64; 4]; const NUM_BITS: u32 = 256; const CAPACITY: u32 = 255; @@ -147,12 +155,32 @@ impl PrimeField for Scalar { self.to_bytes() } + fn to_le_bits(&self) -> ScalarBits { + self.into() + } + fn is_odd(&self) -> bool { self.0[0] as u8 == 1 } - fn char() -> Self::Repr { - unimplemented!(); // removed in newer versions of `ff` + #[cfg(target_pointer_width = "32")] + fn char_le_bits() -> ScalarBits { + [ + 0xfc63_2551, + 0xf3b9_cac2, + 0xa717_9e84, + 0xbce6_faad, + 0xffff_ffff, + 0xffff_ffff, + 0x0000_0000, + 0xffff_ffff, + ] + .into() + } + + #[cfg(target_pointer_width = "64")] + fn char_le_bits() -> ScalarBits { + MODULUS.into() } fn multiplicative_generator() -> Self { @@ -829,6 +857,27 @@ impl Invert for Scalar { } } +#[cfg(target_pointer_width = "32")] +impl From<&Scalar> for ScalarBits { + fn from(scalar: &Scalar) -> ScalarBits { + let mut output = [0u32; 8]; + + for (input, output) in scalar.0.iter().zip(output.chunks_mut(2)) { + output[0] = (input >> 32) as u32; + output[1] = (input & 0xFFFF) as u32; + } + + output.into() + } +} + +#[cfg(target_pointer_width = "64")] +impl From<&Scalar> for ScalarBits { + fn from(scalar: &Scalar) -> ScalarBits { + scalar.0.into() + } +} + impl From for ElementBytes { fn from(scalar: Scalar) -> Self { scalar.to_bytes() @@ -918,4 +967,24 @@ mod tests { let rederived_scalar = Scalar::from_secret_key(&secret).unwrap(); assert_eq!(scalar.0, rederived_scalar.0); } + + #[test] + #[cfg(target_pointer_width = "32")] + fn scalar_into_scalarbits() { + use super::ScalarBits; + + let minus_one = ScalarBits::from([ + 0xfc63_2550, + 0xf3b9_cac2, + 0xa717_9e84, + 0xbce6_faad, + 0xffff_ffff, + 0xffff_ffff, + 0x0000_0000, + 0xffff_ffff, + ]); + + let scalar_bits = ScalarBits::from(&-Scalar::from(1)); + assert_eq!(minus_one, scalar_bits); + } } diff --git a/p256/src/lib.rs b/p256/src/lib.rs index aa9ef0f13..d8cfb36db 100644 --- a/p256/src/lib.rs +++ b/p256/src/lib.rs @@ -25,7 +25,7 @@ //! //! ## Minimum Supported Rust Version //! -//! Rust **1.41** or higher. +//! Rust **1.44** or higher. //! //! Minimum supported Rust version can be changed in the future, but it will be //! done with a minor version bump. @@ -62,7 +62,7 @@ pub use arithmetic::{ affine::AffinePoint, projective::ProjectivePoint, scalar::blinding::BlindedScalar, - scalar::{NonZeroScalar, Scalar}, + scalar::{NonZeroScalar, Scalar, ScalarBits}, }; use elliptic_curve::consts::U32; @@ -109,7 +109,7 @@ impl elliptic_curve::Identifier for NistP256 { const OID: ObjectIdentifier = ObjectIdentifier::new(&[1, 2, 840, 10045, 3, 1, 7]); } -/// NIST P-256 Serialized Field Element. +/// NIST P-256 field element serialized as bytes. /// /// Byte array containing a serialized field element value (base field or scalar). pub type ElementBytes = elliptic_curve::ElementBytes; diff --git a/p384/README.md b/p384/README.md index c5cb264ca..c382b304a 100644 --- a/p384/README.md +++ b/p384/README.md @@ -24,7 +24,7 @@ X.509 PKI. ## Minimum Supported Rust Version -Rust **1.41** or higher. +Rust **1.44** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -56,7 +56,7 @@ dual licensed as above, without any additional terms or conditions. [docs-image]: https://docs.rs/p384/badge.svg [docs-link]: https://docs.rs/p384/ [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.41+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.44+-blue.svg [build-image]: https://github.com/RustCrypto/elliptic-curves/workflows/p384/badge.svg?branch=master&event=push [build-link]: https://github.com/RustCrypto/elliptic-curves/actions?query=workflow%3Ap384 diff --git a/p384/src/lib.rs b/p384/src/lib.rs index d6fa7ca71..49777dc0f 100644 --- a/p384/src/lib.rs +++ b/p384/src/lib.rs @@ -2,7 +2,7 @@ //! //! ## Minimum Supported Rust Version //! -//! Rust **1.41** or higher. +//! Rust **1.44** or higher. //! //! Minimum supported Rust version can be changed in the future, but it will be //! done with a minor version bump. diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 6014fa815..8c068c1fd 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -8,4 +8,3 @@ 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" }