zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit bbbc4ebf0375387763079a2dfdd3f4b0c9184078 (tree)
parent 4133bbd67e1e694ffbeb9972c9b9414cb961ce39
Author: Mateusz Poliwczak <mpoliwczak34@gmail.com>
Date:   Sun, 22 Jan 2023 17:45:44 +0100

support P256 in x509

Diffstat:
Mlib/std/crypto/Certificate.zig | 18++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)

diff --git 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; - }, } }