diff --git a/ed25519-dalek/README.md b/ed25519-dalek/README.md index 364d08538..5381629e3 100644 --- a/ed25519-dalek/README.md +++ b/ed25519-dalek/README.md @@ -22,7 +22,7 @@ This crate is `#[no_std]` compatible with `default-features = false`. | `zeroize` | ✓ | Implements `Zeroize` and `ZeroizeOnDrop` for `SigningKey` | | `rand_core` | | Enables `SigningKey::generate` | | `batch` | | Enables `verify_batch` for verifying many signatures quickly. Also enables `rand_core`. | -| `digest` | | Enables `Context`, `SigningKey::{with_context, sign_prehashed}` and `VerifyingKey::{with_context, verify_prehashed, verify_prehashed_strict}` for Ed25519ph prehashed signatures | +| `digest` | | Enables `Context`, `SigningKey::{with_context, sign_prehashed}` and `VerifyingKey::{with_context, verify_prehashed, verify_prehashed_strict}` for Ed25519ph prehashed signatures. Also implements `KeySizeUser` for `SigningKey` and `VerifyingKey`, and implements `KeyInit` for `SigningKey`. | | `asm` | | Enables assembly optimizations in the SHA-512 compression functions | | `pkcs8` | | Enables [PKCS#8](https://en.wikipedia.org/wiki/PKCS_8) serialization/deserialization for `SigningKey` and `VerifyingKey` | | `pem` | | Enables PEM serialization support for PKCS#8 private keys and SPKI public keys. Also enables `alloc`. | diff --git a/ed25519-dalek/src/signing.rs b/ed25519-dalek/src/signing.rs index f3c1053b2..29b53679d 100644 --- a/ed25519-dalek/src/signing.rs +++ b/ed25519-dalek/src/signing.rs @@ -20,6 +20,9 @@ use rand_core::CryptoRngCore; #[cfg(feature = "serde")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; +#[cfg(feature = "digest")] +use curve25519_dalek::digest::{crypto_common::{KeySizeUser, KeyInit, Key}, typenum::U32}; + use sha2::Sha512; use subtle::{Choice, ConstantTimeEq}; @@ -536,6 +539,18 @@ impl SigningKey { } } +#[cfg(feature = "digest")] +impl KeySizeUser for SigningKey { + type KeySize = U32; +} + +#[cfg(feature = "digest")] +impl KeyInit for SigningKey { + fn new(key: &Key) -> Self { + Self::from_bytes(key.as_ref()) + } +} + impl AsRef for SigningKey { fn as_ref(&self) -> &VerifyingKey { &self.verifying_key diff --git a/ed25519-dalek/src/verifying.rs b/ed25519-dalek/src/verifying.rs index 2bb40ebd7..991869ef4 100644 --- a/ed25519-dalek/src/verifying.rs +++ b/ed25519-dalek/src/verifying.rs @@ -9,6 +9,9 @@ //! ed25519 public keys. +#[cfg(feature = "digest")] +use curve25519_dalek::digest::{crypto_common::KeySizeUser, typenum::U32}; + use core::fmt::Debug; use core::hash::{Hash, Hasher}; @@ -109,6 +112,11 @@ impl From for VerifyingKey { } } +#[cfg(feature = "digest")] +impl KeySizeUser for VerifyingKey { + type KeySize = U32; +} + impl VerifyingKey { /// Convert this public key to a byte array. #[inline]