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 {...@@ -669,7 +669,7 @@ fn mul(a: u8, b: u8) u8 {
669 return @as(u8, @truncate(s));669 return @as(u8, @truncate(s));
670}670}
671671
672const cache_line_bytes = 64;672const cache_line_bytes = std.atomic.cache_line;
673673
674inline fn sbox_lookup(sbox: *align(64) const [256]u8, idx0: u8, idx1: u8, idx2: u8, idx3: u8) [4]u8 {674inline fn sbox_lookup(sbox: *align(64) const [256]u8, idx0: u8, idx1: u8, idx2: u8, idx3: u8) [4]u8 {
675 if (side_channels_mitigations == .none) {675 if (side_channels_mitigations == .none) {
...@@ -683,8 +683,8 @@ inline fn sbox_lookup(sbox: *align(64) const [256]u8, idx0: u8, idx1: u8, idx2:...@@ -683,8 +683,8 @@ inline fn sbox_lookup(sbox: *align(64) const [256]u8, idx0: u8, idx1: u8, idx2:
683 const stride = switch (side_channels_mitigations) {683 const stride = switch (side_channels_mitigations) {
684 .none => unreachable,684 .none => unreachable,
685 .basic => sbox.len / 4,685 .basic => sbox.len / 4,
686 .medium => sbox.len / (sbox.len / cache_line_bytes) * 2,686 .medium => @min(sbox.len, 2 * cache_line_bytes),
687 .full => sbox.len / (sbox.len / cache_line_bytes),687 .full => @min(sbox.len, cache_line_bytes),
688 };688 };
689 const of0 = idx0 % stride;689 const of0 = idx0 % stride;
690 const of1 = idx1 % stride;690 const of1 = idx1 % stride;
...@@ -718,12 +718,11 @@ inline fn table_lookup(table: *align(64) const [4][256]u32, idx0: u8, idx1: u8,...@@ -718,12 +718,11 @@ inline fn table_lookup(table: *align(64) const [4][256]u32, idx0: u8, idx1: u8,
718 table[3][idx3],718 table[3][idx3],
719 };719 };
720 } else {720 } else {
721 const table_bytes = @sizeOf(@TypeOf(table[0]));
722 const stride = switch (side_channels_mitigations) {721 const stride = switch (side_channels_mitigations) {
723 .none => unreachable,722 .none => unreachable,
724 .basic => table[0].len / 4,723 .basic => table[0].len / 4,
725 .medium => table[0].len / (table_bytes / cache_line_bytes) * 2,724 .medium => @max(1, @min(table[0].len, 2 * cache_line_bytes / 4)),
726 .full => table[0].len / (table_bytes / cache_line_bytes),725 .full => @max(1, @min(table[0].len, cache_line_bytes / 4)),
727 };726 };
728 const of0 = idx0 % stride;727 const of0 = idx0 % stride;
729 const of1 = idx1 % stride;728 const of1 = idx1 % stride;