From fe8e4867f76317522caead9c6e7a514d332c29a6 Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Wed, 26 Feb 2025 10:18:33 -0800 Subject: [PATCH] ecdsa: provide a `SigningKey::try_from_rng` --- Cargo.lock | 6 +++--- Cargo.toml | 7 ++++++- ecdsa/src/signing.rs | 7 +++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dc3a351e..ea29432d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -369,7 +369,7 @@ checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" [[package]] name = "elliptic-curve" version = "0.14.0-rc.1" -source = "git+https://github.com/RustCrypto/traits.git#28b6e0d3231fa0fb31dc7f6bfdb62d6558bcfdf6" +source = "git+https://github.com/RustCrypto/traits.git#27835aa66710bded06caef143284892dda83dda5" dependencies = [ "base16ct", "crypto-bigint", @@ -416,7 +416,7 @@ checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" [[package]] name = "ff" version = "0.13.0" -source = "git+https://github.com/pinkforest/ff.git?branch=bump-rand-core#c734f7f21d6639bc6494dde538209d0770207c49" +source = "git+https://github.com/zkcrypto/ff.git?branch=release-0.14.0#1bb634588722b1b7ce986d239c263e332bedda7f" dependencies = [ "rand_core 0.9.2", "subtle", @@ -1084,7 +1084,7 @@ dependencies = [ [[package]] name = "signature" version = "2.3.0-pre.6" -source = "git+https://github.com/RustCrypto/traits.git#28b6e0d3231fa0fb31dc7f6bfdb62d6558bcfdf6" +source = "git+https://github.com/RustCrypto/traits.git#27835aa66710bded06caef143284892dda83dda5" dependencies = [ "digest", "rand_core 0.9.2", diff --git a/Cargo.toml b/Cargo.toml index c565a0b0..b5a68ba2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ sha3 = { git = "https://github.com/RustCrypto/hashes.git" } # https://github.com/RustCrypto/traits/pull/1751 # https://github.com/RustCrypto/traits/pull/1767 +# https://github.com/RustCrypto/traits/pull/1774 elliptic-curve = { git = "https://github.com/RustCrypto/traits.git" } signature = { git = "https://github.com/RustCrypto/traits.git" } @@ -43,7 +44,11 @@ signature = { git = "https://github.com/RustCrypto/traits.git" } crypto-bigint = { git = "https://github.com/RustCrypto/crypto-bigint.git" } # https://github.com/zkcrypto/ff/pull/122 -ff = { git = "https://github.com/pinkforest/ff.git", branch = "bump-rand-core" } +# https://github.com/zkcrypto/ff/pull/126 +# https://github.com/zkcrypto/ff/pull/127 +# https://github.com/zkcrypto/ff/pull/130 +ff = { git = "https://github.com/zkcrypto/ff.git", branch = "release-0.14.0" } + # https://github.com/zkcrypto/group/pull/56 group = { git = "https://github.com/pinkforest/group.git", branch = "bump-rand-0.9" } diff --git a/ecdsa/src/signing.rs b/ecdsa/src/signing.rs index bc49c301..e6c1f3e5 100644 --- a/ecdsa/src/signing.rs +++ b/ecdsa/src/signing.rs @@ -85,6 +85,13 @@ where NonZeroScalar::::random(rng).into() } + /// Generate a cryptographically random [`SigningKey`]. + pub fn try_from_rng( + rng: &mut R, + ) -> core::result::Result { + Ok(NonZeroScalar::::try_from_rng(rng)?.into()) + } + /// Initialize signing key from a raw scalar serialized as a byte array. pub fn from_bytes(bytes: &FieldBytes) -> Result { SecretKey::::from_bytes(bytes)