Skip to content

Commit 3644224

Browse files
committed
openpgp: Add CipherSuite::MLDSA65 and CipherSuite::MLDSA87.
1 parent 64009b7 commit 3644224

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

openpgp/src/cert/builder.rs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ pub enum CipherSuite {
8080
/// 4096 bit RSA with SHA512 and AES256
8181
RSA4k,
8282

83+
/// Composite signature algorithm MLDSA65+Ed25519, and composite
84+
/// KEM MLKEM768+X25519.
85+
MLDSA65,
86+
87+
/// Composite signature algorithm MLDSA78+Ed448, and composite
88+
/// KEM MLKEM1024+X448.
89+
MLDSA87,
90+
8391
// If you add a variant here, be sure to update
8492
// CipherSuite::variants below.
8593
}
@@ -96,7 +104,7 @@ impl CipherSuite {
96104
pub fn variants() -> impl Iterator<Item=CipherSuite> {
97105
use CipherSuite::*;
98106

99-
[ Cv25519, RSA3k, P256, P384, P521, RSA2k, RSA4k ]
107+
[ Cv25519, RSA3k, P256, P384, P521, RSA2k, RSA4k, MLDSA65, MLDSA87 ]
100108
.into_iter()
101109
}
102110

@@ -150,6 +158,10 @@ impl CipherSuite {
150158
check_curve!(Curve::NistP521);
151159
check_pk!(PublicKeyAlgorithm::ECDH);
152160
},
161+
MLDSA65 =>
162+
check_pk!(PublicKeyAlgorithm::MLDSA65_Ed25519),
163+
MLDSA87 =>
164+
check_pk!(PublicKeyAlgorithm::MLDSA87_Ed448),
153165
}
154166
Ok(())
155167
}
@@ -211,6 +223,11 @@ impl CipherSuite {
211223
.into()),
212224
}
213225
},
226+
227+
CipherSuite::MLDSA65 | CipherSuite::MLDSA87 =>
228+
Err(Error::InvalidOperation(
229+
"can't use algorithms for v4 keys".into())
230+
.into()),
214231
}
215232
}
216233

@@ -273,6 +290,28 @@ impl CipherSuite {
273290
.into()),
274291
}
275292
},
293+
294+
a @ CipherSuite::MLDSA65 | a @ CipherSuite::MLDSA87 =>
295+
match (sign, encrypt, a) {
296+
(true, false, CipherSuite::MLDSA65) =>
297+
Key6::generate_mldsa65_ed25519(),
298+
(true, false, CipherSuite::MLDSA87) =>
299+
Key6::generate_mldsa87_ed448(),
300+
(true, false, _) => unreachable!(),
301+
(false, true, CipherSuite::MLDSA65) =>
302+
Key6::generate_mlkem768_x25519(),
303+
(false, true, CipherSuite::MLDSA87) =>
304+
Key6::generate_mlkem1024_x448(),
305+
(false, true, _) => unreachable!(),
306+
(true, true, _) =>
307+
Err(Error::InvalidOperation(
308+
"Can't use key for encryption and signing".into())
309+
.into()),
310+
(false, false, _) =>
311+
Err(Error::InvalidOperation(
312+
"No key flags set".into())
313+
.into()),
314+
},
276315
}
277316
}
278317
}
@@ -1936,9 +1975,12 @@ mod tests {
19361975
for cs in CipherSuite::variants()
19371976
.into_iter().filter(|cs| cs.is_supported().is_ok())
19381977
{
1939-
assert!(CertBuilder::new()
1978+
CertBuilder::new()
1979+
.set_profile(crate::Profile::RFC9580).unwrap()
19401980
.set_cipher_suite(cs)
1941-
.generate().is_ok());
1981+
.add_transport_encryption_subkey()
1982+
.generate()
1983+
.unwrap();
19421984
}
19431985
}
19441986

0 commit comments

Comments
 (0)