authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2024-11-20 04:48:18+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-11-20 03:48:18+00:00
logacba2645f776530e9a1ca287ae2336c928653724
tree4c7b2878e477e0a38ee445de8f7a9a07216721f6
parent5f3a70ed5f5fe21eaaff0a06e95287a13fd2272d
signaturebadge-check Signed by PGP key B5690EEEBB952194

crypto.aes.soft: use std.atomic.cache_line instead of a harcoded value (#22026)


1 files changed, 5 insertions(+), 6 deletions(-)

lib/std/crypto/aes/soft.zig+5-6
......@@ -669,7 +669,7 @@ fn mul(a: u8, b: u8) u8 {
669669 return @as(u8, @truncate(s));
670670}
671671
672const cache_line_bytes = 64;
672const cache_line_bytes = std.atomic.cache_line;
673673
674674inline fn sbox_lookup(sbox: *align(64) const [256]u8, idx0: u8, idx1: u8, idx2: u8, idx3: u8) [4]u8 {
675675 if (side_channels_mitigations == .none) {
......@@ -683,8 +683,8 @@ inline fn sbox_lookup(sbox: *align(64) const [256]u8, idx0: u8, idx1: u8, idx2:
683683 const stride = switch (side_channels_mitigations) {
684684 .none => unreachable,
685685 .basic => sbox.len / 4,
686 .medium => sbox.len / (sbox.len / cache_line_bytes) * 2,
687 .full => sbox.len / (sbox.len / cache_line_bytes),
686 .medium => @min(sbox.len, 2 * cache_line_bytes),
687 .full => @min(sbox.len, cache_line_bytes),
688688 };
689689 const of0 = idx0 % stride;
690690 const of1 = idx1 % stride;
......@@ -718,12 +718,11 @@ inline fn table_lookup(table: *align(64) const [4][256]u32, idx0: u8, idx1: u8,
718718 table[3][idx3],
719719 };
720720 } else {
721 const table_bytes = @sizeOf(@TypeOf(table[0]));
722721 const stride = switch (side_channels_mitigations) {
723722 .none => unreachable,
724723 .basic => table[0].len / 4,
725 .medium => table[0].len / (table_bytes / cache_line_bytes) * 2,
726 .full => table[0].len / (table_bytes / cache_line_bytes),
724 .medium => @max(1, @min(table[0].len, 2 * cache_line_bytes / 4)),
725 .full => @max(1, @min(table[0].len, cache_line_bytes / 4)),
727726 };
728727 const of0 = idx0 % stride;
729728 const of1 = idx1 % stride;