Skip to content

Commit e2f58ed

Browse files
committed
added ECDSA secp256k1 signing
1 parent 26aad71 commit e2f58ed

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ pki-types = { package = "rustls-pki-types", version = "1.4.1" }
2323
ring = "0.17"
2424
rustls-webpki = { version = "0.103", features = ["ring", "std"] }
2525
time = { version = "0.3.6", default-features = false }
26-
x509-parser = "0.18"
26+
x509-parser = { version = "0.18", features = ["verify"] }
2727
yasna = { version = "0.5.2", features = ["time", "std"] }
2828
zeroize = { version = "1.2" }

rcgen/src/key_pair.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,13 @@ impl KeyPair {
264264
KeyPairKind::Rsa(rsakp, &signature::RSA_PSS_SHA256)
265265
} else {
266266
#[cfg(feature = "aws_lc_rs")]
267-
if alg == &PKCS_ECDSA_P521_SHA512 {
267+
if alg == &PKCS_ECDSA_P256K1_SHA256 {
268+
KeyPairKind::Ec(ecdsa_from_pkcs8(
269+
&signature::ECDSA_P256K1_SHA256_ASN1_SIGNING,
270+
&serialized_der,
271+
rng,
272+
)?)
273+
} else if alg == &PKCS_ECDSA_P521_SHA512 {
268274
KeyPairKind::Ec(ecdsa_from_pkcs8(
269275
&signature::ECDSA_P521_SHA512_ASN1_SIGNING,
270276
&serialized_der,
@@ -784,6 +790,8 @@ mod test {
784790
for alg in [
785791
&PKCS_ED25519,
786792
&PKCS_ECDSA_P256_SHA256,
793+
#[cfg(feature = "aws_lc_rs")]
794+
&PKCS_ECDSA_P256K1_SHA256,
787795
&PKCS_ECDSA_P384_SHA384,
788796
#[cfg(feature = "aws_lc_rs")]
789797
&PKCS_ECDSA_P521_SHA512,

rcgen/src/oid.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ pub(crate) const COMMON_NAME: &[u64] = &[2, 5, 4, 3];
1616

1717
/// id-ecPublicKey in [RFC 5480](https://datatracker.ietf.org/doc/html/rfc5480#appendix-A)
1818
pub(crate) const EC_PUBLIC_KEY: &[u64] = &[1, 2, 840, 10045, 2, 1];
19+
/// secp256k1 in [SEC 2, Appendix A.2.1](https://www.secg.org/sec2-v2.pdf)
20+
/// Currently this is only supported with the `aws_lc_rs` feature
21+
#[cfg(feature = "aws_lc_rs")]
22+
pub(crate) const EC_SECP_256_K1: &[u64] = &[1, 3, 132, 0, 10];
1923
/// secp256r1 in [RFC 5480](https://datatracker.ietf.org/doc/html/rfc5480#appendix-A)
2024
pub(crate) const EC_SECP_256_R1: &[u64] = &[1, 2, 840, 10045, 3, 1, 7];
2125
/// secp384r1 in [RFC 5480](https://datatracker.ietf.org/doc/html/rfc5480#appendix-A)

rcgen/src/sign_algo.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ impl fmt::Debug for SignatureAlgorithm {
6464
write!(f, "PKCS_ED25519")
6565
} else {
6666
#[cfg(feature = "aws_lc_rs")]
67-
if self == &PKCS_ECDSA_P521_SHA512 {
67+
if self == &PKCS_ECDSA_P256K1_SHA256 {
68+
return write!(f, "PKCS_ECDSA_P256K1_SHA256");
69+
} else if self == &PKCS_ECDSA_P521_SHA512 {
6870
return write!(f, "PKCS_ECDSA_P521_SHA512");
6971
}
7072

@@ -97,6 +99,8 @@ impl SignatureAlgorithm {
9799
&PKCS_RSA_SHA512,
98100
//&PKCS_RSA_PSS_SHA256,
99101
&PKCS_ECDSA_P256_SHA256,
102+
#[cfg(feature = "aws_lc_rs")]
103+
&PKCS_ECDSA_P256K1_SHA256,
100104
&PKCS_ECDSA_P384_SHA384,
101105
#[cfg(feature = "aws_lc_rs")]
102106
&PKCS_ECDSA_P521_SHA512,
@@ -172,7 +176,19 @@ pub(crate) mod algo {
172176
},
173177
};
174178

175-
/// ECDSA signing using the P-256 curves and SHA-256 hashing as per [RFC 5758](https://tools.ietf.org/html/rfc5758#section-3.2)
179+
/// ECDSA signing using the K-256 curves and SHA-256 hashing as per [SEC 2, Section 2.4.1](https://www.secg.org/sec2-v2.pdf)
180+
/// Currently this is only supported with the `aws_lc_rs` feature
181+
#[cfg(feature = "aws_lc_rs")]
182+
pub static PKCS_ECDSA_P256K1_SHA256: SignatureAlgorithm = SignatureAlgorithm {
183+
oids_sign_alg: &[&EC_PUBLIC_KEY, &EC_SECP_256_K1],
184+
#[cfg(feature = "crypto")]
185+
sign_alg: SignAlgo::EcDsa(&signature::ECDSA_P256K1_SHA256_ASN1_SIGNING),
186+
// ecdsa-with-SHA256 in RFC 5758
187+
oid_components: &[1, 2, 840, 10045, 4, 3, 2],
188+
params: SignatureAlgorithmParams::None,
189+
};
190+
191+
/// ECDSA signing using the P-256 curves with verifiably random parameters and SHA-256 hashing as per [RFC 5758](https://tools.ietf.org/html/rfc5758#section-3.2)
176192
pub static PKCS_ECDSA_P256_SHA256: SignatureAlgorithm = SignatureAlgorithm {
177193
oids_sign_alg: &[EC_PUBLIC_KEY, EC_SECP_256_R1],
178194
#[cfg(feature = "crypto")]

0 commit comments

Comments
 (0)