Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/ssh-key.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
with:
target: ${{ matrix.target }}
- uses: RustCrypto/actions/cargo-hack-install@master
- run: cargo hack build --target ${{ matrix.target }} --feature-powerset --exclude-features default,dsa,ed25519,getrandom,p256,p384,p521,rsa,tdes,std,ppk,unstable-mldsa --release
- run: cargo hack build --target ${{ matrix.target }} --feature-powerset --exclude-features default,dsa,ed25519,getrandom,p256,p384,p521,rsa,tdes,std,ppk,mldsa --release
- run: cargo build --target ${{ matrix.target }} --no-default-features --features alloc,crypto,dsa,encryption,tdes --release

test:
Expand All @@ -72,7 +72,7 @@ jobs:
- uses: actions/checkout@v7
- uses: dtolnay/rust-toolchain@stable
- uses: RustCrypto/actions/cargo-hack-install@master
- run: cargo hack test --feature-powerset --exclude-features default,dsa,ed25519,getrandom,p256,p384,p521,rsa,tdes,std,ppk,unstable-mldsa --release
- run: cargo hack test --feature-powerset --exclude-features default,dsa,ed25519,getrandom,p256,p384,p521,rsa,tdes,std,ppk,mldsa --release
- run: cargo test --release
#- run: cargo test --release --features getrandom # TODO(tarcieri): fix `getrandom` feature
- run: cargo test --release --features std
Expand Down
6 changes: 3 additions & 3 deletions ssh-key/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ sha2 = ["dep:sha2"]
tdes = ["cipher/tdes", "encryption"]

# Composite signatures from draft-ietf-sshm-composite-sigs-01
unstable-mldsa = ["dep:ml-dsa", "ml-dsa/rand_core", "rand_core", "sha2", "signature/rand_core"]
unstable-mldsa-ed25519 = ["unstable-mldsa", "ed25519"]
unstable-mldsa-p384 = ["unstable-mldsa", "p384"]
mldsa = ["dep:ml-dsa", "ml-dsa/rand_core", "rand_core", "sha2", "signature/rand_core"]
mldsa44-ed25519 = ["mldsa", "ed25519"]
mldsa87-p384 = ["mldsa", "p384"]

[lints]
workspace = true
Expand Down
16 changes: 10 additions & 6 deletions ssh-key/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ methods with a type that implements `AssociatedHashAlg`.
| `ssh‑rsa` | ✅ | ✅ | ✅ | ✅️ | ✅️ | ✅ | `rsa` | `alloc` |
| `sk‑ecdsa‑sha2‑nistp256@openssh.com` | ✅ | ✅ | ✅ | ⛔ | ⛔️ | ✅️ | ⛔ | `alloc` |
| `sk‑ssh‑ed25519@openssh.com` | ✅ | ✅ | ✅ | ⛔ | ⛔️ | ✅️️ | `ed25519` | `alloc` |
| `ssh‑mldsa44‑ed25519` | ✅ | ✅ | ✅ | ✅️ | ✅️ | ✅️ | `unstable-mldsa-ed25519` | `no_alloc` |
| `ssh‑mldsa87‑p384` | ✅ | ✅ | ✅ | ✅️ | ✅️ | ✅️ | `unstable-mldsa-p384` | `no_alloc` |
| `ssh-mldsa44-ed25519` | ✅ | ✅ | ✅ | ✅️ | ✅️ | ✅️ | `mldsa44-ed25519` | `no_alloc` |
| `ssh-mldsa87-p384` | ✅ | ✅ | ✅ | ✅️ | ✅️ | ✅️ | `mldsa87-p384` | `no_alloc` |

By default *no SSH signature algorithms are enabled* and you will get an
`Error::AlgorithmUnsupported` error if you try to use them.
Expand All @@ -94,10 +94,12 @@ The "Feature" column lists the name of `ssh-key` crate features which can
be enabled to provide full support for the "Keygen", "Sign", and "Verify"
functionality for a particular SSH key algorithm.

`unstable-mldsa` enables the SSH composite for each enabled curve and requires
at least one of `ed25519` or `p384`. The `unstable-mldsa-ed25519` and
`unstable-mldsa-p384` features enable the corresponding pair. For example,
`crypto` together with `unstable-mldsa` enables both composites.
`mldsa` enables the SSH composite for each enabled curve and requires at least
one of `ed25519` or `p384`. Use `mldsa44-ed25519` or `mldsa87-p384` to select
a pair, or combine `mldsa` with `crypto` to enable both composites.

Both composites are specified in [draft-ietf-sshm-composite-sigs-01].
The Ed25519 variant shipped in [OpenSSH 10.6].

With default features disabled, both composites support key generation, OpenSSH
key encoding and decoding, and signing and verification with `Signature`.
Expand Down Expand Up @@ -136,6 +138,8 @@ dual licensed as above, without any additional terms or conditions.
[//]: # (links)

[RustCrypto]: https://github.com/rustcrypto
[draft-ietf-sshm-composite-sigs-01]: https://datatracker.ietf.org/doc/html/draft-ietf-sshm-composite-sigs-01
[OpenSSH 10.6]: https://www.openssh.org/txt/release-10.6
[RFC4251]: https://datatracker.ietf.org/doc/html/rfc4251
[RFC4253]: https://datatracker.ietf.org/doc/html/rfc4253
[RFC4716]: https://datatracker.ietf.org/doc/html/rfc4716
Expand Down
34 changes: 17 additions & 17 deletions ssh-key/src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ const CERT_SK_ECDSA_SHA2_P256: &str = "sk-ecdsa-sha2-nistp256-cert-v01@openssh.c
const CERT_SK_SSH_ED25519: &str = "sk-ssh-ed25519-cert-v01@openssh.com";

/// OpenSSH certificate for MLDSA44-Ed25519 composite public key
#[cfg(all(feature = "unstable-mldsa", feature = "ed25519"))]
#[cfg(all(feature = "mldsa", feature = "ed25519"))]
const CERT_MLDSA44_ED25519: &str = "ssh-mldsa44-ed25519-cert";

/// SSH certificate for MLDSA87-P384 composite public key
#[cfg(all(feature = "unstable-mldsa", feature = "p384"))]
#[cfg(all(feature = "mldsa", feature = "p384"))]
const CERT_MLDSA87_P384: &str = "ssh-mldsa87-p384-cert";

/// ECDSA with SHA-256 + NIST P-256
Expand Down Expand Up @@ -100,11 +100,11 @@ const SK_ECDSA_SHA2_P256: &str = "sk-ecdsa-sha2-nistp256@openssh.com";
const SK_SSH_ED25519: &str = "sk-ssh-ed25519@openssh.com";

/// MLDSA44-Ed25519-SHA512 composite signature algorithm
#[cfg(all(feature = "unstable-mldsa", feature = "ed25519"))]
#[cfg(all(feature = "mldsa", feature = "ed25519"))]
const SSH_MLDSA44_ED25519: &str = "ssh-mldsa44-ed25519";

/// MLDSA87-P384-SHA512 composite signature algorithm
#[cfg(all(feature = "unstable-mldsa", feature = "p384"))]
#[cfg(all(feature = "mldsa", feature = "p384"))]
const SSH_MLDSA87_P384: &str = "ssh-mldsa87-p384";

/// SSH key algorithms, i.e. digital signature algorithms used with SSH private/public keys.
Expand Down Expand Up @@ -143,11 +143,11 @@ pub enum Algorithm {
SkEd25519,

/// MLDSA44-Ed25519-SHA512 composite signature algorithm.
#[cfg(all(feature = "unstable-mldsa", feature = "ed25519"))]
#[cfg(all(feature = "mldsa", feature = "ed25519"))]
MlDsa44Ed25519,

/// MLDSA87-P384-SHA512 composite signature algorithm.
#[cfg(all(feature = "unstable-mldsa", feature = "p384"))]
#[cfg(all(feature = "mldsa", feature = "p384"))]
MlDsa87P384,

/// Other
Expand Down Expand Up @@ -223,9 +223,9 @@ impl Algorithm {
}),
CERT_SK_ECDSA_SHA2_P256 => Ok(Algorithm::SkEcdsaSha2NistP256),
CERT_SK_SSH_ED25519 => Ok(Algorithm::SkEd25519),
#[cfg(all(feature = "unstable-mldsa", feature = "ed25519"))]
#[cfg(all(feature = "mldsa", feature = "ed25519"))]
CERT_MLDSA44_ED25519 => Ok(Algorithm::MlDsa44Ed25519),
#[cfg(all(feature = "unstable-mldsa", feature = "p384"))]
#[cfg(all(feature = "mldsa", feature = "p384"))]
CERT_MLDSA87_P384 => Ok(Algorithm::MlDsa87P384),
#[cfg(feature = "alloc")]
_ => Ok(Algorithm::Other(AlgorithmName::from_certificate_type(id)?)),
Expand All @@ -252,9 +252,9 @@ impl Algorithm {
},
Algorithm::SkEcdsaSha2NistP256 => SK_ECDSA_SHA2_P256,
Algorithm::SkEd25519 => SK_SSH_ED25519,
#[cfg(all(feature = "unstable-mldsa", feature = "ed25519"))]
#[cfg(all(feature = "mldsa", feature = "ed25519"))]
Algorithm::MlDsa44Ed25519 => SSH_MLDSA44_ED25519,
#[cfg(all(feature = "unstable-mldsa", feature = "p384"))]
#[cfg(all(feature = "mldsa", feature = "p384"))]
Algorithm::MlDsa87P384 => SSH_MLDSA87_P384,
#[cfg(feature = "alloc")]
Algorithm::Other(algorithm) => algorithm.as_str(),
Expand Down Expand Up @@ -288,9 +288,9 @@ impl Algorithm {
} => CERT_RSA_SHA2_512,
Algorithm::SkEcdsaSha2NistP256 => CERT_SK_ECDSA_SHA2_P256,
Algorithm::SkEd25519 => CERT_SK_SSH_ED25519,
#[cfg(all(feature = "unstable-mldsa", feature = "ed25519"))]
#[cfg(all(feature = "mldsa", feature = "ed25519"))]
Algorithm::MlDsa44Ed25519 => CERT_MLDSA44_ED25519,
#[cfg(all(feature = "unstable-mldsa", feature = "p384"))]
#[cfg(all(feature = "mldsa", feature = "p384"))]
Algorithm::MlDsa87P384 => CERT_MLDSA87_P384,
Algorithm::Other(algorithm) => return algorithm.certificate_type(),
}
Expand Down Expand Up @@ -322,14 +322,14 @@ impl Algorithm {
}

/// Is the algorithm the MLDSA44-Ed25519 composite scheme?
#[cfg(all(feature = "unstable-mldsa", feature = "ed25519"))]
#[cfg(all(feature = "mldsa", feature = "ed25519"))]
#[must_use]
pub fn is_mldsa44_ed25519(self) -> bool {
matches!(self, Algorithm::MlDsa44Ed25519)
}

/// Is the algorithm the MLDSA87-P384 composite scheme?
#[cfg(all(feature = "unstable-mldsa", feature = "p384"))]
#[cfg(all(feature = "mldsa", feature = "p384"))]
#[must_use]
pub fn is_mldsa87_p384(self) -> bool {
matches!(self, Algorithm::MlDsa87P384)
Expand Down Expand Up @@ -381,9 +381,9 @@ impl str::FromStr for Algorithm {
SSH_RSA => Ok(Algorithm::Rsa { hash: None }),
SK_ECDSA_SHA2_P256 => Ok(Algorithm::SkEcdsaSha2NistP256),
SK_SSH_ED25519 => Ok(Algorithm::SkEd25519),
#[cfg(all(feature = "unstable-mldsa", feature = "ed25519"))]
#[cfg(all(feature = "mldsa", feature = "ed25519"))]
SSH_MLDSA44_ED25519 => Ok(Algorithm::MlDsa44Ed25519),
#[cfg(all(feature = "unstable-mldsa", feature = "p384"))]
#[cfg(all(feature = "mldsa", feature = "p384"))]
SSH_MLDSA87_P384 => Ok(Algorithm::MlDsa87P384),
#[cfg(feature = "alloc")]
_ => Ok(Algorithm::Other(AlgorithmName::from_str(id)?)),
Expand Down Expand Up @@ -432,7 +432,7 @@ impl EcdsaCurve {
}

/// Get the number of bytes needed to encode a field element for this curve.
#[cfg(any(feature = "alloc", feature = "unstable-mldsa"))]
#[cfg(any(feature = "alloc", feature = "mldsa"))]
pub(crate) const fn field_size(self) -> usize {
match self {
EcdsaCurve::NistP256 => 32,
Expand Down
2 changes: 1 addition & 1 deletion ssh-key/src/composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
//! [draft-ietf-sshm-composite-sigs]: https://www.ietf.org/archive/id/draft-ietf-sshm-composite-sigs-01.html
#[cfg(not(any(feature = "ed25519", feature = "p384")))]
compile_error!("the `unstable-mldsa` feature requires `ed25519` or `p384`");
compile_error!("the `mldsa` feature requires `ed25519` or `p384`");

#[cfg(feature = "ed25519")]
mod mldsa44_ed25519;
Expand Down
6 changes: 3 additions & 3 deletions ssh-key/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ mod kdf;

#[cfg(feature = "alloc")]
mod comment;
#[cfg(feature = "unstable-mldsa")]
#[cfg(feature = "mldsa")]
mod composite;
#[cfg(feature = "std")]
mod dot_ssh;
#[cfg(feature = "ppk")]
mod ppk;
#[cfg(any(feature = "alloc", feature = "unstable-mldsa"))]
#[cfg(any(feature = "alloc", feature = "mldsa"))]
mod signature;
#[cfg(feature = "alloc")]
mod sshsig;
Expand All @@ -162,7 +162,7 @@ pub use encoding::{self, pem::LineEnding};

#[cfg(feature = "std")]
pub use crate::dot_ssh::DotSsh;
#[cfg(any(feature = "alloc", feature = "unstable-mldsa"))]
#[cfg(any(feature = "alloc", feature = "mldsa"))]
pub use crate::signature::{Signature, SigningKey};
#[cfg(feature = "getrandom")]
pub use cipher::cipher::common::getrandom;
Expand Down
12 changes: 6 additions & 6 deletions ssh-key/src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ pub use crate::{
},
};

#[cfg(all(feature = "unstable-mldsa", feature = "ed25519"))]
#[cfg(all(feature = "mldsa", feature = "ed25519"))]
pub use crate::composite::{MlDsa44Ed25519Keypair, MlDsa44Ed25519PrivateKey};
#[cfg(all(feature = "unstable-mldsa", feature = "p384"))]
#[cfg(all(feature = "mldsa", feature = "p384"))]
pub use crate::composite::{MlDsa87P384Keypair, MlDsa87P384PrivateKey};

#[cfg(feature = "ecdsa")]
Expand Down Expand Up @@ -634,9 +634,9 @@ impl PrivateKey {
Algorithm::Rsa { .. } => {
KeypairData::from(RsaKeypair::random(rng, DEFAULT_RSA_KEY_SIZE)?)
}
#[cfg(all(feature = "unstable-mldsa", feature = "ed25519"))]
#[cfg(all(feature = "mldsa", feature = "ed25519"))]
Algorithm::MlDsa44Ed25519 => KeypairData::from(MlDsa44Ed25519Keypair::random(rng)?),
#[cfg(all(feature = "unstable-mldsa", feature = "p384"))]
#[cfg(all(feature = "mldsa", feature = "p384"))]
Algorithm::MlDsa87P384 => KeypairData::from(MlDsa87P384Keypair::random(rng)),
_ => return Err(Error::AlgorithmUnknown),
};
Expand Down Expand Up @@ -1018,7 +1018,7 @@ impl From<RsaKeypair> for PrivateKey {
}
}

#[cfg(all(feature = "unstable-mldsa", feature = "ed25519"))]
#[cfg(all(feature = "mldsa", feature = "ed25519"))]
impl From<MlDsa44Ed25519Keypair> for PrivateKey {
fn from(keypair: MlDsa44Ed25519Keypair) -> PrivateKey {
KeypairData::from(keypair)
Expand All @@ -1027,7 +1027,7 @@ impl From<MlDsa44Ed25519Keypair> for PrivateKey {
}
}

#[cfg(all(feature = "unstable-mldsa", feature = "p384"))]
#[cfg(all(feature = "mldsa", feature = "p384"))]
impl From<MlDsa87P384Keypair> for PrivateKey {
fn from(keypair: MlDsa87P384Keypair) -> PrivateKey {
KeypairData::from(keypair)
Expand Down
Loading