Skip to content
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

Aarch64 feature detection #83

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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 CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 4 additions & 0 deletions generate-implementations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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(
Expand Down Expand Up @@ -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()
Expand Down
14 changes: 7 additions & 7 deletions implementations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -63,19 +63,19 @@ 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]
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
version: 0.4.1
implementations: [clean, avx2, aarch64]
schemes:
- name: falcon-512
Expand Down
12 changes: 10 additions & 2 deletions pqcrypto-classicmceliece/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions pqcrypto-classicmceliece/src/mceliece348864.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions pqcrypto-classicmceliece/src/mceliece348864f.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions pqcrypto-classicmceliece/src/mceliece460896.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions pqcrypto-classicmceliece/src/mceliece460896f.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions pqcrypto-classicmceliece/src/mceliece6688128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions pqcrypto-classicmceliece/src/mceliece6688128f.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions pqcrypto-classicmceliece/src/mceliece6960119.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions pqcrypto-classicmceliece/src/mceliece6960119f.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions pqcrypto-classicmceliece/src/mceliece8192128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions pqcrypto-classicmceliece/src/mceliece8192128f.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down
Loading