aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateusz Poliwczak <mpoliwczak34@gmail.com>2023-01-22 17:45:44 +0100
committerAndrew Kelley <andrew@ziglang.org>2023-01-22 17:24:45 -0500
commitbbbc4ebf0375387763079a2dfdd3f4b0c9184078 (patch)
treee2addc25e3493ba5b67920ec189b206a5d5251f9
parent4133bbd67e1e694ffbeb9972c9b9414cb961ce39 (diff)
downloadzig-bbbc4ebf0375387763079a2dfdd3f4b0c9184078.tar.gz
zig-bbbc4ebf0375387763079a2dfdd3f4b0c9184078.zip
support P256 in x509
-rw-r--r--lib/std/crypto/Certificate.zig18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/std/crypto/Certificate.zig b/lib/std/crypto/Certificate.zig
index bdf4c6ecf0..3b491fa32e 100644
--- a/lib/std/crypto/Certificate.zig
+++ b/lib/std/crypto/Certificate.zig
@@ -95,6 +95,14 @@ pub const NamedCurve = enum {
.{ &[_]u8{ 0x2B, 0x81, 0x04, 0x00, 0x23 }, .secp521r1 },
.{ &[_]u8{ 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07 }, .X9_62_prime256v1 },
});
+
+ pub fn Curve(comptime curve: NamedCurve) type {
+ return switch (curve) {
+ .X9_62_prime256v1 => crypto.ecc.P256,
+ .secp384r1 => crypto.ecc.P384,
+ .secp521r1 => @compileError("unimplemented"),
+ };
+ }
};
pub const ExtensionId = enum {
@@ -783,9 +791,10 @@ fn verify_ecdsa(
.secp521r1 => {
return error.CertificateSignatureNamedCurveUnsupported;
},
- .secp384r1 => {
- const P = crypto.ecc.P384;
- const Ecdsa = crypto.sign.ecdsa.Ecdsa(P, Hash);
+ inline .X9_62_prime256v1,
+ .secp384r1,
+ => |curve| {
+ const Ecdsa = crypto.sign.ecdsa.Ecdsa(curve.Curve(), Hash);
const sig = Ecdsa.Signature.fromDer(encoded_sig) catch |err| switch (err) {
error.InvalidEncoding => return error.CertificateSignatureInvalid,
};
@@ -800,9 +809,6 @@ fn verify_ecdsa(
error.SignatureVerificationFailed => return error.CertificateSignatureInvalid,
};
},
- .X9_62_prime256v1 => {
- return error.CertificateSignatureNamedCurveUnsupported;
- },
}
}