Skip to content

ed25519-dalek: bring signature identifiers #728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ resolver = "2"

[profile.dev]
opt-level = 2

6 changes: 3 additions & 3 deletions curve25519-dalek/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ rustdoc-args = [
features = ["serde", "rand_core", "digest", "legacy_compatibility", "group-bits"]

[dev-dependencies]
sha2 = { version = "0.10", default-features = false }
sha2 = { version = "0.11.0-rc.0", default-features = false }
bincode = "1"
criterion = { version = "0.5", features = ["html_reports"] }
hex = "0.4.2"
Expand All @@ -50,8 +50,8 @@ cfg-if = "1"
ff = { version = "0.13", default-features = false, optional = true }
group = { version = "0.13", default-features = false, optional = true }
rand_core = { version = "0.6.4", default-features = false, optional = true }
digest = { version = "0.10", default-features = false, optional = true }
subtle = { version = "2.6.0", default-features = false, features = ["const-generics"]}
digest = { version = "0.11.0-rc.0", default-features = false, optional = true }
subtle = { version = "2.6.0", default-features = false, features = ["const-generics"] }
serde = { version = "1.0", default-features = false, optional = true, features = ["derive"] }
zeroize = { version = "1", default-features = false, optional = true }

Expand Down
2 changes: 1 addition & 1 deletion curve25519-dalek/src/edwards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ use core::ops::{AddAssign, SubAssign};
use core::ops::{Mul, MulAssign};

#[cfg(feature = "digest")]
use digest::{generic_array::typenum::U64, Digest};
use digest::{array::typenum::U64, Digest};

#[cfg(feature = "group")]
use {
Expand Down
2 changes: 1 addition & 1 deletion curve25519-dalek/src/ristretto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ use core::ops::{Mul, MulAssign};
use rand_core::CryptoRngCore;

#[cfg(feature = "digest")]
use digest::generic_array::typenum::U64;
use digest::array::typenum::U64;
#[cfg(feature = "digest")]
use digest::Digest;

Expand Down
2 changes: 1 addition & 1 deletion curve25519-dalek/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ use rand_core::RngCore;
use rand_core::CryptoRngCore;

#[cfg(feature = "digest")]
use digest::generic_array::typenum::U64;
use digest::array::typenum::U64;
#[cfg(feature = "digest")]
use digest::Digest;

Expand Down
17 changes: 8 additions & 9 deletions ed25519-dalek/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ed25519-dalek"
version = "2.1.1"
version = "2.2.0-pre"
edition = "2021"
authors = [
"isis lovecruft <isis@patternsinthevoid.net>",
Expand All @@ -27,9 +27,9 @@ features = ["batch", "digest", "hazmat", "pem", "serde"]

[dependencies]
curve25519-dalek = { version = "4", path = "../curve25519-dalek", default-features = false, features = ["digest"] }
ed25519 = { version = ">=2.2, <2.3", default-features = false }
signature = { version = ">=2.0, <2.3", optional = true, default-features = false }
sha2 = { version = "0.10", default-features = false }
ed25519 = { version = "=3.0.0-pre.0", default-features = false }
signature = { version = "3.0.0-rc.0", optional = true, default-features = false }
sha2 = { version = "0.11.0-rc.0", default-features = false }
subtle = { version = "2.3.0", default-features = false }

# optional features
Expand All @@ -41,8 +41,8 @@ zeroize = { version = "1.5", default-features = false, optional = true }
[dev-dependencies]
curve25519-dalek = { version = "4", path = "../curve25519-dalek", default-features = false, features = ["digest", "rand_core"] }
x25519-dalek = { version = "2", path = "../x25519-dalek", default-features = false, features = ["static_secrets"] }
blake2 = "0.10"
sha3 = "0.10"
blake2 = "0.11.0-rc.0"
sha3 = "0.11.0-rc.0"
hex = "0.4"
bincode = "1.0"
serde_json = "1.0"
Expand All @@ -60,10 +60,9 @@ required-features = ["rand_core"]

[features]
default = ["fast", "std", "zeroize"]
alloc = ["curve25519-dalek/alloc", "ed25519/alloc", "serde?/alloc", "zeroize/alloc"]
std = ["alloc", "ed25519/std", "serde?/std", "sha2/std"]
alloc = ["curve25519-dalek/alloc", "ed25519/alloc", "serde?/alloc", "signature/alloc", "zeroize/alloc"]
std = ["alloc", "ed25519/std", "serde?/std"]

asm = ["sha2/asm"]
batch = ["alloc", "merlin", "rand_core"]
fast = ["curve25519-dalek/precomputed-tables"]
digest = ["signature/digest"]
Expand Down
4 changes: 2 additions & 2 deletions ed25519-dalek/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ impl Error for InternalError {}
pub type SignatureError = ed25519::signature::Error;

impl From<InternalError> for SignatureError {
#[cfg(not(feature = "std"))]
#[cfg(not(feature = "alloc"))]
fn from(_err: InternalError) -> SignatureError {
SignatureError::new()
}

#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
fn from(err: InternalError) -> SignatureError {
SignatureError::from_source(err)
}
Expand Down
2 changes: 1 addition & 1 deletion ed25519-dalek/src/hazmat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use zeroize::{Zeroize, ZeroizeOnDrop};

// These are used in the functions that are made public when the hazmat feature is set
use crate::{Signature, VerifyingKey};
use curve25519_dalek::digest::{generic_array::typenum::U64, Digest};
use curve25519_dalek::digest::{array::typenum::U64, Digest};

/// Contains the secret scalar and domain separator used for generating signatures.
///
Expand Down
28 changes: 11 additions & 17 deletions ed25519-dalek/src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use sha2::Sha512;
use subtle::{Choice, ConstantTimeEq};

use curve25519_dalek::{
digest::{generic_array::typenum::U64, Digest},
digest::{array::typenum::U64, Digest},
edwards::{CompressedEdwardsY, EdwardsPoint},
scalar::Scalar,
};
Expand Down Expand Up @@ -665,20 +665,6 @@ impl pkcs8::EncodePrivateKey for SigningKey {
}
}

#[cfg(all(feature = "alloc", feature = "pkcs8"))]
impl pkcs8::spki::DynSignatureAlgorithmIdentifier for SigningKey {
fn signature_algorithm_identifier(
&self,
) -> pkcs8::spki::Result<pkcs8::spki::AlgorithmIdentifierOwned> {
// From https://datatracker.ietf.org/doc/html/rfc8410
// `id-Ed25519 OBJECT IDENTIFIER ::= { 1 3 101 112 }`
Ok(pkcs8::spki::AlgorithmIdentifier {
oid: ed25519::pkcs8::ALGORITHM_OID,
parameters: None,
})
}
}

#[cfg(feature = "pkcs8")]
impl TryFrom<pkcs8::KeypairBytes> for SigningKey {
type Error = pkcs8::Error;
Expand Down Expand Up @@ -709,6 +695,14 @@ impl TryFrom<&pkcs8::KeypairBytes> for SigningKey {
}
}

#[cfg(feature = "pkcs8")]
impl pkcs8::spki::SignatureAlgorithmIdentifier for SigningKey {
type Params = pkcs8::spki::der::AnyRef<'static>;

const SIGNATURE_ALGORITHM_IDENTIFIER: pkcs8::spki::AlgorithmIdentifier<Self::Params> =
<Signature as pkcs8::spki::AssociatedAlgorithmIdentifier>::ALGORITHM_IDENTIFIER;
}

#[cfg(feature = "pkcs8")]
impl From<SigningKey> for pkcs8::KeypairBytes {
fn from(signing_key: SigningKey) -> pkcs8::KeypairBytes {
Expand All @@ -727,10 +721,10 @@ impl From<&SigningKey> for pkcs8::KeypairBytes {
}

#[cfg(feature = "pkcs8")]
impl TryFrom<pkcs8::PrivateKeyInfo<'_>> for SigningKey {
impl TryFrom<pkcs8::PrivateKeyInfoRef<'_>> for SigningKey {
type Error = pkcs8::Error;

fn try_from(private_key: pkcs8::PrivateKeyInfo<'_>) -> pkcs8::Result<Self> {
fn try_from(private_key: pkcs8::PrivateKeyInfoRef<'_>) -> pkcs8::Result<Self> {
pkcs8::KeypairBytes::try_from(private_key)?.try_into()
}
}
Expand Down
24 changes: 9 additions & 15 deletions ed25519-dalek/src/verifying.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use core::fmt::Debug;
use core::hash::{Hash, Hasher};

use curve25519_dalek::{
digest::{generic_array::typenum::U64, Digest},
digest::{array::typenum::U64, Digest},
edwards::{CompressedEdwardsY, EdwardsPoint},
montgomery::MontgomeryPoint,
scalar::Scalar,
Expand Down Expand Up @@ -567,6 +567,14 @@ impl TryFrom<&[u8]> for VerifyingKey {
}
}

#[cfg(feature = "pkcs8")]
impl pkcs8::spki::SignatureAlgorithmIdentifier for VerifyingKey {
type Params = pkcs8::spki::der::AnyRef<'static>;

const SIGNATURE_ALGORITHM_IDENTIFIER: pkcs8::spki::AlgorithmIdentifier<Self::Params> =
<ed25519::Signature as pkcs8::spki::AssociatedAlgorithmIdentifier>::ALGORITHM_IDENTIFIER;
}

impl From<VerifyingKey> for EdwardsPoint {
fn from(vk: VerifyingKey) -> EdwardsPoint {
vk.point
Expand All @@ -580,20 +588,6 @@ impl pkcs8::EncodePublicKey for VerifyingKey {
}
}

#[cfg(all(feature = "alloc", feature = "pkcs8"))]
impl pkcs8::spki::DynSignatureAlgorithmIdentifier for VerifyingKey {
fn signature_algorithm_identifier(
&self,
) -> pkcs8::spki::Result<pkcs8::spki::AlgorithmIdentifierOwned> {
// From https://datatracker.ietf.org/doc/html/rfc8410
// `id-Ed25519 OBJECT IDENTIFIER ::= { 1 3 101 112 }`
Ok(ed25519::pkcs8::spki::AlgorithmIdentifierOwned {
oid: ed25519::pkcs8::ALGORITHM_OID,
parameters: None,
})
}
}

#[cfg(feature = "pkcs8")]
impl TryFrom<pkcs8::PublicKeyBytes> for VerifyingKey {
type Error = pkcs8::spki::Error;
Expand Down
Loading