From 86fb10d327301e25234616752ebe5c40158d4a78 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 4 Oct 2026 11:24:21 +0200 Subject: [PATCH 1/2] crypto.aes: correctly set has_hardware_support On macOS with the stage2 C backend, we use the software AES implementation because the C backend can't pass vectors to inline assembly. But because the hardware still supports hardware AES, we use to set `has_hardware_support` to true. Fix that and improve readability by the way. --- lib/std/crypto/aes.zig | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/std/crypto/aes.zig b/lib/std/crypto/aes.zig index 54d1bd0dc8474d9eb299ca823864fdc9a1a001ea..51d73517aed0d52aae4022003e7235be6f550cff 100644 --- a/lib/std/crypto/aes.zig +++ b/lib/std/crypto/aes.zig @@ -5,10 +5,12 @@ const testing = std.testing; const has_aesni = builtin.cpu.has(.x86, .aes); const has_avx = builtin.cpu.has(.x86, .avx); const has_armaes = builtin.cpu.has(.aarch64, .aes); +const use_aesni = builtin.cpu.arch == .x86_64 and has_aesni and has_avx; // C backend doesn't currently support passing vectors to inline asm. -const impl = if (builtin.cpu.arch == .x86_64 and has_aesni and has_avx) impl: { +const use_armaes = builtin.cpu.arch == .aarch64 and (builtin.zig_backend != .stage2_c or !builtin.os.tag.isDarwin()) and has_armaes; +const impl = if (use_aesni) impl: { break :impl @import("aes/aesni.zig"); -} else if (builtin.cpu.arch == .aarch64 and (builtin.zig_backend != .stage2_c or !builtin.os.tag.isDarwin()) and has_armaes) impl: { +} else if (use_armaes) impl: { break :impl @import("aes/armcrypto.zig"); } else impl: { 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: { /// `true` if AES is backed by hardware (AES-NI on x86_64, ARM Crypto Extensions on AArch64). /// Software implementations are much slower, and should be avoided if possible. -pub const has_hardware_support = - (builtin.cpu.arch == .x86_64 and has_aesni and has_avx) or - (builtin.cpu.arch == .aarch64 and has_armaes); +pub const has_hardware_support = use_aesni or use_armaes; pub const Block = impl.Block; pub const BlockVec = impl.BlockVec; -- 2.54.0 From ddf480d78e067bd13f28c13fd47cc0bb22da7a17 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Fri, 16 Oct 2026 08:24:51 +0200 Subject: [PATCH 2/2] Add a reference to the open issue --- lib/std/crypto/aes.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/crypto/aes.zig b/lib/std/crypto/aes.zig index 51d73517aed0d52aae4022003e7235be6f550cff..03eaae374444cde7a7a3825d843dc57cc1d6f6e3 100644 --- a/lib/std/crypto/aes.zig +++ b/lib/std/crypto/aes.zig @@ -6,7 +6,7 @@ const has_aesni = builtin.cpu.has(.x86, .aes); const has_avx = builtin.cpu.has(.x86, .avx); const has_armaes = builtin.cpu.has(.aarch64, .aes); const use_aesni = builtin.cpu.arch == .x86_64 and has_aesni and has_avx; -// C backend doesn't currently support passing vectors to inline asm. +// C backend doesn't currently support passing vectors to inline asm (#37125) const use_armaes = builtin.cpu.arch == .aarch64 and (builtin.zig_backend != .stage2_c or !builtin.os.tag.isDarwin()) and has_armaes; const impl = if (use_aesni) impl: { break :impl @import("aes/aesni.zig"); -- 2.54.0