From 2729882d6557ea776eee555239e77e84b3c84229 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Mon, 6 Mar 2023 08:22:04 -0500 Subject: [PATCH] Update to {k, p}256 0.12 --- Cargo.lock | 75 ++++++++++++++++++++++++++------ coins/ethereum/Cargo.toml | 3 +- coins/ethereum/tests/contract.rs | 2 +- coins/ethereum/tests/crypto.rs | 25 ++++++----- crypto/ciphersuite/Cargo.toml | 4 +- crypto/dleq/Cargo.toml | 2 +- crypto/ff-group-tests/Cargo.toml | 4 +- crypto/multiexp/Cargo.toml | 2 +- 8 files changed, 84 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a4913d97..7b6fa723 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -915,7 +915,7 @@ dependencies = [ "flexible-transcript", "group", "hex", - "k256", + "k256 0.12.0", "minimal-ed448", "p256", "rand_core 0.6.4", @@ -1034,7 +1034,7 @@ dependencies = [ "digest 0.10.6", "getrandom 0.2.8", "hmac 0.12.1", - "k256", + "k256 0.11.6", "lazy_static", "serde", "sha2 0.10.6", @@ -1716,7 +1716,7 @@ dependencies = [ "flexible-transcript", "group", "hex-literal", - "k256", + "k256 0.12.0", "multiexp", "rand_core 0.6.4", "thiserror", @@ -1793,7 +1793,19 @@ dependencies = [ "der", "elliptic-curve", "rfc6979", - "signature", + "signature 1.6.4", +] + +[[package]] +name = "ecdsa" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12844141594ad74185a926d030f3b605f6a903b4e3fec351f3ea338ac5b7637e" +dependencies = [ + "der", + "elliptic-curve", + "rfc6979", + "signature 2.0.0", ] [[package]] @@ -1802,7 +1814,7 @@ version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e9c280362032ea4203659fc489832d0204ef09f247a0506f170dafcac08c369" dependencies = [ - "signature", + "signature 1.6.4", ] [[package]] @@ -1998,11 +2010,12 @@ dependencies = [ "eyre", "group", "hex-literal", - "k256", + "k256 0.12.0", "modular-frost", "rand_core 0.6.4", "serde", "serde_json", + "sha2 0.10.6", "sha3", "thiserror", "tokio", @@ -2126,7 +2139,7 @@ dependencies = [ "ethabi", "generic-array 0.14.6", "hex", - "k256", + "k256 0.11.6", "once_cell", "open-fastrlp", "proc-macro2", @@ -2341,7 +2354,7 @@ name = "ff-group-tests" version = "0.12.0" dependencies = [ "group", - "k256", + "k256 0.12.0", "p256", "rand_core 0.6.4", ] @@ -2593,7 +2606,7 @@ dependencies = [ "frame-metadata", "frame-support-procedural", "impl-trait-for-tuples", - "k256", + "k256 0.11.6", "log", "once_cell", "parity-scale-codec", @@ -3785,12 +3798,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72c1e0b51e7ec0a97369623508396067a486bd0cbed95a2659a4b863d28cfc8b" dependencies = [ "cfg-if", - "ecdsa", + "ecdsa 0.14.8", "elliptic-curve", "sha2 0.10.6", "sha3", ] +[[package]] +name = "k256" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92a55e0ff3b72c262bcf041d9e97f1b84492b68f1c1a384de2323d3dc9403397" +dependencies = [ + "cfg-if", + "ecdsa 0.15.1", + "elliptic-curve", + "once_cell", + "sha2 0.10.6", + "signature 2.0.0", +] + [[package]] name = "keccak" version = "0.1.3" @@ -4765,7 +4792,7 @@ dependencies = [ "dalek-ff-group", "ff", "group", - "k256", + "k256 0.12.0", "rand_core 0.6.4", "zeroize", ] @@ -5177,12 +5204,13 @@ checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" [[package]] name = "p256" -version = "0.11.1" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51f44edd08f51e2ade572f141051021c5af22677e42b7dd28a88155151c33594" +checksum = "49c124b3cbce43bcbac68c58ec181d98ed6cc7e6d0aa7c3ba97b2563410b0e55" dependencies = [ - "ecdsa", + "ecdsa 0.15.1", "elliptic-curve", + "primeorder", "sha2 0.10.6", ] @@ -5844,6 +5872,15 @@ dependencies = [ "syn", ] +[[package]] +name = "primeorder" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b54f7131b3dba65a2f414cf5bd25b66d4682e4608610668eae785750ba4c5b2" +dependencies = [ + "elliptic-curve", +] + [[package]] name = "primitive-types" version = "0.12.1" @@ -7963,6 +8000,16 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "signature" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fe458c98333f9c8152221191a77e2a44e8325d0193484af2e9421a53019e57d" +dependencies = [ + "digest 0.10.6", + "rand_core 0.6.4", +] + [[package]] name = "simba" version = "0.5.1" diff --git a/coins/ethereum/Cargo.toml b/coins/ethereum/Cargo.toml index 9d59efd8..4e837f0e 100644 --- a/coins/ethereum/Cargo.toml +++ b/coins/ethereum/Cargo.toml @@ -20,10 +20,11 @@ rand_core = "0.6" serde_json = "1.0" serde = "1.0" +sha2 = "0.10" sha3 = "0.10" group = "0.12" -k256 = { version = "0.11", features = ["arithmetic", "keccak256", "ecdsa"] } +k256 = { version = "0.12", features = ["arithmetic", "ecdsa"] } frost = { package = "modular-frost", path = "../../crypto/frost", features = ["secp256k1", "tests"] } eyre = "0.6" diff --git a/coins/ethereum/tests/contract.rs b/coins/ethereum/tests/contract.rs index 057f0b4c..70f3320a 100644 --- a/coins/ethereum/tests/contract.rs +++ b/coins/ethereum/tests/contract.rs @@ -2,7 +2,7 @@ use std::{convert::TryFrom, sync::Arc, time::Duration}; use rand_core::OsRng; -use k256::{elliptic_curve::bigint::ArrayEncoding, U256}; +use ::k256::{elliptic_curve::bigint::ArrayEncoding, U256}; use ethers::{ prelude::*, diff --git a/coins/ethereum/tests/crypto.rs b/coins/ethereum/tests/crypto.rs index f48f1869..82f61e01 100644 --- a/coins/ethereum/tests/crypto.rs +++ b/coins/ethereum/tests/crypto.rs @@ -1,29 +1,32 @@ -use ethereum_serai::crypto::*; -use frost::curve::Secp256k1; use k256::{ elliptic_curve::{bigint::ArrayEncoding, ops::Reduce, sec1::ToEncodedPoint}, ProjectivePoint, Scalar, U256, }; +use frost::curve::Secp256k1; + +use ethereum_serai::crypto::*; #[test] fn test_ecrecover() { - use k256::ecdsa::{ - recoverable::Signature, - signature::{Signer, Verifier}, - SigningKey, VerifyingKey, - }; use rand_core::OsRng; + use sha2::Sha256; + use sha3::{Digest, Keccak256}; + use k256::ecdsa::{hazmat::SignPrimitive, signature::DigestVerifier, SigningKey, VerifyingKey}; let private = SigningKey::random(&mut OsRng); let public = VerifyingKey::from(&private); const MESSAGE: &[u8] = b"Hello, World!"; - let sig: Signature = private.sign(MESSAGE); - public.verify(MESSAGE, &sig).unwrap(); + let (sig, recovery_id) = private + .as_nonzero_scalar() + .try_sign_prehashed_rfc6979::(Keccak256::digest(MESSAGE), b"") + .unwrap(); + assert_eq!(public.verify_digest(Keccak256::new_with_prefix(MESSAGE), &sig).unwrap(), ()); assert_eq!( - ecrecover(hash_to_scalar(MESSAGE), sig.as_ref()[64], *sig.r(), *sig.s()).unwrap(), - address(&ProjectivePoint::from(public)) + ecrecover(hash_to_scalar(MESSAGE), recovery_id.unwrap().is_y_odd().into(), *sig.r(), *sig.s()) + .unwrap(), + address(&ProjectivePoint::from(public.as_affine())) ); } diff --git a/crypto/ciphersuite/Cargo.toml b/crypto/ciphersuite/Cargo.toml index 16bb2118..163e7981 100644 --- a/crypto/ciphersuite/Cargo.toml +++ b/crypto/ciphersuite/Cargo.toml @@ -29,8 +29,8 @@ group = "0.12" dalek-ff-group = { path = "../dalek-ff-group", version = "^0.1.2", optional = true } elliptic-curve = { version = "0.12", features = ["hash2curve"], optional = true } -p256 = { version = "0.11", features = ["arithmetic", "bits", "hash2curve"], optional = true } -k256 = { version = "0.11", features = ["arithmetic", "bits", "hash2curve"], optional = true } +p256 = { version = "0.12", features = ["arithmetic", "bits", "hash2curve"], optional = true } +k256 = { version = "0.12", features = ["arithmetic", "bits", "hash2curve"], optional = true } minimal-ed448 = { path = "../ed448", version = "^0.1.2", optional = true } diff --git a/crypto/dleq/Cargo.toml b/crypto/dleq/Cargo.toml index 15ba6b6d..71745a11 100644 --- a/crypto/dleq/Cargo.toml +++ b/crypto/dleq/Cargo.toml @@ -31,7 +31,7 @@ hex-literal = "0.3" blake2 = "0.10" -k256 = { version = "0.11", features = ["arithmetic", "bits"] } +k256 = { version = "0.12", features = ["arithmetic", "bits"] } dalek-ff-group = { path = "../dalek-ff-group" } transcript = { package = "flexible-transcript", path = "../transcript", features = ["recommended"] } diff --git a/crypto/ff-group-tests/Cargo.toml b/crypto/ff-group-tests/Cargo.toml index 94fb8099..67e9eaaf 100644 --- a/crypto/ff-group-tests/Cargo.toml +++ b/crypto/ff-group-tests/Cargo.toml @@ -17,5 +17,5 @@ rand_core = "0.6" group = "0.12" [dev-dependencies] -k256 = { version = "0.11", features = ["bits"] } -p256 = { version = "0.11", features = ["bits"] } +k256 = { version = "0.12", features = ["bits"] } +p256 = { version = "0.12", features = ["bits"] } diff --git a/crypto/multiexp/Cargo.toml b/crypto/multiexp/Cargo.toml index ecddf764..a54ae0d8 100644 --- a/crypto/multiexp/Cargo.toml +++ b/crypto/multiexp/Cargo.toml @@ -23,7 +23,7 @@ rand_core = { version = "0.6", optional = true } [dev-dependencies] rand_core = "0.6" -k256 = { version = "0.11", features = ["bits"] } +k256 = { version = "0.12", features = ["bits"] } dalek-ff-group = { path = "../dalek-ff-group" } [features]