authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-29 05:45:44+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-29 05:45:44+02:00
log7bd363f61b024c8925eaf86cbf87315094d5ae04
treed0d9ed862332423856dd879a1188747005f3baad
parentbb1f225bc8db6fe565f7e39714ef3565cf1b6e0a
parent7a755c4d2d13229537c55c291ff3f322ad6aba85

Merge pull request 'std.crypto.aes: fix BlockVec xorBytes and orBlocks signatures' (#31984) from jedisct1/zig:xorbytes into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31984 Reviewed-by: Andrew Kelley <andrew@ziglang.org>

4 files changed, 21 insertions(+), 9 deletions(-)

lib/std/crypto/aes.zig+12
......@@ -137,6 +137,18 @@ test "BlockVec invMixColumns" {
137137 }
138138}
139139
140test "BlockVec bitwise operations" {
141 const a_bytes: [32]u8 = @splat(0xaa);
142 const b_bytes: [32]u8 = @splat(0xbb);
143 const a = BlockVec(2).fromBytes(&a_bytes);
144 const b = BlockVec(2).fromBytes(&b_bytes);
145
146 try testing.expectEqual(@as([32]u8, @splat(0x11)), a.xorBytes(&b_bytes));
147 try testing.expectEqual(@as([32]u8, @splat(0x11)), a.xorBlocks(b).toBytes());
148 try testing.expectEqual(@as([32]u8, @splat(0xbb)), a.orBlocks(b).toBytes());
149 try testing.expectEqual(@as([32]u8, @splat(0xaa)), a.andBlocks(b).toBytes());
150}
151
140152test "expand 256-bit key" {
141153 const key = [_]u8{
142154 0x60, 0x3d, 0xeb, 0x10,
lib/std/crypto/aes/aesni.zig+1-1
......@@ -312,7 +312,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
312312 }
313313
314314 /// Apply the bitwise OR operation to the content of two block vectors.
315 pub fn orBlocks(block_vec1: Self, block_vec2: Block) Self {
315 pub fn orBlocks(block_vec1: Self, block_vec2: Self) Self {
316316 var out: Self = undefined;
317317 inline for (0..native_words) |i| {
318318 out.repr[i] = block_vec1.repr[i] | block_vec2.repr[i];
lib/std/crypto/aes/armcrypto.zig+4-4
......@@ -216,10 +216,10 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
216216 }
217217
218218 /// XOR the block vector with a byte sequence.
219 pub fn xorBytes(block_vec: Self, bytes: *const [blocks_count * 16]u8) [32]u8 {
220 var out: Self = undefined;
219 pub fn xorBytes(block_vec: Self, bytes: *const [blocks_count * 16]u8) [blocks_count * 16]u8 {
220 var out: [blocks_count * 16]u8 = undefined;
221221 inline for (0..native_words) |i| {
222 out.repr[i] = block_vec.repr[i].xorBytes(bytes[i * native_word_size ..][0..native_word_size]);
222 out[i * native_word_size ..][0..native_word_size].* = block_vec.repr[i].xorBytes(bytes[i * native_word_size ..][0..native_word_size]);
223223 }
224224 return out;
225225 }
......@@ -279,7 +279,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
279279 }
280280
281281 /// Apply the bitwise OR operation to the content of two block vectors.
282 pub fn orBlocks(block_vec1: Self, block_vec2: Block) Self {
282 pub fn orBlocks(block_vec1: Self, block_vec2: Self) Self {
283283 var out: Self = undefined;
284284 inline for (0..native_words) |i| {
285285 out.repr[i] = block_vec1.repr[i].orBlocks(block_vec2.repr[i]);
lib/std/crypto/aes/soft.zig+4-4
......@@ -391,10 +391,10 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
391391 }
392392
393393 /// XOR the block vector with a byte sequence.
394 pub fn xorBytes(block_vec: Self, bytes: *const [blocks_count * 16]u8) [32]u8 {
395 var out: Self = undefined;
394 pub fn xorBytes(block_vec: Self, bytes: *const [blocks_count * 16]u8) [blocks_count * 16]u8 {
395 var out: [blocks_count * 16]u8 = undefined;
396396 for (0..native_words) |i| {
397 out.repr[i] = block_vec.repr[i].xorBytes(bytes[i * native_word_size ..][0..native_word_size]);
397 out[i * native_word_size ..][0..native_word_size].* = block_vec.repr[i].xorBytes(bytes[i * native_word_size ..][0..native_word_size]);
398398 }
399399 return out;
400400 }
......@@ -454,7 +454,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
454454 }
455455
456456 /// Apply the bitwise OR operation to the content of two block vectors.
457 pub fn orBlocks(block_vec1: Self, block_vec2: Block) Self {
457 pub fn orBlocks(block_vec1: Self, block_vec2: Self) Self {
458458 var out: Self = undefined;
459459 for (0..native_words) |i| {
460460 out.repr[i] = block_vec1.repr[i].orBlocks(block_vec2.repr[i]);