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 {...@@ -95,6 +95,14 @@ pub const NamedCurve = enum {
95 .{ &[_]u8{ 0x2B, 0x81, 0x04, 0x00, 0x23 }, .secp521r1 },95 .{ &[_]u8{ 0x2B, 0x81, 0x04, 0x00, 0x23 }, .secp521r1 },
96 .{ &[_]u8{ 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07 }, .X9_62_prime256v1 },96 .{ &[_]u8{ 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07 }, .X9_62_prime256v1 },
97 });97 });
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 }
98};106};
99107
100pub const ExtensionId = enum {108pub const ExtensionId = enum {
...@@ -783,9 +791,10 @@ fn verify_ecdsa(...@@ -783,9 +791,10 @@ fn verify_ecdsa(
783 .secp521r1 => {791 .secp521r1 => {
784 return error.CertificateSignatureNamedCurveUnsupported;792 return error.CertificateSignatureNamedCurveUnsupported;
785 },793 },
786 .secp384r1 => {794 inline .X9_62_prime256v1,
787 const P = crypto.ecc.P384;795 .secp384r1,
788 const Ecdsa = crypto.sign.ecdsa.Ecdsa(P, Hash);796 => |curve| {
797 const Ecdsa = crypto.sign.ecdsa.Ecdsa(curve.Curve(), Hash);
789 const sig = Ecdsa.Signature.fromDer(encoded_sig) catch |err| switch (err) {798 const sig = Ecdsa.Signature.fromDer(encoded_sig) catch |err| switch (err) {
790 error.InvalidEncoding => return error.CertificateSignatureInvalid,799 error.InvalidEncoding => return error.CertificateSignatureInvalid,
791 };800 };
...@@ -800,9 +809,6 @@ fn verify_ecdsa(...@@ -800,9 +809,6 @@ fn verify_ecdsa(
800 error.SignatureVerificationFailed => return error.CertificateSignatureInvalid,809 error.SignatureVerificationFailed => return error.CertificateSignatureInvalid,
801 };810 };
802 },811 },
803 .X9_62_prime256v1 => {
804 return error.CertificateSignatureNamedCurveUnsupported;
805 },
806 }812 }
807}813}
808814