| ... | ... | @@ -669,7 +669,7 @@ fn mul(a: u8, b: u8) u8 { |
| 669 | 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 | 674 | inline fn sbox_lookup(sbox: *align(64) const [256]u8, idx0: u8, idx1: u8, idx2: u8, idx3: u8) [4]u8 { |
| 675 | 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 | 683 | const stride = switch (side_channels_mitigations) { |
| 684 | 684 | .none => unreachable, |
| 685 | 685 | .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), |
| 688 | 688 | }; |
| 689 | 689 | const of0 = idx0 % stride; |
| 690 | 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 | 718 | table[3][idx3], |
| 719 | 719 | }; |
| 720 | 720 | } else { |
| 721 | | const table_bytes = @sizeOf(@TypeOf(table[0])); |
| 722 | 721 | const stride = switch (side_channels_mitigations) { |
| 723 | 722 | .none => unreachable, |
| 724 | 723 | .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)), |
| 727 | 726 | }; |
| 728 | 727 | const of0 = idx0 % stride; |
| 729 | 728 | const of1 = idx1 % stride; |