Skip to content

Commit 4c07016

Browse files
committed
implement runtime feature detection for Aarch64
Enable AArch64 feature detection Bump versions Update changelog Include ml-kem, bump versions Falcon should not be bumped Should be a semantic bump
1 parent c83c48b commit 4c07016

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+625
-450
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 2025-03-03
4+
* Actually enable runtime feature detection on AArch64
5+
36
## 2025-02-27
47
* Update PQClean to today's version
58
* Update SPHINCS+ for some minor improvements. This is not yet SLH-DSA.

generate-implementations.py

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
DEFAULT_X86_AES_GUARD = 'target_arch == "x86_64" && aes_enabled'
1212
DEFAULT_X86_AVX2_GUARD = 'target_arch == "x86_64" && avx2_enabled'
1313
DEFAULT_AARCH64_NEON_GUARD = 'target_arch == "aarch64" && neon_enabled'
14+
DEFAULT_AARCH64_SHA3_GUARD = 'target_arch == "aarch64" && aarch64_sha3_enabled'
1415

1516

1617
def read_yaml():
@@ -33,6 +34,8 @@ def nameize(value):
3334

3435
def render_template(target_dir, target_file, template_file, **templ_vars):
3536
def namespaceize(value):
37+
if value == "aarch64_sha3":
38+
value = "aarch64"
3639
return re.sub(r'(\s|[-_])', '', value).upper()
3740

3841
env = jinja2.Environment(
@@ -87,6 +90,7 @@ def generate_scheme(name, type, properties):
8790
x86_aes_guard=properties.get('x86_aes_guard', DEFAULT_X86_AES_GUARD),
8891
x86_avx2_guard=properties.get('x86_avx2_guard', DEFAULT_X86_AVX2_GUARD),
8992
aarch64_neon_guard=properties.get('aarch64_neon_guard', DEFAULT_AARCH64_NEON_GUARD),
93+
aarch64_sha3_guard=properties.get('aarch64_sha3_guard', DEFAULT_AARCH64_SHA3_GUARD),
9094
)
9195

9296
metadatas = dict()

implementations.yaml

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ traits_version: 0.3.5
55

66
kems:
77
mlkem:
8-
version: 0.1.0
8+
version: 0.2.0
99
x86_avx2_guard: 'target_arch == "x86_64" && avx2_enabled && !is_windows && !is_macos'
10-
implementations: [clean, avx2, aarch64]
10+
implementations: [clean, avx2, aarch64_sha3]
1111
schemes:
1212
- name: ml-kem-512
13-
implementations: [clean, avx2, aarch64]
13+
implementations: [clean, avx2, aarch64_sha3]
1414
- name: ml-kem-768
15-
implementations: [clean, avx2, aarch64]
15+
implementations: [clean, avx2, aarch64_sha3]
1616
- name: ml-kem-1024
17-
implementations: [clean, avx2, aarch64]
17+
implementations: [clean, avx2, aarch64_sha3]
1818
classicmceliece:
1919
version: 0.2.0
2020
notes: |
@@ -63,17 +63,17 @@ kems:
6363

6464
signs:
6565
mldsa:
66-
version: 0.1.1
66+
version: 0.2.0
6767
x86_avx2_guard: 'target_arch == "x86_64" && avx2_enabled && !is_windows'
68-
implementations: [clean, avx2, aarch64]
68+
implementations: [clean, avx2, aarch64_sha3]
6969
supports_context: true
7070
schemes:
7171
- name: ml-dsa-44
72-
implementations: [clean, avx2, aarch64]
72+
implementations: [clean, avx2, aarch64_sha3]
7373
- name: ml-dsa-65
74-
implementations: [clean, avx2, aarch64]
74+
implementations: [clean, avx2, aarch64_sha3]
7575
- name: ml-dsa-87
76-
implementations: [clean, avx2, aarch64]
76+
implementations: [clean, avx2, aarch64_sha3]
7777
falcon:
7878
version: 0.4.0
7979
implementations: [clean, avx2, aarch64]

pqcrypto-classicmceliece/build.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ macro_rules! build_clean {
99
let internals_include_path = &std::env::var("DEP_PQCRYPTO_INTERNALS_INCLUDEPATH").unwrap();
1010
let common_dir = Path::new("pqclean/common");
1111

12+
let implementation_dir = "clean";
13+
1214
let mut builder = cc::Build::new();
13-
let target_dir: PathBuf = ["pqclean", "crypto_kem", $variant, "clean"]
15+
let target_dir: PathBuf = ["pqclean", "crypto_kem", $variant, implementation_dir]
1416
.iter()
1517
.collect();
1618

@@ -41,8 +43,12 @@ macro_rules! build_avx2 {
4143
let internals_include_path = &std::env::var("DEP_PQCRYPTO_INTERNALS_INCLUDEPATH").unwrap();
4244
let common_dir = Path::new("pqclean/common");
4345

46+
let implementation_dir = "avx2";
47+
4448
let mut builder = cc::Build::new();
45-
let target_dir: PathBuf = ["pqclean", "crypto_kem", $variant, "avx2"].iter().collect();
49+
let target_dir: PathBuf = ["pqclean", "crypto_kem", $variant, implementation_dir]
50+
.iter()
51+
.collect();
4652

4753
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
4854
if target_os == "wasi" {
@@ -86,6 +92,8 @@ fn main() {
8692
#[allow(unused_variables)]
8793
let neon_enabled = env::var("CARGO_FEATURE_NEON").is_ok();
8894
#[allow(unused_variables)]
95+
let aarch64_sha3_enabled = env::var("CARGO_FEATURE_AARCH64_SHA3").is_ok();
96+
#[allow(unused_variables)]
8997
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
9098
#[allow(unused_variables)]
9199
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();

pqcrypto-classicmceliece/src/mceliece348864.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ macro_rules! gen_keypair {
132132
pub fn keypair() -> (PublicKey, SecretKey) {
133133
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
134134
{
135-
if std::is_x86_feature_detected!("avx2") {
135+
if std::arch::is_x86_feature_detected!("avx2") {
136136
return gen_keypair!(PQCLEAN_MCELIECE348864_AVX2_crypto_kem_keypair);
137137
}
138138
}
@@ -155,7 +155,7 @@ macro_rules! encap {
155155
pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) {
156156
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
157157
{
158-
if std::is_x86_feature_detected!("avx2") {
158+
if std::arch::is_x86_feature_detected!("avx2") {
159159
return encap!(PQCLEAN_MCELIECE348864_AVX2_crypto_kem_enc, pk);
160160
}
161161
}
@@ -177,7 +177,7 @@ macro_rules! decap {
177177
pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret {
178178
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
179179
{
180-
if std::is_x86_feature_detected!("avx2") {
180+
if std::arch::is_x86_feature_detected!("avx2") {
181181
return decap!(PQCLEAN_MCELIECE348864_AVX2_crypto_kem_dec, ct, sk);
182182
}
183183
}

pqcrypto-classicmceliece/src/mceliece348864f.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ macro_rules! gen_keypair {
135135
pub fn keypair() -> (PublicKey, SecretKey) {
136136
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
137137
{
138-
if std::is_x86_feature_detected!("avx2") {
138+
if std::arch::is_x86_feature_detected!("avx2") {
139139
return gen_keypair!(PQCLEAN_MCELIECE348864F_AVX2_crypto_kem_keypair);
140140
}
141141
}
@@ -158,7 +158,7 @@ macro_rules! encap {
158158
pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) {
159159
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
160160
{
161-
if std::is_x86_feature_detected!("avx2") {
161+
if std::arch::is_x86_feature_detected!("avx2") {
162162
return encap!(PQCLEAN_MCELIECE348864F_AVX2_crypto_kem_enc, pk);
163163
}
164164
}
@@ -180,7 +180,7 @@ macro_rules! decap {
180180
pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret {
181181
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
182182
{
183-
if std::is_x86_feature_detected!("avx2") {
183+
if std::arch::is_x86_feature_detected!("avx2") {
184184
return decap!(PQCLEAN_MCELIECE348864F_AVX2_crypto_kem_dec, ct, sk);
185185
}
186186
}

pqcrypto-classicmceliece/src/mceliece460896.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ macro_rules! gen_keypair {
132132
pub fn keypair() -> (PublicKey, SecretKey) {
133133
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
134134
{
135-
if std::is_x86_feature_detected!("avx2") {
135+
if std::arch::is_x86_feature_detected!("avx2") {
136136
return gen_keypair!(PQCLEAN_MCELIECE460896_AVX2_crypto_kem_keypair);
137137
}
138138
}
@@ -155,7 +155,7 @@ macro_rules! encap {
155155
pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) {
156156
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
157157
{
158-
if std::is_x86_feature_detected!("avx2") {
158+
if std::arch::is_x86_feature_detected!("avx2") {
159159
return encap!(PQCLEAN_MCELIECE460896_AVX2_crypto_kem_enc, pk);
160160
}
161161
}
@@ -177,7 +177,7 @@ macro_rules! decap {
177177
pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret {
178178
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
179179
{
180-
if std::is_x86_feature_detected!("avx2") {
180+
if std::arch::is_x86_feature_detected!("avx2") {
181181
return decap!(PQCLEAN_MCELIECE460896_AVX2_crypto_kem_dec, ct, sk);
182182
}
183183
}

pqcrypto-classicmceliece/src/mceliece460896f.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ macro_rules! gen_keypair {
135135
pub fn keypair() -> (PublicKey, SecretKey) {
136136
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
137137
{
138-
if std::is_x86_feature_detected!("avx2") {
138+
if std::arch::is_x86_feature_detected!("avx2") {
139139
return gen_keypair!(PQCLEAN_MCELIECE460896F_AVX2_crypto_kem_keypair);
140140
}
141141
}
@@ -158,7 +158,7 @@ macro_rules! encap {
158158
pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) {
159159
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
160160
{
161-
if std::is_x86_feature_detected!("avx2") {
161+
if std::arch::is_x86_feature_detected!("avx2") {
162162
return encap!(PQCLEAN_MCELIECE460896F_AVX2_crypto_kem_enc, pk);
163163
}
164164
}
@@ -180,7 +180,7 @@ macro_rules! decap {
180180
pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret {
181181
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
182182
{
183-
if std::is_x86_feature_detected!("avx2") {
183+
if std::arch::is_x86_feature_detected!("avx2") {
184184
return decap!(PQCLEAN_MCELIECE460896F_AVX2_crypto_kem_dec, ct, sk);
185185
}
186186
}

pqcrypto-classicmceliece/src/mceliece6688128.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ macro_rules! gen_keypair {
135135
pub fn keypair() -> (PublicKey, SecretKey) {
136136
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
137137
{
138-
if std::is_x86_feature_detected!("avx2") {
138+
if std::arch::is_x86_feature_detected!("avx2") {
139139
return gen_keypair!(PQCLEAN_MCELIECE6688128_AVX2_crypto_kem_keypair);
140140
}
141141
}
@@ -158,7 +158,7 @@ macro_rules! encap {
158158
pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) {
159159
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
160160
{
161-
if std::is_x86_feature_detected!("avx2") {
161+
if std::arch::is_x86_feature_detected!("avx2") {
162162
return encap!(PQCLEAN_MCELIECE6688128_AVX2_crypto_kem_enc, pk);
163163
}
164164
}
@@ -180,7 +180,7 @@ macro_rules! decap {
180180
pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret {
181181
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
182182
{
183-
if std::is_x86_feature_detected!("avx2") {
183+
if std::arch::is_x86_feature_detected!("avx2") {
184184
return decap!(PQCLEAN_MCELIECE6688128_AVX2_crypto_kem_dec, ct, sk);
185185
}
186186
}

pqcrypto-classicmceliece/src/mceliece6688128f.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ macro_rules! gen_keypair {
135135
pub fn keypair() -> (PublicKey, SecretKey) {
136136
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
137137
{
138-
if std::is_x86_feature_detected!("avx2") {
138+
if std::arch::is_x86_feature_detected!("avx2") {
139139
return gen_keypair!(PQCLEAN_MCELIECE6688128F_AVX2_crypto_kem_keypair);
140140
}
141141
}
@@ -158,7 +158,7 @@ macro_rules! encap {
158158
pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) {
159159
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
160160
{
161-
if std::is_x86_feature_detected!("avx2") {
161+
if std::arch::is_x86_feature_detected!("avx2") {
162162
return encap!(PQCLEAN_MCELIECE6688128F_AVX2_crypto_kem_enc, pk);
163163
}
164164
}
@@ -180,7 +180,7 @@ macro_rules! decap {
180180
pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret {
181181
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
182182
{
183-
if std::is_x86_feature_detected!("avx2") {
183+
if std::arch::is_x86_feature_detected!("avx2") {
184184
return decap!(PQCLEAN_MCELIECE6688128F_AVX2_crypto_kem_dec, ct, sk);
185185
}
186186
}

pqcrypto-classicmceliece/src/mceliece6960119.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ macro_rules! gen_keypair {
135135
pub fn keypair() -> (PublicKey, SecretKey) {
136136
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
137137
{
138-
if std::is_x86_feature_detected!("avx2") {
138+
if std::arch::is_x86_feature_detected!("avx2") {
139139
return gen_keypair!(PQCLEAN_MCELIECE6960119_AVX2_crypto_kem_keypair);
140140
}
141141
}
@@ -158,7 +158,7 @@ macro_rules! encap {
158158
pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) {
159159
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
160160
{
161-
if std::is_x86_feature_detected!("avx2") {
161+
if std::arch::is_x86_feature_detected!("avx2") {
162162
return encap!(PQCLEAN_MCELIECE6960119_AVX2_crypto_kem_enc, pk);
163163
}
164164
}
@@ -180,7 +180,7 @@ macro_rules! decap {
180180
pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret {
181181
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
182182
{
183-
if std::is_x86_feature_detected!("avx2") {
183+
if std::arch::is_x86_feature_detected!("avx2") {
184184
return decap!(PQCLEAN_MCELIECE6960119_AVX2_crypto_kem_dec, ct, sk);
185185
}
186186
}

pqcrypto-classicmceliece/src/mceliece6960119f.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ macro_rules! gen_keypair {
135135
pub fn keypair() -> (PublicKey, SecretKey) {
136136
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
137137
{
138-
if std::is_x86_feature_detected!("avx2") {
138+
if std::arch::is_x86_feature_detected!("avx2") {
139139
return gen_keypair!(PQCLEAN_MCELIECE6960119F_AVX2_crypto_kem_keypair);
140140
}
141141
}
@@ -158,7 +158,7 @@ macro_rules! encap {
158158
pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) {
159159
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
160160
{
161-
if std::is_x86_feature_detected!("avx2") {
161+
if std::arch::is_x86_feature_detected!("avx2") {
162162
return encap!(PQCLEAN_MCELIECE6960119F_AVX2_crypto_kem_enc, pk);
163163
}
164164
}
@@ -180,7 +180,7 @@ macro_rules! decap {
180180
pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret {
181181
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
182182
{
183-
if std::is_x86_feature_detected!("avx2") {
183+
if std::arch::is_x86_feature_detected!("avx2") {
184184
return decap!(PQCLEAN_MCELIECE6960119F_AVX2_crypto_kem_dec, ct, sk);
185185
}
186186
}

pqcrypto-classicmceliece/src/mceliece8192128.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ macro_rules! gen_keypair {
135135
pub fn keypair() -> (PublicKey, SecretKey) {
136136
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
137137
{
138-
if std::is_x86_feature_detected!("avx2") {
138+
if std::arch::is_x86_feature_detected!("avx2") {
139139
return gen_keypair!(PQCLEAN_MCELIECE8192128_AVX2_crypto_kem_keypair);
140140
}
141141
}
@@ -158,7 +158,7 @@ macro_rules! encap {
158158
pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) {
159159
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
160160
{
161-
if std::is_x86_feature_detected!("avx2") {
161+
if std::arch::is_x86_feature_detected!("avx2") {
162162
return encap!(PQCLEAN_MCELIECE8192128_AVX2_crypto_kem_enc, pk);
163163
}
164164
}
@@ -180,7 +180,7 @@ macro_rules! decap {
180180
pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret {
181181
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
182182
{
183-
if std::is_x86_feature_detected!("avx2") {
183+
if std::arch::is_x86_feature_detected!("avx2") {
184184
return decap!(PQCLEAN_MCELIECE8192128_AVX2_crypto_kem_dec, ct, sk);
185185
}
186186
}

pqcrypto-classicmceliece/src/mceliece8192128f.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ macro_rules! gen_keypair {
135135
pub fn keypair() -> (PublicKey, SecretKey) {
136136
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
137137
{
138-
if std::is_x86_feature_detected!("avx2") {
138+
if std::arch::is_x86_feature_detected!("avx2") {
139139
return gen_keypair!(PQCLEAN_MCELIECE8192128F_AVX2_crypto_kem_keypair);
140140
}
141141
}
@@ -158,7 +158,7 @@ macro_rules! encap {
158158
pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) {
159159
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
160160
{
161-
if std::is_x86_feature_detected!("avx2") {
161+
if std::arch::is_x86_feature_detected!("avx2") {
162162
return encap!(PQCLEAN_MCELIECE8192128F_AVX2_crypto_kem_enc, pk);
163163
}
164164
}
@@ -180,7 +180,7 @@ macro_rules! decap {
180180
pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret {
181181
#[cfg(all(enable_x86_avx2, feature = "avx2"))]
182182
{
183-
if std::is_x86_feature_detected!("avx2") {
183+
if std::arch::is_x86_feature_detected!("avx2") {
184184
return decap!(PQCLEAN_MCELIECE8192128F_AVX2_crypto_kem_dec, ct, sk);
185185
}
186186
}

0 commit comments

Comments
 (0)