diff --git a/build.rs b/build.rs index daf2ebfbbd..b632ea628d 100644 --- a/build.rs +++ b/build.rs @@ -269,6 +269,12 @@ const MACOS_ABI: &[&str] = &["ios", MACOS, "tvos"]; const MACOS: &str = "macos"; const WINDOWS: &str = "windows"; +fn find_asm_target(target: &Target) -> Option<&'static AsmTarget> { + ASM_TARGETS.iter().find(|asm_target| { + asm_target.arch == target.arch && asm_target.oss.contains(&target.os.as_ref()) + }) +} + /// Read an environment variable and tell Cargo that we depend on it. /// /// This needs to be used for any environment variable that isn't a standard @@ -418,10 +424,6 @@ fn build_c_code( ) { println!("cargo:rustc-env=RING_CORE_PREFIX={}", ring_core_prefix); - let asm_target = ASM_TARGETS.iter().find(|asm_target| { - asm_target.arch == target.arch && asm_target.oss.contains(&target.os.as_ref()) - }); - let asm_dir = if use_pregenerated { &pregenerated } else { @@ -433,7 +435,9 @@ fn build_c_code( generate_prefix_symbols_asm_headers(out_dir, ring_core_prefix).unwrap(); - let (asm_srcs, obj_srcs) = if let Some(asm_target) = asm_target { + let (asm_srcs, obj_srcs) = if let Some(asm_target) = find_asm_target(target) { + println!("cargo:rustc-cfg=have_perlasm"); + let perlasm_src_dsts = perlasm_src_dsts(asm_dir, asm_target); if !use_pregenerated { @@ -617,6 +621,10 @@ fn configure_cc(c: &mut cc::Build, target: &Target, include_dir: &Path) { if target.force_warnings_into_errors { c.warnings_into_errors(true); } + + if find_asm_target(target).is_some() { + let _ = c.define("RING_HAVE_PERLASM", "1"); + } } /// Assembles the assemply language source `file` into the object file diff --git a/crypto/fipsmodule/ec/p256_shared.h b/crypto/fipsmodule/ec/p256_shared.h index 648619907a..18aedb8b05 100644 --- a/crypto/fipsmodule/ec/p256_shared.h +++ b/crypto/fipsmodule/ec/p256_shared.h @@ -24,7 +24,7 @@ #include "../bn/internal.h" #if !defined(OPENSSL_NO_ASM) && \ - (defined(OPENSSL_X86_64) || defined(OPENSSL_AARCH64)) && \ + defined(RING_HAVE_PERLASM) && \ !defined(OPENSSL_SMALL) # define OPENSSL_USE_NISTZ256 #endif diff --git a/src/aead/aes.rs b/src/aead/aes.rs index 604f480b04..4789f1383e 100644 --- a/src/aead/aes.rs +++ b/src/aead/aes.rs @@ -145,21 +145,27 @@ impl Key { }; match detect_implementation(cpu_features) { - #[cfg(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86_64", - target_arch = "x86" + #[cfg(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86_64", + target_arch = "x86" + ) ))] Implementation::HWAES => { set_encrypt_key!(aes_hw_set_encrypt_key, bytes, key_bits, &mut key)? } - #[cfg(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86_64", - target_arch = "x86" + #[cfg(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86_64", + target_arch = "x86" + ) ))] Implementation::VPAES_BSAES => { set_encrypt_key!(vpaes_set_encrypt_key, bytes, key_bits, &mut key)? @@ -176,19 +182,25 @@ impl Key { #[inline] pub fn encrypt_block(&self, a: Block, cpu_features: cpu::Features) -> Block { match detect_implementation(cpu_features) { - #[cfg(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86_64", - target_arch = "x86" + #[cfg(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86_64", + target_arch = "x86" + ) ))] Implementation::HWAES => encrypt_block!(aes_hw_encrypt, a, self), - #[cfg(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86_64", - target_arch = "x86" + #[cfg(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86_64", + target_arch = "x86" + ) ))] Implementation::VPAES_BSAES => encrypt_block!(vpaes_encrypt, a, self), @@ -215,17 +227,23 @@ impl Key { assert_eq!(in_out_len % BLOCK_LEN, 0); match detect_implementation(cpu_features) { - #[cfg(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86_64", - target_arch = "x86" + #[cfg(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86_64", + target_arch = "x86" + ) ))] Implementation::HWAES => { ctr32_encrypt_blocks!(aes_hw_ctr32_encrypt_blocks, in_out, src, &self.inner, ctr) } - #[cfg(any(target_arch = "aarch64", target_arch = "arm", target_arch = "x86_64"))] + #[cfg(all( + have_perlasm, + any(target_arch = "aarch64", target_arch = "arm", target_arch = "x86_64") + ))] Implementation::VPAES_BSAES => { // 8 blocks is the cut-off point where it's faster to use BSAES. #[cfg(target_arch = "arm")] @@ -285,7 +303,7 @@ impl Key { out } - #[cfg(target_arch = "x86_64")] + #[cfg(all(have_perlasm, target_arch = "x86_64"))] #[must_use] pub fn is_aes_hw(&self, cpu_features: cpu::Features) -> bool { matches!(detect_implementation(cpu_features), Implementation::HWAES) @@ -361,20 +379,26 @@ impl Iv { #[derive(Clone, Copy)] #[allow(clippy::upper_case_acronyms)] pub enum Implementation { - #[cfg(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86_64", - target_arch = "x86" + #[cfg(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86_64", + target_arch = "x86" + ) ))] HWAES = 1, // On "arm" only, this indicates that the bsaes implementation may be used. - #[cfg(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86_64", - target_arch = "x86" + #[cfg(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86_64", + target_arch = "x86" + ) ))] VPAES_BSAES = 2, @@ -383,36 +407,39 @@ pub enum Implementation { fn detect_implementation(cpu_features: cpu::Features) -> Implementation { // `cpu_features` is only used for specific platforms. - #[cfg(not(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86_64", - target_arch = "x86" + #[cfg(not(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86_64", + target_arch = "x86" + ) )))] let _cpu_features = cpu_features; - #[cfg(any(target_arch = "aarch64", target_arch = "arm"))] + #[cfg(all(have_perlasm, any(target_arch = "aarch64", target_arch = "arm")))] { if cpu::arm::AES.available(cpu_features) { return Implementation::HWAES; } } - #[cfg(any(target_arch = "x86_64", target_arch = "x86"))] + #[cfg(all(have_perlasm, any(target_arch = "x86_64", target_arch = "x86")))] { if cpu::intel::AES.available(cpu_features) { return Implementation::HWAES; } } - #[cfg(any(target_arch = "x86_64", target_arch = "x86"))] + #[cfg(all(have_perlasm, any(target_arch = "x86_64", target_arch = "x86")))] { if cpu::intel::SSSE3.available(cpu_features) { return Implementation::VPAES_BSAES; } } - #[cfg(any(target_arch = "aarch64", target_arch = "arm"))] + #[cfg(all(have_perlasm, any(target_arch = "aarch64", target_arch = "arm")))] { if cpu::arm::NEON.available(cpu_features) { return Implementation::VPAES_BSAES; diff --git a/src/aead/aes_gcm.rs b/src/aead/aes_gcm.rs index 73e4ef6cef..4adf863da3 100644 --- a/src/aead/aes_gcm.rs +++ b/src/aead/aes_gcm.rs @@ -91,7 +91,7 @@ fn aes_gcm_seal( let aad_len = aad.0.len(); let mut auth = gcm::Context::new(gcm_key, aad, cpu_features); - #[cfg(target_arch = "x86_64")] + #[cfg(all(have_perlasm, target_arch = "x86_64"))] let in_out = { if !aes_key.is_aes_hw(cpu_features) || !auth.is_avx() { in_out @@ -179,7 +179,7 @@ fn aes_gcm_open( let total_in_out_len = in_out.len() - in_prefix_len; - #[cfg(target_arch = "x86_64")] + #[cfg(all(have_perlasm, target_arch = "x86_64"))] let in_out = { if !aes_key.is_aes_hw(cpu_features) || !auth.is_avx() { in_out diff --git a/src/aead/chacha.rs b/src/aead/chacha.rs index a8771b4a9c..02ce429811 100644 --- a/src/aead/chacha.rs +++ b/src/aead/chacha.rs @@ -17,11 +17,14 @@ use super::{quic::Sample, Nonce}; #[cfg(any( test, - not(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86", - target_arch = "x86_64" + not(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86", + target_arch = "x86_64" + ) )) ))] mod fallback; @@ -88,11 +91,14 @@ impl Key { /// Only call this with `src` equal to `0..` or from `encrypt_within`. #[inline] fn encrypt_less_safe(&self, counter: Counter, in_out: &mut [u8], src: RangeFrom) { - #[cfg(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86", - target_arch = "x86_64" + #[cfg(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86", + target_arch = "x86_64" + ) ))] #[inline(always)] pub(super) fn ChaCha20_ctr32( @@ -125,11 +131,14 @@ impl Key { } } - #[cfg(not(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86", - target_arch = "x86_64" + #[cfg(not(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86", + target_arch = "x86_64" + ) )))] use fallback::ChaCha20_ctr32; @@ -166,11 +175,14 @@ impl Counter { /// the caller. #[cfg(any( test, - not(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86", - target_arch = "x86_64" + not(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86", + target_arch = "x86_64" + ) )) ))] fn into_words_less_safe(self) -> [u32; 4] { diff --git a/src/aead/chacha20_poly1305.rs b/src/aead/chacha20_poly1305.rs index 1c1c7b7bc7..e29f1be6e5 100644 --- a/src/aead/chacha20_poly1305.rs +++ b/src/aead/chacha20_poly1305.rs @@ -57,7 +57,7 @@ fn chacha20_poly1305_seal( _ => unreachable!(), }; - #[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))] + #[cfg(all(have_perlasm, any(target_arch = "aarch64", target_arch = "x86_64")))] if has_integrated(cpu_features) { // XXX: BoringSSL uses `alignas(16)` on `key` instead of on the // structure, but Rust can't do that yet; see @@ -137,7 +137,7 @@ fn chacha20_poly1305_open( _ => unreachable!(), }; - #[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))] + #[cfg(all(have_perlasm, any(target_arch = "aarch64", target_arch = "x86_64")))] if has_integrated(cpu_features) { // XXX: BoringSSL uses `alignas(16)` on `key` instead of on the // structure, but Rust can't do that yet; see @@ -200,7 +200,7 @@ fn chacha20_poly1305_open( finish(auth, aad.as_ref().len(), in_out[src].len()) } -#[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))] +#[cfg(all(have_perlasm, any(target_arch = "aarch64", target_arch = "x86_64")))] #[allow(clippy::needless_return)] #[inline(always)] fn has_integrated(cpu_features: cpu::Features) -> bool { diff --git a/src/aead/gcm.rs b/src/aead/gcm.rs index 78ff8fd351..a09469b9b2 100644 --- a/src/aead/gcm.rs +++ b/src/aead/gcm.rs @@ -38,7 +38,7 @@ impl Key { let h_table = &mut key.h_table; match detect_implementation(cpu_features) { - #[cfg(target_arch = "x86_64")] + #[cfg(all(have_perlasm, target_arch = "x86_64"))] Implementation::CLMUL if has_avx_movbe(cpu_features) => { prefixed_extern! { fn gcm_init_avx(HTable: &mut HTable, h: &[u64; 2]); @@ -48,11 +48,14 @@ impl Key { } } - #[cfg(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86_64", - target_arch = "x86" + #[cfg(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86_64", + target_arch = "x86" + ) ))] Implementation::CLMUL => { prefixed_extern! { @@ -63,7 +66,7 @@ impl Key { } } - #[cfg(any(target_arch = "aarch64", target_arch = "arm"))] + #[cfg(all(have_perlasm, any(target_arch = "aarch64", target_arch = "arm")))] Implementation::NEON => { prefixed_extern! { fn gcm_init_neon(Htable: &mut HTable, h: &[u64; 2]); @@ -133,7 +136,7 @@ impl Context { let h_table = &self.inner.Htable; match detect_implementation(self.cpu_features) { - #[cfg(target_arch = "x86_64")] + #[cfg(all(have_perlasm, target_arch = "x86_64"))] Implementation::CLMUL if has_avx_movbe(self.cpu_features) => { prefixed_extern! { fn gcm_ghash_avx( @@ -148,11 +151,14 @@ impl Context { } } - #[cfg(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86_64", - target_arch = "x86" + #[cfg(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86_64", + target_arch = "x86" + ) ))] Implementation::CLMUL => { prefixed_extern! { @@ -168,7 +174,7 @@ impl Context { } } - #[cfg(any(target_arch = "aarch64", target_arch = "arm"))] + #[cfg(all(have_perlasm, any(target_arch = "aarch64", target_arch = "arm")))] Implementation::NEON => { prefixed_extern! { fn gcm_ghash_neon( @@ -199,11 +205,14 @@ impl Context { let h_table = &self.inner.Htable; match detect_implementation(self.cpu_features) { - #[cfg(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86_64", - target_arch = "x86" + #[cfg(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86_64", + target_arch = "x86" + ) ))] Implementation::CLMUL => { prefixed_extern! { @@ -214,7 +223,7 @@ impl Context { } } - #[cfg(any(target_arch = "aarch64", target_arch = "arm"))] + #[cfg(all(have_perlasm, any(target_arch = "aarch64", target_arch = "arm")))] Implementation::NEON => { prefixed_extern! { fn gcm_gmult_neon(xi: &mut Xi, Htable: &HTable); @@ -237,7 +246,7 @@ impl Context { f(self.inner.Xi.0) } - #[cfg(target_arch = "x86_64")] + #[cfg(all(have_perlasm, target_arch = "x86_64"))] pub(super) fn is_avx(&self) -> bool { match detect_implementation(self.cpu_features) { Implementation::CLMUL => has_avx_movbe(self.cpu_features), @@ -290,15 +299,18 @@ struct ContextInner { #[allow(clippy::upper_case_acronyms)] enum Implementation { - #[cfg(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86_64", - target_arch = "x86" + #[cfg(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86_64", + target_arch = "x86" + ) ))] CLMUL, - #[cfg(any(target_arch = "aarch64", target_arch = "arm"))] + #[cfg(all(have_perlasm, any(target_arch = "aarch64", target_arch = "arm")))] NEON, Fallback, @@ -307,22 +319,25 @@ enum Implementation { #[inline] fn detect_implementation(cpu_features: cpu::Features) -> Implementation { // `cpu_features` is only used for specific platforms. - #[cfg(not(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86_64", - target_arch = "x86" + #[cfg(not(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86_64", + target_arch = "x86" + ) )))] let _cpu_features = cpu_features; - #[cfg(any(target_arch = "aarch64", target_arch = "arm"))] + #[cfg(all(have_perlasm, any(target_arch = "aarch64", target_arch = "arm")))] { if cpu::arm::PMULL.available(cpu_features) { return Implementation::CLMUL; } } - #[cfg(any(target_arch = "x86_64", target_arch = "x86"))] + #[cfg(all(have_perlasm, any(target_arch = "x86_64", target_arch = "x86")))] { if cpu::intel::FXSR.available(cpu_features) && cpu::intel::PCLMULQDQ.available(cpu_features) { @@ -330,7 +345,7 @@ fn detect_implementation(cpu_features: cpu::Features) -> Implementation { } } - #[cfg(any(target_arch = "aarch64", target_arch = "arm"))] + #[cfg(all(have_perlasm, any(target_arch = "aarch64", target_arch = "arm")))] { if cpu::arm::NEON.available(cpu_features) { return Implementation::NEON; diff --git a/src/arithmetic/bigint.rs b/src/arithmetic/bigint.rs index b326c35e74..cb21fd0f21 100644 --- a/src/arithmetic/bigint.rs +++ b/src/arithmetic/bigint.rs @@ -104,7 +104,7 @@ fn from_montgomery_amm(limbs: BoxedLimbs, m: &Modulus) -> Elem Elem { #[inline] pub fn into_unencoded(self, m: &Modulus) -> Elem { @@ -399,7 +399,7 @@ pub(crate) fn elem_exp_vartime( acc } -#[cfg(not(target_arch = "x86_64"))] +#[cfg(not(all(have_perlasm, target_arch = "x86_64")))] pub fn elem_exp_consttime( base: Elem, exponent: &PrivateExponent, @@ -485,7 +485,7 @@ pub fn elem_exp_consttime( Ok(acc.into_unencoded(m)) } -#[cfg(target_arch = "x86_64")] +#[cfg(all(have_perlasm, target_arch = "x86_64"))] pub fn elem_exp_consttime( base: Elem, exponent: &PrivateExponent, diff --git a/src/arithmetic/montgomery.rs b/src/arithmetic/montgomery.rs index b3bed1b14c..16d8b0f1e4 100644 --- a/src/arithmetic/montgomery.rs +++ b/src/arithmetic/montgomery.rs @@ -125,11 +125,14 @@ unsafe fn mul_mont( bn_mul_mont(r, a, b, n, n0, num_limbs) } -#[cfg(not(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86", - target_arch = "x86_64" +#[cfg(not(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86", + target_arch = "x86_64" + ) )))] // TODO: Stop calling this from C and un-export it. #[allow(deprecated)] @@ -165,11 +168,14 @@ prefixed_export! { // we are using the platforms for which we don't have `bn_mul_mont` in assembly. #[cfg(any( feature = "alloc", - not(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86", - target_arch = "x86_64" + not(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86", + target_arch = "x86_64" + ) )) ))] pub(super) fn limbs_from_mont_in_place(r: &mut [Limb], tmp: &mut [Limb], m: &[Limb], n0: &N0) { @@ -198,11 +204,14 @@ pub(super) fn limbs_from_mont_in_place(r: &mut [Limb], tmp: &mut [Limb], m: &[Li .unwrap() } -#[cfg(not(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86", - target_arch = "x86_64" +#[cfg(not(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86", + target_arch = "x86_64" + ) )))] fn limbs_mul(r: &mut [Limb], a: &[Limb], b: &[Limb]) { debug_assert_eq!(r.len(), 2 * a.len()); @@ -219,11 +228,14 @@ fn limbs_mul(r: &mut [Limb], a: &[Limb], b: &[Limb]) { #[cfg(any( test, - not(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86_64", - target_arch = "x86" + not(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86_64", + target_arch = "x86" + ) )) ))] prefixed_extern! { @@ -232,11 +244,14 @@ prefixed_extern! { fn limbs_mul_add_limb(r: *mut Limb, a: *const Limb, b: Limb, num_limbs: c::size_t) -> Limb; } -#[cfg(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86_64", - target_arch = "x86" +#[cfg(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86_64", + target_arch = "x86" + ) ))] prefixed_extern! { // `r` and/or 'a' and/or 'b' may alias. @@ -274,7 +289,7 @@ pub(super) fn limbs_mont_mul( } /// r = a * b -#[cfg(not(target_arch = "x86_64"))] +#[cfg(not(all(have_perlasm, target_arch = "x86_64")))] pub(super) fn limbs_mont_product( r: &mut [Limb], a: &[Limb], diff --git a/src/digest/sha2.rs b/src/digest/sha2.rs index 16a0556bec..e9d784469b 100644 --- a/src/digest/sha2.rs +++ b/src/digest/sha2.rs @@ -18,7 +18,10 @@ use core::{ ops::{Add, AddAssign, BitAnd, BitOr, BitXor, Not, Shr}, }; -#[cfg(not(any(target_arch = "aarch64", target_arch = "arm", target_arch = "x86_64")))] +#[cfg(not(all( + have_perlasm, + any(target_arch = "aarch64", target_arch = "arm", target_arch = "x86_64") +)))] pub(super) extern "C" fn sha256_block_data_order( state: &mut super::State, data: *const u8, @@ -28,7 +31,10 @@ pub(super) extern "C" fn sha256_block_data_order( *state = block_data_order(*state, data, num) } -#[cfg(not(any(target_arch = "aarch64", target_arch = "arm", target_arch = "x86_64")))] +#[cfg(not(all( + have_perlasm, + any(target_arch = "aarch64", target_arch = "arm", target_arch = "x86_64") +)))] pub(super) extern "C" fn sha512_block_data_order( state: &mut super::State, data: *const u8, @@ -370,7 +376,10 @@ impl Sha2 for Wrapping { ]; } -#[cfg(any(target_arch = "aarch64", target_arch = "arm", target_arch = "x86_64"))] +#[cfg(all( + have_perlasm, + any(target_arch = "aarch64", target_arch = "arm", target_arch = "x86_64") +))] prefixed_extern! { pub(super) fn sha256_block_data_order( state: &mut super::State, diff --git a/src/ec/suite_b/ops.rs b/src/ec/suite_b/ops.rs index 15be579828..63c0dac6d5 100644 --- a/src/ec/suite_b/ops.rs +++ b/src/ec/suite_b/ops.rs @@ -625,7 +625,7 @@ mod tests { } // There is no `ecp_nistz256_neg` on other targets. - #[cfg(target_arch = "x86_64")] + #[cfg(all(have_perlasm, target_arch = "x86_64"))] #[test] fn p256_elem_neg_test() { prefixed_extern! { diff --git a/src/ec/suite_b/ops/p256.rs b/src/ec/suite_b/ops/p256.rs index 6b0323cb41..450b9e656a 100644 --- a/src/ec/suite_b/ops/p256.rs +++ b/src/ec/suite_b/ops/p256.rs @@ -121,10 +121,10 @@ pub static PUBLIC_SCALAR_OPS: PublicScalarOps = PublicScalarOps { scalar_ops: &SCALAR_OPS, public_key_ops: &PUBLIC_KEY_OPS, - #[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))] + #[cfg(all(have_perlasm, any(target_arch = "aarch64", target_arch = "x86_64")))] twin_mul: twin_mul_nistz256, - #[cfg(not(any(target_arch = "aarch64", target_arch = "x86_64")))] + #[cfg(not(all(have_perlasm, any(target_arch = "aarch64", target_arch = "x86_64"))))] twin_mul: |g_scalar, p_scalar, p_xy| { twin_mul_inefficient(&PRIVATE_KEY_OPS, g_scalar, p_scalar, p_xy) }, @@ -135,14 +135,14 @@ pub static PUBLIC_SCALAR_OPS: PublicScalarOps = PublicScalarOps { scalar_inv_to_mont_vartime: |s| PRIVATE_SCALAR_OPS.scalar_inv_to_mont(s), }; -#[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))] +#[cfg(all(have_perlasm, any(target_arch = "aarch64", target_arch = "x86_64")))] fn twin_mul_nistz256(g_scalar: &Scalar, p_scalar: &Scalar, p_xy: &(Elem, Elem)) -> Point { let scaled_g = point_mul_base_vartime(g_scalar); let scaled_p = PRIVATE_KEY_OPS.point_mul(p_scalar, p_xy); PRIVATE_KEY_OPS.common.point_sum(&scaled_g, &scaled_p) } -#[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))] +#[cfg(all(have_perlasm, any(target_arch = "aarch64", target_arch = "x86_64")))] fn point_mul_base_vartime(g_scalar: &Scalar) -> Point { prefixed_extern! { fn p256_point_mul_base_vartime(r: *mut Limb, // [3][COMMON_OPS.num_limbs] @@ -316,7 +316,7 @@ prefixed_extern! { #[cfg(test)] mod tests { - #[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))] + #[cfg(all(have_perlasm, any(target_arch = "aarch64", target_arch = "x86_64")))] #[test] fn p256_point_mul_base_vartime_test() { use super::{super::tests::point_mul_base_tests, *}; diff --git a/src/prefixed.rs b/src/prefixed.rs index 6e657e71f9..00e9608fb6 100644 --- a/src/prefixed.rs +++ b/src/prefixed.rs @@ -41,11 +41,14 @@ macro_rules! prefixed_extern { } #[deprecated = "`#[export_name]` creates problems and we will stop doing it."] -#[cfg(not(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "x86", - target_arch = "x86_64" +#[cfg(not(all( + have_perlasm, + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "x86", + target_arch = "x86_64" + ) )))] macro_rules! prefixed_export { // A function.