From 7f20c78c95d54e7fb0958693a9df2dee40dd99d6 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Fri, 1 Nov 2024 16:29:35 -0400 Subject: [PATCH] std.crypto: delete new functions that are only used once --- lib/std/crypto/25519/ed25519.zig | 11 ++--------- lib/std/crypto/ecdsa.zig | 11 ++--------- lib/std/crypto/tls/Client.zig | 8 ++++++-- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/lib/std/crypto/25519/ed25519.zig b/lib/std/crypto/25519/ed25519.zig index 3620cfc4ba..3e5fb8bb3c 100644 --- a/lib/std/crypto/25519/ed25519.zig +++ b/lib/std/crypto/25519/ed25519.zig @@ -229,15 +229,8 @@ pub const Ed25519 = struct { /// Return IdentityElement or NonCanonical if the public key or signature are not in the expected range, /// or SignatureVerificationError if the signature is invalid for the given message and key. pub fn verify(sig: Signature, msg: []const u8, public_key: PublicKey) VerifyError!void { - try sig.concatVerify(&.{msg}, public_key); - } - - /// Verify the signature against a concatenated message and public key. - /// Return IdentityElement or NonCanonical if the public key or signature are not in the expected range, - /// or SignatureVerificationError if the signature is invalid for the given message and key. - pub fn concatVerify(sig: Signature, msg: []const []const u8, public_key: PublicKey) VerifyError!void { - var st = try Verifier.init(sig, public_key); - for (msg) |part| st.update(part); + var st = try sig.verifier(public_key); + st.update(msg); try st.verify(); } }; diff --git a/lib/std/crypto/ecdsa.zig b/lib/std/crypto/ecdsa.zig index a015178f3d..649c967218 100644 --- a/lib/std/crypto/ecdsa.zig +++ b/lib/std/crypto/ecdsa.zig @@ -101,15 +101,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { /// Return IdentityElement or NonCanonical if the public key or signature are not in the expected range, /// or SignatureVerificationError if the signature is invalid for the given message and key. pub fn verify(sig: Signature, msg: []const u8, public_key: PublicKey) VerifyError!void { - try sig.concatVerify(&.{msg}, public_key); - } - - /// Verify the signature against a concatenated message and public key. - /// Return IdentityElement or NonCanonical if the public key or signature are not in the expected range, - /// or SignatureVerificationError if the signature is invalid for the given message and key. - pub fn concatVerify(sig: Signature, msg: []const []const u8, public_key: PublicKey) VerifyError!void { - var st = try Verifier.init(sig, public_key); - for (msg) |part| st.update(part); + var st = try sig.verifier(public_key); + st.update(msg); try st.verify(); } diff --git a/lib/std/crypto/tls/Client.zig b/lib/std/crypto/tls/Client.zig index dc15c7d813..5b1d0a9bf6 100644 --- a/lib/std/crypto/tls/Client.zig +++ b/lib/std/crypto/tls/Client.zig @@ -1735,7 +1735,9 @@ const CertificatePublicKey = struct { const Ecdsa = SchemeEcdsa(comptime_scheme); const sig = try Ecdsa.Signature.fromDer(encoded_sig); const key = try Ecdsa.PublicKey.fromSec1(pub_key); - try sig.concatVerify(msg, key); + var ver = try sig.verifier(key); + for (msg) |part| ver.update(part); + try ver.verify(); }, inline .rsa_pkcs1_sha256, .rsa_pkcs1_sha384, @@ -1769,7 +1771,9 @@ const CertificatePublicKey = struct { const sig = Eddsa.Signature.fromBytes(encoded_sig[0..Eddsa.Signature.encoded_length].*); if (pub_key.len != Eddsa.PublicKey.encoded_length) return error.InvalidEncoding; const key = try Eddsa.PublicKey.fromBytes(pub_key[0..Eddsa.PublicKey.encoded_length].*); - try sig.concatVerify(msg, key); + var ver = try sig.verifier(key); + for (msg) |part| ver.update(part); + try ver.verify(); }, else => unreachable, }