authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-07-14 11:03:11-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-08-05 03:24:56+02:00
logfa515299f3b9bd9fc7aad4ad04dd862b1c925075
treefc4d0819ae2a915333f38f26951c32c4b95ef412
parentb18436dfad20428e661197a71f4dc12143f4dac0

std.crypto.Certificate.rsa.encrypt: accept modulus by pointer

the expected sizes for modulus_len are 128, 256, 384, 512

2 files changed, 7 insertions(+), 7 deletions(-)

lib/std/crypto/Certificate.zig+6-6
......@@ -849,7 +849,7 @@ fn verifyRsa(
849849 inline 128, 256, 384, 512 => |modulus_len| {
850850 const public_key = rsa.PublicKey.fromBytes(exponent, modulus) catch
851851 return error.CertificateSignatureInvalid;
852 rsa.PKCS1v1_5Signature.verify(modulus_len, sig[0..modulus_len].*, msg, public_key, Hash) catch
852 rsa.PKCS1v1_5Signature.verify(modulus_len, sig[0..modulus_len], msg, public_key, Hash) catch
853853 return error.CertificateSignatureInvalid;
854854 },
855855 else => return error.CertificateSignatureUnsupportedBitCount,
......@@ -1039,7 +1039,7 @@ pub const rsa = struct {
10391039
10401040 pub fn concatVerify(
10411041 comptime modulus_len: usize,
1042 sig: [modulus_len]u8,
1042 sig: *const [modulus_len]u8,
10431043 msg: []const []const u8,
10441044 public_key: PublicKey,
10451045 comptime Hash: type,
......@@ -1192,7 +1192,7 @@ pub const rsa = struct {
11921192
11931193 pub fn verify(
11941194 comptime modulus_len: usize,
1195 sig: [modulus_len]u8,
1195 sig: *const [modulus_len]u8,
11961196 msg: []const u8,
11971197 public_key: PublicKey,
11981198 comptime Hash: type,
......@@ -1202,7 +1202,7 @@ pub const rsa = struct {
12021202
12031203 pub fn concatVerify(
12041204 comptime modulus_len: usize,
1205 sig: [modulus_len]u8,
1205 sig: *const [modulus_len]u8,
12061206 msg: []const []const u8,
12071207 public_key: PublicKey,
12081208 comptime Hash: type,
......@@ -1348,8 +1348,8 @@ pub const rsa = struct {
13481348
13491349 const EncryptError = error{MessageTooLong};
13501350
1351 fn encrypt(comptime modulus_len: usize, msg: [modulus_len]u8, public_key: PublicKey) EncryptError![modulus_len]u8 {
1352 const m = Fe.fromBytes(public_key.n, &msg, .big) catch return error.MessageTooLong;
1351 fn encrypt(comptime modulus_len: usize, msg: *const [modulus_len]u8, public_key: PublicKey) EncryptError![modulus_len]u8 {
1352 const m = Fe.fromBytes(public_key.n, msg, .big) catch return error.MessageTooLong;
13531353 const e = public_key.n.powPublic(m, public_key.e) catch unreachable;
13541354 var res: [modulus_len]u8 = undefined;
13551355 e.toBytes(&res, .big) catch unreachable;
lib/std/crypto/tls/Client.zig+1-1
......@@ -1588,7 +1588,7 @@ const CertificatePublicKey = struct {
15881588 inline 128, 256, 384, 512 => |modulus_len| {
15891589 const key: PublicKey = try .fromBytes(exponent, modulus);
15901590 const sig = RsaSignature.fromBytes(modulus_len, encoded_sig);
1591 try RsaSignature.concatVerify(modulus_len, sig, msg, key, Hash);
1591 try RsaSignature.concatVerify(modulus_len, &sig, msg, key, Hash);
15921592 },
15931593 else => return error.TlsBadRsaSignatureBitCount,
15941594 }