Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion curve25519-dalek/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ cfg-if = "1"
ff = { version = "=0.14.0-pre.0", package = "rustcrypto-ff", default-features = false, optional = true }
group = { version = "=0.14.0-pre.0", package = "rustcrypto-group", default-features = false, optional = true }
rand_core = { version = "0.10.0-rc-3", default-features = false, optional = true }
digest = { version = "0.11.0-rc.4", default-features = false, optional = true, features = [
digest = { version = "0.11.0-rc.5", default-features = false, optional = true, features = [
"block-api",
] }
subtle = { version = "2.6.0", default-features = false, features = [
Expand All @@ -77,6 +77,7 @@ group = ["dep:group", "rand_core"]
group-bits = ["group", "ff/bits"]
digest = ["dep:digest"]
lizard = ["digest"]
rand_core = ["dep:rand_core", "digest/rand_core"]

[target.'cfg(all(not(curve25519_dalek_backend = "fiat"), not(curve25519_dalek_backend = "serial"), target_arch = "x86_64"))'.dependencies]
curve25519-dalek-derive = "0.1"
Expand Down
2 changes: 1 addition & 1 deletion ed25519-dalek/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `alloc` and `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. Implements `KeySizeUser` for `VerifyingKey`, and `KeySizeUser + TryKeyInit + Generate` for `SigningKey`.
| `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`. |
| `legacy_compatibility` | | **Unsafe:** Disables certain signature checks. See [below](#malleability-and-the-legacy_compatibility-feature) |
Expand Down
31 changes: 31 additions & 0 deletions ed25519-dalek/src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ use rand_core::CryptoRng;
#[cfg(feature = "serde")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};

#[cfg(feature = "digest")]
use curve25519_dalek::digest::{
Key,
crypto_common::{InvalidKey, KeySizeUser, TryKeyInit},
typenum::U32,
};

#[cfg(all(feature = "digest", feature = "rand_core"))]
use curve25519_dalek::digest::crypto_common::Generate;

use sha2::Sha512;
use subtle::{Choice, ConstantTimeEq};

Expand Down Expand Up @@ -549,6 +559,27 @@ impl SigningKey {
}
}

#[cfg(feature = "digest")]
impl KeySizeUser for SigningKey {
type KeySize = U32;
}

#[cfg(feature = "digest")]
impl TryKeyInit for SigningKey {
fn new(key: &Key<Self>) -> Result<Self, InvalidKey> {
Ok(Self::from_bytes(key.as_ref()))
}
}

#[cfg(all(feature = "digest", feature = "rand_core"))]
impl Generate for SigningKey {
fn try_generate_from_rng<R: rand_core::TryCryptoRng + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
let mut secret = SecretKey::default();
rng.try_fill_bytes(&mut secret)?;
Ok(Self::from_bytes(&secret))
}
}

impl AsRef<VerifyingKey> for SigningKey {
fn as_ref(&self) -> &VerifyingKey {
&self.verifying_key
Expand Down
8 changes: 8 additions & 0 deletions ed25519-dalek/src/verifying.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -116,6 +119,11 @@ impl From<EdwardsPoint> for VerifyingKey {
}
}

#[cfg(feature = "digest")]
impl KeySizeUser for VerifyingKey {
type KeySize = U32;
}

impl VerifyingKey {
/// Convert this public key to a byte array.
#[inline]
Expand Down
Loading