authorgravatar for mpoliwczak34@gmail.comMateusz Poliwczak <mpoliwczak34@gmail.com> 2023-01-22 17:45:44+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-22 17:24:45-05:00
logbbbc4ebf0375387763079a2dfdd3f4b0c9184078
treee2addc25e3493ba5b67920ec189b206a5d5251f9
parent4133bbd67e1e694ffbeb9972c9b9414cb961ce39

support P256 in x509


1 files changed, 12 insertions(+), 6 deletions(-)

lib/std/crypto/Certificate.zig+12-6
......@@ -95,6 +95,14 @@ pub const NamedCurve = enum {
9595 .{ &[_]u8{ 0x2B, 0x81, 0x04, 0x00, 0x23 }, .secp521r1 },
9696 .{ &[_]u8{ 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07 }, .X9_62_prime256v1 },
9797 });
98
99 pub fn Curve(comptime curve: NamedCurve) type {
100 return switch (curve) {
101 .X9_62_prime256v1 => crypto.ecc.P256,
102 .secp384r1 => crypto.ecc.P384,
103 .secp521r1 => @compileError("unimplemented"),
104 };
105 }
98106};
99107
100108pub const ExtensionId = enum {
......@@ -783,9 +791,10 @@ fn verify_ecdsa(
783791 .secp521r1 => {
784792 return error.CertificateSignatureNamedCurveUnsupported;
785793 },
786 .secp384r1 => {
787 const P = crypto.ecc.P384;
788 const Ecdsa = crypto.sign.ecdsa.Ecdsa(P, Hash);
794 inline .X9_62_prime256v1,
795 .secp384r1,
796 => |curve| {
797 const Ecdsa = crypto.sign.ecdsa.Ecdsa(curve.Curve(), Hash);
789798 const sig = Ecdsa.Signature.fromDer(encoded_sig) catch |err| switch (err) {
790799 error.InvalidEncoding => return error.CertificateSignatureInvalid,
791800 };
......@@ -800,9 +809,6 @@ fn verify_ecdsa(
800809 error.SignatureVerificationFailed => return error.CertificateSignatureInvalid,
801810 };
802811 },
803 .X9_62_prime256v1 => {
804 return error.CertificateSignatureNamedCurveUnsupported;
805 },
806812 }
807813}
808814