| ... | @@ -5,10 +5,12 @@ const testing = std.testing; | ... | @@ -5,10 +5,12 @@ const testing = std.testing; |
| 5 | const has_aesni = builtin.cpu.has(.x86, .aes); | 5 | const has_aesni = builtin.cpu.has(.x86, .aes); |
| 6 | const has_avx = builtin.cpu.has(.x86, .avx); | 6 | const has_avx = builtin.cpu.has(.x86, .avx); |
| 7 | const has_armaes = builtin.cpu.has(.aarch64, .aes); | 7 | const has_armaes = builtin.cpu.has(.aarch64, .aes); |
| 8 | // C backend doesn't currently support passing vectors to inline asm. | 8 | const use_aesni = builtin.cpu.arch == .x86_64 and has_aesni and has_avx; |
| 9 | const impl = if (builtin.cpu.arch == .x86_64 and has_aesni and has_avx) impl: { | 9 | // C backend doesn't currently support passing vectors to inline asm (#37125) |
| | 10 | const use_armaes = builtin.cpu.arch == .aarch64 and (builtin.zig_backend != .stage2_c or !builtin.os.tag.isDarwin()) and has_armaes; |
| | 11 | const impl = if (use_aesni) impl: { |
| 10 | break :impl @import("aes/aesni.zig"); | 12 | break :impl @import("aes/aesni.zig"); |
| 11 | } else if (builtin.cpu.arch == .aarch64 and (builtin.zig_backend != .stage2_c or !builtin.os.tag.isDarwin()) and has_armaes) impl: { | 13 | } else if (use_armaes) impl: { |
| 12 | break :impl @import("aes/armcrypto.zig"); | 14 | break :impl @import("aes/armcrypto.zig"); |
| 13 | } else impl: { | 15 | } else impl: { |
| 14 | break :impl @import("aes/soft.zig"); | 16 | break :impl @import("aes/soft.zig"); |
| ... | @@ -16,9 +18,7 @@ const impl = if (builtin.cpu.arch == .x86_64 and has_aesni and has_avx) impl: { | ... | @@ -16,9 +18,7 @@ const impl = if (builtin.cpu.arch == .x86_64 and has_aesni and has_avx) impl: { |
| 16 | | 18 | |
| 17 | /// `true` if AES is backed by hardware (AES-NI on x86_64, ARM Crypto Extensions on AArch64). | 19 | /// `true` if AES is backed by hardware (AES-NI on x86_64, ARM Crypto Extensions on AArch64). |
| 18 | /// Software implementations are much slower, and should be avoided if possible. | 20 | /// Software implementations are much slower, and should be avoided if possible. |
| 19 | pub const has_hardware_support = | 21 | pub const has_hardware_support = use_aesni or use_armaes; |
| 20 | (builtin.cpu.arch == .x86_64 and has_aesni and has_avx) or | | |
| 21 | (builtin.cpu.arch == .aarch64 and has_armaes); | | |
| 22 | | 22 | |
| 23 | pub const Block = impl.Block; | 23 | pub const Block = impl.Block; |
| 24 | pub const BlockVec = impl.BlockVec; | 24 | pub const BlockVec = impl.BlockVec; |