diff --git a/implementations.yaml b/implementations.yaml index df44e11..2d50428 100644 --- a/implementations.yaml +++ b/implementations.yaml @@ -5,14 +5,14 @@ traits_version: 0.3.5 kems: kyber: - version: 0.7.7 + version: 0.7.9 x86_avx2_guard: 'target_arch == "x86_64" && avx2_enabled && !is_windows && !is_macos' - implementations: [clean, avx2, aarch64] + implementations: [clean, avx2] schemes: - name: kyber512 - implementations: [clean, avx2, aarch64] + implementations: [clean, avx2] - name: kyber768 - implementations: [clean, avx2, aarch64] + implementations: [clean, avx2] - name: kyber1024 - implementations: [clean, avx2, aarch64] + implementations: [clean, avx2] signs: {} diff --git a/pqclean b/pqclean index a05c19d..b460281 160000 --- a/pqclean +++ b/pqclean @@ -1 +1 @@ -Subproject commit a05c19d7a892dd41d7b4bbbaa6948c054bf23086 +Subproject commit b460281f6352f0f160cfff9ef87478c426213f3f diff --git a/pqcrypto-kyber/Cargo.toml b/pqcrypto-kyber/Cargo.toml index 8b3dc51..e8dec8e 100644 --- a/pqcrypto-kyber/Cargo.toml +++ b/pqcrypto-kyber/Cargo.toml @@ -2,7 +2,7 @@ name = "pqcrypto-kyber" description = "Post-Quantum Key-Encapsulation Mechanism kyber" readme = "README.md" -version = "0.7.8" +version = "0.7.9" authors = ["Thom Wiggers "] edition = "2021" license = "MIT OR Apache-2.0" @@ -19,9 +19,8 @@ serde = { version = "1.0", features = ["derive"], optional = true } serde-big-array = { version = "0.5.1", optional = true } [features] -default = ["avx2", "neon", "std"] +default = ["avx2", "std"] avx2 = ["std"] -neon = ["std"] std = ["pqcrypto-traits/std"] serialization = ["serde", "serde-big-array"] diff --git a/pqcrypto-kyber/README.md b/pqcrypto-kyber/README.md index b261eaf..271c621 100644 --- a/pqcrypto-kyber/README.md +++ b/pqcrypto-kyber/README.md @@ -22,15 +22,12 @@ methods only. * ``kyber512`` * ``clean`` * ``avx2`` (if supported) - * ``aarch64`` (if supported) * ``kyber768`` * ``clean`` * ``avx2`` (if supported) - * ``aarch64`` (if supported) * ``kyber1024`` * ``clean`` * ``avx2`` (if supported) - * ``aarch64`` (if supported) ## License diff --git a/pqcrypto-kyber/build.rs b/pqcrypto-kyber/build.rs index a86b306..8f62be2 100644 --- a/pqcrypto-kyber/build.rs +++ b/pqcrypto-kyber/build.rs @@ -78,39 +78,6 @@ macro_rules! build_avx2 { }; } -macro_rules! build_aarch64 { - ($variant:expr) => { - let internals_include_path = &std::env::var("DEP_PQCRYPTO_INTERNALS_INCLUDEPATH").unwrap(); - let common_dir = Path::new("pqclean/common"); - - let mut builder = cc::Build::new(); - let target_dir: PathBuf = ["pqclean", "crypto_kem", $variant, "aarch64"] - .iter() - .collect(); - - let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); - if target_os == "wasi" { - let wasi_sdk_path = - &std::env::var("WASI_SDK_DIR").expect("missing environment variable: WASI_SDK_DIR"); - builder.flag(format!("--sysroot={}", wasi_sdk_path).as_str()); - } - - let scheme_files = glob::glob(target_dir.join("*.[csS]").to_str().unwrap()).unwrap(); - builder.flag("-march=armv8-a"); - - builder - .include(internals_include_path) - .include(&common_dir) - .include(target_dir) - .files( - scheme_files - .into_iter() - .map(|p| p.unwrap().to_string_lossy().into_owned()), - ); - builder.compile(format!("{}_aarch64", $variant).as_str()); - }; -} - fn main() { #[allow(unused_variables)] let aes_enabled = env::var("CARGO_FEATURE_AES").is_ok(); @@ -131,30 +98,17 @@ fn main() { if target_arch == "x86_64" && avx2_enabled && !is_windows && !is_macos { build_avx2!("kyber512"); } - if target_arch == "aarch64" && neon_enabled { - build_aarch64!("kyber512"); - } build_clean!("kyber768"); if target_arch == "x86_64" && avx2_enabled && !is_windows && !is_macos { build_avx2!("kyber768"); } - if target_arch == "aarch64" && neon_enabled { - build_aarch64!("kyber768"); - } build_clean!("kyber1024"); if target_arch == "x86_64" && avx2_enabled && !is_windows && !is_macos { build_avx2!("kyber1024"); } - if target_arch == "aarch64" && neon_enabled { - build_aarch64!("kyber1024"); - } if target_arch == "x86_64" && avx2_enabled && !is_windows && !is_macos { // Print enableing flag for AVX2 implementation println!("cargo:rustc-cfg=enable_x86_avx2"); } - if target_arch == "aarch64" && neon_enabled { - // Print enableing flag for AARCH64 implementation - println!("cargo:rustc-cfg=enable_aarch64_neon"); - } } diff --git a/pqcrypto-kyber/src/ffi.rs b/pqcrypto-kyber/src/ffi.rs index 6e64777..0179de6 100644 --- a/pqcrypto-kyber/src/ffi.rs +++ b/pqcrypto-kyber/src/ffi.rs @@ -28,15 +28,6 @@ pub const PQCLEAN_KYBER512_AVX2_CRYPTO_CIPHERTEXTBYTES: usize = 768; #[cfg(enable_x86_avx2)] pub const PQCLEAN_KYBER512_AVX2_CRYPTO_BYTES: usize = 32; -#[cfg(enable_aarch64_neon)] -pub const PQCLEAN_KYBER512_AARCH64_CRYPTO_SECRETKEYBYTES: usize = 1632; -#[cfg(enable_aarch64_neon)] -pub const PQCLEAN_KYBER512_AARCH64_CRYPTO_PUBLICKEYBYTES: usize = 800; -#[cfg(enable_aarch64_neon)] -pub const PQCLEAN_KYBER512_AARCH64_CRYPTO_CIPHERTEXTBYTES: usize = 768; -#[cfg(enable_aarch64_neon)] -pub const PQCLEAN_KYBER512_AARCH64_CRYPTO_BYTES: usize = 32; - pub const PQCLEAN_KYBER768_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 2400; pub const PQCLEAN_KYBER768_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 1184; pub const PQCLEAN_KYBER768_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 1088; @@ -51,15 +42,6 @@ pub const PQCLEAN_KYBER768_AVX2_CRYPTO_CIPHERTEXTBYTES: usize = 1088; #[cfg(enable_x86_avx2)] pub const PQCLEAN_KYBER768_AVX2_CRYPTO_BYTES: usize = 32; -#[cfg(enable_aarch64_neon)] -pub const PQCLEAN_KYBER768_AARCH64_CRYPTO_SECRETKEYBYTES: usize = 2400; -#[cfg(enable_aarch64_neon)] -pub const PQCLEAN_KYBER768_AARCH64_CRYPTO_PUBLICKEYBYTES: usize = 1184; -#[cfg(enable_aarch64_neon)] -pub const PQCLEAN_KYBER768_AARCH64_CRYPTO_CIPHERTEXTBYTES: usize = 1088; -#[cfg(enable_aarch64_neon)] -pub const PQCLEAN_KYBER768_AARCH64_CRYPTO_BYTES: usize = 32; - pub const PQCLEAN_KYBER1024_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 3168; pub const PQCLEAN_KYBER1024_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 1568; pub const PQCLEAN_KYBER1024_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 1568; @@ -74,15 +56,6 @@ pub const PQCLEAN_KYBER1024_AVX2_CRYPTO_CIPHERTEXTBYTES: usize = 1568; #[cfg(enable_x86_avx2)] pub const PQCLEAN_KYBER1024_AVX2_CRYPTO_BYTES: usize = 32; -#[cfg(enable_aarch64_neon)] -pub const PQCLEAN_KYBER1024_AARCH64_CRYPTO_SECRETKEYBYTES: usize = 3168; -#[cfg(enable_aarch64_neon)] -pub const PQCLEAN_KYBER1024_AARCH64_CRYPTO_PUBLICKEYBYTES: usize = 1568; -#[cfg(enable_aarch64_neon)] -pub const PQCLEAN_KYBER1024_AARCH64_CRYPTO_CIPHERTEXTBYTES: usize = 1568; -#[cfg(enable_aarch64_neon)] -pub const PQCLEAN_KYBER1024_AARCH64_CRYPTO_BYTES: usize = 32; - #[link(name = "kyber512_clean")] extern "C" { pub fn PQCLEAN_KYBER512_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; @@ -106,25 +79,6 @@ extern "C" { -> c_int; } -#[cfg(enable_aarch64_neon)] -#[link(name = "kyber512_aarch64")] -extern "C" { - #[cfg(enable_aarch64_neon)] - pub fn PQCLEAN_KYBER512_AARCH64_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - #[cfg(enable_aarch64_neon)] - pub fn PQCLEAN_KYBER512_AARCH64_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - #[cfg(enable_aarch64_neon)] - pub fn PQCLEAN_KYBER512_AARCH64_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; -} - #[link(name = "kyber768_clean")] extern "C" { pub fn PQCLEAN_KYBER768_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; @@ -148,25 +102,6 @@ extern "C" { -> c_int; } -#[cfg(enable_aarch64_neon)] -#[link(name = "kyber768_aarch64")] -extern "C" { - #[cfg(enable_aarch64_neon)] - pub fn PQCLEAN_KYBER768_AARCH64_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - #[cfg(enable_aarch64_neon)] - pub fn PQCLEAN_KYBER768_AARCH64_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - #[cfg(enable_aarch64_neon)] - pub fn PQCLEAN_KYBER768_AARCH64_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; -} - #[link(name = "kyber1024_clean")] extern "C" { pub fn PQCLEAN_KYBER1024_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; @@ -194,25 +129,6 @@ extern "C" { ) -> c_int; } -#[cfg(enable_aarch64_neon)] -#[link(name = "kyber1024_aarch64")] -extern "C" { - #[cfg(enable_aarch64_neon)] - pub fn PQCLEAN_KYBER1024_AARCH64_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - #[cfg(enable_aarch64_neon)] - pub fn PQCLEAN_KYBER1024_AARCH64_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - #[cfg(enable_aarch64_neon)] - pub fn PQCLEAN_KYBER1024_AARCH64_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; -} - #[cfg(test)] mod test_kyber512_clean { use super::*; @@ -287,41 +203,6 @@ mod test_kyber512_avx2 { } } -#[cfg(all(test, enable_aarch64_neon, feature = "neon"))] -mod test_kyber512_aarch64 { - use super::*; - use alloc::vec; - - #[test] - fn test_ffi() { - unsafe { - let mut pk = vec![0u8; PQCLEAN_KYBER512_AARCH64_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_KYBER512_AARCH64_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_KYBER512_AARCH64_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_KYBER512_AARCH64_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_KYBER512_AARCH64_CRYPTO_BYTES]; - - assert_eq!( - 0, - PQCLEAN_KYBER512_AARCH64_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_KYBER512_AARCH64_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_KYBER512_AARCH64_crypto_kem_dec(ss2.as_mut_ptr(), ct.as_ptr(), sk.as_ptr()) - ); - assert_eq!(&ss1[..], &ss2[..], "Shared secrets should be equal"); - } - } -} - #[cfg(test)] mod test_kyber768_clean { use super::*; @@ -396,41 +277,6 @@ mod test_kyber768_avx2 { } } -#[cfg(all(test, enable_aarch64_neon, feature = "neon"))] -mod test_kyber768_aarch64 { - use super::*; - use alloc::vec; - - #[test] - fn test_ffi() { - unsafe { - let mut pk = vec![0u8; PQCLEAN_KYBER768_AARCH64_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_KYBER768_AARCH64_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_KYBER768_AARCH64_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_KYBER768_AARCH64_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_KYBER768_AARCH64_CRYPTO_BYTES]; - - assert_eq!( - 0, - PQCLEAN_KYBER768_AARCH64_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_KYBER768_AARCH64_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_KYBER768_AARCH64_crypto_kem_dec(ss2.as_mut_ptr(), ct.as_ptr(), sk.as_ptr()) - ); - assert_eq!(&ss1[..], &ss2[..], "Shared secrets should be equal"); - } - } -} - #[cfg(test)] mod test_kyber1024_clean { use super::*; @@ -504,42 +350,3 @@ mod test_kyber1024_avx2 { } } } - -#[cfg(all(test, enable_aarch64_neon, feature = "neon"))] -mod test_kyber1024_aarch64 { - use super::*; - use alloc::vec; - - #[test] - fn test_ffi() { - unsafe { - let mut pk = vec![0u8; PQCLEAN_KYBER1024_AARCH64_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_KYBER1024_AARCH64_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_KYBER1024_AARCH64_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_KYBER1024_AARCH64_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_KYBER1024_AARCH64_CRYPTO_BYTES]; - - assert_eq!( - 0, - PQCLEAN_KYBER1024_AARCH64_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_KYBER1024_AARCH64_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_KYBER1024_AARCH64_crypto_kem_dec( - ss2.as_mut_ptr(), - ct.as_ptr(), - sk.as_ptr() - ) - ); - assert_eq!(&ss1[..], &ss2[..], "Shared secrets should be equal"); - } - } -} diff --git a/pqcrypto-kyber/src/kyber1024.rs b/pqcrypto-kyber/src/kyber1024.rs index b322e8d..c5b4ba4 100644 --- a/pqcrypto-kyber/src/kyber1024.rs +++ b/pqcrypto-kyber/src/kyber1024.rs @@ -136,15 +136,6 @@ pub fn keypair() -> (PublicKey, SecretKey) { return gen_keypair!(PQCLEAN_KYBER1024_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 { - return gen_keypair!(PQCLEAN_KYBER1024_AARCH64_crypto_kem_keypair); - } - } gen_keypair!(PQCLEAN_KYBER1024_CLEAN_crypto_kem_keypair) } @@ -168,12 +159,6 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { return encap!(PQCLEAN_KYBER1024_AVX2_crypto_kem_enc, pk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] - { - if true { - return encap!(PQCLEAN_KYBER1024_AARCH64_crypto_kem_enc, pk); - } - } encap!(PQCLEAN_KYBER1024_CLEAN_crypto_kem_enc, pk) } @@ -196,12 +181,6 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { return decap!(PQCLEAN_KYBER1024_AVX2_crypto_kem_dec, ct, sk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] - { - if true { - return decap!(PQCLEAN_KYBER1024_AARCH64_crypto_kem_dec, ct, sk); - } - } decap!(PQCLEAN_KYBER1024_CLEAN_crypto_kem_dec, ct, sk) } diff --git a/pqcrypto-kyber/src/kyber512.rs b/pqcrypto-kyber/src/kyber512.rs index 2c1bc60..562c546 100644 --- a/pqcrypto-kyber/src/kyber512.rs +++ b/pqcrypto-kyber/src/kyber512.rs @@ -130,15 +130,6 @@ pub fn keypair() -> (PublicKey, SecretKey) { return gen_keypair!(PQCLEAN_KYBER512_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 { - return gen_keypair!(PQCLEAN_KYBER512_AARCH64_crypto_kem_keypair); - } - } gen_keypair!(PQCLEAN_KYBER512_CLEAN_crypto_kem_keypair) } @@ -162,12 +153,6 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { return encap!(PQCLEAN_KYBER512_AVX2_crypto_kem_enc, pk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] - { - if true { - return encap!(PQCLEAN_KYBER512_AARCH64_crypto_kem_enc, pk); - } - } encap!(PQCLEAN_KYBER512_CLEAN_crypto_kem_enc, pk) } @@ -190,12 +175,6 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { return decap!(PQCLEAN_KYBER512_AVX2_crypto_kem_dec, ct, sk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] - { - if true { - return decap!(PQCLEAN_KYBER512_AARCH64_crypto_kem_dec, ct, sk); - } - } decap!(PQCLEAN_KYBER512_CLEAN_crypto_kem_dec, ct, sk) } diff --git a/pqcrypto-kyber/src/kyber768.rs b/pqcrypto-kyber/src/kyber768.rs index 238cfb4..9129a30 100644 --- a/pqcrypto-kyber/src/kyber768.rs +++ b/pqcrypto-kyber/src/kyber768.rs @@ -130,15 +130,6 @@ pub fn keypair() -> (PublicKey, SecretKey) { return gen_keypair!(PQCLEAN_KYBER768_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 { - return gen_keypair!(PQCLEAN_KYBER768_AARCH64_crypto_kem_keypair); - } - } gen_keypair!(PQCLEAN_KYBER768_CLEAN_crypto_kem_keypair) } @@ -162,12 +153,6 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { return encap!(PQCLEAN_KYBER768_AVX2_crypto_kem_enc, pk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] - { - if true { - return encap!(PQCLEAN_KYBER768_AARCH64_crypto_kem_enc, pk); - } - } encap!(PQCLEAN_KYBER768_CLEAN_crypto_kem_enc, pk) } @@ -190,12 +175,6 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { return decap!(PQCLEAN_KYBER768_AVX2_crypto_kem_dec, ct, sk); } } - #[cfg(all(enable_aarch64_neon, feature = "neon"))] - { - if true { - return decap!(PQCLEAN_KYBER768_AARCH64_crypto_kem_dec, ct, sk); - } - } decap!(PQCLEAN_KYBER768_CLEAN_crypto_kem_dec, ct, sk) }