Skip to content

Put aarch64 simd feature behind nightly feature flag #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rust/bridge/ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ license = "AGPL-3.0-only"
name = "signal_ffi"
crate-type = ["staticlib"]

[features]
nightly = ["signal-crypto/nightly", "libsignal-protocol/nightly"]

[dependencies]
libsignal-protocol = { path = "../../protocol" }
device-transfer = { path = "../../device-transfer" }
Expand Down
3 changes: 3 additions & 0 deletions rust/bridge/jni/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ license = "AGPL-3.0-only"
name = "signal_jni"
crate-type = ["cdylib"]

[features]
nightly = ["libsignal-protocol/nightly", "signal-crypto/nightly"]

[dependencies]
libsignal-protocol = { path = "../../protocol" }
signal-crypto = { path = "../../crypto" }
Expand Down
3 changes: 3 additions & 0 deletions rust/bridge/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ edition = "2018"
name = "signal_node"
crate-type = ["cdylib"]

[features]
nightly = ["libsignal-protocol/nightly", "libsignal-bridge/nightly"]

[dependencies]
libsignal-protocol = { path = "../../protocol" }
libsignal-bridge = { path = "../shared", features = ["node"] }
Expand Down
1 change: 1 addition & 0 deletions rust/bridge/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ signal-neon-futures = { path = "../node/futures", optional = true }
ffi = ["libc", "libsignal-bridge-macros/ffi"]
jni = ["jni_crate", "libsignal-bridge-macros/jni"]
node = ["neon", "linkme", "signal-neon-futures", "libsignal-bridge-macros/node"]
nightly = ["signal-crypto/nightly", "libsignal-protocol/nightly"]
3 changes: 3 additions & 0 deletions rust/crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ rand = "0.7.3"
sha-1 = "0.9"
sha2 = "0.9"

[features]
nightly = []

[target.'cfg(all(target_arch = "aarch64", any(target_os = "linux")))'.dependencies]
libc = "0.2" # for getauxval

Expand Down
8 changes: 4 additions & 4 deletions rust/crypto/src/aes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
//

#[cfg(target_arch = "aarch64")]
#[cfg(all(target_arch = "aarch64", feature = "nightly"))]
mod aarch64;

use crate::error::{Error, Result};
Expand All @@ -17,7 +17,7 @@ pub enum Aes256 {
Soft(aes_soft::Aes256),
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
AesNi(aesni::Aes256),
#[cfg(target_arch = "aarch64")]
#[cfg(all(target_arch = "aarch64", feature = "nightly"))]
Aarch64(aarch64::Aes256Aarch64),
}

Expand All @@ -27,7 +27,7 @@ impl Aes256 {
return Err(Error::InvalidKeySize);
}

#[cfg(target_arch = "aarch64")]
#[cfg(all(target_arch = "aarch64", feature = "nightly"))]
{
if crate::cpuid::has_armv8_crypto() {
unsafe {
Expand Down Expand Up @@ -85,7 +85,7 @@ impl Aes256 {
Aes256::Soft(aes) => trait_encrypt(aes, buf),
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Aes256::AesNi(aes) => trait_encrypt(aes, buf),
#[cfg(target_arch = "aarch64")]
#[cfg(all(target_arch = "aarch64", feature = "nightly"))]
Aes256::Aarch64(aes) => unsafe { aes.encrypt(buf) },
}
}
Expand Down
5 changes: 3 additions & 2 deletions rust/crypto/src/cpuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@
// SPDX-License-Identifier: AGPL-3.0-only
//

#[cfg(all(target_arch = "aarch64", target_os = "linux"))]
#[cfg(all(target_arch = "aarch64", feature = "nightly", target_os = "linux"))]
pub fn has_armv8_crypto() -> bool {
// Require NEON, AES and PMULL
let hwcap_crypto = (1 << 1) | (1 << 3) | (1 << 4);
let hwcap = unsafe { libc::getauxval(libc::AT_HWCAP) };
hwcap & hwcap_crypto == hwcap_crypto
}

#[cfg(all(target_arch = "aarch64", target_os = "ios"))]
#[cfg(all(target_arch = "aarch64", feature = "nightly", target_os = "ios"))]
pub fn has_armv8_crypto() -> bool {
// All 64-bit iOS devices have AES/PMUL support
true
}

#[cfg(all(
target_arch = "aarch64",
feature = "nightly",
not(any(target_os = "linux", target_os = "ios"))
))]
pub fn has_armv8_crypto() -> bool {
Expand Down
7 changes: 5 additions & 2 deletions rust/crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
// SPDX-License-Identifier: AGPL-3.0-only
//

#![cfg_attr(target_arch = "aarch64", feature(stdsimd))]
#![cfg_attr(target_arch = "aarch64", feature(aarch64_target_feature))]
#![cfg_attr(all(target_arch = "aarch64", feature = "nightly"), feature(stdsimd))]
#![cfg_attr(
all(target_arch = "aarch64", feature = "nightly"),
feature(aarch64_target_feature)
)]
#![deny(clippy::unwrap_used)]

mod error;
Expand Down
12 changes: 6 additions & 6 deletions rust/crypto/src/polyval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ mod polyval_soft;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod polyval_clmul;

#[cfg(target_arch = "aarch64")]
#[cfg(all(target_arch = "aarch64", feature = "nightly"))]
mod polyval_pmul;

#[derive(Clone)]
pub enum Polyval {
Soft(polyval_soft::PolyvalSoft),
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Clmul(polyval_clmul::PolyvalClmul),
#[cfg(target_arch = "aarch64")]
#[cfg(all(target_arch = "aarch64", feature = "nightly"))]
Pmul(polyval_pmul::PolyvalPmul),
}

Expand All @@ -35,7 +35,7 @@ impl Polyval {
}
}

#[cfg(target_arch = "aarch64")]
#[cfg(all(target_arch = "aarch64", feature = "nightly"))]
{
if crate::cpuid::has_armv8_crypto() {
return Ok(Polyval::Pmul(polyval_pmul::PolyvalPmul::new(key)?));
Expand All @@ -54,7 +54,7 @@ impl Polyval {
Polyval::Soft(polyval) => polyval.update(data),
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Polyval::Clmul(polyval) => polyval.update(data),
#[cfg(target_arch = "aarch64")]
#[cfg(all(target_arch = "aarch64", feature = "nightly"))]
Polyval::Pmul(polyval) => polyval.update(data),
}
}
Expand All @@ -64,7 +64,7 @@ impl Polyval {
Polyval::Soft(polyval) => polyval.update_padded(data),
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Polyval::Clmul(polyval) => polyval.update_padded(data),
#[cfg(target_arch = "aarch64")]
#[cfg(all(target_arch = "aarch64", feature = "nightly"))]
Polyval::Pmul(polyval) => polyval.update_padded(data),
}
}
Expand All @@ -74,7 +74,7 @@ impl Polyval {
Polyval::Soft(polyval) => polyval.finalize(),
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Polyval::Clmul(polyval) => polyval.finalize(),
#[cfg(target_arch = "aarch64")]
#[cfg(all(target_arch = "aarch64", feature = "nightly"))]
Polyval::Pmul(polyval) => polyval.finalize(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion rust/protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ default = ["u64_backend"]
u32_backend = ["curve25519-dalek/u32_backend"]
u64_backend = ["curve25519-dalek/u64_backend"]
simd_backend = ["curve25519-dalek/simd_backend"]
nightly = ["curve25519-dalek/nightly"]
nightly = ["curve25519-dalek/nightly", "signal-crypto/nightly"]

[dev-dependencies]
criterion = "0.3"
Expand Down