From 02640db931f5963b3342610920483518a85bbc69 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 5 May 2024 16:20:50 +0800 Subject: [PATCH] commit the other half of the AES patch this creates a feature flag for cramium-soc targets. This should be unset for builds that don't target cramium-soc, and this discipline is managed by xtask. --- services/aes/Cargo.toml | 6 +++++- services/aes/src/lib.rs | 11 +++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/services/aes/Cargo.toml b/services/aes/Cargo.toml index 89862afb6..db531e65f 100644 --- a/services/aes/Cargo.toml +++ b/services/aes/Cargo.toml @@ -11,5 +11,9 @@ cipher = "0.4.2" zeroize = { version = "1.6.0", optional = true, default_features = false } [features] -hazmat = [] # Expose cryptographically hazardous APIs +hazmat = [] # Expose cryptographically hazardous APIs +cramium-soc = [] +# Note: this default line should always be empty. If it has the 'cramium-soc' feature +# checkd in, then AES acceleration gets disabled for all targets. This hack only exists +# because in the MPW version of the silicon, HW AES in broken on the RV32. default = [] diff --git a/services/aes/src/lib.rs b/services/aes/src/lib.rs index b77723904..153c8be65 100644 --- a/services/aes/src/lib.rs +++ b/services/aes/src/lib.rs @@ -25,17 +25,20 @@ pub type Block = GenericArray; pub type Block8 = GenericArray; // vex patches -#[cfg(target_arch = "riscv32")] +#[cfg(all(target_arch = "riscv32", not(feature = "cramium-soc")))] mod vex; // Note that we can't use 'feature' flags (for precursor, renode, hosted) because the AES // library is patched into functions that are oblivious to these features. // so this library has to fall back on the legacy method of determining which build target // is being specified. -#[cfg(all(not(target_arch = "riscv32"), not(target_os = "none"), not(target_os = "xous"),))] +#[cfg(not(all(target_arch = "riscv32", not(feature = "cramium-soc"))))] pub use soft::Aes128Soft as Aes128; -#[cfg(all(not(target_arch = "riscv32"), not(target_os = "none"), not(target_os = "xous"),))] +#[cfg(not(all(target_arch = "riscv32", not(feature = "cramium-soc"))))] pub use soft::Aes256Soft as Aes256; -#[cfg(all(target_arch = "riscv32", any(target_os = "none", target_os = "xous"),))] +#[cfg(all( + all(target_arch = "riscv32", not(feature = "cramium-soc")), + any(target_os = "none", target_os = "xous"), +))] pub use vex::{Aes128, Aes256}; /// Size of an AES block (128-bits; 16-bytes)