| ... | @@ -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 | } |
| 671 | | 671 | |
| 672 | const cache_line_bytes = 64; | 672 | const cache_line_bytes = std.atomic.cache_line; |
| 673 | | 673 | |
| 674 | inline fn sbox_lookup(sbox: *align(64) const [256]u8, idx0: u8, idx1: u8, idx2: u8, idx3: u8) [4]u8 { | 674 | inline 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; |