From a3e0bc56897a2e1b3d4521c31f2642552b13ff8b Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Mon, 3 Mar 2025 12:19:10 +0100 Subject: [PATCH 1/4] implement runtime feature detection for Aarch64 --- generate-implementations.py | 4 + implementations.yaml | 8 +- pqcrypto-template/scheme/Cargo.toml.j2 | 4 +- pqcrypto-template/scheme/build.rs.j2 | 26 +++- pqcrypto-template/scheme/src/ffi.rs.j2 | 40 ++++++ pqcrypto-template/scheme/src/scheme.rs.j2 | 158 +++++++++++++++++----- 6 files changed, 198 insertions(+), 42 deletions(-) diff --git a/generate-implementations.py b/generate-implementations.py index 4577de1..ceb3aea 100755 --- a/generate-implementations.py +++ b/generate-implementations.py @@ -11,6 +11,7 @@ DEFAULT_X86_AES_GUARD = 'target_arch == "x86_64" && aes_enabled' DEFAULT_X86_AVX2_GUARD = 'target_arch == "x86_64" && avx2_enabled' DEFAULT_AARCH64_NEON_GUARD = 'target_arch == "aarch64" && neon_enabled' +DEFAULT_AARCH64_SHA3_GUARD = 'target_arch == "aarch64" && aarch64_sha3_enabled' def read_yaml(): @@ -33,6 +34,8 @@ def nameize(value): def render_template(target_dir, target_file, template_file, **templ_vars): def namespaceize(value): + if value == "aarch64_sha3": + value = "aarch64" return re.sub(r'(\s|[-_])', '', value).upper() env = jinja2.Environment( @@ -87,6 +90,7 @@ def generate_scheme(name, type, properties): x86_aes_guard=properties.get('x86_aes_guard', DEFAULT_X86_AES_GUARD), x86_avx2_guard=properties.get('x86_avx2_guard', DEFAULT_X86_AVX2_GUARD), aarch64_neon_guard=properties.get('aarch64_neon_guard', DEFAULT_AARCH64_NEON_GUARD), + aarch64_sha3_guard=properties.get('aarch64_sha3_guard', DEFAULT_AARCH64_SHA3_GUARD), ) metadatas = dict() diff --git a/implementations.yaml b/implementations.yaml index e46c11d..b387f81 100644 --- a/implementations.yaml +++ b/implementations.yaml @@ -65,15 +65,15 @@ signs: mldsa: version: 0.1.1 x86_avx2_guard: 'target_arch == "x86_64" && avx2_enabled && !is_windows' - implementations: [clean, avx2, aarch64] + implementations: [clean, avx2, aarch64_sha3] supports_context: true schemes: - name: ml-dsa-44 - implementations: [clean, avx2, aarch64] + implementations: [clean, avx2, aarch64_sha3] - name: ml-dsa-65 - implementations: [clean, avx2, aarch64] + implementations: [clean, avx2, aarch64_sha3] - name: ml-dsa-87 - implementations: [clean, avx2, aarch64] + implementations: [clean, avx2, aarch64_sha3] falcon: version: 0.4.0 implementations: [clean, avx2, aarch64] diff --git a/pqcrypto-template/scheme/Cargo.toml.j2 b/pqcrypto-template/scheme/Cargo.toml.j2 index 7b9e3cf..9c062cc 100644 --- a/pqcrypto-template/scheme/Cargo.toml.j2 +++ b/pqcrypto-template/scheme/Cargo.toml.j2 @@ -22,7 +22,7 @@ paste = "1.0" {% endif %} [features] -default = [{% if 'avx2' in implementations or 'avx' in implementations %}"avx2", {% endif %}{% if 'aesni' in implementations %}"aes", {% endif %}{% if 'aarch64' in implementations %}"neon", {% endif %}"std"] +default = [{% if 'avx2' in implementations or 'avx' in implementations %}"avx2", {% endif %}{% if 'aesni' in implementations %}"aes", {% endif %}{% if 'aarch64' in implementations %}"neon", {% elif 'aarch64_sha3' in implementations %}"aarch64-sha3", {% endif %}"std"] {% if 'avx2' in implementations or 'avx' in implementations %} avx2 = ["std"] {% endif %} @@ -31,6 +31,8 @@ aes = ["std"] {% endif %} {% if 'aarch64' in implementations %} neon = ["std"] +{% elif 'aarch64_sha3' in implementations %} +aarch64-sha3 = ["std"] {% endif %} std = ["pqcrypto-traits/std"] serialization = ["serde", "serde-big-array"] diff --git a/pqcrypto-template/scheme/build.rs.j2 b/pqcrypto-template/scheme/build.rs.j2 index 81dca28..206bf1d 100644 --- a/pqcrypto-template/scheme/build.rs.j2 +++ b/pqcrypto-template/scheme/build.rs.j2 @@ -8,6 +8,7 @@ use std::path::{Path, PathBuf}; {% set globals.x86_aes = False %} {% set globals.x86_avx2 = False %} {% set globals.aarch64_neon = False %} +{% set globals.aarch64_sha3 = False %} {% for implementation in implementations %} macro_rules! build_{{ implementation }} { @@ -15,8 +16,14 @@ macro_rules! build_{{ implementation }} { let internals_include_path = &std::env::var("DEP_PQCRYPTO_INTERNALS_INCLUDEPATH").unwrap(); let common_dir = Path::new("pqclean/common"); + {% if implementation == "aarch64_sha3" %} + let implementation_dir = "aarch64"; + {% else %} + let implementation_dir = "{{ implementation }}"; + {% endif %} + let mut builder = cc::Build::new(); - let target_dir: PathBuf = ["pqclean", "crypto_{{ type }}", $variant, "{{ implementation }}"] + let target_dir: PathBuf = ["pqclean", "crypto_{{ type }}", $variant, implementation_dir] .iter() .collect(); @@ -55,6 +62,10 @@ macro_rules! build_{{ implementation }} { {% set globals.aarch64_neon = True %} let scheme_files = glob::glob(target_dir.join("*.[csS]").to_str().unwrap()).unwrap(); builder.flag("-march=armv8-a"); + {% elif implementation == 'aarch64_sha3' %} + {% set globals.aarch64_sha3 = True %} + let scheme_files = glob::glob(target_dir.join("*.[csS]").to_str().unwrap()).unwrap(); + builder.flag("-march=armv8.2-a+sha3"); {% else %} let scheme_files = glob::glob(target_dir.join("*.c").to_str().unwrap()).unwrap(); {% endif %} @@ -82,6 +93,8 @@ fn main() { #[allow(unused_variables)] let neon_enabled = env::var("CARGO_FEATURE_NEON").is_ok(); #[allow(unused_variables)] + let aarch64_sha3_enabled = env::var("CARGO_FEATURE_AARCH64_SHA3").is_ok(); + #[allow(unused_variables)] let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); #[allow(unused_variables)] let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); @@ -104,6 +117,10 @@ fn main() { if {{ aarch64_neon_guard }} { build_{{ implementation }}!("{{ scheme.name }}"); } + {% elif implementation == 'aarch64_sha3' %} + if {{ aarch64_sha3_guard }} { + build_aarch64_sha3!("{{ scheme.name }}"); + } {% else %} build_{{ implementation }}!("{{ scheme.name }}"); {% endif %} @@ -131,4 +148,11 @@ fn main() { println!("cargo:rustc-cfg=enable_aarch64_neon"); } {% endif %} + {% if globals.aarch64_sha3 %} + println!("cargo::rustc-check-cfg=cfg(enable_aarch64_sha3)"); + if {{ aarch64_sha3_guard }} { + // Print enableing flag for AARCH64 implementation + println!("cargo:rustc-cfg=enable_aarch64_sha3"); + } + {% endif %} } diff --git a/pqcrypto-template/scheme/src/ffi.rs.j2 b/pqcrypto-template/scheme/src/ffi.rs.j2 index 3a49522..ddd049f 100644 --- a/pqcrypto-template/scheme/src/ffi.rs.j2 +++ b/pqcrypto-template/scheme/src/ffi.rs.j2 @@ -24,6 +24,8 @@ use pqcrypto_internals::*; #[cfg(enable_x86_aes)] {% elif implementation == 'aarch64' %} #[cfg(enable_aarch64_neon)] +{% elif implementation == 'aarch64_sha3' %} +#[cfg(enable_aarch64_sha3)] {% endif %} {% if insecure %} #[deprecated(note = "Insecure cryptography, do not use in production")] @@ -35,6 +37,8 @@ pub const PQCLEAN_{{ NS_NAME }}_CRYPTO_SECRETKEYBYTES: usize = {{ metadata['leng #[cfg(enable_x86_aes)] {% elif implementation == 'aarch64' %} #[cfg(enable_aarch64_neon)] +{% elif implementation == 'aarch64_sha3' %} +#[cfg(enable_aarch64_sha3)] {% endif %} {% if insecure %} #[deprecated(note = "Insecure cryptography, do not use in production")] @@ -47,6 +51,8 @@ pub const PQCLEAN_{{ NS_NAME }}_CRYPTO_PUBLICKEYBYTES: usize = {{ metadata['leng #[cfg(enable_x86_aes)] {% elif implementation == 'aarch64' %} #[cfg(enable_aarch64_neon)] + {% elif implementation == 'aarch64_sha3' %} + #[cfg(enable_aarch64_sha3)] {% endif %} {% if insecure %} #[deprecated(note = "Insecure cryptography, do not use in production")] @@ -58,6 +64,8 @@ pub const PQCLEAN_{{ NS_NAME }}_CRYPTO_PUBLICKEYBYTES: usize = {{ metadata['leng #[cfg(enable_x86_aes)] {% elif implementation == 'aarch64' %} #[cfg(enable_aarch64_neon)] + {% elif implementation == 'aarch64_sha3' %} + #[cfg(enable_aarch64_sha3)] {% endif %} {% if insecure %} #[deprecated(note = "Insecure cryptography, do not use in production")] @@ -70,6 +78,8 @@ pub const PQCLEAN_{{ NS_NAME }}_CRYPTO_PUBLICKEYBYTES: usize = {{ metadata['leng #[cfg(enable_x86_aes)] {% elif implementation == 'aarch64' %} #[cfg(enable_aarch64_neon)] + {% elif implementation == 'aarch64_sha3' %} + #[cfg(enable_aarch64_sha3)] {% endif %} {% if insecure %} #[deprecated(note = "Insecure cryptography, do not use in production")] @@ -90,6 +100,8 @@ pub const PQCLEAN_{{ NS_NAME }}_CRYPTO_PUBLICKEYBYTES: usize = {{ metadata['leng #[cfg(enable_x86_aes)] {% elif implementation == 'aarch64' %} #[cfg(enable_aarch64_neon)] +{% elif implementation == 'aarch64_sha3' %} +#[cfg(enable_aarch64_sha3)] {% endif %} #[link(name = "{{ scheme.name }}_{{ implementation }}")] extern "C" { @@ -100,6 +112,8 @@ extern "C" { #[cfg(enable_x86_aes)] {% elif implementation == 'aarch64' %} #[cfg(enable_aarch64_neon)] + {% elif implementation == 'aarch64_sha3' %} + #[cfg(enable_aarch64_sha3)] {% endif %} {% if insecure %} #[deprecated(note = "Insecure cryptography, do not use in production")] @@ -111,6 +125,8 @@ extern "C" { #[cfg(enable_x86_aes)] {% elif implementation == 'aarch64' %} #[cfg(enable_aarch64_neon)] + {% elif implementation == 'aarch64_sha3' %} + #[cfg(enable_aarch64_sha3)] {% endif %} {% if insecure %} #[deprecated(note = "Insecure cryptography, do not use in production")] @@ -122,6 +138,8 @@ extern "C" { #[cfg(enable_x86_aes)] {% elif implementation == 'aarch64' %} #[cfg(enable_aarch64_neon)] + {% elif implementation == 'aarch64_sha3' %} + #[cfg(enable_aarch64_sha3)] {% endif %} {% if insecure %} #[deprecated(note = "Insecure cryptography, do not use in production")] @@ -138,6 +156,8 @@ extern "C" { #[cfg(enable_x86_aes)] {% elif implementation == 'aarch64' %} #[cfg(enable_aarch64_neon)] + {% elif implementation == 'aarch64_sha3' %} + #[cfg(enable_aarch64_sha3)] {% endif %} {% if insecure %} #[deprecated(note = "Insecure cryptography, do not use in production")] @@ -149,6 +169,8 @@ extern "C" { #[cfg(enable_x86_aes)] {% elif implementation == 'aarch64' %} #[cfg(enable_aarch64_neon)] + {% elif implementation == 'aarch64_sha3' %} + #[cfg(enable_aarch64_sha3)] {% endif %} {% if insecure %} #[deprecated(note = "Insecure cryptography, do not use in production")] @@ -161,6 +183,8 @@ extern "C" { #[cfg(enable_x86_aes)] {% elif implementation == 'aarch64' %} #[cfg(enable_aarch64_neon)] + {% elif implementation == 'aarch64_sha3' %} + #[cfg(enable_aarch64_sha3)] {% endif %} {% if insecure %} #[deprecated(note = "Insecure cryptography, do not use in production")] @@ -173,6 +197,8 @@ extern "C" { #[cfg(enable_x86_aes)] {% elif implementation == 'aarch64' %} #[cfg(enable_aarch64_neon)] + {% elif implementation == 'aarch64_sha3' %} + #[cfg(enable_aarch64_sha3)] {% endif %} {% if insecure %} #[deprecated(note = "Insecure cryptography, do not use in production")] @@ -185,6 +211,8 @@ extern "C" { #[cfg(enable_x86_aes)] {% elif implementation == 'aarch64' %} #[cfg(enable_aarch64_neon)] + {% elif implementation == 'aarch64_sha3' %} + #[cfg(enable_aarch64_sha3)] {% endif %} {% if insecure %} #[deprecated(note = "Insecure cryptography, do not use in production")] @@ -197,6 +225,8 @@ extern "C" { #[cfg(enable_x86_aes)] {% elif implementation == 'aarch64' %} #[cfg(enable_aarch64_neon)] + {% elif implementation == 'aarch64_sha3' %} + #[cfg(enable_aarch64_sha3)] {% endif %} {% if insecure %} #[deprecated(note = "Insecure cryptography, do not use in production")] @@ -209,6 +239,8 @@ extern "C" { #[cfg(enable_x86_aes)] {% elif implementation == 'aarch64' %} #[cfg(enable_aarch64_neon)] + {% elif implementation == 'aarch64_sha3' %} + #[cfg(enable_aarch64_sha3)] {% endif %} {% if insecure %} #[deprecated(note = "Insecure cryptography, do not use in production")] @@ -221,6 +253,8 @@ extern "C" { #[cfg(enable_x86_aes)] {% elif implementation == 'aarch64' %} #[cfg(enable_aarch64_neon)] + {% elif implementation == 'aarch64_sha3' %} + #[cfg(enable_aarch64_sha3)] {% endif %} {% if insecure %} #[deprecated(note = "Insecure cryptography, do not use in production")] @@ -233,6 +267,8 @@ extern "C" { #[cfg(enable_x86_aes)] {% elif implementation == 'aarch64' %} #[cfg(enable_aarch64_neon)] + {% elif implementation == 'aarch64_sha3' %} + #[cfg(enable_aarch64_sha3)] {% endif %} {% if insecure %} #[deprecated(note = "Insecure cryptography, do not use in production")] @@ -257,6 +293,8 @@ extern "C" { #[cfg(all(test, enable_x86_aes, feature = "aes", feature = "cryptographically-insecure"))] {% elif implementation == 'aarch64' %} #[cfg(all(test, enable_aarch64_neon, feature = "neon", feature = "cryptographically-insecure"))] + {% elif implementation == 'aarch64_sha3' %} + #[cfg(all(test, enable_aarch64_sha3, feature = "aarch64-sha3", feature = "cryptographically-insecure")] {% else %} #[cfg(all(test, feature = "cryptographically-insecure"))] {% endif %} @@ -267,6 +305,8 @@ extern "C" { #[cfg(all(test, enable_x86_aes, feature = "aes"))] {% elif implementation == 'aarch64' %} #[cfg(all(test, enable_aarch64_neon, feature = "neon"))] + {% elif implementation == 'aarch64_sha3' %} + #[cfg(all(test, enable_aarch64_sha3, feature = "aarch64-sha3"))] {% else %} #[cfg(test)] {% endif %} diff --git a/pqcrypto-template/scheme/src/scheme.rs.j2 b/pqcrypto-template/scheme/src/scheme.rs.j2 index 4371522..0e3cf1b 100644 --- a/pqcrypto-template/scheme/src/scheme.rs.j2 +++ b/pqcrypto-template/scheme/src/scheme.rs.j2 @@ -39,6 +39,7 @@ {% set globals.x86_aes = False %} {% set globals.x86_avx2 = False %} {% set globals.aarch64_neon = False %} +{% set globals.aarch64_sha3 = False %} #[cfg(feature = "serialization")] use serde::{Deserialize, Serialize}; @@ -126,6 +127,9 @@ macro_rules! simple_struct { {% if 'aarch64' in scheme.implementations %} {% set globals.aarch64_neon = True %} {% set AARCH64_NAME = [scheme.name|namespaceize, 'aarch64'|namespaceize]|join('_') %} +{% elif 'aarch64_sha3' in scheme.implementations %} +{% set globals.aarch64_sha3 = True %} +{% set AARCH64_NAME = [scheme.name|namespaceize, 'aarch64'|namespaceize]|join('_') %} {% endif %} simple_struct!(PublicKey, ffi::PQCLEAN_{{ NS_NAME }}_CRYPTO_PUBLICKEYBYTES); @@ -251,7 +255,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { {% if globals.x86_avx2 %} #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { {% if type == "kem" %} return gen_keypair!(PQCLEAN_{{ AVX2_NAME }}_crypto_kem_keypair); {% else %} @@ -263,7 +267,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { {% if globals.x86_aes %} #[cfg(all(enable_x86_aes, feature = "aes"))] { - if std::is_x86_feature_detected!("aes") { + if std::arch::is_x86_feature_detected!("aes") { {% if type == "kem" %} return gen_keypair!(PQCLEAN_{{ AES_NAME }}_crypto_kem_keypair); {% else %} @@ -275,10 +279,18 @@ pub fn keypair() -> (PublicKey, SecretKey) { {% if globals.aarch64_neon %} #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - // always use AArch64 code, when target is detected as all AArch64 targets have NEON - // support, and std::is_aarch64_feature_detected!("neon") works only with Rust nightly at - // the moment - if true { + if std::arch::is_aarch64_feature_detected!("neon") { + {% if type == "kem" %} + return gen_keypair!(PQCLEAN_{{ AARCH64_NAME }}_crypto_kem_keypair); + {% else %} + return gen_keypair!(PQCLEAN_{{ AARCH64_NAME }}_crypto_sign_keypair); + {% endif %} + } + } + {% elif globals.aarch64_sha3 %} + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] + { + if std::arch::is_aarch64_feature_detected!("sha3") { {% if type == "kem" %} return gen_keypair!(PQCLEAN_{{ AARCH64_NAME }}_crypto_kem_keypair); {% else %} @@ -320,7 +332,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { {% if globals.x86_avx2 %} #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return encap!(PQCLEAN_{{ AVX2_NAME }}_crypto_kem_enc, pk); } } @@ -328,7 +340,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { {% if globals.x86_aes %} #[cfg(all(enable_x86_aes, feature = "aes"))] { - if std::is_x86_feature_detected!("aes") { + if std::arch::is_x86_feature_detected!("aes") { return encap!(PQCLEAN_{{ AES_NAME }}_crypto_kem_enc, pk); } } @@ -336,10 +348,21 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { {% if globals.aarch64_neon %} #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return encap!(PQCLEAN_{{ AARCH64_NAME }}_crypto_kem_enc, pk); } } + {% elif globals.aarch64_sha3 %} + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] + { + if std::arch::is_aarch64_feature_detected!("sha3") { + {% if type == "kem" %} + return encap!(PQCLEAN_{{ AARCH64_NAME }}_crypto_kem_enc); + {% else %} + return encap!(PQCLEAN_{{ AARCH64_NAME }}_crypto_sign_enc); + {% endif %} + } + } {% endif %} encap!(PQCLEAN_{{ NS_NAME }}_crypto_kem_enc, pk) } @@ -371,7 +394,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { {% if globals.x86_avx2 %} #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return decap!(PQCLEAN_{{ AVX2_NAME }}_crypto_kem_dec, ct, sk); } } @@ -379,7 +402,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { {% if globals.x86_aes %} #[cfg(all(enable_x86_aes, feature = "aes"))] { - if std::is_x86_feature_detected!("aes") { + if std::arch::is_x86_feature_detected!("aes") { return decap!(PQCLEAN_{{ AES_NAME }}_crypto_kem_dec, ct, sk); } } @@ -387,10 +410,17 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { {% if globals.aarch64_neon %} #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return decap!(PQCLEAN_{{ AARCH64_NAME }}_crypto_kem_dec, ct, sk); } } + {% elif globals.aarch64_sha3 %} + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] + { + if std::arch::is_aarch64_feature_detected!("sha3") { + return decap!(PQCLEAN_{{ AARCH64_NAME }}_crypto_kem_keypair); + } + } {% endif %} decap!(PQCLEAN_{{ NS_NAME }}_crypto_kem_dec, ct, sk) } @@ -468,7 +498,7 @@ pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { {% if globals.x86_avx2 %} #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature!(PQCLEAN_{{ AVX2_NAME }}_crypto_sign, msg, sk); } } @@ -476,7 +506,7 @@ pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { {% if globals.x86_aes %} #[cfg(all(enable_x86_aes, feature = "aes"))] { - if std::is_x86_feature_detected!("aes") { + if std::arch::is_x86_feature_detected!("aes") { return gen_signature!(PQCLEAN_{{ AES_NAME }}_crypto_sign, msg, sk); } } @@ -484,7 +514,14 @@ pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { {% if globals.aarch64_neon %} #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { + return gen_signature!(PQCLEAN_{{ AARCH64_NAME }}_crypto_sign, msg, sk); + } + } + {% elif globals.aarch64_sha3 %} + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] + { + if std::arch::is_aarch64_feature_detected!("sha3") { return gen_signature!(PQCLEAN_{{ AARCH64_NAME }}_crypto_sign, msg, sk); } } @@ -501,7 +538,7 @@ pub fn sign_ctx(msg: &[u8], ctx: &[u8], sk: &SecretKey) -> SignedMessage { {% if globals.x86_avx2 %} #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature_ctx!(PQCLEAN_{{ AVX2_NAME }}_crypto_sign_ctx, msg, ctx, sk); } } @@ -509,7 +546,7 @@ pub fn sign_ctx(msg: &[u8], ctx: &[u8], sk: &SecretKey) -> SignedMessage { {% if globals.x86_aes %} #[cfg(all(enable_x86_aes, feature = "aes"))] { - if std::is_x86_feature_detected!("aes") { + if std::arch::is_x86_feature_detected!("aes") { return gen_signature_ctx!(PQCLEAN_{{ AES_NAME }}_crypto_sign_ctx, msg, ctx, sk); } } @@ -517,7 +554,14 @@ pub fn sign_ctx(msg: &[u8], ctx: &[u8], sk: &SecretKey) -> SignedMessage { {% if globals.aarch64_neon %} #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { + return gen_signature_ctx!(PQCLEAN_{{ AARCH64_NAME }}_crypto_sign_ctx, msg, ctx, sk); + } + } + {% elif globals.aarch64_sha3 %} + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] + { + if std::arch::is_aarch64_feature_detected!("sha3") { return gen_signature_ctx!(PQCLEAN_{{ AARCH64_NAME }}_crypto_sign_ctx, msg, ctx, sk); } } @@ -602,7 +646,7 @@ pub fn open( {% if globals.x86_avx2 %} #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed!(PQCLEAN_{{ AVX2_NAME }}_crypto_sign_open, sm, pk); } } @@ -610,7 +654,7 @@ pub fn open( {% if globals.x86_aes %} #[cfg(all(enable_x86_aes, feature = "aes"))] { - if std::is_x86_feature_detected!("aes") { + if std::arch::is_x86_feature_detected!("aes") { return open_signed!(PQCLEAN_{{ AES_NAME }}_crypto_sign_open, sm, pk); } } @@ -618,7 +662,14 @@ pub fn open( {% if globals.aarch64_neon %} #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { + return open_signed!(PQCLEAN_{{ AARCH64_NAME }}_crypto_sign_open, sm, pk); + } + } + {% elif globals.aarch64_sha3 %} + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] + { + if std::arch::is_aarch64_feature_detected!("sha3") { return open_signed!(PQCLEAN_{{ AARCH64_NAME }}_crypto_sign_open, sm, pk); } } @@ -639,7 +690,7 @@ pub fn open_ctx( {% if globals.x86_avx2 %} #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed_ctx!(PQCLEAN_{{ AVX2_NAME }}_crypto_sign_open_ctx, sm, ctx, pk); } } @@ -647,7 +698,7 @@ pub fn open_ctx( {% if globals.x86_aes %} #[cfg(all(enable_x86_aes, feature = "aes"))] { - if std::is_x86_feature_detected!("aes") { + if std::arch::is_x86_feature_detected!("aes") { return open_signed_ctx!(PQCLEAN_{{ AES_NAME }}_crypto_sign_open_ctx, sm, ctx, pk); } } @@ -655,7 +706,14 @@ pub fn open_ctx( {% if globals.aarch64_neon %} #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { + return open_signed_ctx!(PQCLEAN_{{ AARCH64_NAME }}_crypto_sign_open_ctx, sm, ctx, pk); + } + } + {% elif globals.aarch64_sha3 %} + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] + { + if std::arch::is_aarch64_feature_detected!("sha3") { return open_signed_ctx!(PQCLEAN_{{ AARCH64_NAME }}_crypto_sign_open_ctx, sm, ctx, pk); } } @@ -725,7 +783,7 @@ pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { {% if globals.x86_avx2 %} #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature!(PQCLEAN_{{ AVX2_NAME }}_crypto_sign_signature, msg, sk); } } @@ -733,7 +791,7 @@ pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { {% if globals.x86_aes %} #[cfg(all(enable_x86_aes, feature = "aes"))] { - if std::is_x86_feature_detected!("aes") { + if std::arch::is_x86_feature_detected!("aes") { return detached_signature!(PQCLEAN_{{ AES_NAME }}_crypto_sign_signature, msg, sk); } } @@ -741,7 +799,14 @@ pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { {% if globals.aarch64_neon %} #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { + return detached_signature!(PQCLEAN_{{ AARCH64_NAME }}_crypto_sign_signature, msg, sk); + } + } + {% elif globals.aarch64_sha3 %} + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] + { + if std::arch::is_aarch64_feature_detected!("sha3") { return detached_signature!(PQCLEAN_{{ AARCH64_NAME }}_crypto_sign_signature, msg, sk); } } @@ -758,7 +823,7 @@ pub fn detached_sign_ctx(msg: &[u8], ctx: &[u8], sk: &SecretKey) -> DetachedSign {% if globals.x86_avx2 %} #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature_ctx!(PQCLEAN_{{ AVX2_NAME }}_crypto_sign_signature_ctx, msg, ctx, sk); } } @@ -766,7 +831,7 @@ pub fn detached_sign_ctx(msg: &[u8], ctx: &[u8], sk: &SecretKey) -> DetachedSign {% if globals.x86_aes %} #[cfg(all(enable_x86_aes, feature = "aes"))] { - if std::is_x86_feature_detected!("aes") { + if std::arch::is_x86_feature_detected!("aes") { return detached_signature_ctx!(PQCLEAN_{{ AES_NAME }}_crypto_sign_signature_ctx, msg, ctx, sk); } } @@ -774,7 +839,14 @@ pub fn detached_sign_ctx(msg: &[u8], ctx: &[u8], sk: &SecretKey) -> DetachedSign {% if globals.aarch64_neon %} #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { + return detached_signature_ctx!(PQCLEAN_{{ AARCH64_NAME }}_crypto_sign_signature_ctx, msg, ctx, sk); + } + } + {% elif globals.aarch64_sha3 %} + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] + { + if std::arch::is_aarch64_feature_detected!("sha3") { return detached_signature_ctx!(PQCLEAN_{{ AARCH64_NAME }}_crypto_sign_signature_ctx, msg, ctx, sk); } } @@ -850,7 +922,7 @@ pub fn verify_detached_signature(sig: &DetachedSignature, msg: &[u8], pk: &Publi {% if globals.x86_avx2 %} #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig!(PQCLEAN_{{ AVX2_NAME }}_crypto_sign_verify, sig, msg, pk); } } @@ -858,7 +930,7 @@ pub fn verify_detached_signature(sig: &DetachedSignature, msg: &[u8], pk: &Publi {% if globals.x86_aes %} #[cfg(all(enable_x86_aes, feature = "aes"))] { - if std::is_x86_feature_detected!("aes") { + if std::arch::is_x86_feature_detected!("aes") { return verify_detached_sig!(PQCLEAN_{{ AES_NAME }}_crypto_sign_verify, sig, msg, pk); } } @@ -866,7 +938,14 @@ pub fn verify_detached_signature(sig: &DetachedSignature, msg: &[u8], pk: &Publi {% if globals.aarch64_neon %} #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { + return verify_detached_sig!(PQCLEAN_{{ AARCH64_NAME }}_crypto_sign_verify, sig, msg, pk); + } + } + {% elif globals.aarch64_sha3 %} + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] + { + if std::arch::is_aarch64_feature_detected!("sha3") { return verify_detached_sig!(PQCLEAN_{{ AARCH64_NAME }}_crypto_sign_verify, sig, msg, pk); } } @@ -884,7 +963,7 @@ pub fn verify_detached_signature_ctx(sig: &DetachedSignature, msg: &[u8], ctx: & {% if globals.x86_avx2 %} #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig_ctx!(PQCLEAN_{{ AVX2_NAME }}_crypto_sign_verify_ctx, sig, msg, ctx, pk); } } @@ -892,7 +971,7 @@ pub fn verify_detached_signature_ctx(sig: &DetachedSignature, msg: &[u8], ctx: & {% if globals.x86_aes %} #[cfg(all(enable_x86_aes, feature = "aes"))] { - if std::is_x86_feature_detected!("aes") { + if std::arch::is_x86_feature_detected!("aes") { return verify_detached_sig_ctx!(PQCLEAN_{{ AES_NAME }}_crypto_sign_verify_ctx, sig, msg, ctx, pk); } } @@ -900,7 +979,14 @@ pub fn verify_detached_signature_ctx(sig: &DetachedSignature, msg: &[u8], ctx: & {% if globals.aarch64_neon %} #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { + return verify_detached_sig_ctx!(PQCLEAN_{{ AARCH64_NAME }}_crypto_sign_verify_ctx, sig, msg, ctx, pk); + } + } + {% elif globals.aarch64_sha3 %} + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] + { + if std::arch::is_aarch64_feature_detected!("sha3") { return verify_detached_sig_ctx!(PQCLEAN_{{ AARCH64_NAME }}_crypto_sign_verify_ctx, sig, msg, ctx, pk); } } From 07fa72f08c4c35234c649c1e42ba7dde0d9ed42a Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Mon, 3 Mar 2025 12:21:47 +0100 Subject: [PATCH 2/4] Enable AArch64 feature detection --- pqcrypto-classicmceliece/build.rs | 12 ++- .../src/mceliece348864.rs | 6 +- .../src/mceliece348864f.rs | 6 +- .../src/mceliece460896.rs | 6 +- .../src/mceliece460896f.rs | 6 +- .../src/mceliece6688128.rs | 6 +- .../src/mceliece6688128f.rs | 6 +- .../src/mceliece6960119.rs | 6 +- .../src/mceliece6960119f.rs | 6 +- .../src/mceliece8192128.rs | 6 +- .../src/mceliece8192128f.rs | 6 +- pqcrypto-falcon/build.rs | 14 ++- pqcrypto-falcon/src/falcon1024.rs | 23 ++--- pqcrypto-falcon/src/falcon512.rs | 23 ++--- pqcrypto-falcon/src/falconpadded1024.rs | 23 ++--- pqcrypto-falcon/src/falconpadded512.rs | 23 ++--- pqcrypto-hqc/build.rs | 6 +- pqcrypto-mldsa/Cargo.toml | 4 +- pqcrypto-mldsa/build.rs | 38 +++++--- pqcrypto-mldsa/src/ffi.rs | 96 +++++++++---------- pqcrypto-mldsa/src/mldsa44.rs | 57 ++++++----- pqcrypto-mldsa/src/mldsa65.rs | 57 ++++++----- pqcrypto-mldsa/src/mldsa87.rs | 57 ++++++----- pqcrypto-mlkem/build.rs | 16 +++- pqcrypto-mlkem/src/mlkem1024.rs | 15 ++- pqcrypto-mlkem/src/mlkem512.rs | 15 ++- pqcrypto-mlkem/src/mlkem768.rs | 15 ++- pqcrypto-sphincsplus/build.rs | 10 +- .../src/sphincssha2128fsimple.rs | 10 +- .../src/sphincssha2128ssimple.rs | 10 +- .../src/sphincssha2192fsimple.rs | 10 +- .../src/sphincssha2192ssimple.rs | 10 +- .../src/sphincssha2256fsimple.rs | 10 +- .../src/sphincssha2256ssimple.rs | 10 +- .../src/sphincsshake128fsimple.rs | 10 +- .../src/sphincsshake128ssimple.rs | 10 +- .../src/sphincsshake192fsimple.rs | 10 +- .../src/sphincsshake192ssimple.rs | 10 +- .../src/sphincsshake256fsimple.rs | 10 +- .../src/sphincsshake256ssimple.rs | 10 +- pqcrypto-template/scheme/README.md.j2 | 4 +- 41 files changed, 352 insertions(+), 336 deletions(-) diff --git a/pqcrypto-classicmceliece/build.rs b/pqcrypto-classicmceliece/build.rs index ee04a9a..9edc41d 100644 --- a/pqcrypto-classicmceliece/build.rs +++ b/pqcrypto-classicmceliece/build.rs @@ -9,8 +9,10 @@ macro_rules! build_clean { let internals_include_path = &std::env::var("DEP_PQCRYPTO_INTERNALS_INCLUDEPATH").unwrap(); let common_dir = Path::new("pqclean/common"); + let implementation_dir = "clean"; + let mut builder = cc::Build::new(); - let target_dir: PathBuf = ["pqclean", "crypto_kem", $variant, "clean"] + let target_dir: PathBuf = ["pqclean", "crypto_kem", $variant, implementation_dir] .iter() .collect(); @@ -41,8 +43,12 @@ macro_rules! build_avx2 { let internals_include_path = &std::env::var("DEP_PQCRYPTO_INTERNALS_INCLUDEPATH").unwrap(); let common_dir = Path::new("pqclean/common"); + let implementation_dir = "avx2"; + let mut builder = cc::Build::new(); - let target_dir: PathBuf = ["pqclean", "crypto_kem", $variant, "avx2"].iter().collect(); + let target_dir: PathBuf = ["pqclean", "crypto_kem", $variant, implementation_dir] + .iter() + .collect(); let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); if target_os == "wasi" { @@ -86,6 +92,8 @@ fn main() { #[allow(unused_variables)] let neon_enabled = env::var("CARGO_FEATURE_NEON").is_ok(); #[allow(unused_variables)] + let aarch64_sha3_enabled = env::var("CARGO_FEATURE_AARCH64_SHA3").is_ok(); + #[allow(unused_variables)] let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); #[allow(unused_variables)] let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); diff --git a/pqcrypto-classicmceliece/src/mceliece348864.rs b/pqcrypto-classicmceliece/src/mceliece348864.rs index bb24e41..2880fcc 100644 --- a/pqcrypto-classicmceliece/src/mceliece348864.rs +++ b/pqcrypto-classicmceliece/src/mceliece348864.rs @@ -132,7 +132,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_MCELIECE348864_AVX2_crypto_kem_keypair); } } @@ -155,7 +155,7 @@ macro_rules! encap { pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return encap!(PQCLEAN_MCELIECE348864_AVX2_crypto_kem_enc, pk); } } @@ -177,7 +177,7 @@ macro_rules! decap { pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return decap!(PQCLEAN_MCELIECE348864_AVX2_crypto_kem_dec, ct, sk); } } diff --git a/pqcrypto-classicmceliece/src/mceliece348864f.rs b/pqcrypto-classicmceliece/src/mceliece348864f.rs index 56b463d..66b50b4 100644 --- a/pqcrypto-classicmceliece/src/mceliece348864f.rs +++ b/pqcrypto-classicmceliece/src/mceliece348864f.rs @@ -135,7 +135,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_MCELIECE348864F_AVX2_crypto_kem_keypair); } } @@ -158,7 +158,7 @@ macro_rules! encap { pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return encap!(PQCLEAN_MCELIECE348864F_AVX2_crypto_kem_enc, pk); } } @@ -180,7 +180,7 @@ macro_rules! decap { pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return decap!(PQCLEAN_MCELIECE348864F_AVX2_crypto_kem_dec, ct, sk); } } diff --git a/pqcrypto-classicmceliece/src/mceliece460896.rs b/pqcrypto-classicmceliece/src/mceliece460896.rs index 09e038d..b3689f7 100644 --- a/pqcrypto-classicmceliece/src/mceliece460896.rs +++ b/pqcrypto-classicmceliece/src/mceliece460896.rs @@ -132,7 +132,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_MCELIECE460896_AVX2_crypto_kem_keypair); } } @@ -155,7 +155,7 @@ macro_rules! encap { pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return encap!(PQCLEAN_MCELIECE460896_AVX2_crypto_kem_enc, pk); } } @@ -177,7 +177,7 @@ macro_rules! decap { pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return decap!(PQCLEAN_MCELIECE460896_AVX2_crypto_kem_dec, ct, sk); } } diff --git a/pqcrypto-classicmceliece/src/mceliece460896f.rs b/pqcrypto-classicmceliece/src/mceliece460896f.rs index 7bb9a28..4b55aca 100644 --- a/pqcrypto-classicmceliece/src/mceliece460896f.rs +++ b/pqcrypto-classicmceliece/src/mceliece460896f.rs @@ -135,7 +135,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_MCELIECE460896F_AVX2_crypto_kem_keypair); } } @@ -158,7 +158,7 @@ macro_rules! encap { pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return encap!(PQCLEAN_MCELIECE460896F_AVX2_crypto_kem_enc, pk); } } @@ -180,7 +180,7 @@ macro_rules! decap { pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return decap!(PQCLEAN_MCELIECE460896F_AVX2_crypto_kem_dec, ct, sk); } } diff --git a/pqcrypto-classicmceliece/src/mceliece6688128.rs b/pqcrypto-classicmceliece/src/mceliece6688128.rs index 673aabd..fbcbdd2 100644 --- a/pqcrypto-classicmceliece/src/mceliece6688128.rs +++ b/pqcrypto-classicmceliece/src/mceliece6688128.rs @@ -135,7 +135,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_MCELIECE6688128_AVX2_crypto_kem_keypair); } } @@ -158,7 +158,7 @@ macro_rules! encap { pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return encap!(PQCLEAN_MCELIECE6688128_AVX2_crypto_kem_enc, pk); } } @@ -180,7 +180,7 @@ macro_rules! decap { pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return decap!(PQCLEAN_MCELIECE6688128_AVX2_crypto_kem_dec, ct, sk); } } diff --git a/pqcrypto-classicmceliece/src/mceliece6688128f.rs b/pqcrypto-classicmceliece/src/mceliece6688128f.rs index ffbffcd..5c9cb15 100644 --- a/pqcrypto-classicmceliece/src/mceliece6688128f.rs +++ b/pqcrypto-classicmceliece/src/mceliece6688128f.rs @@ -135,7 +135,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_MCELIECE6688128F_AVX2_crypto_kem_keypair); } } @@ -158,7 +158,7 @@ macro_rules! encap { pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return encap!(PQCLEAN_MCELIECE6688128F_AVX2_crypto_kem_enc, pk); } } @@ -180,7 +180,7 @@ macro_rules! decap { pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return decap!(PQCLEAN_MCELIECE6688128F_AVX2_crypto_kem_dec, ct, sk); } } diff --git a/pqcrypto-classicmceliece/src/mceliece6960119.rs b/pqcrypto-classicmceliece/src/mceliece6960119.rs index 83a3c99..f7b8056 100644 --- a/pqcrypto-classicmceliece/src/mceliece6960119.rs +++ b/pqcrypto-classicmceliece/src/mceliece6960119.rs @@ -135,7 +135,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_MCELIECE6960119_AVX2_crypto_kem_keypair); } } @@ -158,7 +158,7 @@ macro_rules! encap { pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return encap!(PQCLEAN_MCELIECE6960119_AVX2_crypto_kem_enc, pk); } } @@ -180,7 +180,7 @@ macro_rules! decap { pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return decap!(PQCLEAN_MCELIECE6960119_AVX2_crypto_kem_dec, ct, sk); } } diff --git a/pqcrypto-classicmceliece/src/mceliece6960119f.rs b/pqcrypto-classicmceliece/src/mceliece6960119f.rs index 8f1e720..078bf17 100644 --- a/pqcrypto-classicmceliece/src/mceliece6960119f.rs +++ b/pqcrypto-classicmceliece/src/mceliece6960119f.rs @@ -135,7 +135,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_MCELIECE6960119F_AVX2_crypto_kem_keypair); } } @@ -158,7 +158,7 @@ macro_rules! encap { pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return encap!(PQCLEAN_MCELIECE6960119F_AVX2_crypto_kem_enc, pk); } } @@ -180,7 +180,7 @@ macro_rules! decap { pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return decap!(PQCLEAN_MCELIECE6960119F_AVX2_crypto_kem_dec, ct, sk); } } diff --git a/pqcrypto-classicmceliece/src/mceliece8192128.rs b/pqcrypto-classicmceliece/src/mceliece8192128.rs index 6820380..decaffd 100644 --- a/pqcrypto-classicmceliece/src/mceliece8192128.rs +++ b/pqcrypto-classicmceliece/src/mceliece8192128.rs @@ -135,7 +135,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_MCELIECE8192128_AVX2_crypto_kem_keypair); } } @@ -158,7 +158,7 @@ macro_rules! encap { pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return encap!(PQCLEAN_MCELIECE8192128_AVX2_crypto_kem_enc, pk); } } @@ -180,7 +180,7 @@ macro_rules! decap { pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return decap!(PQCLEAN_MCELIECE8192128_AVX2_crypto_kem_dec, ct, sk); } } diff --git a/pqcrypto-classicmceliece/src/mceliece8192128f.rs b/pqcrypto-classicmceliece/src/mceliece8192128f.rs index e247b5c..7087147 100644 --- a/pqcrypto-classicmceliece/src/mceliece8192128f.rs +++ b/pqcrypto-classicmceliece/src/mceliece8192128f.rs @@ -135,7 +135,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_MCELIECE8192128F_AVX2_crypto_kem_keypair); } } @@ -158,7 +158,7 @@ macro_rules! encap { pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return encap!(PQCLEAN_MCELIECE8192128F_AVX2_crypto_kem_enc, pk); } } @@ -180,7 +180,7 @@ macro_rules! decap { pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return decap!(PQCLEAN_MCELIECE8192128F_AVX2_crypto_kem_dec, ct, sk); } } diff --git a/pqcrypto-falcon/build.rs b/pqcrypto-falcon/build.rs index 0074a90..03e3d9a 100644 --- a/pqcrypto-falcon/build.rs +++ b/pqcrypto-falcon/build.rs @@ -9,8 +9,10 @@ macro_rules! build_clean { let internals_include_path = &std::env::var("DEP_PQCRYPTO_INTERNALS_INCLUDEPATH").unwrap(); let common_dir = Path::new("pqclean/common"); + let implementation_dir = "clean"; + let mut builder = cc::Build::new(); - let target_dir: PathBuf = ["pqclean", "crypto_sign", $variant, "clean"] + let target_dir: PathBuf = ["pqclean", "crypto_sign", $variant, implementation_dir] .iter() .collect(); @@ -41,8 +43,10 @@ macro_rules! build_avx2 { let internals_include_path = &std::env::var("DEP_PQCRYPTO_INTERNALS_INCLUDEPATH").unwrap(); let common_dir = Path::new("pqclean/common"); + let implementation_dir = "avx2"; + let mut builder = cc::Build::new(); - let target_dir: PathBuf = ["pqclean", "crypto_sign", $variant, "avx2"] + let target_dir: PathBuf = ["pqclean", "crypto_sign", $variant, implementation_dir] .iter() .collect(); @@ -85,8 +89,10 @@ macro_rules! build_aarch64 { let internals_include_path = &std::env::var("DEP_PQCRYPTO_INTERNALS_INCLUDEPATH").unwrap(); let common_dir = Path::new("pqclean/common"); + let implementation_dir = "aarch64"; + let mut builder = cc::Build::new(); - let target_dir: PathBuf = ["pqclean", "crypto_sign", $variant, "aarch64"] + let target_dir: PathBuf = ["pqclean", "crypto_sign", $variant, implementation_dir] .iter() .collect(); @@ -121,6 +127,8 @@ fn main() { #[allow(unused_variables)] let neon_enabled = env::var("CARGO_FEATURE_NEON").is_ok(); #[allow(unused_variables)] + let aarch64_sha3_enabled = env::var("CARGO_FEATURE_AARCH64_SHA3").is_ok(); + #[allow(unused_variables)] let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); #[allow(unused_variables)] let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); diff --git a/pqcrypto-falcon/src/falcon1024.rs b/pqcrypto-falcon/src/falcon1024.rs index 5f40fd2..28545fc 100644 --- a/pqcrypto-falcon/src/falcon1024.rs +++ b/pqcrypto-falcon/src/falcon1024.rs @@ -186,16 +186,13 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_FALCON1024_AVX2_crypto_sign_keypair); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - // always use AArch64 code, when target is detected as all AArch64 targets have NEON - // support, and std::is_aarch64_feature_detected!("neon") works only with Rust nightly at - // the moment - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return gen_keypair!(PQCLEAN_FALCON1024_AARCH64_crypto_sign_keypair); } } @@ -226,13 +223,13 @@ macro_rules! gen_signature { pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature!(PQCLEAN_FALCON1024_AVX2_crypto_sign, msg, sk); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return gen_signature!(PQCLEAN_FALCON1024_AARCH64_crypto_sign, msg, sk); } } @@ -269,13 +266,13 @@ pub fn open( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed!(PQCLEAN_FALCON1024_AVX2_crypto_sign_open, sm, pk); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return open_signed!(PQCLEAN_FALCON1024_AARCH64_crypto_sign_open, sm, pk); } } @@ -302,13 +299,13 @@ macro_rules! detached_signature { pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature!(PQCLEAN_FALCON1024_AVX2_crypto_sign_signature, msg, sk); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return detached_signature!(PQCLEAN_FALCON1024_AARCH64_crypto_sign_signature, msg, sk); } } @@ -342,13 +339,13 @@ pub fn verify_detached_signature( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig!(PQCLEAN_FALCON1024_AVX2_crypto_sign_verify, sig, msg, pk); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return verify_detached_sig!( PQCLEAN_FALCON1024_AARCH64_crypto_sign_verify, sig, diff --git a/pqcrypto-falcon/src/falcon512.rs b/pqcrypto-falcon/src/falcon512.rs index e46c66f..09cc905 100644 --- a/pqcrypto-falcon/src/falcon512.rs +++ b/pqcrypto-falcon/src/falcon512.rs @@ -186,16 +186,13 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_FALCON512_AVX2_crypto_sign_keypair); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - // always use AArch64 code, when target is detected as all AArch64 targets have NEON - // support, and std::is_aarch64_feature_detected!("neon") works only with Rust nightly at - // the moment - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return gen_keypair!(PQCLEAN_FALCON512_AARCH64_crypto_sign_keypair); } } @@ -226,13 +223,13 @@ macro_rules! gen_signature { pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature!(PQCLEAN_FALCON512_AVX2_crypto_sign, msg, sk); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return gen_signature!(PQCLEAN_FALCON512_AARCH64_crypto_sign, msg, sk); } } @@ -269,13 +266,13 @@ pub fn open( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed!(PQCLEAN_FALCON512_AVX2_crypto_sign_open, sm, pk); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return open_signed!(PQCLEAN_FALCON512_AARCH64_crypto_sign_open, sm, pk); } } @@ -302,13 +299,13 @@ macro_rules! detached_signature { pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature!(PQCLEAN_FALCON512_AVX2_crypto_sign_signature, msg, sk); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return detached_signature!(PQCLEAN_FALCON512_AARCH64_crypto_sign_signature, msg, sk); } } @@ -342,13 +339,13 @@ pub fn verify_detached_signature( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig!(PQCLEAN_FALCON512_AVX2_crypto_sign_verify, sig, msg, pk); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return verify_detached_sig!( PQCLEAN_FALCON512_AARCH64_crypto_sign_verify, sig, diff --git a/pqcrypto-falcon/src/falconpadded1024.rs b/pqcrypto-falcon/src/falconpadded1024.rs index 46fddcd..2917e46 100644 --- a/pqcrypto-falcon/src/falconpadded1024.rs +++ b/pqcrypto-falcon/src/falconpadded1024.rs @@ -186,16 +186,13 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_FALCONPADDED1024_AVX2_crypto_sign_keypair); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - // always use AArch64 code, when target is detected as all AArch64 targets have NEON - // support, and std::is_aarch64_feature_detected!("neon") works only with Rust nightly at - // the moment - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return gen_keypair!(PQCLEAN_FALCONPADDED1024_AARCH64_crypto_sign_keypair); } } @@ -226,13 +223,13 @@ macro_rules! gen_signature { pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature!(PQCLEAN_FALCONPADDED1024_AVX2_crypto_sign, msg, sk); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return gen_signature!(PQCLEAN_FALCONPADDED1024_AARCH64_crypto_sign, msg, sk); } } @@ -269,13 +266,13 @@ pub fn open( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed!(PQCLEAN_FALCONPADDED1024_AVX2_crypto_sign_open, sm, pk); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return open_signed!(PQCLEAN_FALCONPADDED1024_AARCH64_crypto_sign_open, sm, pk); } } @@ -302,7 +299,7 @@ macro_rules! detached_signature { pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature!( PQCLEAN_FALCONPADDED1024_AVX2_crypto_sign_signature, msg, @@ -312,7 +309,7 @@ pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return detached_signature!( PQCLEAN_FALCONPADDED1024_AARCH64_crypto_sign_signature, msg, @@ -354,7 +351,7 @@ pub fn verify_detached_signature( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig!( PQCLEAN_FALCONPADDED1024_AVX2_crypto_sign_verify, sig, @@ -365,7 +362,7 @@ pub fn verify_detached_signature( } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return verify_detached_sig!( PQCLEAN_FALCONPADDED1024_AARCH64_crypto_sign_verify, sig, diff --git a/pqcrypto-falcon/src/falconpadded512.rs b/pqcrypto-falcon/src/falconpadded512.rs index 0a1d3e9..6d22848 100644 --- a/pqcrypto-falcon/src/falconpadded512.rs +++ b/pqcrypto-falcon/src/falconpadded512.rs @@ -186,16 +186,13 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_FALCONPADDED512_AVX2_crypto_sign_keypair); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - // always use AArch64 code, when target is detected as all AArch64 targets have NEON - // support, and std::is_aarch64_feature_detected!("neon") works only with Rust nightly at - // the moment - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return gen_keypair!(PQCLEAN_FALCONPADDED512_AARCH64_crypto_sign_keypair); } } @@ -226,13 +223,13 @@ macro_rules! gen_signature { pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature!(PQCLEAN_FALCONPADDED512_AVX2_crypto_sign, msg, sk); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return gen_signature!(PQCLEAN_FALCONPADDED512_AARCH64_crypto_sign, msg, sk); } } @@ -269,13 +266,13 @@ pub fn open( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed!(PQCLEAN_FALCONPADDED512_AVX2_crypto_sign_open, sm, pk); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return open_signed!(PQCLEAN_FALCONPADDED512_AARCH64_crypto_sign_open, sm, pk); } } @@ -302,7 +299,7 @@ macro_rules! detached_signature { pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature!( PQCLEAN_FALCONPADDED512_AVX2_crypto_sign_signature, msg, @@ -312,7 +309,7 @@ pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return detached_signature!( PQCLEAN_FALCONPADDED512_AARCH64_crypto_sign_signature, msg, @@ -350,7 +347,7 @@ pub fn verify_detached_signature( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig!( PQCLEAN_FALCONPADDED512_AVX2_crypto_sign_verify, sig, @@ -361,7 +358,7 @@ pub fn verify_detached_signature( } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return verify_detached_sig!( PQCLEAN_FALCONPADDED512_AARCH64_crypto_sign_verify, sig, diff --git a/pqcrypto-hqc/build.rs b/pqcrypto-hqc/build.rs index 57e3210..4513d93 100644 --- a/pqcrypto-hqc/build.rs +++ b/pqcrypto-hqc/build.rs @@ -9,8 +9,10 @@ macro_rules! build_clean { let internals_include_path = &std::env::var("DEP_PQCRYPTO_INTERNALS_INCLUDEPATH").unwrap(); let common_dir = Path::new("pqclean/common"); + let implementation_dir = "clean"; + let mut builder = cc::Build::new(); - let target_dir: PathBuf = ["pqclean", "crypto_kem", $variant, "clean"] + let target_dir: PathBuf = ["pqclean", "crypto_kem", $variant, implementation_dir] .iter() .collect(); @@ -44,6 +46,8 @@ fn main() { #[allow(unused_variables)] let neon_enabled = env::var("CARGO_FEATURE_NEON").is_ok(); #[allow(unused_variables)] + let aarch64_sha3_enabled = env::var("CARGO_FEATURE_AARCH64_SHA3").is_ok(); + #[allow(unused_variables)] let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); #[allow(unused_variables)] let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); diff --git a/pqcrypto-mldsa/Cargo.toml b/pqcrypto-mldsa/Cargo.toml index 0b1e010..c45c38f 100644 --- a/pqcrypto-mldsa/Cargo.toml +++ b/pqcrypto-mldsa/Cargo.toml @@ -20,9 +20,9 @@ serde-big-array = { version = "0.5.1", optional = true } paste = "1.0" [features] -default = ["avx2", "neon", "std"] +default = ["avx2", "aarch64-sha3", "std"] avx2 = ["std"] -neon = ["std"] +aarch64-sha3 = ["std"] std = ["pqcrypto-traits/std"] serialization = ["serde", "serde-big-array"] diff --git a/pqcrypto-mldsa/build.rs b/pqcrypto-mldsa/build.rs index 790447d..fc917fa 100644 --- a/pqcrypto-mldsa/build.rs +++ b/pqcrypto-mldsa/build.rs @@ -9,8 +9,10 @@ macro_rules! build_clean { let internals_include_path = &std::env::var("DEP_PQCRYPTO_INTERNALS_INCLUDEPATH").unwrap(); let common_dir = Path::new("pqclean/common"); + let implementation_dir = "clean"; + let mut builder = cc::Build::new(); - let target_dir: PathBuf = ["pqclean", "crypto_sign", $variant, "clean"] + let target_dir: PathBuf = ["pqclean", "crypto_sign", $variant, implementation_dir] .iter() .collect(); @@ -41,8 +43,10 @@ macro_rules! build_avx2 { let internals_include_path = &std::env::var("DEP_PQCRYPTO_INTERNALS_INCLUDEPATH").unwrap(); let common_dir = Path::new("pqclean/common"); + let implementation_dir = "avx2"; + let mut builder = cc::Build::new(); - let target_dir: PathBuf = ["pqclean", "crypto_sign", $variant, "avx2"] + let target_dir: PathBuf = ["pqclean", "crypto_sign", $variant, implementation_dir] .iter() .collect(); @@ -80,13 +84,15 @@ macro_rules! build_avx2 { }; } -macro_rules! build_aarch64 { +macro_rules! build_aarch64_sha3 { ($variant:expr) => { let internals_include_path = &std::env::var("DEP_PQCRYPTO_INTERNALS_INCLUDEPATH").unwrap(); let common_dir = Path::new("pqclean/common"); + let implementation_dir = "aarch64"; + let mut builder = cc::Build::new(); - let target_dir: PathBuf = ["pqclean", "crypto_sign", $variant, "aarch64"] + let target_dir: PathBuf = ["pqclean", "crypto_sign", $variant, implementation_dir] .iter() .collect(); @@ -98,7 +104,7 @@ macro_rules! build_aarch64 { } let scheme_files = glob::glob(target_dir.join("*.[csS]").to_str().unwrap()).unwrap(); - builder.flag("-march=armv8-a"); + builder.flag("-march=armv8.2-a+sha3"); builder .include(internals_include_path) @@ -109,7 +115,7 @@ macro_rules! build_aarch64 { .into_iter() .map(|p| p.unwrap().to_string_lossy().into_owned()), ); - builder.compile(format!("{}_aarch64", $variant).as_str()); + builder.compile(format!("{}_aarch64_sha3", $variant).as_str()); }; } @@ -121,6 +127,8 @@ fn main() { #[allow(unused_variables)] let neon_enabled = env::var("CARGO_FEATURE_NEON").is_ok(); #[allow(unused_variables)] + let aarch64_sha3_enabled = env::var("CARGO_FEATURE_AARCH64_SHA3").is_ok(); + #[allow(unused_variables)] let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); #[allow(unused_variables)] let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); @@ -133,22 +141,22 @@ fn main() { if target_arch == "x86_64" && avx2_enabled && !is_windows { build_avx2!("ml-dsa-44"); } - if target_arch == "aarch64" && neon_enabled { - build_aarch64!("ml-dsa-44"); + if target_arch == "aarch64" && aarch64_sha3_enabled { + build_aarch64_sha3!("ml-dsa-44"); } build_clean!("ml-dsa-65"); if target_arch == "x86_64" && avx2_enabled && !is_windows { build_avx2!("ml-dsa-65"); } - if target_arch == "aarch64" && neon_enabled { - build_aarch64!("ml-dsa-65"); + if target_arch == "aarch64" && aarch64_sha3_enabled { + build_aarch64_sha3!("ml-dsa-65"); } build_clean!("ml-dsa-87"); if target_arch == "x86_64" && avx2_enabled && !is_windows { build_avx2!("ml-dsa-87"); } - if target_arch == "aarch64" && neon_enabled { - build_aarch64!("ml-dsa-87"); + if target_arch == "aarch64" && aarch64_sha3_enabled { + build_aarch64_sha3!("ml-dsa-87"); } println!("cargo::rustc-check-cfg=cfg(enable_x86_avx2)"); @@ -156,9 +164,9 @@ fn main() { // Print enableing flag for AVX2 implementation println!("cargo:rustc-cfg=enable_x86_avx2"); } - println!("cargo::rustc-check-cfg=cfg(enable_aarch64_neon)"); - if target_arch == "aarch64" && neon_enabled { + println!("cargo::rustc-check-cfg=cfg(enable_aarch64_sha3)"); + if target_arch == "aarch64" && aarch64_sha3_enabled { // Print enableing flag for AARCH64 implementation - println!("cargo:rustc-cfg=enable_aarch64_neon"); + println!("cargo:rustc-cfg=enable_aarch64_sha3"); } } diff --git a/pqcrypto-mldsa/src/ffi.rs b/pqcrypto-mldsa/src/ffi.rs index ea27510..f4645d1 100644 --- a/pqcrypto-mldsa/src/ffi.rs +++ b/pqcrypto-mldsa/src/ffi.rs @@ -25,11 +25,11 @@ pub const PQCLEAN_MLDSA44_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 1312; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MLDSA44_AVX2_CRYPTO_BYTES: usize = 2420; -#[cfg(enable_aarch64_neon)] +#[cfg(enable_aarch64_sha3)] pub const PQCLEAN_MLDSA44_AARCH64_CRYPTO_SECRETKEYBYTES: usize = 2560; -#[cfg(enable_aarch64_neon)] +#[cfg(enable_aarch64_sha3)] pub const PQCLEAN_MLDSA44_AARCH64_CRYPTO_PUBLICKEYBYTES: usize = 1312; -#[cfg(enable_aarch64_neon)] +#[cfg(enable_aarch64_sha3)] pub const PQCLEAN_MLDSA44_AARCH64_CRYPTO_BYTES: usize = 2420; pub const PQCLEAN_MLDSA65_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 4032; @@ -43,11 +43,11 @@ pub const PQCLEAN_MLDSA65_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 1952; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MLDSA65_AVX2_CRYPTO_BYTES: usize = 3309; -#[cfg(enable_aarch64_neon)] +#[cfg(enable_aarch64_sha3)] pub const PQCLEAN_MLDSA65_AARCH64_CRYPTO_SECRETKEYBYTES: usize = 4032; -#[cfg(enable_aarch64_neon)] +#[cfg(enable_aarch64_sha3)] pub const PQCLEAN_MLDSA65_AARCH64_CRYPTO_PUBLICKEYBYTES: usize = 1952; -#[cfg(enable_aarch64_neon)] +#[cfg(enable_aarch64_sha3)] pub const PQCLEAN_MLDSA65_AARCH64_CRYPTO_BYTES: usize = 3309; pub const PQCLEAN_MLDSA87_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 4896; @@ -61,11 +61,11 @@ pub const PQCLEAN_MLDSA87_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 2592; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MLDSA87_AVX2_CRYPTO_BYTES: usize = 4627; -#[cfg(enable_aarch64_neon)] +#[cfg(enable_aarch64_sha3)] pub const PQCLEAN_MLDSA87_AARCH64_CRYPTO_SECRETKEYBYTES: usize = 4896; -#[cfg(enable_aarch64_neon)] +#[cfg(enable_aarch64_sha3)] pub const PQCLEAN_MLDSA87_AARCH64_CRYPTO_PUBLICKEYBYTES: usize = 2592; -#[cfg(enable_aarch64_neon)] +#[cfg(enable_aarch64_sha3)] pub const PQCLEAN_MLDSA87_AARCH64_CRYPTO_BYTES: usize = 4627; #[link(name = "ml-dsa-44_clean")] @@ -218,12 +218,12 @@ extern "C" { } -#[cfg(enable_aarch64_neon)] -#[link(name = "ml-dsa-44_aarch64")] +#[cfg(enable_aarch64_sha3)] +#[link(name = "ml-dsa-44_aarch64_sha3")] extern "C" { - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA44_AARCH64_crypto_sign_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA44_AARCH64_crypto_sign( sm: *mut u8, smlen: *mut usize, @@ -231,7 +231,7 @@ extern "C" { len: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA44_AARCH64_crypto_sign_ctx( sm: *mut u8, smlen: *mut usize, @@ -241,7 +241,7 @@ extern "C" { ctxlen: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA44_AARCH64_crypto_sign_open( m: *mut u8, mlen: *mut usize, @@ -249,7 +249,7 @@ extern "C" { smlen: usize, pk: *const u8, ) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA44_AARCH64_crypto_sign_open_ctx( m: *mut u8, mlen: *mut usize, @@ -259,7 +259,7 @@ extern "C" { ctxlen: usize, pk: *const u8, ) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA44_AARCH64_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, @@ -267,7 +267,7 @@ extern "C" { mlen: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA44_AARCH64_crypto_sign_signature_ctx( sig: *mut u8, siglen: *mut usize, @@ -277,7 +277,7 @@ extern "C" { ctxlen: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA44_AARCH64_crypto_sign_verify( sig: *const u8, siglen: usize, @@ -285,7 +285,7 @@ extern "C" { mlen: usize, pk: *const u8, ) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA44_AARCH64_crypto_sign_verify_ctx( sig: *const u8, siglen: usize, @@ -448,12 +448,12 @@ extern "C" { } -#[cfg(enable_aarch64_neon)] -#[link(name = "ml-dsa-65_aarch64")] +#[cfg(enable_aarch64_sha3)] +#[link(name = "ml-dsa-65_aarch64_sha3")] extern "C" { - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA65_AARCH64_crypto_sign_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA65_AARCH64_crypto_sign( sm: *mut u8, smlen: *mut usize, @@ -461,7 +461,7 @@ extern "C" { len: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA65_AARCH64_crypto_sign_ctx( sm: *mut u8, smlen: *mut usize, @@ -471,7 +471,7 @@ extern "C" { ctxlen: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA65_AARCH64_crypto_sign_open( m: *mut u8, mlen: *mut usize, @@ -479,7 +479,7 @@ extern "C" { smlen: usize, pk: *const u8, ) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA65_AARCH64_crypto_sign_open_ctx( m: *mut u8, mlen: *mut usize, @@ -489,7 +489,7 @@ extern "C" { ctxlen: usize, pk: *const u8, ) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA65_AARCH64_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, @@ -497,7 +497,7 @@ extern "C" { mlen: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA65_AARCH64_crypto_sign_signature_ctx( sig: *mut u8, siglen: *mut usize, @@ -507,7 +507,7 @@ extern "C" { ctxlen: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA65_AARCH64_crypto_sign_verify( sig: *const u8, siglen: usize, @@ -515,7 +515,7 @@ extern "C" { mlen: usize, pk: *const u8, ) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA65_AARCH64_crypto_sign_verify_ctx( sig: *const u8, siglen: usize, @@ -678,12 +678,12 @@ extern "C" { } -#[cfg(enable_aarch64_neon)] -#[link(name = "ml-dsa-87_aarch64")] +#[cfg(enable_aarch64_sha3)] +#[link(name = "ml-dsa-87_aarch64_sha3")] extern "C" { - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA87_AARCH64_crypto_sign_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA87_AARCH64_crypto_sign( sm: *mut u8, smlen: *mut usize, @@ -691,7 +691,7 @@ extern "C" { len: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA87_AARCH64_crypto_sign_ctx( sm: *mut u8, smlen: *mut usize, @@ -701,7 +701,7 @@ extern "C" { ctxlen: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA87_AARCH64_crypto_sign_open( m: *mut u8, mlen: *mut usize, @@ -709,7 +709,7 @@ extern "C" { smlen: usize, pk: *const u8, ) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA87_AARCH64_crypto_sign_open_ctx( m: *mut u8, mlen: *mut usize, @@ -719,7 +719,7 @@ extern "C" { ctxlen: usize, pk: *const u8, ) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA87_AARCH64_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, @@ -727,7 +727,7 @@ extern "C" { mlen: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA87_AARCH64_crypto_sign_signature_ctx( sig: *mut u8, siglen: *mut usize, @@ -737,7 +737,7 @@ extern "C" { ctxlen: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA87_AARCH64_crypto_sign_verify( sig: *const u8, siglen: usize, @@ -745,7 +745,7 @@ extern "C" { mlen: usize, pk: *const u8, ) -> c_int; - #[cfg(enable_aarch64_neon)] + #[cfg(enable_aarch64_sha3)] pub fn PQCLEAN_MLDSA87_AARCH64_crypto_sign_verify_ctx( sig: *const u8, siglen: usize, @@ -1144,8 +1144,8 @@ mod test_mldsa44_avx2 { } } -#[cfg(all(test, enable_aarch64_neon, feature = "neon"))] -mod test_mldsa44_aarch64 { +#[cfg(all(test, enable_aarch64_sha3, feature = "aarch64-sha3"))] +mod test_mldsa44_aarch64sha3 { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -1727,8 +1727,8 @@ mod test_mldsa65_avx2 { } } -#[cfg(all(test, enable_aarch64_neon, feature = "neon"))] -mod test_mldsa65_aarch64 { +#[cfg(all(test, enable_aarch64_sha3, feature = "aarch64-sha3"))] +mod test_mldsa65_aarch64sha3 { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -2310,8 +2310,8 @@ mod test_mldsa87_avx2 { } } -#[cfg(all(test, enable_aarch64_neon, feature = "neon"))] -mod test_mldsa87_aarch64 { +#[cfg(all(test, enable_aarch64_sha3, feature = "aarch64-sha3"))] +mod test_mldsa87_aarch64sha3 { use super::*; use alloc::vec; use alloc::vec::Vec; diff --git a/pqcrypto-mldsa/src/mldsa44.rs b/pqcrypto-mldsa/src/mldsa44.rs index 5006296..2284f61 100644 --- a/pqcrypto-mldsa/src/mldsa44.rs +++ b/pqcrypto-mldsa/src/mldsa44.rs @@ -182,16 +182,13 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_MLDSA44_AVX2_crypto_sign_keypair); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - // always use AArch64 code, when target is detected as all AArch64 targets have NEON - // support, and std::is_aarch64_feature_detected!("neon") works only with Rust nightly at - // the moment - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return gen_keypair!(PQCLEAN_MLDSA44_AARCH64_crypto_sign_keypair); } } @@ -247,13 +244,13 @@ macro_rules! gen_signature_ctx { pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature!(PQCLEAN_MLDSA44_AVX2_crypto_sign, msg, sk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return gen_signature!(PQCLEAN_MLDSA44_AARCH64_crypto_sign, msg, sk); } } @@ -264,13 +261,13 @@ pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { pub fn sign_ctx(msg: &[u8], ctx: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature_ctx!(PQCLEAN_MLDSA44_AVX2_crypto_sign_ctx, msg, ctx, sk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return gen_signature_ctx!(PQCLEAN_MLDSA44_AARCH64_crypto_sign_ctx, msg, ctx, sk); } } @@ -333,13 +330,13 @@ pub fn open( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed!(PQCLEAN_MLDSA44_AVX2_crypto_sign_open, sm, pk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return open_signed!(PQCLEAN_MLDSA44_AARCH64_crypto_sign_open, sm, pk); } } @@ -354,13 +351,13 @@ pub fn open_ctx( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed_ctx!(PQCLEAN_MLDSA44_AVX2_crypto_sign_open_ctx, sm, ctx, pk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return open_signed_ctx!(PQCLEAN_MLDSA44_AARCH64_crypto_sign_open_ctx, sm, ctx, pk); } } @@ -408,13 +405,13 @@ macro_rules! detached_signature_ctx { pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature!(PQCLEAN_MLDSA44_AVX2_crypto_sign_signature, msg, sk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return detached_signature!(PQCLEAN_MLDSA44_AARCH64_crypto_sign_signature, msg, sk); } } @@ -425,7 +422,7 @@ pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { pub fn detached_sign_ctx(msg: &[u8], ctx: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature_ctx!( PQCLEAN_MLDSA44_AVX2_crypto_sign_signature_ctx, msg, @@ -434,9 +431,9 @@ pub fn detached_sign_ctx(msg: &[u8], ctx: &[u8], sk: &SecretKey) -> DetachedSign ); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return detached_signature_ctx!( PQCLEAN_MLDSA44_AARCH64_crypto_sign_signature_ctx, msg, @@ -504,13 +501,13 @@ pub fn verify_detached_signature( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig!(PQCLEAN_MLDSA44_AVX2_crypto_sign_verify, sig, msg, pk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return verify_detached_sig!(PQCLEAN_MLDSA44_AARCH64_crypto_sign_verify, sig, msg, pk); } } @@ -526,7 +523,7 @@ pub fn verify_detached_signature_ctx( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig_ctx!( PQCLEAN_MLDSA44_AVX2_crypto_sign_verify_ctx, sig, @@ -536,9 +533,9 @@ pub fn verify_detached_signature_ctx( ); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return verify_detached_sig_ctx!( PQCLEAN_MLDSA44_AARCH64_crypto_sign_verify_ctx, sig, diff --git a/pqcrypto-mldsa/src/mldsa65.rs b/pqcrypto-mldsa/src/mldsa65.rs index 826733b..a6dde45 100644 --- a/pqcrypto-mldsa/src/mldsa65.rs +++ b/pqcrypto-mldsa/src/mldsa65.rs @@ -182,16 +182,13 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_MLDSA65_AVX2_crypto_sign_keypair); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - // always use AArch64 code, when target is detected as all AArch64 targets have NEON - // support, and std::is_aarch64_feature_detected!("neon") works only with Rust nightly at - // the moment - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return gen_keypair!(PQCLEAN_MLDSA65_AARCH64_crypto_sign_keypair); } } @@ -247,13 +244,13 @@ macro_rules! gen_signature_ctx { pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature!(PQCLEAN_MLDSA65_AVX2_crypto_sign, msg, sk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return gen_signature!(PQCLEAN_MLDSA65_AARCH64_crypto_sign, msg, sk); } } @@ -264,13 +261,13 @@ pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { pub fn sign_ctx(msg: &[u8], ctx: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature_ctx!(PQCLEAN_MLDSA65_AVX2_crypto_sign_ctx, msg, ctx, sk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return gen_signature_ctx!(PQCLEAN_MLDSA65_AARCH64_crypto_sign_ctx, msg, ctx, sk); } } @@ -333,13 +330,13 @@ pub fn open( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed!(PQCLEAN_MLDSA65_AVX2_crypto_sign_open, sm, pk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return open_signed!(PQCLEAN_MLDSA65_AARCH64_crypto_sign_open, sm, pk); } } @@ -354,13 +351,13 @@ pub fn open_ctx( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed_ctx!(PQCLEAN_MLDSA65_AVX2_crypto_sign_open_ctx, sm, ctx, pk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return open_signed_ctx!(PQCLEAN_MLDSA65_AARCH64_crypto_sign_open_ctx, sm, ctx, pk); } } @@ -408,13 +405,13 @@ macro_rules! detached_signature_ctx { pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature!(PQCLEAN_MLDSA65_AVX2_crypto_sign_signature, msg, sk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return detached_signature!(PQCLEAN_MLDSA65_AARCH64_crypto_sign_signature, msg, sk); } } @@ -425,7 +422,7 @@ pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { pub fn detached_sign_ctx(msg: &[u8], ctx: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature_ctx!( PQCLEAN_MLDSA65_AVX2_crypto_sign_signature_ctx, msg, @@ -434,9 +431,9 @@ pub fn detached_sign_ctx(msg: &[u8], ctx: &[u8], sk: &SecretKey) -> DetachedSign ); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return detached_signature_ctx!( PQCLEAN_MLDSA65_AARCH64_crypto_sign_signature_ctx, msg, @@ -504,13 +501,13 @@ pub fn verify_detached_signature( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig!(PQCLEAN_MLDSA65_AVX2_crypto_sign_verify, sig, msg, pk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return verify_detached_sig!(PQCLEAN_MLDSA65_AARCH64_crypto_sign_verify, sig, msg, pk); } } @@ -526,7 +523,7 @@ pub fn verify_detached_signature_ctx( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig_ctx!( PQCLEAN_MLDSA65_AVX2_crypto_sign_verify_ctx, sig, @@ -536,9 +533,9 @@ pub fn verify_detached_signature_ctx( ); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return verify_detached_sig_ctx!( PQCLEAN_MLDSA65_AARCH64_crypto_sign_verify_ctx, sig, diff --git a/pqcrypto-mldsa/src/mldsa87.rs b/pqcrypto-mldsa/src/mldsa87.rs index 2fa1702..e402441 100644 --- a/pqcrypto-mldsa/src/mldsa87.rs +++ b/pqcrypto-mldsa/src/mldsa87.rs @@ -182,16 +182,13 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_MLDSA87_AVX2_crypto_sign_keypair); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - // always use AArch64 code, when target is detected as all AArch64 targets have NEON - // support, and std::is_aarch64_feature_detected!("neon") works only with Rust nightly at - // the moment - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return gen_keypair!(PQCLEAN_MLDSA87_AARCH64_crypto_sign_keypair); } } @@ -247,13 +244,13 @@ macro_rules! gen_signature_ctx { pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature!(PQCLEAN_MLDSA87_AVX2_crypto_sign, msg, sk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return gen_signature!(PQCLEAN_MLDSA87_AARCH64_crypto_sign, msg, sk); } } @@ -264,13 +261,13 @@ pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { pub fn sign_ctx(msg: &[u8], ctx: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature_ctx!(PQCLEAN_MLDSA87_AVX2_crypto_sign_ctx, msg, ctx, sk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return gen_signature_ctx!(PQCLEAN_MLDSA87_AARCH64_crypto_sign_ctx, msg, ctx, sk); } } @@ -333,13 +330,13 @@ pub fn open( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed!(PQCLEAN_MLDSA87_AVX2_crypto_sign_open, sm, pk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return open_signed!(PQCLEAN_MLDSA87_AARCH64_crypto_sign_open, sm, pk); } } @@ -354,13 +351,13 @@ pub fn open_ctx( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed_ctx!(PQCLEAN_MLDSA87_AVX2_crypto_sign_open_ctx, sm, ctx, pk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return open_signed_ctx!(PQCLEAN_MLDSA87_AARCH64_crypto_sign_open_ctx, sm, ctx, pk); } } @@ -408,13 +405,13 @@ macro_rules! detached_signature_ctx { pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature!(PQCLEAN_MLDSA87_AVX2_crypto_sign_signature, msg, sk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return detached_signature!(PQCLEAN_MLDSA87_AARCH64_crypto_sign_signature, msg, sk); } } @@ -425,7 +422,7 @@ pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { pub fn detached_sign_ctx(msg: &[u8], ctx: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature_ctx!( PQCLEAN_MLDSA87_AVX2_crypto_sign_signature_ctx, msg, @@ -434,9 +431,9 @@ pub fn detached_sign_ctx(msg: &[u8], ctx: &[u8], sk: &SecretKey) -> DetachedSign ); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return detached_signature_ctx!( PQCLEAN_MLDSA87_AARCH64_crypto_sign_signature_ctx, msg, @@ -504,13 +501,13 @@ pub fn verify_detached_signature( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig!(PQCLEAN_MLDSA87_AVX2_crypto_sign_verify, sig, msg, pk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return verify_detached_sig!(PQCLEAN_MLDSA87_AARCH64_crypto_sign_verify, sig, msg, pk); } } @@ -526,7 +523,7 @@ pub fn verify_detached_signature_ctx( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig_ctx!( PQCLEAN_MLDSA87_AVX2_crypto_sign_verify_ctx, sig, @@ -536,9 +533,9 @@ pub fn verify_detached_signature_ctx( ); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] + #[cfg(all(enable_aarch64_sha3, feature = "aarch64-sha3"))] { - if true { + if std::arch::is_aarch64_feature_detected!("sha3") { return verify_detached_sig_ctx!( PQCLEAN_MLDSA87_AARCH64_crypto_sign_verify_ctx, sig, diff --git a/pqcrypto-mlkem/build.rs b/pqcrypto-mlkem/build.rs index 969aa59..e37dba3 100644 --- a/pqcrypto-mlkem/build.rs +++ b/pqcrypto-mlkem/build.rs @@ -9,8 +9,10 @@ macro_rules! build_clean { let internals_include_path = &std::env::var("DEP_PQCRYPTO_INTERNALS_INCLUDEPATH").unwrap(); let common_dir = Path::new("pqclean/common"); + let implementation_dir = "clean"; + let mut builder = cc::Build::new(); - let target_dir: PathBuf = ["pqclean", "crypto_kem", $variant, "clean"] + let target_dir: PathBuf = ["pqclean", "crypto_kem", $variant, implementation_dir] .iter() .collect(); @@ -41,8 +43,12 @@ macro_rules! build_avx2 { let internals_include_path = &std::env::var("DEP_PQCRYPTO_INTERNALS_INCLUDEPATH").unwrap(); let common_dir = Path::new("pqclean/common"); + let implementation_dir = "avx2"; + let mut builder = cc::Build::new(); - let target_dir: PathBuf = ["pqclean", "crypto_kem", $variant, "avx2"].iter().collect(); + let target_dir: PathBuf = ["pqclean", "crypto_kem", $variant, implementation_dir] + .iter() + .collect(); let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); if target_os == "wasi" { @@ -83,8 +89,10 @@ macro_rules! build_aarch64 { let internals_include_path = &std::env::var("DEP_PQCRYPTO_INTERNALS_INCLUDEPATH").unwrap(); let common_dir = Path::new("pqclean/common"); + let implementation_dir = "aarch64"; + let mut builder = cc::Build::new(); - let target_dir: PathBuf = ["pqclean", "crypto_kem", $variant, "aarch64"] + let target_dir: PathBuf = ["pqclean", "crypto_kem", $variant, implementation_dir] .iter() .collect(); @@ -119,6 +127,8 @@ fn main() { #[allow(unused_variables)] let neon_enabled = env::var("CARGO_FEATURE_NEON").is_ok(); #[allow(unused_variables)] + let aarch64_sha3_enabled = env::var("CARGO_FEATURE_AARCH64_SHA3").is_ok(); + #[allow(unused_variables)] let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); #[allow(unused_variables)] let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); diff --git a/pqcrypto-mlkem/src/mlkem1024.rs b/pqcrypto-mlkem/src/mlkem1024.rs index 067ffec..9cc5cdc 100644 --- a/pqcrypto-mlkem/src/mlkem1024.rs +++ b/pqcrypto-mlkem/src/mlkem1024.rs @@ -132,16 +132,13 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_MLKEM1024_AVX2_crypto_kem_keypair); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - // always use AArch64 code, when target is detected as all AArch64 targets have NEON - // support, and std::is_aarch64_feature_detected!("neon") works only with Rust nightly at - // the moment - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return gen_keypair!(PQCLEAN_MLKEM1024_AARCH64_crypto_kem_keypair); } } @@ -164,13 +161,13 @@ macro_rules! encap { pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return encap!(PQCLEAN_MLKEM1024_AVX2_crypto_kem_enc, pk); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return encap!(PQCLEAN_MLKEM1024_AARCH64_crypto_kem_enc, pk); } } @@ -192,13 +189,13 @@ macro_rules! decap { pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return decap!(PQCLEAN_MLKEM1024_AVX2_crypto_kem_dec, ct, sk); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return decap!(PQCLEAN_MLKEM1024_AARCH64_crypto_kem_dec, ct, sk); } } diff --git a/pqcrypto-mlkem/src/mlkem512.rs b/pqcrypto-mlkem/src/mlkem512.rs index 5d4efcb..5a8772f 100644 --- a/pqcrypto-mlkem/src/mlkem512.rs +++ b/pqcrypto-mlkem/src/mlkem512.rs @@ -126,16 +126,13 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_MLKEM512_AVX2_crypto_kem_keypair); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - // always use AArch64 code, when target is detected as all AArch64 targets have NEON - // support, and std::is_aarch64_feature_detected!("neon") works only with Rust nightly at - // the moment - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return gen_keypair!(PQCLEAN_MLKEM512_AARCH64_crypto_kem_keypair); } } @@ -158,13 +155,13 @@ macro_rules! encap { pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return encap!(PQCLEAN_MLKEM512_AVX2_crypto_kem_enc, pk); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return encap!(PQCLEAN_MLKEM512_AARCH64_crypto_kem_enc, pk); } } @@ -186,13 +183,13 @@ macro_rules! decap { pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return decap!(PQCLEAN_MLKEM512_AVX2_crypto_kem_dec, ct, sk); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return decap!(PQCLEAN_MLKEM512_AARCH64_crypto_kem_dec, ct, sk); } } diff --git a/pqcrypto-mlkem/src/mlkem768.rs b/pqcrypto-mlkem/src/mlkem768.rs index 2895e1c..c31b05e 100644 --- a/pqcrypto-mlkem/src/mlkem768.rs +++ b/pqcrypto-mlkem/src/mlkem768.rs @@ -126,16 +126,13 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_MLKEM768_AVX2_crypto_kem_keypair); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - // always use AArch64 code, when target is detected as all AArch64 targets have NEON - // support, and std::is_aarch64_feature_detected!("neon") works only with Rust nightly at - // the moment - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return gen_keypair!(PQCLEAN_MLKEM768_AARCH64_crypto_kem_keypair); } } @@ -158,13 +155,13 @@ macro_rules! encap { pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return encap!(PQCLEAN_MLKEM768_AVX2_crypto_kem_enc, pk); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return encap!(PQCLEAN_MLKEM768_AARCH64_crypto_kem_enc, pk); } } @@ -186,13 +183,13 @@ macro_rules! decap { pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return decap!(PQCLEAN_MLKEM768_AVX2_crypto_kem_dec, ct, sk); } } #[cfg(all(enable_aarch64_neon, feature = "neon"))] { - if true { + if std::arch::is_aarch64_feature_detected!("neon") { return decap!(PQCLEAN_MLKEM768_AARCH64_crypto_kem_dec, ct, sk); } } diff --git a/pqcrypto-sphincsplus/build.rs b/pqcrypto-sphincsplus/build.rs index 013e61d..112a4ed 100644 --- a/pqcrypto-sphincsplus/build.rs +++ b/pqcrypto-sphincsplus/build.rs @@ -9,8 +9,10 @@ macro_rules! build_clean { let internals_include_path = &std::env::var("DEP_PQCRYPTO_INTERNALS_INCLUDEPATH").unwrap(); let common_dir = Path::new("pqclean/common"); + let implementation_dir = "clean"; + let mut builder = cc::Build::new(); - let target_dir: PathBuf = ["pqclean", "crypto_sign", $variant, "clean"] + let target_dir: PathBuf = ["pqclean", "crypto_sign", $variant, implementation_dir] .iter() .collect(); @@ -41,8 +43,10 @@ macro_rules! build_avx2 { let internals_include_path = &std::env::var("DEP_PQCRYPTO_INTERNALS_INCLUDEPATH").unwrap(); let common_dir = Path::new("pqclean/common"); + let implementation_dir = "avx2"; + let mut builder = cc::Build::new(); - let target_dir: PathBuf = ["pqclean", "crypto_sign", $variant, "avx2"] + let target_dir: PathBuf = ["pqclean", "crypto_sign", $variant, implementation_dir] .iter() .collect(); @@ -88,6 +92,8 @@ fn main() { #[allow(unused_variables)] let neon_enabled = env::var("CARGO_FEATURE_NEON").is_ok(); #[allow(unused_variables)] + let aarch64_sha3_enabled = env::var("CARGO_FEATURE_AARCH64_SHA3").is_ok(); + #[allow(unused_variables)] let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); #[allow(unused_variables)] let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); diff --git a/pqcrypto-sphincsplus/src/sphincssha2128fsimple.rs b/pqcrypto-sphincsplus/src/sphincssha2128fsimple.rs index 43b5d97..20d4066 100644 --- a/pqcrypto-sphincsplus/src/sphincssha2128fsimple.rs +++ b/pqcrypto-sphincsplus/src/sphincssha2128fsimple.rs @@ -189,7 +189,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_keypair); } } @@ -220,7 +220,7 @@ macro_rules! gen_signature { pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature!(PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign, msg, sk); } } @@ -257,7 +257,7 @@ pub fn open( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed!(PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_open, sm, pk); } } @@ -284,7 +284,7 @@ macro_rules! detached_signature { pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature!( PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_signature, msg, @@ -326,7 +326,7 @@ pub fn verify_detached_signature( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig!( PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_verify, sig, diff --git a/pqcrypto-sphincsplus/src/sphincssha2128ssimple.rs b/pqcrypto-sphincsplus/src/sphincssha2128ssimple.rs index b8dd9c7..56ea202 100644 --- a/pqcrypto-sphincsplus/src/sphincssha2128ssimple.rs +++ b/pqcrypto-sphincsplus/src/sphincssha2128ssimple.rs @@ -189,7 +189,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_keypair); } } @@ -220,7 +220,7 @@ macro_rules! gen_signature { pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature!(PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign, msg, sk); } } @@ -257,7 +257,7 @@ pub fn open( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed!(PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_open, sm, pk); } } @@ -284,7 +284,7 @@ macro_rules! detached_signature { pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature!( PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_signature, msg, @@ -326,7 +326,7 @@ pub fn verify_detached_signature( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig!( PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_verify, sig, diff --git a/pqcrypto-sphincsplus/src/sphincssha2192fsimple.rs b/pqcrypto-sphincsplus/src/sphincssha2192fsimple.rs index 70a04e3..84de3be 100644 --- a/pqcrypto-sphincsplus/src/sphincssha2192fsimple.rs +++ b/pqcrypto-sphincsplus/src/sphincssha2192fsimple.rs @@ -189,7 +189,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_keypair); } } @@ -220,7 +220,7 @@ macro_rules! gen_signature { pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature!(PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign, msg, sk); } } @@ -257,7 +257,7 @@ pub fn open( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed!(PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_open, sm, pk); } } @@ -284,7 +284,7 @@ macro_rules! detached_signature { pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature!( PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_signature, msg, @@ -326,7 +326,7 @@ pub fn verify_detached_signature( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig!( PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_verify, sig, diff --git a/pqcrypto-sphincsplus/src/sphincssha2192ssimple.rs b/pqcrypto-sphincsplus/src/sphincssha2192ssimple.rs index f23d110..71e2df2 100644 --- a/pqcrypto-sphincsplus/src/sphincssha2192ssimple.rs +++ b/pqcrypto-sphincsplus/src/sphincssha2192ssimple.rs @@ -189,7 +189,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_keypair); } } @@ -220,7 +220,7 @@ macro_rules! gen_signature { pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature!(PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign, msg, sk); } } @@ -257,7 +257,7 @@ pub fn open( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed!(PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_open, sm, pk); } } @@ -284,7 +284,7 @@ macro_rules! detached_signature { pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature!( PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_signature, msg, @@ -326,7 +326,7 @@ pub fn verify_detached_signature( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig!( PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_verify, sig, diff --git a/pqcrypto-sphincsplus/src/sphincssha2256fsimple.rs b/pqcrypto-sphincsplus/src/sphincssha2256fsimple.rs index c62e93a..0277268 100644 --- a/pqcrypto-sphincsplus/src/sphincssha2256fsimple.rs +++ b/pqcrypto-sphincsplus/src/sphincssha2256fsimple.rs @@ -189,7 +189,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_keypair); } } @@ -220,7 +220,7 @@ macro_rules! gen_signature { pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature!(PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign, msg, sk); } } @@ -257,7 +257,7 @@ pub fn open( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed!(PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_open, sm, pk); } } @@ -284,7 +284,7 @@ macro_rules! detached_signature { pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature!( PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_signature, msg, @@ -326,7 +326,7 @@ pub fn verify_detached_signature( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig!( PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_verify, sig, diff --git a/pqcrypto-sphincsplus/src/sphincssha2256ssimple.rs b/pqcrypto-sphincsplus/src/sphincssha2256ssimple.rs index a325c7c..0a44731 100644 --- a/pqcrypto-sphincsplus/src/sphincssha2256ssimple.rs +++ b/pqcrypto-sphincsplus/src/sphincssha2256ssimple.rs @@ -189,7 +189,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_SPHINCSSHA2256SSIMPLE_AVX2_crypto_sign_keypair); } } @@ -220,7 +220,7 @@ macro_rules! gen_signature { pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature!(PQCLEAN_SPHINCSSHA2256SSIMPLE_AVX2_crypto_sign, msg, sk); } } @@ -257,7 +257,7 @@ pub fn open( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed!(PQCLEAN_SPHINCSSHA2256SSIMPLE_AVX2_crypto_sign_open, sm, pk); } } @@ -284,7 +284,7 @@ macro_rules! detached_signature { pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature!( PQCLEAN_SPHINCSSHA2256SSIMPLE_AVX2_crypto_sign_signature, msg, @@ -326,7 +326,7 @@ pub fn verify_detached_signature( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig!( PQCLEAN_SPHINCSSHA2256SSIMPLE_AVX2_crypto_sign_verify, sig, diff --git a/pqcrypto-sphincsplus/src/sphincsshake128fsimple.rs b/pqcrypto-sphincsplus/src/sphincsshake128fsimple.rs index c76bf71..21e1918 100644 --- a/pqcrypto-sphincsplus/src/sphincsshake128fsimple.rs +++ b/pqcrypto-sphincsplus/src/sphincsshake128fsimple.rs @@ -189,7 +189,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_keypair); } } @@ -220,7 +220,7 @@ macro_rules! gen_signature { pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature!(PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign, msg, sk); } } @@ -257,7 +257,7 @@ pub fn open( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed!(PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_open, sm, pk); } } @@ -288,7 +288,7 @@ macro_rules! detached_signature { pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature!( PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_signature, msg, @@ -330,7 +330,7 @@ pub fn verify_detached_signature( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig!( PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_verify, sig, diff --git a/pqcrypto-sphincsplus/src/sphincsshake128ssimple.rs b/pqcrypto-sphincsplus/src/sphincsshake128ssimple.rs index e40af48..2322331 100644 --- a/pqcrypto-sphincsplus/src/sphincsshake128ssimple.rs +++ b/pqcrypto-sphincsplus/src/sphincsshake128ssimple.rs @@ -189,7 +189,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_keypair); } } @@ -220,7 +220,7 @@ macro_rules! gen_signature { pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature!(PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign, msg, sk); } } @@ -257,7 +257,7 @@ pub fn open( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed!(PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_open, sm, pk); } } @@ -288,7 +288,7 @@ macro_rules! detached_signature { pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature!( PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_signature, msg, @@ -330,7 +330,7 @@ pub fn verify_detached_signature( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig!( PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_verify, sig, diff --git a/pqcrypto-sphincsplus/src/sphincsshake192fsimple.rs b/pqcrypto-sphincsplus/src/sphincsshake192fsimple.rs index db1d08d..71301f4 100644 --- a/pqcrypto-sphincsplus/src/sphincsshake192fsimple.rs +++ b/pqcrypto-sphincsplus/src/sphincsshake192fsimple.rs @@ -189,7 +189,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_keypair); } } @@ -220,7 +220,7 @@ macro_rules! gen_signature { pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature!(PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign, msg, sk); } } @@ -257,7 +257,7 @@ pub fn open( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed!(PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_open, sm, pk); } } @@ -288,7 +288,7 @@ macro_rules! detached_signature { pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature!( PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_signature, msg, @@ -330,7 +330,7 @@ pub fn verify_detached_signature( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig!( PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_verify, sig, diff --git a/pqcrypto-sphincsplus/src/sphincsshake192ssimple.rs b/pqcrypto-sphincsplus/src/sphincsshake192ssimple.rs index 9a28792..c8ea234 100644 --- a/pqcrypto-sphincsplus/src/sphincsshake192ssimple.rs +++ b/pqcrypto-sphincsplus/src/sphincsshake192ssimple.rs @@ -189,7 +189,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_keypair); } } @@ -220,7 +220,7 @@ macro_rules! gen_signature { pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature!(PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign, msg, sk); } } @@ -257,7 +257,7 @@ pub fn open( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed!(PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_open, sm, pk); } } @@ -288,7 +288,7 @@ macro_rules! detached_signature { pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature!( PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_signature, msg, @@ -330,7 +330,7 @@ pub fn verify_detached_signature( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig!( PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_verify, sig, diff --git a/pqcrypto-sphincsplus/src/sphincsshake256fsimple.rs b/pqcrypto-sphincsplus/src/sphincsshake256fsimple.rs index 2b65f1d..9986bab 100644 --- a/pqcrypto-sphincsplus/src/sphincsshake256fsimple.rs +++ b/pqcrypto-sphincsplus/src/sphincsshake256fsimple.rs @@ -189,7 +189,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_keypair); } } @@ -220,7 +220,7 @@ macro_rules! gen_signature { pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature!(PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign, msg, sk); } } @@ -257,7 +257,7 @@ pub fn open( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed!(PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_open, sm, pk); } } @@ -288,7 +288,7 @@ macro_rules! detached_signature { pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature!( PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_signature, msg, @@ -330,7 +330,7 @@ pub fn verify_detached_signature( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig!( PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_verify, sig, diff --git a/pqcrypto-sphincsplus/src/sphincsshake256ssimple.rs b/pqcrypto-sphincsplus/src/sphincsshake256ssimple.rs index 50d6646..b0d3a15 100644 --- a/pqcrypto-sphincsplus/src/sphincsshake256ssimple.rs +++ b/pqcrypto-sphincsplus/src/sphincsshake256ssimple.rs @@ -189,7 +189,7 @@ macro_rules! gen_keypair { pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_keypair!(PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_keypair); } } @@ -220,7 +220,7 @@ macro_rules! gen_signature { pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return gen_signature!(PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign, msg, sk); } } @@ -257,7 +257,7 @@ pub fn open( ) -> core::result::Result, primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return open_signed!(PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_open, sm, pk); } } @@ -288,7 +288,7 @@ macro_rules! detached_signature { pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return detached_signature!( PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_signature, msg, @@ -330,7 +330,7 @@ pub fn verify_detached_signature( ) -> core::result::Result<(), primitive::VerificationError> { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { - if std::is_x86_feature_detected!("avx2") { + if std::arch::is_x86_feature_detected!("avx2") { return verify_detached_sig!( PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_verify, sig, diff --git a/pqcrypto-template/scheme/README.md.j2 b/pqcrypto-template/scheme/README.md.j2 index 06c7f62..68520d9 100644 --- a/pqcrypto-template/scheme/README.md.j2 +++ b/pqcrypto-template/scheme/README.md.j2 @@ -28,7 +28,9 @@ methods only. {% for scheme in schemes %} * ``{{ scheme.name }}`` {% for implementation in scheme.implementations %} -{% if implementation == 'avx2' or implementation == 'avx' or implementation == 'aesni' or implementation == 'aarch64' %} +{% if implementation == 'aarch64_sha3' %} + * ``aarch64`` (if supported) +{% elif implementation == 'avx2' or implementation == 'avx' or implementation == 'aesni' or implementation == 'aarch64' %} * ``{{ implementation }}`` (if supported) {% else %} * ``{{ implementation }}`` From 0132e2e41e980d766e870f5678cd0fcbadceac61 Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Mon, 3 Mar 2025 12:23:20 +0100 Subject: [PATCH 3/4] Bump versions --- implementations.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/implementations.yaml b/implementations.yaml index b387f81..a21bac4 100644 --- a/implementations.yaml +++ b/implementations.yaml @@ -5,7 +5,7 @@ traits_version: 0.3.5 kems: mlkem: - version: 0.1.0 + version: 0.1.1 x86_avx2_guard: 'target_arch == "x86_64" && avx2_enabled && !is_windows && !is_macos' implementations: [clean, avx2, aarch64] schemes: @@ -63,7 +63,7 @@ kems: signs: mldsa: - version: 0.1.1 + version: 0.2.0 x86_avx2_guard: 'target_arch == "x86_64" && avx2_enabled && !is_windows' implementations: [clean, avx2, aarch64_sha3] supports_context: true @@ -75,7 +75,7 @@ signs: - name: ml-dsa-87 implementations: [clean, avx2, aarch64_sha3] falcon: - version: 0.4.0 + version: 0.4.1 implementations: [clean, avx2, aarch64] schemes: - name: falcon-512 From 025c971a0e2d2711ca0cbe39987d2df12aeb6838 Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Mon, 3 Mar 2025 12:23:52 +0100 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 992120e..de4df64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 2025-03-03 +* Actually enable runtime feature detection on AArch64 + ## 2025-02-27 * Update PQClean to today's version * Update SPHINCS+ for some minor improvements. This is not yet SLH-DSA.