From bfcaa1291936202d7946f34065c094677ea72b17 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Mon, 17 Jan 2022 10:33:23 +0100 Subject: [PATCH 01/10] Update elliptic-curve, digest and ecdsa --- Cargo.lock | 61 ++++++++++++----------------------- bp256/Cargo.toml | 6 ++-- bp384/Cargo.toml | 6 ++-- k256/Cargo.toml | 10 +++--- k256/src/ecdsa/recoverable.rs | 6 ++-- k256/src/ecdsa/sign.rs | 61 +++++++++++++++++++++++++++++------ k256/src/ecdsa/verify.rs | 2 +- p256/Cargo.toml | 8 ++--- p384/Cargo.toml | 6 ++-- 9 files changed, 94 insertions(+), 72 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3b92af72..6701526c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -72,20 +72,13 @@ checksum = "847495c209977a90e8aad588b959d0ca9f5dc228096d29a6bd3defd53f35eaec" [[package]] name = "block-buffer" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +checksum = "f1d36a02058e76b040de25a4464ba1c80935655595b661505c8b39b664828b95" dependencies = [ - "block-padding", "generic-array", ] -[[package]] -name = "block-padding" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" - [[package]] name = "bp256" version = "0.3.0" @@ -264,13 +257,12 @@ dependencies = [ ] [[package]] -name = "crypto-mac" -version = "0.11.1" +name = "crypto-common" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" +checksum = "683d6b536309245c849479fba3da410962a43ed8e51c26b729208ec0ac2798d0" dependencies = [ "generic-array", - "subtle", ] [[package]] @@ -307,18 +299,20 @@ dependencies = [ [[package]] name = "digest" -version = "0.9.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +checksum = "b697d66081d42af4fba142d56918a3cb21dc8eb63372c6b85d14f44fb9c5979b" dependencies = [ + "block-buffer", + "crypto-common", "generic-array", + "subtle", ] [[package]] name = "ecdsa" version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0d69ae62e0ce582d56380743515fefaf1a8c70cec685d9677636d7e30ae9dc9" +source = "git+https://github.com/khonsulabs/signatures?branch=elliptic-curve-digest#e40669d20d045b354f4101ea84324570b24bda3d" dependencies = [ "der", "elliptic-curve", @@ -335,8 +329,7 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "elliptic-curve" version = "0.11.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79a4c0d14ef894e75cec382d55c2cad1d29974c4a89bf72184ab3646b76ae13a" +source = "git+https://github.com/khonsulabs/traits?branch=digest#0d6db2f38e89aed51c5ed44cba1b90103a955e59" dependencies = [ "base16ct", "base64ct", @@ -443,11 +436,10 @@ checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" [[package]] name = "hmac" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" +checksum = "ddca131f3e7f2ce2df364b57949a9d47915cfbd35e46cfee355ccebbf794d6a2" dependencies = [ - "crypto-mac", "digest", ] @@ -597,12 +589,6 @@ version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - [[package]] name = "p256" version = "0.10.1" @@ -844,8 +830,7 @@ dependencies = [ [[package]] name = "rfc6979" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96ef608575f6392792f9ecf7890c00086591d29a83910939d430753f7c050525" +source = "git+https://github.com/khonsulabs/signatures?branch=elliptic-curve-digest#e40669d20d045b354f4101ea84324570b24bda3d" dependencies = [ "crypto-bigint", "hmac", @@ -954,34 +939,30 @@ dependencies = [ [[package]] name = "sha2" -version = "0.9.9" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +checksum = "99c3bd8169c58782adad9290a9af5939994036b76187f7b4f0e6de91dbbfc0ec" dependencies = [ - "block-buffer", "cfg-if", "cpufeatures", "digest", - "opaque-debug", ] [[package]] name = "sha3" -version = "0.9.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" +checksum = "31f935e31cf406e8c0e96c2815a5516181b7004ae8c5f296293221e9b1e356bd" dependencies = [ - "block-buffer", "digest", "keccak", - "opaque-debug", ] [[package]] name = "signature" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02658e48d89f2bec991f9a78e69cfa4c316f8d6a6c4ec12fae1aeb263d486788" +checksum = "f054c6c1a6e95179d6f23ed974060dcefb2d9388bb7256900badad682c499de4" dependencies = [ "digest", "rand_core", diff --git a/bp256/Cargo.toml b/bp256/Cargo.toml index f73d5eac..8bb7941a 100644 --- a/bp256/Cargo.toml +++ b/bp256/Cargo.toml @@ -13,12 +13,12 @@ edition = "2021" rust-version = "1.56" [dependencies] -elliptic-curve = { version = "0.11", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { git = "https://github.com/khonsulabs/traits", branch = "digest", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } # optional dependencies -ecdsa = { version = "0.13", optional = true, default-features = false, features = ["der"] } -sha2 = { version = "0.9", optional = true, default-features = false } +ecdsa = { git = "https://github.com/khonsulabs/signatures", branch = "elliptic-curve-digest", optional = true, default-features = false, features = ["der"] } +sha2 = { version = "0.10", optional = true, default-features = false } [features] default = ["pkcs8", "std"] diff --git a/bp384/Cargo.toml b/bp384/Cargo.toml index e0b67501..4c228ef7 100644 --- a/bp384/Cargo.toml +++ b/bp384/Cargo.toml @@ -13,12 +13,12 @@ edition = "2021" rust-version = "1.56" [dependencies] -elliptic-curve = { version = "0.11", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { git = "https://github.com/khonsulabs/traits", branch = "digest", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } # optional dependencies -ecdsa = { version = "0.13", optional = true, default-features = false, features = ["der"] } -sha2 = { version = "0.9", optional = true, default-features = false } +ecdsa = { git = "https://github.com/khonsulabs/signatures", branch = "elliptic-curve-digest", optional = true, default-features = false, features = ["der"] } +sha2 = { version = "0.10", optional = true, default-features = false } [features] default = ["pkcs8", "std"] diff --git a/k256/Cargo.toml b/k256/Cargo.toml index b78a06d3..ec09ad34 100644 --- a/k256/Cargo.toml +++ b/k256/Cargo.toml @@ -19,19 +19,19 @@ rust-version = "1.56" [dependencies] cfg-if = "1.0" -elliptic-curve = { version = "0.11.7", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { git = "https://github.com/khonsulabs/traits", branch = "digest", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } # optional dependencies -ecdsa-core = { version = "0.13", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { git = "https://github.com/khonsulabs/signatures", branch = "elliptic-curve-digest", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.3", optional = true } -sha2 = { version = "0.9", optional = true, default-features = false } -sha3 = { version = "0.9", optional = true, default-features = false } +sha2 = { version = "0.10", optional = true, default-features = false } +sha3 = { version = "0.10", optional = true, default-features = false } [dev-dependencies] blobby = "0.3" criterion = "0.3" -ecdsa-core = { version = "0.13", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { git = "https://github.com/khonsulabs/signatures", branch = "elliptic-curve-digest", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.3" num-bigint = "0.4" num-traits = "0.2" diff --git a/k256/src/ecdsa/recoverable.rs b/k256/src/ecdsa/recoverable.rs index ea7e1fe2..9153baa9 100644 --- a/k256/src/ecdsa/recoverable.rs +++ b/k256/src/ecdsa/recoverable.rs @@ -107,7 +107,7 @@ impl Signature { msg: &[u8], signature: &super::Signature, ) -> Result { - Self::from_digest_trial_recovery(public_key, Keccak256::new().chain(msg), signature) + Self::from_digest_trial_recovery(public_key, Keccak256::new().chain_update(msg), signature) } /// Given a public key, message digest, and signature, use trial recovery @@ -148,7 +148,7 @@ impl Signature { #[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)) + self.recover_verify_key_from_digest(Keccak256::new().chain_update(msg)) } /// Recover the public key used to create the given signature as a @@ -362,7 +362,7 @@ mod tests { fn public_key_recovery() { for vector in VECTORS { let sig = Signature::try_from(&vector.sig[..]).unwrap(); - let prehash = Sha256::new().chain(vector.msg); + let prehash = Sha256::new().chain_update(vector.msg); let pk = sig.recover_verify_key_from_digest(prehash).unwrap(); assert_eq!(&vector.pk[..], EncodedPoint::from(&pk).as_bytes()); } diff --git a/k256/src/ecdsa/sign.rs b/k256/src/ecdsa/sign.rs index e1d3dd92..47d7548a 100644 --- a/k256/src/ecdsa/sign.rs +++ b/k256/src/ecdsa/sign.rs @@ -9,7 +9,12 @@ use core::{ use ecdsa_core::{ hazmat::{rfc6979_generate_k, SignPrimitive}, signature::{ - digest::{BlockInput, FixedOutput, Reset, Update}, + digest::{ + block_buffer::Eager, + core_api::{BlockSizeUser, BufferKindUser, CoreProxy, FixedOutputCore}, + generic_array::typenum::{self, IsLess, Le, NonZero}, + Digest, HashMarker, OutputSizeUser, + }, DigestSigner, RandomizedDigestSigner, }, }; @@ -24,7 +29,7 @@ use elliptic_curve::{ }; #[cfg(any(feature = "keccak256", feature = "sha256"))] -use ecdsa_core::signature::{self, digest::Digest, PrehashSignature, RandomizedSigner}; +use ecdsa_core::signature::{self, PrehashSignature, RandomizedSigner}; #[cfg(feature = "pkcs8")] use crate::pkcs8::{self, DecodePrivateKey}; @@ -77,7 +82,7 @@ where Self: DigestSigner, { fn try_sign(&self, msg: &[u8]) -> Result { - self.try_sign_digest(Digest::chain(S::Digest::new(), msg)) + self.try_sign_digest(Digest::chain_update(S::Digest::new(), msg)) } } @@ -88,13 +93,22 @@ where Self: RandomizedDigestSigner, { fn try_sign_with_rng(&self, rng: impl CryptoRng + RngCore, msg: &[u8]) -> Result { - self.try_sign_digest_with_rng(rng, S::Digest::new().chain(msg)) + self.try_sign_digest_with_rng(rng, S::Digest::new().chain_update(msg)) } } impl DigestSigner for SigningKey where - D: BlockInput + FixedOutput + Clone + Default + Reset + Update, + D: CoreProxy + Digest + OutputSizeUser, + D::Core: BlockSizeUser + + BufferKindUser + + Clone + + Default + + FixedOutputCore + + HashMarker + + OutputSizeUser, + ::BlockSize: IsLess, + Le<::BlockSize, typenum::U256>: NonZero, { fn try_sign_digest(&self, digest: D) -> Result { let sig: recoverable::Signature = self.try_sign_digest(digest)?; @@ -104,10 +118,19 @@ where impl DigestSigner for SigningKey where - D: BlockInput + FixedOutput + Clone + Default + Reset + Update, + D: CoreProxy + Digest + OutputSizeUser, + D::Core: BlockSizeUser + + BufferKindUser + + Clone + + Default + + FixedOutputCore + + HashMarker + + OutputSizeUser, + ::BlockSize: IsLess, + Le<::BlockSize, typenum::U256>: NonZero, { fn try_sign_digest(&self, msg_digest: D) -> Result { - let z = >::from_be_bytes_reduced(msg_digest.finalize_fixed()); + let z = >::from_be_bytes_reduced(msg_digest.finalize()); let k = rfc6979_generate_k::<_, D>(&self.inner, &z, &[]); let (signature, recid) = self.inner.try_sign_prehashed(**k, z)?; let recoverable_id = recid.ok_or_else(Error::new)?.try_into()?; @@ -117,7 +140,16 @@ where impl RandomizedDigestSigner for SigningKey where - D: BlockInput + FixedOutput + Clone + Default + Reset + Update, + D: CoreProxy + OutputSizeUser + Digest, + D::Core: BlockSizeUser + + BufferKindUser + + Clone + + Default + + FixedOutputCore + + HashMarker + + OutputSizeUser, + ::BlockSize: IsLess, + Le<::BlockSize, typenum::U256>: NonZero, { fn try_sign_digest_with_rng( &self, @@ -131,7 +163,16 @@ where impl RandomizedDigestSigner for SigningKey where - D: BlockInput + FixedOutput + Clone + Default + Reset + Update, + D: CoreProxy + OutputSizeUser + Digest, + D::Core: BlockSizeUser + + BufferKindUser + + Clone + + Default + + FixedOutputCore + + HashMarker + + OutputSizeUser, + ::BlockSize: IsLess, + Le<::BlockSize, typenum::U256>: NonZero, { fn try_sign_digest_with_rng( &self, @@ -141,7 +182,7 @@ where let mut added_entropy = FieldBytes::default(); rng.fill_bytes(&mut added_entropy); - let z = >::from_be_bytes_reduced(msg_digest.finalize_fixed()); + let z = >::from_be_bytes_reduced(msg_digest.finalize()); let k = rfc6979_generate_k::<_, D>(&self.inner, &z, &added_entropy); let (signature, recid) = self.inner.try_sign_prehashed(**k, z)?; let recoverable_id = recid.ok_or_else(Error::new)?.try_into()?; diff --git a/k256/src/ecdsa/verify.rs b/k256/src/ecdsa/verify.rs index 8f811e1e..24d5b739 100644 --- a/k256/src/ecdsa/verify.rs +++ b/k256/src/ecdsa/verify.rs @@ -73,7 +73,7 @@ where Self: DigestVerifier, { fn verify(&self, msg: &[u8], signature: &S) -> Result<(), Error> { - self.verify_digest(S::Digest::new().chain(msg), signature) + self.verify_digest(S::Digest::new().chain_update(msg), signature) } } diff --git a/p256/Cargo.toml b/p256/Cargo.toml index 0a4c4926..9e7c5abb 100644 --- a/p256/Cargo.toml +++ b/p256/Cargo.toml @@ -17,17 +17,17 @@ edition = "2021" rust-version = "1.56" [dependencies] -elliptic-curve = { version = "0.11.7", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { git = "https://github.com/khonsulabs/traits", branch = "digest", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } # optional dependencies -ecdsa-core = { version = "0.13", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { git = "https://github.com/khonsulabs/signatures", branch = "elliptic-curve-digest", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.3", optional = true } -sha2 = { version = "0.9", optional = true, default-features = false } +sha2 = { version = "0.10", optional = true, default-features = false } [dev-dependencies] blobby = "0.3" -ecdsa-core = { version = "0.13", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { git = "https://github.com/khonsulabs/signatures", branch = "elliptic-curve-digest", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.3" proptest = "1.0" rand_core = { version = "0.6", features = ["getrandom"] } diff --git a/p384/Cargo.toml b/p384/Cargo.toml index 2bd80c01..d7f8dd12 100644 --- a/p384/Cargo.toml +++ b/p384/Cargo.toml @@ -13,10 +13,10 @@ edition = "2021" rust-version = "1.56" [dependencies] -ecdsa = { version = "0.13", optional = true, default-features = false, features = ["der"] } -elliptic-curve = { version = "0.11.7", default-features = false, features = ["hazmat", "sec1"] } +ecdsa = { git = "https://github.com/khonsulabs/signatures", branch = "elliptic-curve-digest", optional = true, default-features = false, features = ["der"] } +elliptic-curve = { git = "https://github.com/khonsulabs/traits", branch = "digest", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } -sha2 = { version = "0.9", optional = true, default-features = false } +sha2 = { version = "0.10", optional = true, default-features = false } [dev-dependencies] hex-literal = "0.3" From 8d97cf7403057e2179b40a40add6617b049e99e4 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Tue, 18 Jan 2022 15:09:08 +0100 Subject: [PATCH 02/10] Move elliptic-curve git dependency to RustCrypto's repo --- Cargo.lock | 8 ++++---- bp256/Cargo.toml | 2 +- bp384/Cargo.toml | 2 +- k256/Cargo.toml | 2 +- k256/src/ecdsa/recoverable.rs | 2 +- k256/src/ecdsa/sign.rs | 4 ++-- k256/src/ecdsa/verify.rs | 2 +- p256/Cargo.toml | 2 +- p256/src/arithmetic/affine.rs | 22 +++++++++++++--------- p256/src/arithmetic/scalar/blinded.rs | 2 +- p384/Cargo.toml | 2 +- 11 files changed, 27 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6701526c..2aa3f452 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -312,7 +312,7 @@ dependencies = [ [[package]] name = "ecdsa" version = "0.13.4" -source = "git+https://github.com/khonsulabs/signatures?branch=elliptic-curve-digest#e40669d20d045b354f4101ea84324570b24bda3d" +source = "git+https://github.com/khonsulabs/signatures?branch=elliptic-curve-digest#b4d16876c68bcae11e9897ea1b40462601dc82e3" dependencies = [ "der", "elliptic-curve", @@ -328,8 +328,8 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "elliptic-curve" -version = "0.11.8" -source = "git+https://github.com/khonsulabs/traits?branch=digest#0d6db2f38e89aed51c5ed44cba1b90103a955e59" +version = "0.12.0-pre" +source = "git+https://github.com/RustCrypto/traits#f899a15cb2cd293d69d1b6502e7cc537d3da480d" dependencies = [ "base16ct", "base64ct", @@ -830,7 +830,7 @@ dependencies = [ [[package]] name = "rfc6979" version = "0.1.0" -source = "git+https://github.com/khonsulabs/signatures?branch=elliptic-curve-digest#e40669d20d045b354f4101ea84324570b24bda3d" +source = "git+https://github.com/khonsulabs/signatures?branch=elliptic-curve-digest#b4d16876c68bcae11e9897ea1b40462601dc82e3" dependencies = [ "crypto-bigint", "hmac", diff --git a/bp256/Cargo.toml b/bp256/Cargo.toml index 8bb7941a..d98aed11 100644 --- a/bp256/Cargo.toml +++ b/bp256/Cargo.toml @@ -13,7 +13,7 @@ edition = "2021" rust-version = "1.56" [dependencies] -elliptic-curve = { git = "https://github.com/khonsulabs/traits", branch = "digest", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { git = "https://github.com/RustCrypto/traits", version = "0.12.0-pre", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } # optional dependencies diff --git a/bp384/Cargo.toml b/bp384/Cargo.toml index 4c228ef7..253c8d52 100644 --- a/bp384/Cargo.toml +++ b/bp384/Cargo.toml @@ -13,7 +13,7 @@ edition = "2021" rust-version = "1.56" [dependencies] -elliptic-curve = { git = "https://github.com/khonsulabs/traits", branch = "digest", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { git = "https://github.com/RustCrypto/traits", version = "0.12.0-pre", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } # optional dependencies diff --git a/k256/Cargo.toml b/k256/Cargo.toml index ec09ad34..bcd27152 100644 --- a/k256/Cargo.toml +++ b/k256/Cargo.toml @@ -19,7 +19,7 @@ rust-version = "1.56" [dependencies] cfg-if = "1.0" -elliptic-curve = { git = "https://github.com/khonsulabs/traits", branch = "digest", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { git = "https://github.com/RustCrypto/traits", version = "0.12.0-pre", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } # optional dependencies diff --git a/k256/src/ecdsa/recoverable.rs b/k256/src/ecdsa/recoverable.rs index 9153baa9..7c08a26b 100644 --- a/k256/src/ecdsa/recoverable.rs +++ b/k256/src/ecdsa/recoverable.rs @@ -181,7 +181,7 @@ impl Signature { } let R = ProjectivePoint::from(R.unwrap()); - let r_inv = r.invert().unwrap(); + let r_inv = *r.invert(); let u1 = -(r_inv * z); let u2 = r_inv * *s; let pk = ProjectivePoint::lincomb(&ProjectivePoint::GENERATOR, &u1, &R, &u2).to_affine(); diff --git a/k256/src/ecdsa/sign.rs b/k256/src/ecdsa/sign.rs index 47d7548a..58a572d3 100644 --- a/k256/src/ecdsa/sign.rs +++ b/k256/src/ecdsa/sign.rs @@ -23,7 +23,7 @@ use elliptic_curve::{ consts::U32, ops::{Invert, Reduce}, rand_core::{CryptoRng, RngCore}, - subtle::{Choice, ConstantTimeEq}, + subtle::{Choice, ConstantTimeEq, CtOption}, zeroize::Zeroize, IsHigh, }; @@ -198,7 +198,7 @@ impl SignPrimitive for Scalar { z: Scalar, ) -> Result<(Signature, Option), Error> where - K: Borrow + Invert, + K: Borrow + Invert>, { let k_inverse = ephemeral_scalar.invert(); let k = ephemeral_scalar.borrow(); diff --git a/k256/src/ecdsa/verify.rs b/k256/src/ecdsa/verify.rs index 24d5b739..53099a71 100644 --- a/k256/src/ecdsa/verify.rs +++ b/k256/src/ecdsa/verify.rs @@ -106,7 +106,7 @@ impl VerifyPrimitive for AffinePoint { return Err(Error::new()); } - let s_inv = s.invert().unwrap(); + let s_inv = *s.invert(); let u1 = z * s_inv; let u2 = *r * s_inv; diff --git a/p256/Cargo.toml b/p256/Cargo.toml index 9e7c5abb..d0d04f43 100644 --- a/p256/Cargo.toml +++ b/p256/Cargo.toml @@ -17,7 +17,7 @@ edition = "2021" rust-version = "1.56" [dependencies] -elliptic-curve = { git = "https://github.com/khonsulabs/traits", branch = "digest", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { git = "https://github.com/RustCrypto/traits", version = "0.12.0-pre", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } # optional dependencies diff --git a/p256/src/arithmetic/affine.rs b/p256/src/arithmetic/affine.rs index 7821f000..4afecbf2 100644 --- a/p256/src/arithmetic/affine.rs +++ b/p256/src/arithmetic/affine.rs @@ -260,20 +260,24 @@ impl ToEncodedPoint for AffinePoint { impl ToCompactEncodedPoint for AffinePoint { /// Serialize this value as a SEC1 compact [`EncodedPoint`] - fn to_compact_encoded_point(&self) -> Option { + fn to_compact_encoded_point(&self) -> CtOption { // Convert to canonical form for comparisons let y = self.y.to_canonical(); let (p_y, borrow) = MODULUS.informed_subtract(&y); assert_eq!(borrow, 0); let (_, borrow) = p_y.informed_subtract(&y); - if borrow != 0 { - return None; - } - // Reuse the CompressedPoint type since it's the same size as a compact point - let mut bytes = CompressedPoint::default(); - bytes[0] = sec1::Tag::Compact.into(); - bytes[1..(::UInt::BYTE_SIZE + 1)].copy_from_slice(&self.x.to_bytes()); - Some(EncodedPoint::from_bytes(bytes).expect("compact key")) + + CtOption::new( + { + // Reuse the CompressedPoint type since it's the same size as a compact point + let mut bytes = CompressedPoint::default(); + bytes[0] = sec1::Tag::Compact.into(); + bytes[1..(::UInt::BYTE_SIZE + 1)] + .copy_from_slice(&self.x.to_bytes()); + EncodedPoint::from_bytes(bytes).expect("compact key") + }, + u8::from(borrow == 0).into(), + ) } } diff --git a/p256/src/arithmetic/scalar/blinded.rs b/p256/src/arithmetic/scalar/blinded.rs index 627d08b3..4aac591d 100644 --- a/p256/src/arithmetic/scalar/blinded.rs +++ b/p256/src/arithmetic/scalar/blinded.rs @@ -44,7 +44,7 @@ impl Borrow for BlindedScalar { } impl Invert for BlindedScalar { - type Output = Scalar; + type Output = CtOption; fn invert(&self) -> CtOption { // prevent side channel analysis of scalar inversion by pre-and-post-multiplying diff --git a/p384/Cargo.toml b/p384/Cargo.toml index d7f8dd12..8d79f35d 100644 --- a/p384/Cargo.toml +++ b/p384/Cargo.toml @@ -14,7 +14,7 @@ rust-version = "1.56" [dependencies] ecdsa = { git = "https://github.com/khonsulabs/signatures", branch = "elliptic-curve-digest", optional = true, default-features = false, features = ["der"] } -elliptic-curve = { git = "https://github.com/khonsulabs/traits", branch = "digest", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { git = "https://github.com/RustCrypto/traits", version = "0.12.0-pre", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } sha2 = { version = "0.10", optional = true, default-features = false } From 18570f1657a76d6c3e42724cbf99c49c95ab6ff4 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Tue, 18 Jan 2022 15:31:19 +0100 Subject: [PATCH 03/10] Use `[patch]` instead of git dependencies --- Cargo.lock | 4 ++-- Cargo.toml | 4 ++++ bp256/Cargo.toml | 4 ++-- bp384/Cargo.toml | 4 ++-- k256/Cargo.toml | 6 +++--- p256/Cargo.toml | 6 +++--- p384/Cargo.toml | 4 ++-- 7 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2aa3f452..8e535697 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -312,7 +312,7 @@ dependencies = [ [[package]] name = "ecdsa" version = "0.13.4" -source = "git+https://github.com/khonsulabs/signatures?branch=elliptic-curve-digest#b4d16876c68bcae11e9897ea1b40462601dc82e3" +source = "git+https://github.com/khonsulabs/signatures?branch=elliptic-curve-digest#ea9faaaf85fb3fa36f969420acb6c56bcaa841d1" dependencies = [ "der", "elliptic-curve", @@ -830,7 +830,7 @@ dependencies = [ [[package]] name = "rfc6979" version = "0.1.0" -source = "git+https://github.com/khonsulabs/signatures?branch=elliptic-curve-digest#b4d16876c68bcae11e9897ea1b40462601dc82e3" +source = "git+https://github.com/khonsulabs/signatures?branch=elliptic-curve-digest#ea9faaaf85fb3fa36f969420acb6c56bcaa841d1" dependencies = [ "crypto-bigint", "hmac", diff --git a/Cargo.toml b/Cargo.toml index 96a9e9b2..ff1c844a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,7 @@ members = [ "p256", "p384", ] + +[patch.crates-io] +elliptic-curve = { git = "https://github.com/RustCrypto/traits" } +ecdsa = { git = "https://github.com/khonsulabs/signatures", branch = "elliptic-curve-digest" } diff --git a/bp256/Cargo.toml b/bp256/Cargo.toml index d98aed11..0d278f53 100644 --- a/bp256/Cargo.toml +++ b/bp256/Cargo.toml @@ -13,11 +13,11 @@ edition = "2021" rust-version = "1.56" [dependencies] -elliptic-curve = { git = "https://github.com/RustCrypto/traits", version = "0.12.0-pre", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "0.12.0-pre", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } # optional dependencies -ecdsa = { git = "https://github.com/khonsulabs/signatures", branch = "elliptic-curve-digest", optional = true, default-features = false, features = ["der"] } +ecdsa = { version = "0.13", optional = true, default-features = false, features = ["der"] } sha2 = { version = "0.10", optional = true, default-features = false } [features] diff --git a/bp384/Cargo.toml b/bp384/Cargo.toml index 253c8d52..f5f25305 100644 --- a/bp384/Cargo.toml +++ b/bp384/Cargo.toml @@ -13,11 +13,11 @@ edition = "2021" rust-version = "1.56" [dependencies] -elliptic-curve = { git = "https://github.com/RustCrypto/traits", version = "0.12.0-pre", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "0.12.0-pre", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } # optional dependencies -ecdsa = { git = "https://github.com/khonsulabs/signatures", branch = "elliptic-curve-digest", optional = true, default-features = false, features = ["der"] } +ecdsa = { version = "0.13", optional = true, default-features = false, features = ["der"] } sha2 = { version = "0.10", optional = true, default-features = false } [features] diff --git a/k256/Cargo.toml b/k256/Cargo.toml index bcd27152..b4507437 100644 --- a/k256/Cargo.toml +++ b/k256/Cargo.toml @@ -19,11 +19,11 @@ rust-version = "1.56" [dependencies] cfg-if = "1.0" -elliptic-curve = { git = "https://github.com/RustCrypto/traits", version = "0.12.0-pre", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "0.12.0-pre", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } # optional dependencies -ecdsa-core = { git = "https://github.com/khonsulabs/signatures", branch = "elliptic-curve-digest", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { version = "0.13", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.3", optional = true } sha2 = { version = "0.10", optional = true, default-features = false } sha3 = { version = "0.10", optional = true, default-features = false } @@ -31,7 +31,7 @@ sha3 = { version = "0.10", optional = true, default-features = false } [dev-dependencies] blobby = "0.3" criterion = "0.3" -ecdsa-core = { git = "https://github.com/khonsulabs/signatures", branch = "elliptic-curve-digest", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { version = "0.13", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.3" num-bigint = "0.4" num-traits = "0.2" diff --git a/p256/Cargo.toml b/p256/Cargo.toml index d0d04f43..7243cb31 100644 --- a/p256/Cargo.toml +++ b/p256/Cargo.toml @@ -17,17 +17,17 @@ edition = "2021" rust-version = "1.56" [dependencies] -elliptic-curve = { git = "https://github.com/RustCrypto/traits", version = "0.12.0-pre", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "0.12.0-pre", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } # optional dependencies -ecdsa-core = { git = "https://github.com/khonsulabs/signatures", branch = "elliptic-curve-digest", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { version = "0.13", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.3", optional = true } sha2 = { version = "0.10", optional = true, default-features = false } [dev-dependencies] blobby = "0.3" -ecdsa-core = { git = "https://github.com/khonsulabs/signatures", branch = "elliptic-curve-digest", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { version = "0.13", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.3" proptest = "1.0" rand_core = { version = "0.6", features = ["getrandom"] } diff --git a/p384/Cargo.toml b/p384/Cargo.toml index 8d79f35d..81e5e25a 100644 --- a/p384/Cargo.toml +++ b/p384/Cargo.toml @@ -13,8 +13,8 @@ edition = "2021" rust-version = "1.56" [dependencies] -ecdsa = { git = "https://github.com/khonsulabs/signatures", branch = "elliptic-curve-digest", optional = true, default-features = false, features = ["der"] } -elliptic-curve = { git = "https://github.com/RustCrypto/traits", version = "0.12.0-pre", default-features = false, features = ["hazmat", "sec1"] } +ecdsa = { version = "0.13", optional = true, default-features = false, features = ["der"] } +elliptic-curve = { version = "0.12.0-pre", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } sha2 = { version = "0.10", optional = true, default-features = false } From c956b6f9ea4be1a007ddef7d5554a76f8c414a20 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Tue, 18 Jan 2022 17:24:34 +0100 Subject: [PATCH 04/10] Update to elliptic-curve release --- Cargo.lock | 13 +++++++------ Cargo.toml | 1 - bp256/Cargo.toml | 2 +- bp384/Cargo.toml | 2 +- k256/Cargo.toml | 2 +- p256/Cargo.toml | 2 +- p384/Cargo.toml | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8e535697..f68c5a7e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -246,9 +246,9 @@ dependencies = [ [[package]] name = "crypto-bigint" -version = "0.3.2" +version = "0.4.0-pre.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03c6a1d5fa1de37e071642dfa44ec552ca5b299adb128fab16138e24b548fd21" +checksum = "6a9df9647255ed398be26379810e02ed1d58263570b3bcd243ee2481f79c88b1" dependencies = [ "generic-array", "rand_core", @@ -312,7 +312,7 @@ dependencies = [ [[package]] name = "ecdsa" version = "0.13.4" -source = "git+https://github.com/khonsulabs/signatures?branch=elliptic-curve-digest#ea9faaaf85fb3fa36f969420acb6c56bcaa841d1" +source = "git+https://github.com/khonsulabs/signatures?branch=elliptic-curve-digest#574859fb19e121c3366a52ea03b89f4365717862" dependencies = [ "der", "elliptic-curve", @@ -328,8 +328,9 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "elliptic-curve" -version = "0.12.0-pre" -source = "git+https://github.com/RustCrypto/traits#f899a15cb2cd293d69d1b6502e7cc537d3da480d" +version = "0.12.0-pre.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91d80a4ec12dfafce02027223bef70efaca0dc2bef6d0a26e8e508e1061cefbc" dependencies = [ "base16ct", "base64ct", @@ -830,7 +831,7 @@ dependencies = [ [[package]] name = "rfc6979" version = "0.1.0" -source = "git+https://github.com/khonsulabs/signatures?branch=elliptic-curve-digest#ea9faaaf85fb3fa36f969420acb6c56bcaa841d1" +source = "git+https://github.com/khonsulabs/signatures?branch=elliptic-curve-digest#574859fb19e121c3366a52ea03b89f4365717862" dependencies = [ "crypto-bigint", "hmac", diff --git a/Cargo.toml b/Cargo.toml index ff1c844a..72e8d166 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,5 +9,4 @@ members = [ ] [patch.crates-io] -elliptic-curve = { git = "https://github.com/RustCrypto/traits" } ecdsa = { git = "https://github.com/khonsulabs/signatures", branch = "elliptic-curve-digest" } diff --git a/bp256/Cargo.toml b/bp256/Cargo.toml index 0d278f53..8ac6cd56 100644 --- a/bp256/Cargo.toml +++ b/bp256/Cargo.toml @@ -13,7 +13,7 @@ edition = "2021" rust-version = "1.56" [dependencies] -elliptic-curve = { version = "0.12.0-pre", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "0.12.0-pre.0", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } # optional dependencies diff --git a/bp384/Cargo.toml b/bp384/Cargo.toml index f5f25305..ca5cc2d0 100644 --- a/bp384/Cargo.toml +++ b/bp384/Cargo.toml @@ -13,7 +13,7 @@ edition = "2021" rust-version = "1.56" [dependencies] -elliptic-curve = { version = "0.12.0-pre", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "0.12.0-pre.0", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } # optional dependencies diff --git a/k256/Cargo.toml b/k256/Cargo.toml index b4507437..857598a9 100644 --- a/k256/Cargo.toml +++ b/k256/Cargo.toml @@ -19,7 +19,7 @@ rust-version = "1.56" [dependencies] cfg-if = "1.0" -elliptic-curve = { version = "0.12.0-pre", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "0.12.0-pre.0", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } # optional dependencies diff --git a/p256/Cargo.toml b/p256/Cargo.toml index 7243cb31..b2440e21 100644 --- a/p256/Cargo.toml +++ b/p256/Cargo.toml @@ -17,7 +17,7 @@ edition = "2021" rust-version = "1.56" [dependencies] -elliptic-curve = { version = "0.12.0-pre", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "0.12.0-pre.0", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } # optional dependencies diff --git a/p384/Cargo.toml b/p384/Cargo.toml index 81e5e25a..2f94731c 100644 --- a/p384/Cargo.toml +++ b/p384/Cargo.toml @@ -14,7 +14,7 @@ rust-version = "1.56" [dependencies] ecdsa = { version = "0.13", optional = true, default-features = false, features = ["der"] } -elliptic-curve = { version = "0.12.0-pre", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "0.12.0-pre.0", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } sha2 = { version = "0.10", optional = true, default-features = false } From c9dcf647b325674f2e7dd280e8a269b83daace0d Mon Sep 17 00:00:00 2001 From: daxpedda Date: Tue, 18 Jan 2022 17:29:34 +0100 Subject: [PATCH 05/10] Update MSRV --- .github/workflows/bp256.yml | 4 ++-- .github/workflows/bp384.yml | 4 ++-- .github/workflows/k256.yml | 14 +++++++------- .github/workflows/p256.yml | 12 ++++++------ .github/workflows/p384.yml | 4 ++-- .github/workflows/workspace.yml | 2 +- README.md | 4 ++-- bp256/Cargo.toml | 2 +- bp256/README.md | 4 ++-- bp384/Cargo.toml | 2 +- bp384/README.md | 4 ++-- k256/Cargo.toml | 2 +- k256/README.md | 4 ++-- p256/Cargo.toml | 2 +- p256/README.md | 4 ++-- p384/Cargo.toml | 2 +- p384/README.md | 4 ++-- 17 files changed, 37 insertions(+), 37 deletions(-) diff --git a/.github/workflows/bp256.yml b/.github/workflows/bp256.yml index a3295b3c..fb5da564 100644 --- a/.github/workflows/bp256.yml +++ b/.github/workflows/bp256.yml @@ -22,7 +22,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.57.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -48,7 +48,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.57.0 # MSRV - stable steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/bp384.yml b/.github/workflows/bp384.yml index 733ab41f..95fcd9bd 100644 --- a/.github/workflows/bp384.yml +++ b/.github/workflows/bp384.yml @@ -22,7 +22,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.57.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -48,7 +48,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.57.0 # MSRV - stable steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/k256.yml b/.github/workflows/k256.yml index f86d33c9..c0ff1ecf 100644 --- a/.github/workflows/k256.yml +++ b/.github/workflows/k256.yml @@ -22,7 +22,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.57.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -57,7 +57,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.57.0 # MSRV - stable steps: - uses: actions/checkout@v2 @@ -75,7 +75,7 @@ jobs: include: # 32-bit Linux - target: i686-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.57.0 # MSRV deps: sudo apt update && sudo apt install gcc-multilib - target: i686-unknown-linux-gnu rust: stable @@ -83,7 +83,7 @@ jobs: # 64-bit Linux - target: x86_64-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.57.0 # MSRV - target: x86_64-unknown-linux-gnu rust: stable @@ -107,19 +107,19 @@ jobs: include: # ARM32 - target: armv7-unknown-linux-gnueabihf - rust: 1.56.0 # MSRV + rust: 1.57.0 # MSRV - target: armv7-unknown-linux-gnueabihf rust: stable # ARM64 - target: aarch64-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.57.0 # MSRV - target: aarch64-unknown-linux-gnu rust: stable # PPC32 - target: powerpc-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.57.0 # MSRV - target: powerpc-unknown-linux-gnu rust: stable diff --git a/.github/workflows/p256.yml b/.github/workflows/p256.yml index f27ad4c3..bf952e22 100644 --- a/.github/workflows/p256.yml +++ b/.github/workflows/p256.yml @@ -22,7 +22,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.57.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -57,7 +57,7 @@ jobs: include: # 32-bit Linux - target: i686-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.57.0 # MSRV deps: sudo apt update && sudo apt install gcc-multilib - target: i686-unknown-linux-gnu rust: stable @@ -65,7 +65,7 @@ jobs: # 64-bit Linux - target: x86_64-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.57.0 # MSRV - target: x86_64-unknown-linux-gnu rust: stable @@ -89,19 +89,19 @@ jobs: include: # ARM32 - target: armv7-unknown-linux-gnueabihf - rust: 1.56.0 # MSRV + rust: 1.57.0 # MSRV - target: armv7-unknown-linux-gnueabihf rust: stable # ARM64 - target: aarch64-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.57.0 # MSRV - target: aarch64-unknown-linux-gnu rust: stable # PPC32 - target: powerpc-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.57.0 # MSRV - target: powerpc-unknown-linux-gnu rust: stable diff --git a/.github/workflows/p384.yml b/.github/workflows/p384.yml index eed83cf5..ee898760 100644 --- a/.github/workflows/p384.yml +++ b/.github/workflows/p384.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.57.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -53,7 +53,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.57.0 # MSRV - stable steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/workspace.yml b/.github/workflows/workspace.yml index 4bd325a8..39e35ffc 100644 --- a/.github/workflows/workspace.yml +++ b/.github/workflows/workspace.yml @@ -20,7 +20,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: - toolchain: 1.56.0 + toolchain: 1.57.0 components: clippy override: true profile: minimal diff --git a/README.md b/README.md index 3d34c2f1..c9807393 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ if you are interested in curves beyond the ones listed here. ## Minimum Supported Rust Version -All crates in this repository support Rust **1.56** or higher. +All crates in this repository support Rust **1.57** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -50,7 +50,7 @@ dual licensed as above, without any additional terms or conditions. [//]: # (badges) -[rustc-image]: https://img.shields.io/badge/rustc-1.56+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.57+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260040-elliptic-curves [deps-image]: https://deps.rs/repo/github/RustCrypto/elliptic-curves/status.svg diff --git a/bp256/Cargo.toml b/bp256/Cargo.toml index 8ac6cd56..ae534706 100644 --- a/bp256/Cargo.toml +++ b/bp256/Cargo.toml @@ -10,7 +10,7 @@ readme = "README.md" categories = ["cryptography", "no-std"] keywords = ["brainpool", "crypto", "ecc"] edition = "2021" -rust-version = "1.56" +rust-version = "1.57" [dependencies] elliptic-curve = { version = "0.12.0-pre.0", default-features = false, features = ["hazmat", "sec1"] } diff --git a/bp256/README.md b/bp256/README.md index 5c6fb2be..aa729d4e 100644 --- a/bp256/README.md +++ b/bp256/README.md @@ -14,7 +14,7 @@ implemented in terms of traits from the [`elliptic-curve`] crate. ## Minimum Supported Rust Version -Rust **1.56** or higher. +Rust **1.57** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -46,7 +46,7 @@ dual licensed as above, without any additional terms or conditions. [docs-image]: https://docs.rs/bp256/badge.svg [docs-link]: https://docs.rs/bp256/ [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.56+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.57+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260040-elliptic-curves [build-image]: https://github.com/RustCrypto/elliptic-curves/workflows/bp256/badge.svg?branch=master&event=push diff --git a/bp384/Cargo.toml b/bp384/Cargo.toml index ca5cc2d0..98b05796 100644 --- a/bp384/Cargo.toml +++ b/bp384/Cargo.toml @@ -10,7 +10,7 @@ readme = "README.md" categories = ["cryptography", "no-std"] keywords = ["brainpool", "crypto", "ecc"] edition = "2021" -rust-version = "1.56" +rust-version = "1.57" [dependencies] elliptic-curve = { version = "0.12.0-pre.0", default-features = false, features = ["hazmat", "sec1"] } diff --git a/bp384/README.md b/bp384/README.md index 5c934261..859156e0 100644 --- a/bp384/README.md +++ b/bp384/README.md @@ -14,7 +14,7 @@ implemented in terms of traits from the [`elliptic-curve`] crate. ## Minimum Supported Rust Version -Rust **1.56** or higher. +Rust **1.57** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -46,7 +46,7 @@ dual licensed as above, without any additional terms or conditions. [docs-image]: https://docs.rs/bp384/badge.svg [docs-link]: https://docs.rs/bp384/ [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.56+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.57+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260040-elliptic-curves [build-image]: https://github.com/RustCrypto/elliptic-curves/workflows/bp384/badge.svg?branch=master&event=push diff --git a/k256/Cargo.toml b/k256/Cargo.toml index 857598a9..61d7251e 100644 --- a/k256/Cargo.toml +++ b/k256/Cargo.toml @@ -15,7 +15,7 @@ readme = "README.md" categories = ["cryptography", "cryptography::cryptocurrencies", "no-std"] keywords = ["bitcoin", "crypto", "ecc", "ethereum", "secp256k1"] edition = "2021" -rust-version = "1.56" +rust-version = "1.57" [dependencies] cfg-if = "1.0" diff --git a/k256/README.md b/k256/README.md index 6293c993..e3889227 100644 --- a/k256/README.md +++ b/k256/README.md @@ -63,7 +63,7 @@ most popular and commonly used elliptic curves. ## Minimum Supported Rust Version -Rust **1.56** or higher. +Rust **1.57** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -95,7 +95,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.56+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.57+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260040-elliptic-curves [build-image]: https://github.com/RustCrypto/elliptic-curves/workflows/k256/badge.svg?branch=master&event=push diff --git a/p256/Cargo.toml b/p256/Cargo.toml index b2440e21..41c3b404 100644 --- a/p256/Cargo.toml +++ b/p256/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" categories = ["cryptography", "no-std"] keywords = ["crypto", "ecc", "nist", "prime256v1", "secp256r1"] edition = "2021" -rust-version = "1.56" +rust-version = "1.57" [dependencies] elliptic-curve = { version = "0.12.0-pre.0", default-features = false, features = ["hazmat", "sec1"] } diff --git a/p256/README.md b/p256/README.md index 90dd22d0..89a2241f 100644 --- a/p256/README.md +++ b/p256/README.md @@ -47,7 +47,7 @@ like TLS and the associated X.509 PKI. ## Minimum Supported Rust Version -Rust **1.56** or higher. +Rust **1.57** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -79,7 +79,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.56+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.57+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260040-elliptic-curves [build-image]: https://github.com/RustCrypto/elliptic-curves/workflows/p256/badge.svg?branch=master&event=push diff --git a/p384/Cargo.toml b/p384/Cargo.toml index 2f94731c..3d6bfe99 100644 --- a/p384/Cargo.toml +++ b/p384/Cargo.toml @@ -10,7 +10,7 @@ readme = "README.md" categories = ["cryptography", "no-std"] keywords = ["crypto", "ecc", "nist", "secp384r1"] edition = "2021" -rust-version = "1.56" +rust-version = "1.57" [dependencies] ecdsa = { version = "0.13", optional = true, default-features = false, features = ["der"] } diff --git a/p384/README.md b/p384/README.md index 35127770..1e7c94fa 100644 --- a/p384/README.md +++ b/p384/README.md @@ -25,7 +25,7 @@ X.509 PKI. ## Minimum Supported Rust Version -Rust **1.56** or higher. +Rust **1.57** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -57,7 +57,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.56+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.57+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260040-elliptic-curves [build-image]: https://github.com/RustCrypto/elliptic-curves/workflows/p384/badge.svg?branch=master&event=push From 3859fb2ddc773d5f4578e76ee431d6f1c81272e5 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Tue, 18 Jan 2022 21:58:17 +0100 Subject: [PATCH 06/10] Update to ecdsa release --- Cargo.lock | 10 ++++++---- Cargo.toml | 3 --- bp256/Cargo.toml | 2 +- bp384/Cargo.toml | 2 +- k256/Cargo.toml | 4 ++-- p256/Cargo.toml | 4 ++-- p384/Cargo.toml | 2 +- 7 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f68c5a7e..f89b7cce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -311,8 +311,9 @@ dependencies = [ [[package]] name = "ecdsa" -version = "0.13.4" -source = "git+https://github.com/khonsulabs/signatures?branch=elliptic-curve-digest#574859fb19e121c3366a52ea03b89f4365717862" +version = "0.14.0-pre.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5af2c84d2a2c98b2834e7b502fbd2de41028d707218fcd796a416672b6b01143" dependencies = [ "der", "elliptic-curve", @@ -830,8 +831,9 @@ dependencies = [ [[package]] name = "rfc6979" -version = "0.1.0" -source = "git+https://github.com/khonsulabs/signatures?branch=elliptic-curve-digest#574859fb19e121c3366a52ea03b89f4365717862" +version = "0.2.0-pre.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b5fc62eda367f95399820ccb69ffa1695519e053001ae0b7517d16438d26ef2" dependencies = [ "crypto-bigint", "hmac", diff --git a/Cargo.toml b/Cargo.toml index 72e8d166..96a9e9b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,3 @@ members = [ "p256", "p384", ] - -[patch.crates-io] -ecdsa = { git = "https://github.com/khonsulabs/signatures", branch = "elliptic-curve-digest" } diff --git a/bp256/Cargo.toml b/bp256/Cargo.toml index ae534706..930fb341 100644 --- a/bp256/Cargo.toml +++ b/bp256/Cargo.toml @@ -17,7 +17,7 @@ elliptic-curve = { version = "0.12.0-pre.0", default-features = false, features sec1 = { version = "0.2", default-features = false } # optional dependencies -ecdsa = { version = "0.13", optional = true, default-features = false, features = ["der"] } +ecdsa = { version = "0.14.0-pre.0", optional = true, default-features = false, features = ["der"] } sha2 = { version = "0.10", optional = true, default-features = false } [features] diff --git a/bp384/Cargo.toml b/bp384/Cargo.toml index 98b05796..94cdc855 100644 --- a/bp384/Cargo.toml +++ b/bp384/Cargo.toml @@ -17,7 +17,7 @@ elliptic-curve = { version = "0.12.0-pre.0", default-features = false, features sec1 = { version = "0.2", default-features = false } # optional dependencies -ecdsa = { version = "0.13", optional = true, default-features = false, features = ["der"] } +ecdsa = { version = "0.14.0-pre.0", optional = true, default-features = false, features = ["der"] } sha2 = { version = "0.10", optional = true, default-features = false } [features] diff --git a/k256/Cargo.toml b/k256/Cargo.toml index 61d7251e..b9a6fc9e 100644 --- a/k256/Cargo.toml +++ b/k256/Cargo.toml @@ -23,7 +23,7 @@ elliptic-curve = { version = "0.12.0-pre.0", default-features = false, features sec1 = { version = "0.2", default-features = false } # optional dependencies -ecdsa-core = { version = "0.13", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { version = "0.14.0-pre.0", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.3", optional = true } sha2 = { version = "0.10", optional = true, default-features = false } sha3 = { version = "0.10", optional = true, default-features = false } @@ -31,7 +31,7 @@ sha3 = { version = "0.10", optional = true, default-features = false } [dev-dependencies] blobby = "0.3" criterion = "0.3" -ecdsa-core = { version = "0.13", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { version = "0.14.0-pre.0", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.3" num-bigint = "0.4" num-traits = "0.2" diff --git a/p256/Cargo.toml b/p256/Cargo.toml index 41c3b404..b6756e6e 100644 --- a/p256/Cargo.toml +++ b/p256/Cargo.toml @@ -21,13 +21,13 @@ elliptic-curve = { version = "0.12.0-pre.0", default-features = false, features sec1 = { version = "0.2", default-features = false } # optional dependencies -ecdsa-core = { version = "0.13", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { version = "0.14.0-pre.0", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.3", optional = true } sha2 = { version = "0.10", optional = true, default-features = false } [dev-dependencies] blobby = "0.3" -ecdsa-core = { version = "0.13", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { version = "0.14.0-pre.0", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.3" proptest = "1.0" rand_core = { version = "0.6", features = ["getrandom"] } diff --git a/p384/Cargo.toml b/p384/Cargo.toml index 3d6bfe99..90399b5f 100644 --- a/p384/Cargo.toml +++ b/p384/Cargo.toml @@ -13,7 +13,7 @@ edition = "2021" rust-version = "1.57" [dependencies] -ecdsa = { version = "0.13", optional = true, default-features = false, features = ["der"] } +ecdsa = { version = "0.14.0-pre.0", optional = true, default-features = false, features = ["der"] } elliptic-curve = { version = "0.12.0-pre.0", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } sha2 = { version = "0.10", optional = true, default-features = false } From 1801805948c3f68f4ac53730eb158cc60af881ce Mon Sep 17 00:00:00 2001 From: daxpedda Date: Wed, 19 Jan 2022 08:36:31 +0100 Subject: [PATCH 07/10] Address review --- p256/src/arithmetic/affine.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/p256/src/arithmetic/affine.rs b/p256/src/arithmetic/affine.rs index 4afecbf2..d6547fe9 100644 --- a/p256/src/arithmetic/affine.rs +++ b/p256/src/arithmetic/affine.rs @@ -267,16 +267,13 @@ impl ToCompactEncodedPoint for AffinePoint { assert_eq!(borrow, 0); let (_, borrow) = p_y.informed_subtract(&y); + // Reuse the CompressedPoint type since it's the same size as a compact point + let mut bytes = CompressedPoint::default(); + bytes[0] = sec1::Tag::Compact.into(); + bytes[1..(::UInt::BYTE_SIZE + 1)].copy_from_slice(&self.x.to_bytes()); CtOption::new( - { - // Reuse the CompressedPoint type since it's the same size as a compact point - let mut bytes = CompressedPoint::default(); - bytes[0] = sec1::Tag::Compact.into(); - bytes[1..(::UInt::BYTE_SIZE + 1)] - .copy_from_slice(&self.x.to_bytes()); - EncodedPoint::from_bytes(bytes).expect("compact key") - }, - u8::from(borrow == 0).into(), + EncodedPoint::from_bytes(bytes).expect("compact key"), + Choice::from(u8::from(borrow == 0)), ) } } From 95c59001da6d88a3f53d028093dbca449bb84313 Mon Sep 17 00:00:00 2001 From: dAxpeDDa Date: Wed, 19 Jan 2022 22:05:52 +0100 Subject: [PATCH 08/10] Address review --- p256/src/arithmetic/affine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p256/src/arithmetic/affine.rs b/p256/src/arithmetic/affine.rs index d6547fe9..7414c100 100644 --- a/p256/src/arithmetic/affine.rs +++ b/p256/src/arithmetic/affine.rs @@ -273,7 +273,7 @@ impl ToCompactEncodedPoint for AffinePoint { bytes[1..(::UInt::BYTE_SIZE + 1)].copy_from_slice(&self.x.to_bytes()); CtOption::new( EncodedPoint::from_bytes(bytes).expect("compact key"), - Choice::from(u8::from(borrow == 0)), + borrow.ct_eq(&0), ) } } From 49ab96fa8a96dfd82a5446c284e4c44e3a90f1a6 Mon Sep 17 00:00:00 2001 From: dAxpeDDa Date: Thu, 20 Jan 2022 01:03:44 +0100 Subject: [PATCH 09/10] Update to latest elliptic-curve and ecdsa --- Cargo.lock | 8 ++++---- bp256/Cargo.toml | 4 ++-- bp384/Cargo.toml | 4 ++-- k256/Cargo.toml | 6 +++--- k256/src/arithmetic/hash2curve.rs | 14 +++++--------- k256/src/ecdsa/recoverable.rs | 7 +++++-- k256/src/ecdsa/sign.rs | 14 +++++++------- k256/src/ecdsa/verify.rs | 7 ++++--- p256/Cargo.toml | 6 +++--- p256/src/arithmetic/hash2curve.rs | 12 ++++-------- p384/Cargo.toml | 4 ++-- 11 files changed, 41 insertions(+), 45 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f89b7cce..3254c10a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -311,9 +311,9 @@ dependencies = [ [[package]] name = "ecdsa" -version = "0.14.0-pre.0" +version = "0.14.0-pre.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5af2c84d2a2c98b2834e7b502fbd2de41028d707218fcd796a416672b6b01143" +checksum = "734abc41546cac3773230c5719ac16a3bbdff020e8f22393372537334f46d699" dependencies = [ "der", "elliptic-curve", @@ -329,9 +329,9 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "elliptic-curve" -version = "0.12.0-pre.0" +version = "0.12.0-pre.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91d80a4ec12dfafce02027223bef70efaca0dc2bef6d0a26e8e508e1061cefbc" +checksum = "0b8d8eb14e60f3254bd24d2f4b5675b79c1dc79318e37fb8274e607c4d82ebd9" dependencies = [ "base16ct", "base64ct", diff --git a/bp256/Cargo.toml b/bp256/Cargo.toml index 930fb341..c7090e13 100644 --- a/bp256/Cargo.toml +++ b/bp256/Cargo.toml @@ -13,11 +13,11 @@ edition = "2021" rust-version = "1.57" [dependencies] -elliptic-curve = { version = "0.12.0-pre.0", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "0.12.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } # optional dependencies -ecdsa = { version = "0.14.0-pre.0", optional = true, default-features = false, features = ["der"] } +ecdsa = { version = "0.14.0-pre.1", optional = true, default-features = false, features = ["der"] } sha2 = { version = "0.10", optional = true, default-features = false } [features] diff --git a/bp384/Cargo.toml b/bp384/Cargo.toml index 94cdc855..e22c7a11 100644 --- a/bp384/Cargo.toml +++ b/bp384/Cargo.toml @@ -13,11 +13,11 @@ edition = "2021" rust-version = "1.57" [dependencies] -elliptic-curve = { version = "0.12.0-pre.0", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "0.12.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } # optional dependencies -ecdsa = { version = "0.14.0-pre.0", optional = true, default-features = false, features = ["der"] } +ecdsa = { version = "0.14.0-pre.1", optional = true, default-features = false, features = ["der"] } sha2 = { version = "0.10", optional = true, default-features = false } [features] diff --git a/k256/Cargo.toml b/k256/Cargo.toml index b9a6fc9e..0511dbcb 100644 --- a/k256/Cargo.toml +++ b/k256/Cargo.toml @@ -19,11 +19,11 @@ rust-version = "1.57" [dependencies] cfg-if = "1.0" -elliptic-curve = { version = "0.12.0-pre.0", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "0.12.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } # optional dependencies -ecdsa-core = { version = "0.14.0-pre.0", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { version = "0.14.0-pre.1", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.3", optional = true } sha2 = { version = "0.10", optional = true, default-features = false } sha3 = { version = "0.10", optional = true, default-features = false } @@ -31,7 +31,7 @@ sha3 = { version = "0.10", optional = true, default-features = false } [dev-dependencies] blobby = "0.3" criterion = "0.3" -ecdsa-core = { version = "0.14.0-pre.0", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { version = "0.14.0-pre.1", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.3" num-bigint = "0.4" num-traits = "0.2" diff --git a/k256/src/arithmetic/hash2curve.rs b/k256/src/arithmetic/hash2curve.rs index fb3e4df0..d546df7a 100644 --- a/k256/src/arithmetic/hash2curve.rs +++ b/k256/src/arithmetic/hash2curve.rs @@ -1,14 +1,11 @@ use elliptic_curve::consts::{U4, U48}; use elliptic_curve::generic_array::GenericArray; use elliptic_curve::group::cofactor::CofactorGroup; +use elliptic_curve::hash2curve::{ + FromOkm, GroupDigest, Isogeny, IsogenyCoefficients, MapToCurve, OsswuMap, OsswuMapParams, Sgn0, +}; use elliptic_curve::subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}; use elliptic_curve::Field; -use elliptic_curve::{ - hash2curve::{ - GroupDigest, Isogeny, IsogenyCoefficients, MapToCurve, OsswuMap, OsswuMapParams, Sgn0, - }, - hash2field::FromOkm, -}; use crate::{AffinePoint, ProjectivePoint, Secp256k1}; @@ -16,7 +13,6 @@ use super::FieldElement; impl GroupDigest for Secp256k1 { type FieldElement = FieldElement; - type Output = ProjectivePoint; } impl FromOkm for FieldElement { @@ -257,7 +253,7 @@ impl CofactorGroup for ProjectivePoint { #[test] fn hash_to_curve() { - use elliptic_curve::hash2field::{self, ExpandMsgXmd}; + use elliptic_curve::hash2curve::{self, ExpandMsgXmd}; use hex_literal::hex; use sha2::Sha256; @@ -336,7 +332,7 @@ fn hash_to_curve() { for test_vector in TEST_VECTORS { // in parts let mut u = [FieldElement::default(), FieldElement::default()]; - hash2field::hash_to_field::, FieldElement>( + hash2curve::hash_to_field::, FieldElement>( &[test_vector.msg], DST, &mut u, diff --git a/k256/src/ecdsa/recoverable.rs b/k256/src/ecdsa/recoverable.rs index 7c08a26b..73d3dee2 100644 --- a/k256/src/ecdsa/recoverable.rs +++ b/k256/src/ecdsa/recoverable.rs @@ -42,7 +42,10 @@ use elliptic_curve::subtle::Choice; #[cfg(feature = "ecdsa")] use crate::{ ecdsa::{ - signature::{digest::Digest, DigestVerifier}, + signature::{ + digest::{Digest, FixedOutput}, + DigestVerifier, + }, VerifyingKey, }, elliptic_curve::{ @@ -121,7 +124,7 @@ impl Signature { signature: &super::Signature, ) -> Result where - D: Clone + Digest, + D: Clone + Digest + FixedOutput, { let signature = signature.normalize_s().unwrap_or(*signature); diff --git a/k256/src/ecdsa/sign.rs b/k256/src/ecdsa/sign.rs index 58a572d3..76855098 100644 --- a/k256/src/ecdsa/sign.rs +++ b/k256/src/ecdsa/sign.rs @@ -13,7 +13,7 @@ use ecdsa_core::{ block_buffer::Eager, core_api::{BlockSizeUser, BufferKindUser, CoreProxy, FixedOutputCore}, generic_array::typenum::{self, IsLess, Le, NonZero}, - Digest, HashMarker, OutputSizeUser, + Digest, FixedOutput, HashMarker, OutputSizeUser, }, DigestSigner, RandomizedDigestSigner, }, @@ -99,7 +99,7 @@ where impl DigestSigner for SigningKey where - D: CoreProxy + Digest + OutputSizeUser, + D: CoreProxy + Digest + FixedOutput, D::Core: BlockSizeUser + BufferKindUser + Clone @@ -118,7 +118,7 @@ where impl DigestSigner for SigningKey where - D: CoreProxy + Digest + OutputSizeUser, + D: CoreProxy + Digest + FixedOutput, D::Core: BlockSizeUser + BufferKindUser + Clone @@ -130,7 +130,7 @@ where Le<::BlockSize, typenum::U256>: NonZero, { fn try_sign_digest(&self, msg_digest: D) -> Result { - let z = >::from_be_bytes_reduced(msg_digest.finalize()); + let z = >::from_be_digest_reduced(msg_digest); let k = rfc6979_generate_k::<_, D>(&self.inner, &z, &[]); let (signature, recid) = self.inner.try_sign_prehashed(**k, z)?; let recoverable_id = recid.ok_or_else(Error::new)?.try_into()?; @@ -140,7 +140,7 @@ where impl RandomizedDigestSigner for SigningKey where - D: CoreProxy + OutputSizeUser + Digest, + D: CoreProxy + Digest + FixedOutput, D::Core: BlockSizeUser + BufferKindUser + Clone @@ -163,7 +163,7 @@ where impl RandomizedDigestSigner for SigningKey where - D: CoreProxy + OutputSizeUser + Digest, + D: CoreProxy + Digest + FixedOutput, D::Core: BlockSizeUser + BufferKindUser + Clone @@ -182,7 +182,7 @@ where let mut added_entropy = FieldBytes::default(); rng.fill_bytes(&mut added_entropy); - let z = >::from_be_bytes_reduced(msg_digest.finalize()); + let z = >::from_be_digest_reduced(msg_digest); let k = rfc6979_generate_k::<_, D>(&self.inner, &z, &added_entropy); let (signature, recid) = self.inner.try_sign_prehashed(**k, z)?; let recoverable_id = recid.ok_or_else(Error::new)?.try_into()?; diff --git a/k256/src/ecdsa/verify.rs b/k256/src/ecdsa/verify.rs index 53099a71..7719467e 100644 --- a/k256/src/ecdsa/verify.rs +++ b/k256/src/ecdsa/verify.rs @@ -12,7 +12,8 @@ use elliptic_curve::{ sec1::ToEncodedPoint, IsHigh, }; -use signature::{digest::Digest, DigestVerifier}; +use signature::digest::{Digest, FixedOutput}; +use signature::DigestVerifier; #[cfg(feature = "sha256")] use signature::PrehashSignature; @@ -79,7 +80,7 @@ where impl DigestVerifier for VerifyingKey where - D: Digest, + D: Digest + FixedOutput, { fn verify_digest(&self, digest: D, signature: &Signature) -> Result<(), Error> { self.inner.verify_digest(digest, signature) @@ -88,7 +89,7 @@ where impl DigestVerifier for VerifyingKey where - D: Digest, + D: Digest + FixedOutput, { fn verify_digest(&self, digest: D, signature: &recoverable::Signature) -> Result<(), Error> { self.inner diff --git a/p256/Cargo.toml b/p256/Cargo.toml index b6756e6e..b48c70a8 100644 --- a/p256/Cargo.toml +++ b/p256/Cargo.toml @@ -17,17 +17,17 @@ edition = "2021" rust-version = "1.57" [dependencies] -elliptic-curve = { version = "0.12.0-pre.0", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "0.12.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } # optional dependencies -ecdsa-core = { version = "0.14.0-pre.0", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { version = "0.14.0-pre.1", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.3", optional = true } sha2 = { version = "0.10", optional = true, default-features = false } [dev-dependencies] blobby = "0.3" -ecdsa-core = { version = "0.14.0-pre.0", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { version = "0.14.0-pre.1", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.3" proptest = "1.0" rand_core = { version = "0.6", features = ["getrandom"] } diff --git a/p256/src/arithmetic/hash2curve.rs b/p256/src/arithmetic/hash2curve.rs index 819b043a..68d1f44b 100644 --- a/p256/src/arithmetic/hash2curve.rs +++ b/p256/src/arithmetic/hash2curve.rs @@ -3,11 +3,8 @@ use elliptic_curve::consts::U48; use elliptic_curve::generic_array::GenericArray; use elliptic_curve::group::cofactor::CofactorGroup; use elliptic_curve::hash2curve::OsswuMap; +use elliptic_curve::hash2curve::{FromOkm, GroupDigest, MapToCurve, OsswuMapParams, Sgn0}; use elliptic_curve::subtle::{Choice, CtOption}; -use elliptic_curve::{ - hash2curve::{GroupDigest, MapToCurve, OsswuMapParams, Sgn0}, - hash2field::FromOkm, -}; use crate::{AffinePoint, NistP256, ProjectivePoint, Scalar}; @@ -15,7 +12,6 @@ use super::FieldElement; impl GroupDigest for NistP256 { type FieldElement = FieldElement; - type Output = ProjectivePoint; } impl FromOkm for FieldElement { @@ -140,7 +136,7 @@ impl FromOkm for Scalar { #[test] fn hash_to_curve() { - use elliptic_curve::hash2field::{self, ExpandMsgXmd}; + use elliptic_curve::hash2curve::{self, ExpandMsgXmd}; use hex_literal::hex; use sha2::Sha256; @@ -219,7 +215,7 @@ fn hash_to_curve() { for test_vector in TEST_VECTORS { // in parts let mut u = [FieldElement::default(), FieldElement::default()]; - hash2field::hash_to_field::, FieldElement>( + hash2curve::hash_to_field::, FieldElement>( &[test_vector.msg], DST, &mut u, @@ -254,7 +250,7 @@ fn hash_to_curve() { #[test] fn hash_to_scalar_voprf() { - use elliptic_curve::hash2field::ExpandMsgXmd; + use elliptic_curve::hash2curve::ExpandMsgXmd; use hex_literal::hex; use sha2::Sha256; diff --git a/p384/Cargo.toml b/p384/Cargo.toml index 90399b5f..9e5ebe84 100644 --- a/p384/Cargo.toml +++ b/p384/Cargo.toml @@ -13,8 +13,8 @@ edition = "2021" rust-version = "1.57" [dependencies] -ecdsa = { version = "0.14.0-pre.0", optional = true, default-features = false, features = ["der"] } -elliptic-curve = { version = "0.12.0-pre.0", default-features = false, features = ["hazmat", "sec1"] } +ecdsa = { version = "0.14.0-pre.1", optional = true, default-features = false, features = ["der"] } +elliptic-curve = { version = "0.12.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } sha2 = { version = "0.10", optional = true, default-features = false } From 4ecd07b56dff22efef3c3439a452f994f2205710 Mon Sep 17 00:00:00 2001 From: dAxpeDDa Date: Thu, 20 Jan 2022 01:16:00 +0100 Subject: [PATCH 10/10] Address review --- k256/src/ecdsa/recoverable.rs | 6 +++--- k256/src/ecdsa/sign.rs | 4 ++-- k256/src/ecdsa/verify.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/k256/src/ecdsa/recoverable.rs b/k256/src/ecdsa/recoverable.rs index 73d3dee2..fb5754c3 100644 --- a/k256/src/ecdsa/recoverable.rs +++ b/k256/src/ecdsa/recoverable.rs @@ -110,7 +110,7 @@ impl Signature { msg: &[u8], signature: &super::Signature, ) -> Result { - Self::from_digest_trial_recovery(public_key, Keccak256::new().chain_update(msg), signature) + Self::from_digest_trial_recovery(public_key, Keccak256::new_with_prefix(msg), signature) } /// Given a public key, message digest, and signature, use trial recovery @@ -151,7 +151,7 @@ impl Signature { #[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_update(msg)) + self.recover_verify_key_from_digest(Keccak256::new_with_prefix(msg)) } /// Recover the public key used to create the given signature as a @@ -365,7 +365,7 @@ mod tests { fn public_key_recovery() { for vector in VECTORS { let sig = Signature::try_from(&vector.sig[..]).unwrap(); - let prehash = Sha256::new().chain_update(vector.msg); + let prehash = Sha256::new_with_prefix(vector.msg); let pk = sig.recover_verify_key_from_digest(prehash).unwrap(); assert_eq!(&vector.pk[..], EncodedPoint::from(&pk).as_bytes()); } diff --git a/k256/src/ecdsa/sign.rs b/k256/src/ecdsa/sign.rs index 76855098..4b69e62e 100644 --- a/k256/src/ecdsa/sign.rs +++ b/k256/src/ecdsa/sign.rs @@ -82,7 +82,7 @@ where Self: DigestSigner, { fn try_sign(&self, msg: &[u8]) -> Result { - self.try_sign_digest(Digest::chain_update(S::Digest::new(), msg)) + self.try_sign_digest(S::Digest::new_with_prefix(msg)) } } @@ -93,7 +93,7 @@ where Self: RandomizedDigestSigner, { fn try_sign_with_rng(&self, rng: impl CryptoRng + RngCore, msg: &[u8]) -> Result { - self.try_sign_digest_with_rng(rng, S::Digest::new().chain_update(msg)) + self.try_sign_digest_with_rng(rng, S::Digest::new_with_prefix(msg)) } } diff --git a/k256/src/ecdsa/verify.rs b/k256/src/ecdsa/verify.rs index 7719467e..5c640d8e 100644 --- a/k256/src/ecdsa/verify.rs +++ b/k256/src/ecdsa/verify.rs @@ -74,7 +74,7 @@ where Self: DigestVerifier, { fn verify(&self, msg: &[u8], signature: &S) -> Result<(), Error> { - self.verify_digest(S::Digest::new().chain_update(msg), signature) + self.verify_digest(S::Digest::new_with_prefix(msg), signature) } }