Skip to content

Commit a5d5a33

Browse files
AlvenixAbdullah Alyan
authored andcommitted
Support ECDSA_P521_SHA512 when using aes_lc_rs feature
1 parent f1f89ae commit a5d5a33

File tree

6 files changed

+75
-3
lines changed

6 files changed

+75
-3
lines changed

rcgen/src/key_pair.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,18 @@ impl KeyPair {
243243
let rsakp = RsaKeyPair::from_pkcs8(pkcs8)._err()?;
244244
KeyPairKind::Rsa(rsakp, &signature::RSA_PSS_SHA256)
245245
} else {
246+
#[cfg(all(feature = "aws_lc_rs", not(feature = "ring")))]
247+
if alg == &PKCS_ECDSA_P521_SHA512 {
248+
KeyPairKind::Ec(ecdsa_from_pkcs8(
249+
&signature::ECDSA_P521_SHA512_ASN1_SIGNING,
250+
pkcs8,
251+
rng,
252+
)?)
253+
} else {
254+
panic!("Unknown SignatureAlgorithm specified!");
255+
}
256+
257+
#[cfg(not(all(feature = "aws_lc_rs", not(feature = "ring"))))]
246258
panic!("Unknown SignatureAlgorithm specified!");
247259
};
248260

@@ -274,7 +286,19 @@ impl KeyPair {
274286
&PKCS_RSA_SHA256,
275287
)
276288
} else {
277-
return Err(Error::CouldNotParseKeyPair);
289+
#[cfg(all(feature = "aws_lc_rs", not(feature = "ring")))]
290+
if let Ok(eckp) =
291+
ecdsa_from_pkcs8(&signature::ECDSA_P521_SHA512_ASN1_SIGNING, pkcs8, &rng)
292+
{
293+
(KeyPairKind::Ec(eckp), &PKCS_ECDSA_P521_SHA512)
294+
} else {
295+
return Err(Error::CouldNotParseKeyPair);
296+
}
297+
298+
#[cfg(not(all(feature = "aws_lc_rs", not(feature = "ring"))))]
299+
{
300+
return Err(Error::CouldNotParseKeyPair);
301+
}
278302
};
279303
Ok((kind, alg))
280304
}

rcgen/src/oid.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ pub(crate) const EC_PUBLIC_KEY: &[u64] = &[1, 2, 840, 10045, 2, 1];
2020
pub(crate) const EC_SECP_256_R1: &[u64] = &[1, 2, 840, 10045, 3, 1, 7];
2121
/// secp384r1 in [RFC 5480](https://datatracker.ietf.org/doc/html/rfc5480#appendix-A)
2222
pub(crate) const EC_SECP_384_R1: &[u64] = &[1, 3, 132, 0, 34];
23+
/// secp521r1 in [RFC 5480](https://datatracker.ietf.org/doc/html/rfc5480#appendix-A)
24+
/// Currently this is only supported when using aws_lc_rs feature
25+
#[cfg(all(feature = "aws_lc_rs", not(feature = "ring")))]
26+
pub(crate) const EC_SECP_521_R1: &[u64] = &[1, 3, 132, 0, 35];
2327

2428
/// rsaEncryption in [RFC 4055](https://www.rfc-editor.org/rfc/rfc4055#section-6)
2529
pub(crate) const RSA_ENCRYPTION: &[u64] = &[1, 2, 840, 113549, 1, 1, 1];

rcgen/src/sign_algo.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ impl fmt::Debug for SignatureAlgorithm {
5555
} else if self == &PKCS_ED25519 {
5656
write!(f, "PKCS_ED25519")
5757
} else {
58+
#[cfg(all(feature = "aws_lc_rs", not(feature = "ring")))]
59+
if self == &PKCS_ECDSA_P521_SHA512 {
60+
write!(f, "PKCS_ECDSA_P521_SHA512")
61+
} else {
62+
write!(f, "Unknown")
63+
}
64+
65+
#[cfg(not(all(feature = "aws_lc_rs", not(feature = "ring"))))]
5866
write!(f, "Unknown")
5967
}
6068
}
@@ -85,6 +93,8 @@ impl SignatureAlgorithm {
8593
//&PKCS_RSA_PSS_SHA256,
8694
&PKCS_ECDSA_P256_SHA256,
8795
&PKCS_ECDSA_P384_SHA384,
96+
#[cfg(all(feature = "aws_lc_rs", not(feature = "ring")))]
97+
&PKCS_ECDSA_P521_SHA512,
8898
&PKCS_ED25519,
8999
];
90100
ALGORITHMS.iter()
@@ -177,8 +187,17 @@ pub(crate) mod algo {
177187
oid_components: &[1, 2, 840, 10045, 4, 3, 3],
178188
params: SignatureAlgorithmParams::None,
179189
};
180-
181-
// TODO PKCS_ECDSA_P521_SHA512 https://github.com/briansmith/ring/issues/824
190+
/// ECDSA signing using the P-521 curves and SHA-512 hashing as per [RFC 5758](https://tools.ietf.org/html/rfc5758#section-3.2)
191+
/// Currently this is only supported when using aws_lc_rs feature
192+
#[cfg(all(feature = "aws_lc_rs", not(feature = "ring")))]
193+
pub static PKCS_ECDSA_P521_SHA512: SignatureAlgorithm = SignatureAlgorithm {
194+
oids_sign_alg: &[&EC_PUBLIC_KEY, &EC_SECP_521_R1],
195+
#[cfg(feature = "crypto")]
196+
sign_alg: SignAlgo::EcDsa(&signature::ECDSA_P521_SHA512_ASN1_SIGNING),
197+
// ecdsa-with-SHA512 in RFC 5758
198+
oid_components: &[1, 2, 840, 10045, 4, 3, 4],
199+
params: SignatureAlgorithmParams::None,
200+
};
182201

183202
/// ED25519 curve signing as per [RFC 8410](https://tools.ietf.org/html/rfc8410)
184203
pub static PKCS_ED25519: SignatureAlgorithm = SignatureAlgorithm {

rcgen/tests/botan.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ fn test_botan_384() {
7676
check_cert(cert.der(), &cert);
7777
}
7878

79+
#[test]
80+
#[cfg(all(feature = "aws_lc_rs", not(feature = "ring")))]
81+
fn test_botan_521() {
82+
let (params, _) = default_params();
83+
let key_pair = KeyPair::generate_for(&rcgen::PKCS_ECDSA_P521_SHA512).unwrap();
84+
let cert = Certificate::generate_self_signed(params, &key_pair).unwrap();
85+
86+
// Now verify the certificate.
87+
check_cert(cert.der(), &cert);
88+
}
89+
7990
#[test]
8091
fn test_botan_25519() {
8192
let (params, _) = default_params();

rcgen/tests/generic.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ mod test_key_params_mismatch {
1919
&rcgen::PKCS_RSA_SHA256,
2020
&rcgen::PKCS_ECDSA_P256_SHA256,
2121
&rcgen::PKCS_ECDSA_P384_SHA384,
22+
#[cfg(all(feature = "aws_lc_rs", not(feature = "ring")))]
23+
&rcgen::PKCS_ECDSA_P521_SHA512,
2224
&rcgen::PKCS_ED25519,
2325
];
2426
for (i, kalg_1) in available_key_params.iter().enumerate() {

rcgen/tests/openssl.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,18 @@ fn test_openssl_384() {
206206
verify_csr(&cert, &key_pair);
207207
}
208208

209+
#[test]
210+
#[cfg(all(feature = "aws_lc_rs", not(feature = "ring")))]
211+
fn test_openssl_521() {
212+
let (params, _) = util::default_params();
213+
let key_pair = KeyPair::generate_for(&rcgen::PKCS_ECDSA_P521_SHA512).unwrap();
214+
let cert = Certificate::generate_self_signed(params, &key_pair).unwrap();
215+
216+
// Now verify the certificate.
217+
verify_cert(&cert, &key_pair);
218+
verify_csr(&cert, &key_pair);
219+
}
220+
209221
#[test]
210222
fn test_openssl_25519() {
211223
let (params, _) = util::default_params();

0 commit comments

Comments
 (0)