Skip to content
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

feat: implement support for Ed25519 signing #87

Merged
merged 5 commits into from
Oct 31, 2023
Merged
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
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ ecdsa = { version = "0.16", default-features = false, features = [
"verifying",
"alloc",
] }

ed25519-dalek = { version = "2", default-features = false, features = [
"zeroize",
"rand_core",
] }

signature = { version = "2.1.0", default-features = false }
subtle = { version = "2.5", default-features = false }
# FIXME: remove this when we can use const generics
Expand Down
64 changes: 12 additions & 52 deletions src/jwk/okp.rs
Original file line number Diff line number Diff line change
@@ -1,52 +1,10 @@
//! Key types for Curve25519 and Curve448 (`crv` parameter = `OKP`)

use self::{
curve25519::{Curve25519Private, Curve25519Public},
curve448::{Curve448Private, Curve448Public},
};
use self::curve25519::{Curve25519Private, Curve25519Public};

/// Curve25519 key types (EdDSA and ECDH)
pub mod curve25519 {
/// EdDSA part of Curve25519
pub mod ed25519 {
/// An Ed25519 public key used to verify signatures
#[derive(Debug)]
pub struct Ed25519PublicKey;
pub mod curve25519;

/// An Ed25519 private key used to create signatures
#[derive(Debug)]
pub struct Ed25519PrivateKey;
}

/// ECDH part of Curve25519
pub mod x25519 {
/// An ECDH public key
#[derive(Debug)]
pub struct X25519PublicKey;

/// An ECDH private key
#[derive(Debug)]
pub struct X25519PrivateKey;
}

/// Either a public key for Ed25519 or X25519 (Diffie-Hellman)
#[derive(Debug)]
pub enum Curve25519Public {
/// Public Ed25519 part
Ed(ed25519::Ed25519PublicKey),
/// Public X25519 part
X(x25519::X25519PublicKey),
}

/// Either a private key for Ed25519 or X25519 (Diffie-Hellman)
#[derive(Debug)]
pub enum Curve25519Private {
/// Private Ed25519 part
Ed(ed25519::Ed25519PrivateKey),
/// Private X25519 part
X(x25519::X25519PrivateKey),
}
}
use serde::{Deserialize, Serialize};

/// TODO: unsupported, no implementation available
#[allow(missing_docs)]
Expand All @@ -62,7 +20,6 @@
pub mod x448 {
#[derive(Debug)]
pub struct X448Public;

#[derive(Debug)]
pub struct X448Private;
}
Expand All @@ -82,20 +39,23 @@

/// The public part of an `OKP` key type
#[non_exhaustive]
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]

Check warning on line 42 in src/jwk/okp.rs

View check run for this annotation

Codecov / codecov/patch

src/jwk/okp.rs#L42

Added line #L42 was not covered by tests
#[serde(untagged)]

pub enum OkpPublic {
/// `kty` is `OKP` and `crv` is either `Ed25519` or `X25519`
Curve25519(Curve25519Public),
/// `kty` is `OKP` and `crv` is either `Ed448` or `X448`
Curve448(Curve448Public),
// /// `kty` is `OKP` and `crv` is either `Ed448` or `X448`
// Curve448(Curve448Public),
}

/// The private part of an `OKP` key type
#[non_exhaustive]
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OkpPrivate {
/// `kty` is `OKP` and `crv` is either `Ed25519` or `X25519`
Curve25519(Curve25519Private),
/// `kty` is `OKP` and `crv` is either `Ed448` or `X448`
Curve448(Curve448Private),
// /// `kty` is `OKP` and `crv` is either `Ed448` or `X448`
// Curve448(Curve448Private),
}
29 changes: 29 additions & 0 deletions src/jwk/okp/curve25519.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! Key types for Curve-25519
mod ed25519;
mod x25519;

use serde::{Deserialize, Serialize};

pub use self::ed25519::{Ed25519PrivateKey, Ed25519PublicKey, Ed25519Signer, Ed25519Verifier};

/// Either a public key for Ed25519 or X25519 (Diffie-Hellman)
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
#[serde(untagged)]
pub enum Curve25519Public {
/// Public Ed25519 part
Ed(Ed25519PublicKey),
// /// Public X25519 part
// X(X25519PublicKey),
}

/// Either a private key for Ed25519 or X25519 (Diffie-Hellman)
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
#[serde(untagged)]
pub enum Curve25519Private {
/// Private Ed25519 part
Ed(Ed25519PrivateKey),
// /// Private X25519 part
// X(X25519PrivateKey),
}
Loading
Loading