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(...@@ -849,7 +849,7 @@ fn verifyRsa(
849 inline 128, 256, 384, 512 => |modulus_len| {849 inline 128, 256, 384, 512 => |modulus_len| {
850 const public_key = rsa.PublicKey.fromBytes(exponent, modulus) catch850 const public_key = rsa.PublicKey.fromBytes(exponent, modulus) catch
851 return error.CertificateSignatureInvalid;851 return error.CertificateSignatureInvalid;
852 rsa.PKCS1v1_5Signature.verify(modulus_len, sig[0..modulus_len].*, msg, public_key, Hash) catch852 rsa.PKCS1v1_5Signature.verify(modulus_len, sig[0..modulus_len], msg, public_key, Hash) catch
853 return error.CertificateSignatureInvalid;853 return error.CertificateSignatureInvalid;
854 },854 },
855 else => return error.CertificateSignatureUnsupportedBitCount,855 else => return error.CertificateSignatureUnsupportedBitCount,
...@@ -1039,7 +1039,7 @@ pub const rsa = struct {...@@ -1039,7 +1039,7 @@ pub const rsa = struct {
10391039
1040 pub fn concatVerify(1040 pub fn concatVerify(
1041 comptime modulus_len: usize,1041 comptime modulus_len: usize,
1042 sig: [modulus_len]u8,1042 sig: *const [modulus_len]u8,
1043 msg: []const []const u8,1043 msg: []const []const u8,
1044 public_key: PublicKey,1044 public_key: PublicKey,
1045 comptime Hash: type,1045 comptime Hash: type,
...@@ -1192,7 +1192,7 @@ pub const rsa = struct {...@@ -1192,7 +1192,7 @@ pub const rsa = struct {
11921192
1193 pub fn verify(1193 pub fn verify(
1194 comptime modulus_len: usize,1194 comptime modulus_len: usize,
1195 sig: [modulus_len]u8,1195 sig: *const [modulus_len]u8,
1196 msg: []const u8,1196 msg: []const u8,
1197 public_key: PublicKey,1197 public_key: PublicKey,
1198 comptime Hash: type,1198 comptime Hash: type,
...@@ -1202,7 +1202,7 @@ pub const rsa = struct {...@@ -1202,7 +1202,7 @@ pub const rsa = struct {
12021202
1203 pub fn concatVerify(1203 pub fn concatVerify(
1204 comptime modulus_len: usize,1204 comptime modulus_len: usize,
1205 sig: [modulus_len]u8,1205 sig: *const [modulus_len]u8,
1206 msg: []const []const u8,1206 msg: []const []const u8,
1207 public_key: PublicKey,1207 public_key: PublicKey,
1208 comptime Hash: type,1208 comptime Hash: type,
...@@ -1348,8 +1348,8 @@ pub const rsa = struct {...@@ -1348,8 +1348,8 @@ pub const rsa = struct {
13481348
1349 const EncryptError = error{MessageTooLong};1349 const EncryptError = error{MessageTooLong};
13501350
1351 fn encrypt(comptime modulus_len: usize, msg: [modulus_len]u8, public_key: PublicKey) EncryptError![modulus_len]u8 {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;1352 const m = Fe.fromBytes(public_key.n, msg, .big) catch return error.MessageTooLong;
1353 const e = public_key.n.powPublic(m, public_key.e) catch unreachable;1353 const e = public_key.n.powPublic(m, public_key.e) catch unreachable;
1354 var res: [modulus_len]u8 = undefined;1354 var res: [modulus_len]u8 = undefined;
1355 e.toBytes(&res, .big) catch unreachable;1355 e.toBytes(&res, .big) catch unreachable;
lib/std/crypto/tls/Client.zig+1-1
...@@ -1588,7 +1588,7 @@ const CertificatePublicKey = struct {...@@ -1588,7 +1588,7 @@ const CertificatePublicKey = struct {
1588 inline 128, 256, 384, 512 => |modulus_len| {1588 inline 128, 256, 384, 512 => |modulus_len| {
1589 const key: PublicKey = try .fromBytes(exponent, modulus);1589 const key: PublicKey = try .fromBytes(exponent, modulus);
1590 const sig = RsaSignature.fromBytes(modulus_len, encoded_sig);1590 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);
1592 },1592 },
1593 else => return error.TlsBadRsaSignatureBitCount,1593 else => return error.TlsBadRsaSignatureBitCount,
1594 }1594 }