Skip to content

Commit

Permalink
support P256 in x509
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz834 authored and andrewrk committed Jan 22, 2023
1 parent 4133bbd commit bbbc4eb
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/std/crypto/Certificate.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
};
Expand All @@ -800,9 +809,6 @@ fn verify_ecdsa(
error.SignatureVerificationFailed => return error.CertificateSignatureInvalid,
};
},
.X9_62_prime256v1 => {
return error.CertificateSignatureNamedCurveUnsupported;
},
}
}

Expand Down

0 comments on commit bbbc4eb

Please sign in to comment.