Skip to content

Commit

Permalink
ecdsa: provide a SigningKey::try_from_rng
Browse files Browse the repository at this point in the history
  • Loading branch information
baloo committed Mar 1, 2025
1 parent 0e69f92 commit 7c22f3e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,19 @@ sha3 = { git = "https://github.com/RustCrypto/hashes.git" }

# https://github.com/RustCrypto/traits/pull/1751
# https://github.com/RustCrypto/traits/pull/1767
elliptic-curve = { git = "https://github.com/RustCrypto/traits.git" }
# https://github.com/RustCrypto/traits/pull/1774
elliptic-curve = { git = "https://github.com/baloo/traits.git", branch = "baloo/elliptic-curve/scalar-try-from-rng" }
signature = { git = "https://github.com/RustCrypto/traits.git" }

# https://github.com/RustCrypto/crypto-bigint/pull/762
# https://github.com/RustCrypto/crypto-bigint/pull/765
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
ff = { git = "https://github.com/baloo/ff.git", branch = "baloo/try_from_rng" }

# https://github.com/zkcrypto/group/pull/56
group = { git = "https://github.com/pinkforest/group.git", branch = "bump-rand-0.9" }

Expand Down
7 changes: 7 additions & 0 deletions ecdsa/src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ where
NonZeroScalar::<C>::random(rng).into()
}

/// Generate a cryptographically random [`SigningKey`].
pub fn try_from_rng<R: TryCryptoRng + ?Sized>(
rng: &mut R,
) -> core::result::Result<Self, R::Error> {
Ok(NonZeroScalar::<C>::try_from_rng(rng)?.into())
}

/// Initialize signing key from a raw scalar serialized as a byte array.
pub fn from_bytes(bytes: &FieldBytes<C>) -> Result<Self> {
SecretKey::<C>::from_bytes(bytes)
Expand Down

0 comments on commit 7c22f3e

Please sign in to comment.