From cfe44a1c750e5c3599fa41b710fb5f4d6112d0ec Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Mon, 16 Oct 2023 16:06:14 +0200 Subject: [PATCH 1/7] Update schemes --- CHANGELOG.md | 10 + implementations.yaml | 104 +- pqclean | 2 +- pqcrypto-classicmceliece/Cargo.toml | 2 +- pqcrypto-classicmceliece/README.md | 10 - pqcrypto-classicmceliece/build.rs | 40 - pqcrypto-classicmceliece/src/ffi.rs | 670 +- pqcrypto-classicmceliece/src/lib.rs | 20 +- .../src/mceliece348864.rs | 24 +- .../src/mceliece348864f.rs | 27 +- .../src/mceliece460896.rs | 24 +- .../src/mceliece460896f.rs | 27 +- .../src/mceliece6688128.rs | 27 +- .../src/mceliece6688128f.rs | 27 +- .../src/mceliece6960119.rs | 27 +- .../src/mceliece6960119f.rs | 27 +- .../src/mceliece8192128.rs | 27 +- .../src/mceliece8192128f.rs | 27 +- pqcrypto-dilithium/Cargo.toml | 2 +- pqcrypto-dilithium/README.md | 9 - pqcrypto-dilithium/build.rs | 12 - pqcrypto-dilithium/src/dilithium2aes.rs | 358 - pqcrypto-dilithium/src/dilithium3aes.rs | 358 - pqcrypto-dilithium/src/dilithium5aes.rs | 358 - pqcrypto-dilithium/src/ffi.rs | 999 +- pqcrypto-dilithium/src/lib.rs | 27 - pqcrypto-falcon/README.md | 2 + pqcrypto-falcon/build.rs | 6 + pqcrypto-falcon/src/falcon1024.rs | 38 + pqcrypto-falcon/src/falcon512.rs | 38 + pqcrypto-falcon/src/ffi.rs | 326 + pqcrypto-hqc/Cargo.toml | 2 +- pqcrypto-hqc/README.md | 6 +- pqcrypto-hqc/build.rs | 6 +- pqcrypto-hqc/src/ffi.rs | 144 +- pqcrypto-hqc/src/{hqcrmrs192.rs => hqc128.rs} | 43 +- pqcrypto-hqc/src/{hqcrmrs256.rs => hqc192.rs} | 43 +- pqcrypto-hqc/src/{hqcrmrs128.rs => hqc256.rs} | 43 +- pqcrypto-hqc/src/lib.rs | 45 +- pqcrypto-kyber/README.md | 9 - pqcrypto-kyber/build.rs | 12 - pqcrypto-kyber/src/ffi.rs | 385 - pqcrypto-kyber/src/kyber102490s.rs | 198 - pqcrypto-kyber/src/kyber51290s.rs | 198 - pqcrypto-kyber/src/kyber76890s.rs | 198 - pqcrypto-kyber/src/lib.rs | 27 - pqcrypto-sphincsplus/README.md | 72 - pqcrypto-sphincsplus/build.rs | 96 - pqcrypto-sphincsplus/src/ffi.rs | 9470 ++--------------- pqcrypto-sphincsplus/src/lib.rs | 246 - .../src/sphincsharaka128frobust.rs | 382 - .../src/sphincsharaka128fsimple.rs | 382 - .../src/sphincsharaka128srobust.rs | 382 - .../src/sphincsharaka128ssimple.rs | 382 - .../src/sphincsharaka192frobust.rs | 382 - .../src/sphincsharaka192fsimple.rs | 382 - .../src/sphincsharaka192srobust.rs | 382 - .../src/sphincsharaka192ssimple.rs | 382 - .../src/sphincsharaka256frobust.rs | 382 - .../src/sphincsharaka256fsimple.rs | 382 - .../src/sphincsharaka256srobust.rs | 382 - .../src/sphincsharaka256ssimple.rs | 382 - .../src/sphincssha2128frobust.rs | 374 - .../src/sphincssha2128srobust.rs | 374 - .../src/sphincssha2192frobust.rs | 374 - .../src/sphincssha2192srobust.rs | 374 - .../src/sphincssha2256frobust.rs | 374 - .../src/sphincssha2256srobust.rs | 374 - .../src/sphincsshake128frobust.rs | 378 - .../src/sphincsshake128srobust.rs | 378 - .../src/sphincsshake192frobust.rs | 378 - .../src/sphincsshake192srobust.rs | 378 - .../src/sphincsshake256frobust.rs | 378 - .../src/sphincsshake256srobust.rs | 378 - pqcrypto/Cargo.toml | 6 +- pqcrypto/src/lib.rs | 25 +- 76 files changed, 1479 insertions(+), 22546 deletions(-) delete mode 100644 pqcrypto-dilithium/src/dilithium2aes.rs delete mode 100644 pqcrypto-dilithium/src/dilithium3aes.rs delete mode 100644 pqcrypto-dilithium/src/dilithium5aes.rs rename pqcrypto-hqc/src/{hqcrmrs192.rs => hqc128.rs} (80%) rename pqcrypto-hqc/src/{hqcrmrs256.rs => hqc192.rs} (80%) rename pqcrypto-hqc/src/{hqcrmrs128.rs => hqc256.rs} (80%) delete mode 100644 pqcrypto-kyber/src/kyber102490s.rs delete mode 100644 pqcrypto-kyber/src/kyber51290s.rs delete mode 100644 pqcrypto-kyber/src/kyber76890s.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincsharaka128frobust.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincsharaka128fsimple.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincsharaka128srobust.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincsharaka128ssimple.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincsharaka192frobust.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincsharaka192fsimple.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincsharaka192srobust.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincsharaka192ssimple.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincsharaka256frobust.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincsharaka256fsimple.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincsharaka256srobust.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincsharaka256ssimple.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincssha2128frobust.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincssha2128srobust.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincssha2192frobust.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincssha2192srobust.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincssha2256frobust.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincssha2256srobust.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincsshake128frobust.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincsshake128srobust.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincsshake192frobust.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincsshake192srobust.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincsshake256frobust.rs delete mode 100644 pqcrypto-sphincsplus/src/sphincsshake256srobust.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index a85e96e2..b8f9f6df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## 2023-10-16 + +* Update Kyber to draft FIPS standard +* Update Dilithium to draft FIPS standard +* Update McEliece implementation +* Small fix in Falcon +* Add Falcon NEON implementation + +## 2023-04-26 + * Update Rust dependencies * Update SPHINCS+ implementation * Update Falcon implementation diff --git a/implementations.yaml b/implementations.yaml index ff46755e..ffc9e35b 100644 --- a/implementations.yaml +++ b/implementations.yaml @@ -15,61 +15,55 @@ kems: implementations: [clean, avx2, aarch64] - name: kyber1024 implementations: [clean, avx2, aarch64] - - name: kyber512-90s - implementations: [clean, avx2] - - name: kyber768-90s - implementations: [clean, avx2] - - name: kyber1024-90s - implementations: [clean, avx2] classicmceliece: - version: 0.1.8 + version: 0.2.0 notes: | This implementation requires a lot of stack space. You need to specify ``RUST_MIN_STACK=800000000``, probably. x86_avx2_guard: 'target_arch == "x86_64" && avx2_enabled && !is_windows' - implementations: [vec, clean, avx] + implementations: [clean, avx] schemes: - name: mceliece348864 - implementations: [vec, clean, avx] + implementations: [clean, avx] - name: mceliece348864f - implementations: [vec, clean, avx] + implementations: [clean, avx] - name: mceliece460896 - implementations: [vec, clean, avx] + implementations: [clean, avx] - name: mceliece460896f - implementations: [vec, clean, avx] + implementations: [clean, avx] - name: mceliece6688128 - implementations: [vec, clean, avx] + implementations: [clean, avx] doctest: no - name: mceliece6688128f - implementations: [vec, clean, avx] + implementations: [clean, avx] doctest: no - name: mceliece6960119 - implementations: [vec, clean, avx] + implementations: [clean, avx] doctest: no - name: mceliece6960119f - implementations: [vec, clean, avx] + implementations: [clean, avx] doctest: no - name: mceliece8192128 - implementations: [vec, clean, avx] + implementations: [clean, avx] doctest: no - name: mceliece8192128f - implementations: [vec, clean, avx] + implementations: [clean, avx] doctest: no hqc: - version: 0.1.7 + version: 0.2.0 implementations: [clean] schemes: - - name: hqc-rmrs-128 - implementations: [clean] # avx2 is excluded - - name: hqc-rmrs-192 - implementations: [clean] # avx2 is excluded - - name: hqc-rmrs-256 - implementations: [clean] # avx2 is excluded + - name: hqc-128 + implementations: [clean] + - name: hqc-192 + implementations: [clean] + - name: hqc-256 + implementations: [clean] signs: dilithium: - version: 0.4.7 + version: 0.5.0 x86_avx2_guard: 'target_arch == "x86_64" && avx2_enabled && !is_windows' implementations: [clean, avx2, aarch64] schemes: @@ -79,94 +73,40 @@ signs: implementations: [clean, avx2, aarch64] - name: dilithium5 implementations: [clean, avx2, aarch64] - - name: dilithium2aes - implementations: [clean, avx2] - - name: dilithium3aes - implementations: [clean, avx2] - - name: dilithium5aes - implementations: [clean, avx2] falcon: version: 0.3.0 implementations: [clean, avx2] schemes: - name: falcon-512 - implementations: [clean, avx2] + implementations: [clean, avx2, aarch64] - name: falcon-1024 - implementations: [clean, avx2] + implementations: [clean, avx2, aarch64] sphincsplus: version: 0.7.0 implementations: [clean, aesni, avx2] schemes: - - name: sphincs-haraka-128f-robust - implementations: [clean, aesni] - - name: sphincs-haraka-128f-simple - implementations: [clean, aesni] - - name: sphincs-haraka-128s-robust - implementations: [clean, aesni] - - name: sphincs-haraka-128s-simple - implementations: [clean, aesni] - - name: sphincs-haraka-192f-robust - implementations: [clean, aesni] - - name: sphincs-haraka-192f-simple - implementations: [clean, aesni] - - name: sphincs-haraka-192s-robust - implementations: [clean, aesni] - - name: sphincs-haraka-192s-simple - implementations: [clean, aesni] - - name: sphincs-haraka-256f-robust - implementations: [clean, aesni] - - name: sphincs-haraka-256f-simple - implementations: [clean, aesni] - - name: sphincs-haraka-256s-robust - implementations: [clean, aesni] - - name: sphincs-haraka-256s-simple - implementations: [clean, aesni] - - name: sphincs-shake-128f-robust - implementations: [clean, avx2] - name: sphincs-shake-128f-simple implementations: [clean, avx2] - - name: sphincs-shake-128s-robust - implementations: [clean, avx2] - name: sphincs-shake-128s-simple implementations: [clean, avx2] - - name: sphincs-shake-192f-robust - implementations: [clean, avx2] - name: sphincs-shake-192f-simple implementations: [clean, avx2] - - name: sphincs-shake-192s-robust - implementations: [clean, avx2] - name: sphincs-shake-192s-simple implementations: [clean, avx2] - - name: sphincs-shake-256f-robust - implementations: [clean, avx2] - name: sphincs-shake-256f-simple implementations: [clean, avx2] - - name: sphincs-shake-256s-robust - implementations: [clean, avx2] - name: sphincs-shake-256s-simple implementations: [clean, avx2] - - name: sphincs-sha2-128f-robust - implementations: [clean, avx2] - name: sphincs-sha2-128f-simple implementations: [clean, avx2] - - name: sphincs-sha2-128s-robust - implementations: [clean, avx2] - name: sphincs-sha2-128s-simple implementations: [clean, avx2] - - name: sphincs-sha2-192f-robust - implementations: [clean, avx2] - name: sphincs-sha2-192f-simple implementations: [clean, avx2] - - name: sphincs-sha2-192s-robust - implementations: [clean, avx2] - name: sphincs-sha2-192s-simple implementations: [clean, avx2] - - name: sphincs-sha2-256f-robust - implementations: [clean, avx2] - name: sphincs-sha2-256f-simple implementations: [clean, avx2] - - name: sphincs-sha2-256s-robust - implementations: [clean, avx2] - name: sphincs-sha2-256s-simple implementations: [clean, avx2] diff --git a/pqclean b/pqclean index c1b19a86..0657749a 160000 --- a/pqclean +++ b/pqclean @@ -1 +1 @@ -Subproject commit c1b19a865de329e87e9b3e9152362fcb709da8ab +Subproject commit 0657749a785db30e7f49e9435452cb042edb1852 diff --git a/pqcrypto-classicmceliece/Cargo.toml b/pqcrypto-classicmceliece/Cargo.toml index 89e05b6a..912afee8 100644 --- a/pqcrypto-classicmceliece/Cargo.toml +++ b/pqcrypto-classicmceliece/Cargo.toml @@ -2,7 +2,7 @@ name = "pqcrypto-classicmceliece" description = "Post-Quantum Key-Encapsulation Mechanism classicmceliece" readme = "README.md" -version = "0.1.8" +version = "0.2.0" authors = ["Thom Wiggers "] edition = "2018" license = "MIT OR Apache-2.0" diff --git a/pqcrypto-classicmceliece/README.md b/pqcrypto-classicmceliece/README.md index e9669b9f..018c95e2 100644 --- a/pqcrypto-classicmceliece/README.md +++ b/pqcrypto-classicmceliece/README.md @@ -20,43 +20,33 @@ Rust-friendly interface, alternative implementations are exposed as ``ffi`` methods only. * ``mceliece348864`` - * ``vec`` * ``clean`` * ``avx`` (if supported) * ``mceliece348864f`` - * ``vec`` * ``clean`` * ``avx`` (if supported) * ``mceliece460896`` - * ``vec`` * ``clean`` * ``avx`` (if supported) * ``mceliece460896f`` - * ``vec`` * ``clean`` * ``avx`` (if supported) * ``mceliece6688128`` - * ``vec`` * ``clean`` * ``avx`` (if supported) * ``mceliece6688128f`` - * ``vec`` * ``clean`` * ``avx`` (if supported) * ``mceliece6960119`` - * ``vec`` * ``clean`` * ``avx`` (if supported) * ``mceliece6960119f`` - * ``vec`` * ``clean`` * ``avx`` (if supported) * ``mceliece8192128`` - * ``vec`` * ``clean`` * ``avx`` (if supported) * ``mceliece8192128f`` - * ``vec`` * ``clean`` * ``avx`` (if supported) diff --git a/pqcrypto-classicmceliece/build.rs b/pqcrypto-classicmceliece/build.rs index 3865a655..d386f587 100644 --- a/pqcrypto-classicmceliece/build.rs +++ b/pqcrypto-classicmceliece/build.rs @@ -4,36 +4,6 @@ extern crate glob; use std::env; use std::path::{Path, PathBuf}; -macro_rules! build_vec { - ($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, "vec"].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("*.c").to_str().unwrap()).unwrap(); - - 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!("{}_vec", $variant).as_str()); - }; -} - macro_rules! build_clean { ($variant:expr) => { let internals_include_path = &std::env::var("DEP_PQCRYPTO_INTERNALS_INCLUDEPATH").unwrap(); @@ -124,52 +94,42 @@ fn main() { #[allow(unused_variables)] let is_macos = target_os == "macos"; - build_vec!("mceliece348864"); build_clean!("mceliece348864"); if target_arch == "x86_64" && avx2_enabled && !is_windows { build_avx!("mceliece348864"); } - build_vec!("mceliece348864f"); build_clean!("mceliece348864f"); if target_arch == "x86_64" && avx2_enabled && !is_windows { build_avx!("mceliece348864f"); } - build_vec!("mceliece460896"); build_clean!("mceliece460896"); if target_arch == "x86_64" && avx2_enabled && !is_windows { build_avx!("mceliece460896"); } - build_vec!("mceliece460896f"); build_clean!("mceliece460896f"); if target_arch == "x86_64" && avx2_enabled && !is_windows { build_avx!("mceliece460896f"); } - build_vec!("mceliece6688128"); build_clean!("mceliece6688128"); if target_arch == "x86_64" && avx2_enabled && !is_windows { build_avx!("mceliece6688128"); } - build_vec!("mceliece6688128f"); build_clean!("mceliece6688128f"); if target_arch == "x86_64" && avx2_enabled && !is_windows { build_avx!("mceliece6688128f"); } - build_vec!("mceliece6960119"); build_clean!("mceliece6960119"); if target_arch == "x86_64" && avx2_enabled && !is_windows { build_avx!("mceliece6960119"); } - build_vec!("mceliece6960119f"); build_clean!("mceliece6960119f"); if target_arch == "x86_64" && avx2_enabled && !is_windows { build_avx!("mceliece6960119f"); } - build_vec!("mceliece8192128"); build_clean!("mceliece8192128"); if target_arch == "x86_64" && avx2_enabled && !is_windows { build_avx!("mceliece8192128"); } - build_vec!("mceliece8192128f"); build_clean!("mceliece8192128f"); if target_arch == "x86_64" && avx2_enabled && !is_windows { build_avx!("mceliece8192128f"); diff --git a/pqcrypto-classicmceliece/src/ffi.rs b/pqcrypto-classicmceliece/src/ffi.rs index 749b965d..c3827c9a 100644 --- a/pqcrypto-classicmceliece/src/ffi.rs +++ b/pqcrypto-classicmceliece/src/ffi.rs @@ -21,211 +21,146 @@ use libc::c_int; #[allow(unused_imports)] use pqcrypto_internals::*; -pub const PQCLEAN_MCELIECE348864_VEC_CRYPTO_SECRETKEYBYTES: usize = 6452; -pub const PQCLEAN_MCELIECE348864_VEC_CRYPTO_PUBLICKEYBYTES: usize = 261120; -pub const PQCLEAN_MCELIECE348864_VEC_CRYPTO_CIPHERTEXTBYTES: usize = 128; -pub const PQCLEAN_MCELIECE348864_VEC_CRYPTO_BYTES: usize = 32; - -pub const PQCLEAN_MCELIECE348864_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 6452; +pub const PQCLEAN_MCELIECE348864_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 6492; pub const PQCLEAN_MCELIECE348864_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 261120; -pub const PQCLEAN_MCELIECE348864_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 128; +pub const PQCLEAN_MCELIECE348864_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 96; pub const PQCLEAN_MCELIECE348864_CLEAN_CRYPTO_BYTES: usize = 32; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE348864_AVX_CRYPTO_SECRETKEYBYTES: usize = 6452; +pub const PQCLEAN_MCELIECE348864_AVX_CRYPTO_SECRETKEYBYTES: usize = 6492; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MCELIECE348864_AVX_CRYPTO_PUBLICKEYBYTES: usize = 261120; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE348864_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 128; +pub const PQCLEAN_MCELIECE348864_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 96; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MCELIECE348864_AVX_CRYPTO_BYTES: usize = 32; -pub const PQCLEAN_MCELIECE348864F_VEC_CRYPTO_SECRETKEYBYTES: usize = 6452; -pub const PQCLEAN_MCELIECE348864F_VEC_CRYPTO_PUBLICKEYBYTES: usize = 261120; -pub const PQCLEAN_MCELIECE348864F_VEC_CRYPTO_CIPHERTEXTBYTES: usize = 128; -pub const PQCLEAN_MCELIECE348864F_VEC_CRYPTO_BYTES: usize = 32; - -pub const PQCLEAN_MCELIECE348864F_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 6452; +pub const PQCLEAN_MCELIECE348864F_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 6492; pub const PQCLEAN_MCELIECE348864F_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 261120; -pub const PQCLEAN_MCELIECE348864F_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 128; +pub const PQCLEAN_MCELIECE348864F_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 96; pub const PQCLEAN_MCELIECE348864F_CLEAN_CRYPTO_BYTES: usize = 32; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE348864F_AVX_CRYPTO_SECRETKEYBYTES: usize = 6452; +pub const PQCLEAN_MCELIECE348864F_AVX_CRYPTO_SECRETKEYBYTES: usize = 6492; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MCELIECE348864F_AVX_CRYPTO_PUBLICKEYBYTES: usize = 261120; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE348864F_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 128; +pub const PQCLEAN_MCELIECE348864F_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 96; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MCELIECE348864F_AVX_CRYPTO_BYTES: usize = 32; -pub const PQCLEAN_MCELIECE460896_VEC_CRYPTO_SECRETKEYBYTES: usize = 13568; -pub const PQCLEAN_MCELIECE460896_VEC_CRYPTO_PUBLICKEYBYTES: usize = 524160; -pub const PQCLEAN_MCELIECE460896_VEC_CRYPTO_CIPHERTEXTBYTES: usize = 188; -pub const PQCLEAN_MCELIECE460896_VEC_CRYPTO_BYTES: usize = 32; - -pub const PQCLEAN_MCELIECE460896_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 13568; +pub const PQCLEAN_MCELIECE460896_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 13608; pub const PQCLEAN_MCELIECE460896_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 524160; -pub const PQCLEAN_MCELIECE460896_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 188; +pub const PQCLEAN_MCELIECE460896_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 156; pub const PQCLEAN_MCELIECE460896_CLEAN_CRYPTO_BYTES: usize = 32; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE460896_AVX_CRYPTO_SECRETKEYBYTES: usize = 13568; +pub const PQCLEAN_MCELIECE460896_AVX_CRYPTO_SECRETKEYBYTES: usize = 13608; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MCELIECE460896_AVX_CRYPTO_PUBLICKEYBYTES: usize = 524160; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE460896_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 188; +pub const PQCLEAN_MCELIECE460896_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 156; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MCELIECE460896_AVX_CRYPTO_BYTES: usize = 32; -pub const PQCLEAN_MCELIECE460896F_VEC_CRYPTO_SECRETKEYBYTES: usize = 13568; -pub const PQCLEAN_MCELIECE460896F_VEC_CRYPTO_PUBLICKEYBYTES: usize = 524160; -pub const PQCLEAN_MCELIECE460896F_VEC_CRYPTO_CIPHERTEXTBYTES: usize = 188; -pub const PQCLEAN_MCELIECE460896F_VEC_CRYPTO_BYTES: usize = 32; - -pub const PQCLEAN_MCELIECE460896F_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 13568; +pub const PQCLEAN_MCELIECE460896F_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 13608; pub const PQCLEAN_MCELIECE460896F_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 524160; -pub const PQCLEAN_MCELIECE460896F_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 188; +pub const PQCLEAN_MCELIECE460896F_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 156; pub const PQCLEAN_MCELIECE460896F_CLEAN_CRYPTO_BYTES: usize = 32; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE460896F_AVX_CRYPTO_SECRETKEYBYTES: usize = 13568; +pub const PQCLEAN_MCELIECE460896F_AVX_CRYPTO_SECRETKEYBYTES: usize = 13608; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MCELIECE460896F_AVX_CRYPTO_PUBLICKEYBYTES: usize = 524160; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE460896F_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 188; +pub const PQCLEAN_MCELIECE460896F_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 156; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MCELIECE460896F_AVX_CRYPTO_BYTES: usize = 32; -pub const PQCLEAN_MCELIECE6688128_VEC_CRYPTO_SECRETKEYBYTES: usize = 13892; -pub const PQCLEAN_MCELIECE6688128_VEC_CRYPTO_PUBLICKEYBYTES: usize = 1044992; -pub const PQCLEAN_MCELIECE6688128_VEC_CRYPTO_CIPHERTEXTBYTES: usize = 240; -pub const PQCLEAN_MCELIECE6688128_VEC_CRYPTO_BYTES: usize = 32; - -pub const PQCLEAN_MCELIECE6688128_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 13892; +pub const PQCLEAN_MCELIECE6688128_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 13932; pub const PQCLEAN_MCELIECE6688128_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 1044992; -pub const PQCLEAN_MCELIECE6688128_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 240; +pub const PQCLEAN_MCELIECE6688128_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 208; pub const PQCLEAN_MCELIECE6688128_CLEAN_CRYPTO_BYTES: usize = 32; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6688128_AVX_CRYPTO_SECRETKEYBYTES: usize = 13892; +pub const PQCLEAN_MCELIECE6688128_AVX_CRYPTO_SECRETKEYBYTES: usize = 13932; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MCELIECE6688128_AVX_CRYPTO_PUBLICKEYBYTES: usize = 1044992; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6688128_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 240; +pub const PQCLEAN_MCELIECE6688128_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 208; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MCELIECE6688128_AVX_CRYPTO_BYTES: usize = 32; -pub const PQCLEAN_MCELIECE6688128F_VEC_CRYPTO_SECRETKEYBYTES: usize = 13892; -pub const PQCLEAN_MCELIECE6688128F_VEC_CRYPTO_PUBLICKEYBYTES: usize = 1044992; -pub const PQCLEAN_MCELIECE6688128F_VEC_CRYPTO_CIPHERTEXTBYTES: usize = 240; -pub const PQCLEAN_MCELIECE6688128F_VEC_CRYPTO_BYTES: usize = 32; - -pub const PQCLEAN_MCELIECE6688128F_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 13892; +pub const PQCLEAN_MCELIECE6688128F_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 13932; pub const PQCLEAN_MCELIECE6688128F_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 1044992; -pub const PQCLEAN_MCELIECE6688128F_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 240; +pub const PQCLEAN_MCELIECE6688128F_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 208; pub const PQCLEAN_MCELIECE6688128F_CLEAN_CRYPTO_BYTES: usize = 32; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6688128F_AVX_CRYPTO_SECRETKEYBYTES: usize = 13892; +pub const PQCLEAN_MCELIECE6688128F_AVX_CRYPTO_SECRETKEYBYTES: usize = 13932; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MCELIECE6688128F_AVX_CRYPTO_PUBLICKEYBYTES: usize = 1044992; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6688128F_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 240; +pub const PQCLEAN_MCELIECE6688128F_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 208; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MCELIECE6688128F_AVX_CRYPTO_BYTES: usize = 32; -pub const PQCLEAN_MCELIECE6960119_VEC_CRYPTO_SECRETKEYBYTES: usize = 13908; -pub const PQCLEAN_MCELIECE6960119_VEC_CRYPTO_PUBLICKEYBYTES: usize = 1047319; -pub const PQCLEAN_MCELIECE6960119_VEC_CRYPTO_CIPHERTEXTBYTES: usize = 226; -pub const PQCLEAN_MCELIECE6960119_VEC_CRYPTO_BYTES: usize = 32; - -pub const PQCLEAN_MCELIECE6960119_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 13908; +pub const PQCLEAN_MCELIECE6960119_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 13948; pub const PQCLEAN_MCELIECE6960119_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 1047319; -pub const PQCLEAN_MCELIECE6960119_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 226; +pub const PQCLEAN_MCELIECE6960119_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 194; pub const PQCLEAN_MCELIECE6960119_CLEAN_CRYPTO_BYTES: usize = 32; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6960119_AVX_CRYPTO_SECRETKEYBYTES: usize = 13908; +pub const PQCLEAN_MCELIECE6960119_AVX_CRYPTO_SECRETKEYBYTES: usize = 13948; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MCELIECE6960119_AVX_CRYPTO_PUBLICKEYBYTES: usize = 1047319; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6960119_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 226; +pub const PQCLEAN_MCELIECE6960119_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 194; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MCELIECE6960119_AVX_CRYPTO_BYTES: usize = 32; -pub const PQCLEAN_MCELIECE6960119F_VEC_CRYPTO_SECRETKEYBYTES: usize = 13908; -pub const PQCLEAN_MCELIECE6960119F_VEC_CRYPTO_PUBLICKEYBYTES: usize = 1047319; -pub const PQCLEAN_MCELIECE6960119F_VEC_CRYPTO_CIPHERTEXTBYTES: usize = 226; -pub const PQCLEAN_MCELIECE6960119F_VEC_CRYPTO_BYTES: usize = 32; - -pub const PQCLEAN_MCELIECE6960119F_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 13908; +pub const PQCLEAN_MCELIECE6960119F_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 13948; pub const PQCLEAN_MCELIECE6960119F_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 1047319; -pub const PQCLEAN_MCELIECE6960119F_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 226; +pub const PQCLEAN_MCELIECE6960119F_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 194; pub const PQCLEAN_MCELIECE6960119F_CLEAN_CRYPTO_BYTES: usize = 32; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6960119F_AVX_CRYPTO_SECRETKEYBYTES: usize = 13908; +pub const PQCLEAN_MCELIECE6960119F_AVX_CRYPTO_SECRETKEYBYTES: usize = 13948; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MCELIECE6960119F_AVX_CRYPTO_PUBLICKEYBYTES: usize = 1047319; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6960119F_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 226; +pub const PQCLEAN_MCELIECE6960119F_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 194; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MCELIECE6960119F_AVX_CRYPTO_BYTES: usize = 32; -pub const PQCLEAN_MCELIECE8192128_VEC_CRYPTO_SECRETKEYBYTES: usize = 14080; -pub const PQCLEAN_MCELIECE8192128_VEC_CRYPTO_PUBLICKEYBYTES: usize = 1357824; -pub const PQCLEAN_MCELIECE8192128_VEC_CRYPTO_CIPHERTEXTBYTES: usize = 240; -pub const PQCLEAN_MCELIECE8192128_VEC_CRYPTO_BYTES: usize = 32; - -pub const PQCLEAN_MCELIECE8192128_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 14080; +pub const PQCLEAN_MCELIECE8192128_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 14120; pub const PQCLEAN_MCELIECE8192128_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 1357824; -pub const PQCLEAN_MCELIECE8192128_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 240; +pub const PQCLEAN_MCELIECE8192128_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 208; pub const PQCLEAN_MCELIECE8192128_CLEAN_CRYPTO_BYTES: usize = 32; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE8192128_AVX_CRYPTO_SECRETKEYBYTES: usize = 14080; +pub const PQCLEAN_MCELIECE8192128_AVX_CRYPTO_SECRETKEYBYTES: usize = 14120; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MCELIECE8192128_AVX_CRYPTO_PUBLICKEYBYTES: usize = 1357824; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE8192128_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 240; +pub const PQCLEAN_MCELIECE8192128_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 208; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MCELIECE8192128_AVX_CRYPTO_BYTES: usize = 32; -pub const PQCLEAN_MCELIECE8192128F_VEC_CRYPTO_SECRETKEYBYTES: usize = 14080; -pub const PQCLEAN_MCELIECE8192128F_VEC_CRYPTO_PUBLICKEYBYTES: usize = 1357824; -pub const PQCLEAN_MCELIECE8192128F_VEC_CRYPTO_CIPHERTEXTBYTES: usize = 240; -pub const PQCLEAN_MCELIECE8192128F_VEC_CRYPTO_BYTES: usize = 32; - -pub const PQCLEAN_MCELIECE8192128F_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 14080; +pub const PQCLEAN_MCELIECE8192128F_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 14120; pub const PQCLEAN_MCELIECE8192128F_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 1357824; -pub const PQCLEAN_MCELIECE8192128F_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 240; +pub const PQCLEAN_MCELIECE8192128F_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 208; pub const PQCLEAN_MCELIECE8192128F_CLEAN_CRYPTO_BYTES: usize = 32; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE8192128F_AVX_CRYPTO_SECRETKEYBYTES: usize = 14080; +pub const PQCLEAN_MCELIECE8192128F_AVX_CRYPTO_SECRETKEYBYTES: usize = 14120; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MCELIECE8192128F_AVX_CRYPTO_PUBLICKEYBYTES: usize = 1357824; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE8192128F_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 240; +pub const PQCLEAN_MCELIECE8192128F_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 208; #[cfg(enable_x86_avx2)] pub const PQCLEAN_MCELIECE8192128F_AVX_CRYPTO_BYTES: usize = 32; -#[link(name = "mceliece348864_vec")] -extern "C" { - pub fn PQCLEAN_MCELIECE348864_VEC_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - pub fn PQCLEAN_MCELIECE348864_VEC_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_MCELIECE348864_VEC_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; -} - #[link(name = "mceliece348864_clean")] extern "C" { pub fn PQCLEAN_MCELIECE348864_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; @@ -260,21 +195,6 @@ extern "C" { ) -> c_int; } -#[link(name = "mceliece348864f_vec")] -extern "C" { - pub fn PQCLEAN_MCELIECE348864F_VEC_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - pub fn PQCLEAN_MCELIECE348864F_VEC_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_MCELIECE348864F_VEC_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; -} - #[link(name = "mceliece348864f_clean")] extern "C" { pub fn PQCLEAN_MCELIECE348864F_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; @@ -309,21 +229,6 @@ extern "C" { ) -> c_int; } -#[link(name = "mceliece460896_vec")] -extern "C" { - pub fn PQCLEAN_MCELIECE460896_VEC_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - pub fn PQCLEAN_MCELIECE460896_VEC_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_MCELIECE460896_VEC_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; -} - #[link(name = "mceliece460896_clean")] extern "C" { pub fn PQCLEAN_MCELIECE460896_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; @@ -358,21 +263,6 @@ extern "C" { ) -> c_int; } -#[link(name = "mceliece460896f_vec")] -extern "C" { - pub fn PQCLEAN_MCELIECE460896F_VEC_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - pub fn PQCLEAN_MCELIECE460896F_VEC_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_MCELIECE460896F_VEC_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; -} - #[link(name = "mceliece460896f_clean")] extern "C" { pub fn PQCLEAN_MCELIECE460896F_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; @@ -407,21 +297,6 @@ extern "C" { ) -> c_int; } -#[link(name = "mceliece6688128_vec")] -extern "C" { - pub fn PQCLEAN_MCELIECE6688128_VEC_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - pub fn PQCLEAN_MCELIECE6688128_VEC_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_MCELIECE6688128_VEC_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; -} - #[link(name = "mceliece6688128_clean")] extern "C" { pub fn PQCLEAN_MCELIECE6688128_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; @@ -456,21 +331,6 @@ extern "C" { ) -> c_int; } -#[link(name = "mceliece6688128f_vec")] -extern "C" { - pub fn PQCLEAN_MCELIECE6688128F_VEC_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - pub fn PQCLEAN_MCELIECE6688128F_VEC_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_MCELIECE6688128F_VEC_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; -} - #[link(name = "mceliece6688128f_clean")] extern "C" { pub fn PQCLEAN_MCELIECE6688128F_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; @@ -505,21 +365,6 @@ extern "C" { ) -> c_int; } -#[link(name = "mceliece6960119_vec")] -extern "C" { - pub fn PQCLEAN_MCELIECE6960119_VEC_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - pub fn PQCLEAN_MCELIECE6960119_VEC_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_MCELIECE6960119_VEC_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; -} - #[link(name = "mceliece6960119_clean")] extern "C" { pub fn PQCLEAN_MCELIECE6960119_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; @@ -554,21 +399,6 @@ extern "C" { ) -> c_int; } -#[link(name = "mceliece6960119f_vec")] -extern "C" { - pub fn PQCLEAN_MCELIECE6960119F_VEC_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - pub fn PQCLEAN_MCELIECE6960119F_VEC_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_MCELIECE6960119F_VEC_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; -} - #[link(name = "mceliece6960119f_clean")] extern "C" { pub fn PQCLEAN_MCELIECE6960119F_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; @@ -603,21 +433,6 @@ extern "C" { ) -> c_int; } -#[link(name = "mceliece8192128_vec")] -extern "C" { - pub fn PQCLEAN_MCELIECE8192128_VEC_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - pub fn PQCLEAN_MCELIECE8192128_VEC_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_MCELIECE8192128_VEC_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; -} - #[link(name = "mceliece8192128_clean")] extern "C" { pub fn PQCLEAN_MCELIECE8192128_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; @@ -652,21 +467,6 @@ extern "C" { ) -> c_int; } -#[link(name = "mceliece8192128f_vec")] -extern "C" { - pub fn PQCLEAN_MCELIECE8192128F_VEC_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - pub fn PQCLEAN_MCELIECE8192128F_VEC_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_MCELIECE8192128F_VEC_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; -} - #[link(name = "mceliece8192128f_clean")] extern "C" { pub fn PQCLEAN_MCELIECE8192128F_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; @@ -701,45 +501,6 @@ extern "C" { ) -> c_int; } -#[cfg(test)] -mod test_mceliece348864_vec { - use super::*; - use alloc::vec; - - #[test] - fn test_ffi() { - unsafe { - let mut pk = vec![0u8; PQCLEAN_MCELIECE348864_VEC_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_MCELIECE348864_VEC_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_MCELIECE348864_VEC_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_MCELIECE348864_VEC_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_MCELIECE348864_VEC_CRYPTO_BYTES]; - - assert_eq!( - 0, - PQCLEAN_MCELIECE348864_VEC_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_MCELIECE348864_VEC_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_MCELIECE348864_VEC_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_mceliece348864_clean { use super::*; @@ -822,45 +583,6 @@ mod test_mceliece348864_avx { } } -#[cfg(test)] -mod test_mceliece348864f_vec { - use super::*; - use alloc::vec; - - #[test] - fn test_ffi() { - unsafe { - let mut pk = vec![0u8; PQCLEAN_MCELIECE348864F_VEC_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_MCELIECE348864F_VEC_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_MCELIECE348864F_VEC_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_MCELIECE348864F_VEC_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_MCELIECE348864F_VEC_CRYPTO_BYTES]; - - assert_eq!( - 0, - PQCLEAN_MCELIECE348864F_VEC_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_MCELIECE348864F_VEC_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_MCELIECE348864F_VEC_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_mceliece348864f_clean { use super::*; @@ -943,45 +665,6 @@ mod test_mceliece348864f_avx { } } -#[cfg(test)] -mod test_mceliece460896_vec { - use super::*; - use alloc::vec; - - #[test] - fn test_ffi() { - unsafe { - let mut pk = vec![0u8; PQCLEAN_MCELIECE460896_VEC_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_MCELIECE460896_VEC_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_MCELIECE460896_VEC_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_MCELIECE460896_VEC_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_MCELIECE460896_VEC_CRYPTO_BYTES]; - - assert_eq!( - 0, - PQCLEAN_MCELIECE460896_VEC_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_MCELIECE460896_VEC_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_MCELIECE460896_VEC_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_mceliece460896_clean { use super::*; @@ -1064,45 +747,6 @@ mod test_mceliece460896_avx { } } -#[cfg(test)] -mod test_mceliece460896f_vec { - use super::*; - use alloc::vec; - - #[test] - fn test_ffi() { - unsafe { - let mut pk = vec![0u8; PQCLEAN_MCELIECE460896F_VEC_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_MCELIECE460896F_VEC_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_MCELIECE460896F_VEC_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_MCELIECE460896F_VEC_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_MCELIECE460896F_VEC_CRYPTO_BYTES]; - - assert_eq!( - 0, - PQCLEAN_MCELIECE460896F_VEC_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_MCELIECE460896F_VEC_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_MCELIECE460896F_VEC_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_mceliece460896f_clean { use super::*; @@ -1185,45 +829,6 @@ mod test_mceliece460896f_avx { } } -#[cfg(test)] -mod test_mceliece6688128_vec { - use super::*; - use alloc::vec; - - #[test] - fn test_ffi() { - unsafe { - let mut pk = vec![0u8; PQCLEAN_MCELIECE6688128_VEC_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_MCELIECE6688128_VEC_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_MCELIECE6688128_VEC_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_MCELIECE6688128_VEC_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_MCELIECE6688128_VEC_CRYPTO_BYTES]; - - assert_eq!( - 0, - PQCLEAN_MCELIECE6688128_VEC_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_MCELIECE6688128_VEC_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_MCELIECE6688128_VEC_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_mceliece6688128_clean { use super::*; @@ -1306,45 +911,6 @@ mod test_mceliece6688128_avx { } } -#[cfg(test)] -mod test_mceliece6688128f_vec { - use super::*; - use alloc::vec; - - #[test] - fn test_ffi() { - unsafe { - let mut pk = vec![0u8; PQCLEAN_MCELIECE6688128F_VEC_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_MCELIECE6688128F_VEC_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_MCELIECE6688128F_VEC_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_MCELIECE6688128F_VEC_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_MCELIECE6688128F_VEC_CRYPTO_BYTES]; - - assert_eq!( - 0, - PQCLEAN_MCELIECE6688128F_VEC_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_MCELIECE6688128F_VEC_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_MCELIECE6688128F_VEC_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_mceliece6688128f_clean { use super::*; @@ -1427,45 +993,6 @@ mod test_mceliece6688128f_avx { } } -#[cfg(test)] -mod test_mceliece6960119_vec { - use super::*; - use alloc::vec; - - #[test] - fn test_ffi() { - unsafe { - let mut pk = vec![0u8; PQCLEAN_MCELIECE6960119_VEC_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_MCELIECE6960119_VEC_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_MCELIECE6960119_VEC_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_MCELIECE6960119_VEC_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_MCELIECE6960119_VEC_CRYPTO_BYTES]; - - assert_eq!( - 0, - PQCLEAN_MCELIECE6960119_VEC_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_MCELIECE6960119_VEC_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_MCELIECE6960119_VEC_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_mceliece6960119_clean { use super::*; @@ -1548,45 +1075,6 @@ mod test_mceliece6960119_avx { } } -#[cfg(test)] -mod test_mceliece6960119f_vec { - use super::*; - use alloc::vec; - - #[test] - fn test_ffi() { - unsafe { - let mut pk = vec![0u8; PQCLEAN_MCELIECE6960119F_VEC_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_MCELIECE6960119F_VEC_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_MCELIECE6960119F_VEC_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_MCELIECE6960119F_VEC_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_MCELIECE6960119F_VEC_CRYPTO_BYTES]; - - assert_eq!( - 0, - PQCLEAN_MCELIECE6960119F_VEC_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_MCELIECE6960119F_VEC_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_MCELIECE6960119F_VEC_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_mceliece6960119f_clean { use super::*; @@ -1669,45 +1157,6 @@ mod test_mceliece6960119f_avx { } } -#[cfg(test)] -mod test_mceliece8192128_vec { - use super::*; - use alloc::vec; - - #[test] - fn test_ffi() { - unsafe { - let mut pk = vec![0u8; PQCLEAN_MCELIECE8192128_VEC_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_MCELIECE8192128_VEC_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_MCELIECE8192128_VEC_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_MCELIECE8192128_VEC_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_MCELIECE8192128_VEC_CRYPTO_BYTES]; - - assert_eq!( - 0, - PQCLEAN_MCELIECE8192128_VEC_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_MCELIECE8192128_VEC_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_MCELIECE8192128_VEC_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_mceliece8192128_clean { use super::*; @@ -1790,45 +1239,6 @@ mod test_mceliece8192128_avx { } } -#[cfg(test)] -mod test_mceliece8192128f_vec { - use super::*; - use alloc::vec; - - #[test] - fn test_ffi() { - unsafe { - let mut pk = vec![0u8; PQCLEAN_MCELIECE8192128F_VEC_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_MCELIECE8192128F_VEC_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_MCELIECE8192128F_VEC_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_MCELIECE8192128F_VEC_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_MCELIECE8192128F_VEC_CRYPTO_BYTES]; - - assert_eq!( - 0, - PQCLEAN_MCELIECE8192128F_VEC_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_MCELIECE8192128F_VEC_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_MCELIECE8192128F_VEC_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_mceliece8192128f_clean { use super::*; diff --git a/pqcrypto-classicmceliece/src/lib.rs b/pqcrypto-classicmceliece/src/lib.rs index 968c45ef..e861cd69 100644 --- a/pqcrypto-classicmceliece/src/lib.rs +++ b/pqcrypto-classicmceliece/src/lib.rs @@ -3,16 +3,16 @@ //! This crate provides bindings to and wrappers around the following //! implementations from [PQClean][pqc]: //! -//! * mceliece348864 - vec -//! * mceliece348864f - vec -//! * mceliece460896 - vec -//! * mceliece460896f - vec -//! * mceliece6688128 - vec -//! * mceliece6688128f - vec -//! * mceliece6960119 - vec -//! * mceliece6960119f - vec -//! * mceliece8192128 - vec -//! * mceliece8192128f - vec +//! * mceliece348864 - clean +//! * mceliece348864f - clean +//! * mceliece460896 - clean +//! * mceliece460896f - clean +//! * mceliece6688128 - clean +//! * mceliece6688128f - clean +//! * mceliece6960119 - clean +//! * mceliece6960119f - clean +//! * mceliece8192128 - clean +//! * mceliece8192128f - clean //! //! [pqc]: https://github.com/pqclean/pqclean/ //! diff --git a/pqcrypto-classicmceliece/src/mceliece348864.rs b/pqcrypto-classicmceliece/src/mceliece348864.rs index ba8033e6..b9eb6c51 100644 --- a/pqcrypto-classicmceliece/src/mceliece348864.rs +++ b/pqcrypto-classicmceliece/src/mceliece348864.rs @@ -1,6 +1,6 @@ //! mceliece348864 //! -//! These bindings use the vec version from [PQClean][pqc] +//! These bindings use the clean version from [PQClean][pqc] //! //! # Example //! ``` @@ -84,36 +84,36 @@ macro_rules! simple_struct { simple_struct!( PublicKey, - ffi::PQCLEAN_MCELIECE348864_VEC_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_MCELIECE348864_CLEAN_CRYPTO_PUBLICKEYBYTES ); simple_struct!( SecretKey, - ffi::PQCLEAN_MCELIECE348864_VEC_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_MCELIECE348864_CLEAN_CRYPTO_SECRETKEYBYTES ); simple_struct!( Ciphertext, - ffi::PQCLEAN_MCELIECE348864_VEC_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_MCELIECE348864_CLEAN_CRYPTO_CIPHERTEXTBYTES ); -simple_struct!(SharedSecret, ffi::PQCLEAN_MCELIECE348864_VEC_CRYPTO_BYTES); +simple_struct!(SharedSecret, ffi::PQCLEAN_MCELIECE348864_CLEAN_CRYPTO_BYTES); /// Get the number of bytes for a public key pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_MCELIECE348864_VEC_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_MCELIECE348864_CLEAN_CRYPTO_PUBLICKEYBYTES } /// Get the number of bytes for a secret key pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_MCELIECE348864_VEC_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_MCELIECE348864_CLEAN_CRYPTO_SECRETKEYBYTES } /// Get the number of bytes for the encapsulated ciphertext pub const fn ciphertext_bytes() -> usize { - ffi::PQCLEAN_MCELIECE348864_VEC_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_MCELIECE348864_CLEAN_CRYPTO_CIPHERTEXTBYTES } /// Get the number of bytes for the shared secret pub const fn shared_secret_bytes() -> usize { - ffi::PQCLEAN_MCELIECE348864_VEC_CRYPTO_BYTES + ffi::PQCLEAN_MCELIECE348864_CLEAN_CRYPTO_BYTES } macro_rules! gen_keypair { @@ -136,7 +136,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { return gen_keypair!(PQCLEAN_MCELIECE348864_AVX_crypto_kem_keypair); } } - gen_keypair!(PQCLEAN_MCELIECE348864_VEC_crypto_kem_keypair) + gen_keypair!(PQCLEAN_MCELIECE348864_CLEAN_crypto_kem_keypair) } macro_rules! encap { @@ -159,7 +159,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { return encap!(PQCLEAN_MCELIECE348864_AVX_crypto_kem_enc, pk); } } - encap!(PQCLEAN_MCELIECE348864_VEC_crypto_kem_enc, pk) + encap!(PQCLEAN_MCELIECE348864_CLEAN_crypto_kem_enc, pk) } macro_rules! decap { @@ -181,7 +181,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { return decap!(PQCLEAN_MCELIECE348864_AVX_crypto_kem_dec, ct, sk); } } - decap!(PQCLEAN_MCELIECE348864_VEC_crypto_kem_dec, ct, sk) + decap!(PQCLEAN_MCELIECE348864_CLEAN_crypto_kem_dec, ct, sk) } #[cfg(test)] diff --git a/pqcrypto-classicmceliece/src/mceliece348864f.rs b/pqcrypto-classicmceliece/src/mceliece348864f.rs index c5cd40d7..801e74de 100644 --- a/pqcrypto-classicmceliece/src/mceliece348864f.rs +++ b/pqcrypto-classicmceliece/src/mceliece348864f.rs @@ -1,6 +1,6 @@ //! mceliece348864f //! -//! These bindings use the vec version from [PQClean][pqc] +//! These bindings use the clean version from [PQClean][pqc] //! //! # Example //! ``` @@ -84,36 +84,39 @@ macro_rules! simple_struct { simple_struct!( PublicKey, - ffi::PQCLEAN_MCELIECE348864F_VEC_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_MCELIECE348864F_CLEAN_CRYPTO_PUBLICKEYBYTES ); simple_struct!( SecretKey, - ffi::PQCLEAN_MCELIECE348864F_VEC_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_MCELIECE348864F_CLEAN_CRYPTO_SECRETKEYBYTES ); simple_struct!( Ciphertext, - ffi::PQCLEAN_MCELIECE348864F_VEC_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_MCELIECE348864F_CLEAN_CRYPTO_CIPHERTEXTBYTES +); +simple_struct!( + SharedSecret, + ffi::PQCLEAN_MCELIECE348864F_CLEAN_CRYPTO_BYTES ); -simple_struct!(SharedSecret, ffi::PQCLEAN_MCELIECE348864F_VEC_CRYPTO_BYTES); /// Get the number of bytes for a public key pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_MCELIECE348864F_VEC_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_MCELIECE348864F_CLEAN_CRYPTO_PUBLICKEYBYTES } /// Get the number of bytes for a secret key pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_MCELIECE348864F_VEC_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_MCELIECE348864F_CLEAN_CRYPTO_SECRETKEYBYTES } /// Get the number of bytes for the encapsulated ciphertext pub const fn ciphertext_bytes() -> usize { - ffi::PQCLEAN_MCELIECE348864F_VEC_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_MCELIECE348864F_CLEAN_CRYPTO_CIPHERTEXTBYTES } /// Get the number of bytes for the shared secret pub const fn shared_secret_bytes() -> usize { - ffi::PQCLEAN_MCELIECE348864F_VEC_CRYPTO_BYTES + ffi::PQCLEAN_MCELIECE348864F_CLEAN_CRYPTO_BYTES } macro_rules! gen_keypair { @@ -136,7 +139,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { return gen_keypair!(PQCLEAN_MCELIECE348864F_AVX_crypto_kem_keypair); } } - gen_keypair!(PQCLEAN_MCELIECE348864F_VEC_crypto_kem_keypair) + gen_keypair!(PQCLEAN_MCELIECE348864F_CLEAN_crypto_kem_keypair) } macro_rules! encap { @@ -159,7 +162,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { return encap!(PQCLEAN_MCELIECE348864F_AVX_crypto_kem_enc, pk); } } - encap!(PQCLEAN_MCELIECE348864F_VEC_crypto_kem_enc, pk) + encap!(PQCLEAN_MCELIECE348864F_CLEAN_crypto_kem_enc, pk) } macro_rules! decap { @@ -181,7 +184,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { return decap!(PQCLEAN_MCELIECE348864F_AVX_crypto_kem_dec, ct, sk); } } - decap!(PQCLEAN_MCELIECE348864F_VEC_crypto_kem_dec, ct, sk) + decap!(PQCLEAN_MCELIECE348864F_CLEAN_crypto_kem_dec, ct, sk) } #[cfg(test)] diff --git a/pqcrypto-classicmceliece/src/mceliece460896.rs b/pqcrypto-classicmceliece/src/mceliece460896.rs index 4889116f..8db83632 100644 --- a/pqcrypto-classicmceliece/src/mceliece460896.rs +++ b/pqcrypto-classicmceliece/src/mceliece460896.rs @@ -1,6 +1,6 @@ //! mceliece460896 //! -//! These bindings use the vec version from [PQClean][pqc] +//! These bindings use the clean version from [PQClean][pqc] //! //! # Example //! ``` @@ -84,36 +84,36 @@ macro_rules! simple_struct { simple_struct!( PublicKey, - ffi::PQCLEAN_MCELIECE460896_VEC_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_MCELIECE460896_CLEAN_CRYPTO_PUBLICKEYBYTES ); simple_struct!( SecretKey, - ffi::PQCLEAN_MCELIECE460896_VEC_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_MCELIECE460896_CLEAN_CRYPTO_SECRETKEYBYTES ); simple_struct!( Ciphertext, - ffi::PQCLEAN_MCELIECE460896_VEC_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_MCELIECE460896_CLEAN_CRYPTO_CIPHERTEXTBYTES ); -simple_struct!(SharedSecret, ffi::PQCLEAN_MCELIECE460896_VEC_CRYPTO_BYTES); +simple_struct!(SharedSecret, ffi::PQCLEAN_MCELIECE460896_CLEAN_CRYPTO_BYTES); /// Get the number of bytes for a public key pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_MCELIECE460896_VEC_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_MCELIECE460896_CLEAN_CRYPTO_PUBLICKEYBYTES } /// Get the number of bytes for a secret key pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_MCELIECE460896_VEC_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_MCELIECE460896_CLEAN_CRYPTO_SECRETKEYBYTES } /// Get the number of bytes for the encapsulated ciphertext pub const fn ciphertext_bytes() -> usize { - ffi::PQCLEAN_MCELIECE460896_VEC_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_MCELIECE460896_CLEAN_CRYPTO_CIPHERTEXTBYTES } /// Get the number of bytes for the shared secret pub const fn shared_secret_bytes() -> usize { - ffi::PQCLEAN_MCELIECE460896_VEC_CRYPTO_BYTES + ffi::PQCLEAN_MCELIECE460896_CLEAN_CRYPTO_BYTES } macro_rules! gen_keypair { @@ -136,7 +136,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { return gen_keypair!(PQCLEAN_MCELIECE460896_AVX_crypto_kem_keypair); } } - gen_keypair!(PQCLEAN_MCELIECE460896_VEC_crypto_kem_keypair) + gen_keypair!(PQCLEAN_MCELIECE460896_CLEAN_crypto_kem_keypair) } macro_rules! encap { @@ -159,7 +159,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { return encap!(PQCLEAN_MCELIECE460896_AVX_crypto_kem_enc, pk); } } - encap!(PQCLEAN_MCELIECE460896_VEC_crypto_kem_enc, pk) + encap!(PQCLEAN_MCELIECE460896_CLEAN_crypto_kem_enc, pk) } macro_rules! decap { @@ -181,7 +181,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { return decap!(PQCLEAN_MCELIECE460896_AVX_crypto_kem_dec, ct, sk); } } - decap!(PQCLEAN_MCELIECE460896_VEC_crypto_kem_dec, ct, sk) + decap!(PQCLEAN_MCELIECE460896_CLEAN_crypto_kem_dec, ct, sk) } #[cfg(test)] diff --git a/pqcrypto-classicmceliece/src/mceliece460896f.rs b/pqcrypto-classicmceliece/src/mceliece460896f.rs index 8271825a..dbce7bc4 100644 --- a/pqcrypto-classicmceliece/src/mceliece460896f.rs +++ b/pqcrypto-classicmceliece/src/mceliece460896f.rs @@ -1,6 +1,6 @@ //! mceliece460896f //! -//! These bindings use the vec version from [PQClean][pqc] +//! These bindings use the clean version from [PQClean][pqc] //! //! # Example //! ``` @@ -84,36 +84,39 @@ macro_rules! simple_struct { simple_struct!( PublicKey, - ffi::PQCLEAN_MCELIECE460896F_VEC_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_MCELIECE460896F_CLEAN_CRYPTO_PUBLICKEYBYTES ); simple_struct!( SecretKey, - ffi::PQCLEAN_MCELIECE460896F_VEC_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_MCELIECE460896F_CLEAN_CRYPTO_SECRETKEYBYTES ); simple_struct!( Ciphertext, - ffi::PQCLEAN_MCELIECE460896F_VEC_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_MCELIECE460896F_CLEAN_CRYPTO_CIPHERTEXTBYTES +); +simple_struct!( + SharedSecret, + ffi::PQCLEAN_MCELIECE460896F_CLEAN_CRYPTO_BYTES ); -simple_struct!(SharedSecret, ffi::PQCLEAN_MCELIECE460896F_VEC_CRYPTO_BYTES); /// Get the number of bytes for a public key pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_MCELIECE460896F_VEC_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_MCELIECE460896F_CLEAN_CRYPTO_PUBLICKEYBYTES } /// Get the number of bytes for a secret key pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_MCELIECE460896F_VEC_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_MCELIECE460896F_CLEAN_CRYPTO_SECRETKEYBYTES } /// Get the number of bytes for the encapsulated ciphertext pub const fn ciphertext_bytes() -> usize { - ffi::PQCLEAN_MCELIECE460896F_VEC_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_MCELIECE460896F_CLEAN_CRYPTO_CIPHERTEXTBYTES } /// Get the number of bytes for the shared secret pub const fn shared_secret_bytes() -> usize { - ffi::PQCLEAN_MCELIECE460896F_VEC_CRYPTO_BYTES + ffi::PQCLEAN_MCELIECE460896F_CLEAN_CRYPTO_BYTES } macro_rules! gen_keypair { @@ -136,7 +139,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { return gen_keypair!(PQCLEAN_MCELIECE460896F_AVX_crypto_kem_keypair); } } - gen_keypair!(PQCLEAN_MCELIECE460896F_VEC_crypto_kem_keypair) + gen_keypair!(PQCLEAN_MCELIECE460896F_CLEAN_crypto_kem_keypair) } macro_rules! encap { @@ -159,7 +162,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { return encap!(PQCLEAN_MCELIECE460896F_AVX_crypto_kem_enc, pk); } } - encap!(PQCLEAN_MCELIECE460896F_VEC_crypto_kem_enc, pk) + encap!(PQCLEAN_MCELIECE460896F_CLEAN_crypto_kem_enc, pk) } macro_rules! decap { @@ -181,7 +184,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { return decap!(PQCLEAN_MCELIECE460896F_AVX_crypto_kem_dec, ct, sk); } } - decap!(PQCLEAN_MCELIECE460896F_VEC_crypto_kem_dec, ct, sk) + decap!(PQCLEAN_MCELIECE460896F_CLEAN_crypto_kem_dec, ct, sk) } #[cfg(test)] diff --git a/pqcrypto-classicmceliece/src/mceliece6688128.rs b/pqcrypto-classicmceliece/src/mceliece6688128.rs index 5e62d0e2..bd462e2f 100644 --- a/pqcrypto-classicmceliece/src/mceliece6688128.rs +++ b/pqcrypto-classicmceliece/src/mceliece6688128.rs @@ -1,6 +1,6 @@ //! mceliece6688128 //! -//! These bindings use the vec version from [PQClean][pqc] +//! These bindings use the clean version from [PQClean][pqc] //! //! # Example //! ```no_run @@ -84,36 +84,39 @@ macro_rules! simple_struct { simple_struct!( PublicKey, - ffi::PQCLEAN_MCELIECE6688128_VEC_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_MCELIECE6688128_CLEAN_CRYPTO_PUBLICKEYBYTES ); simple_struct!( SecretKey, - ffi::PQCLEAN_MCELIECE6688128_VEC_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_MCELIECE6688128_CLEAN_CRYPTO_SECRETKEYBYTES ); simple_struct!( Ciphertext, - ffi::PQCLEAN_MCELIECE6688128_VEC_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_MCELIECE6688128_CLEAN_CRYPTO_CIPHERTEXTBYTES +); +simple_struct!( + SharedSecret, + ffi::PQCLEAN_MCELIECE6688128_CLEAN_CRYPTO_BYTES ); -simple_struct!(SharedSecret, ffi::PQCLEAN_MCELIECE6688128_VEC_CRYPTO_BYTES); /// Get the number of bytes for a public key pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_MCELIECE6688128_VEC_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_MCELIECE6688128_CLEAN_CRYPTO_PUBLICKEYBYTES } /// Get the number of bytes for a secret key pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_MCELIECE6688128_VEC_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_MCELIECE6688128_CLEAN_CRYPTO_SECRETKEYBYTES } /// Get the number of bytes for the encapsulated ciphertext pub const fn ciphertext_bytes() -> usize { - ffi::PQCLEAN_MCELIECE6688128_VEC_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_MCELIECE6688128_CLEAN_CRYPTO_CIPHERTEXTBYTES } /// Get the number of bytes for the shared secret pub const fn shared_secret_bytes() -> usize { - ffi::PQCLEAN_MCELIECE6688128_VEC_CRYPTO_BYTES + ffi::PQCLEAN_MCELIECE6688128_CLEAN_CRYPTO_BYTES } macro_rules! gen_keypair { @@ -136,7 +139,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { return gen_keypair!(PQCLEAN_MCELIECE6688128_AVX_crypto_kem_keypair); } } - gen_keypair!(PQCLEAN_MCELIECE6688128_VEC_crypto_kem_keypair) + gen_keypair!(PQCLEAN_MCELIECE6688128_CLEAN_crypto_kem_keypair) } macro_rules! encap { @@ -159,7 +162,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { return encap!(PQCLEAN_MCELIECE6688128_AVX_crypto_kem_enc, pk); } } - encap!(PQCLEAN_MCELIECE6688128_VEC_crypto_kem_enc, pk) + encap!(PQCLEAN_MCELIECE6688128_CLEAN_crypto_kem_enc, pk) } macro_rules! decap { @@ -181,7 +184,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { return decap!(PQCLEAN_MCELIECE6688128_AVX_crypto_kem_dec, ct, sk); } } - decap!(PQCLEAN_MCELIECE6688128_VEC_crypto_kem_dec, ct, sk) + decap!(PQCLEAN_MCELIECE6688128_CLEAN_crypto_kem_dec, ct, sk) } #[cfg(test)] diff --git a/pqcrypto-classicmceliece/src/mceliece6688128f.rs b/pqcrypto-classicmceliece/src/mceliece6688128f.rs index aca2c3e2..2b177871 100644 --- a/pqcrypto-classicmceliece/src/mceliece6688128f.rs +++ b/pqcrypto-classicmceliece/src/mceliece6688128f.rs @@ -1,6 +1,6 @@ //! mceliece6688128f //! -//! These bindings use the vec version from [PQClean][pqc] +//! These bindings use the clean version from [PQClean][pqc] //! //! # Example //! ```no_run @@ -84,36 +84,39 @@ macro_rules! simple_struct { simple_struct!( PublicKey, - ffi::PQCLEAN_MCELIECE6688128F_VEC_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_MCELIECE6688128F_CLEAN_CRYPTO_PUBLICKEYBYTES ); simple_struct!( SecretKey, - ffi::PQCLEAN_MCELIECE6688128F_VEC_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_MCELIECE6688128F_CLEAN_CRYPTO_SECRETKEYBYTES ); simple_struct!( Ciphertext, - ffi::PQCLEAN_MCELIECE6688128F_VEC_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_MCELIECE6688128F_CLEAN_CRYPTO_CIPHERTEXTBYTES +); +simple_struct!( + SharedSecret, + ffi::PQCLEAN_MCELIECE6688128F_CLEAN_CRYPTO_BYTES ); -simple_struct!(SharedSecret, ffi::PQCLEAN_MCELIECE6688128F_VEC_CRYPTO_BYTES); /// Get the number of bytes for a public key pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_MCELIECE6688128F_VEC_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_MCELIECE6688128F_CLEAN_CRYPTO_PUBLICKEYBYTES } /// Get the number of bytes for a secret key pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_MCELIECE6688128F_VEC_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_MCELIECE6688128F_CLEAN_CRYPTO_SECRETKEYBYTES } /// Get the number of bytes for the encapsulated ciphertext pub const fn ciphertext_bytes() -> usize { - ffi::PQCLEAN_MCELIECE6688128F_VEC_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_MCELIECE6688128F_CLEAN_CRYPTO_CIPHERTEXTBYTES } /// Get the number of bytes for the shared secret pub const fn shared_secret_bytes() -> usize { - ffi::PQCLEAN_MCELIECE6688128F_VEC_CRYPTO_BYTES + ffi::PQCLEAN_MCELIECE6688128F_CLEAN_CRYPTO_BYTES } macro_rules! gen_keypair { @@ -136,7 +139,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { return gen_keypair!(PQCLEAN_MCELIECE6688128F_AVX_crypto_kem_keypair); } } - gen_keypair!(PQCLEAN_MCELIECE6688128F_VEC_crypto_kem_keypair) + gen_keypair!(PQCLEAN_MCELIECE6688128F_CLEAN_crypto_kem_keypair) } macro_rules! encap { @@ -159,7 +162,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { return encap!(PQCLEAN_MCELIECE6688128F_AVX_crypto_kem_enc, pk); } } - encap!(PQCLEAN_MCELIECE6688128F_VEC_crypto_kem_enc, pk) + encap!(PQCLEAN_MCELIECE6688128F_CLEAN_crypto_kem_enc, pk) } macro_rules! decap { @@ -181,7 +184,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { return decap!(PQCLEAN_MCELIECE6688128F_AVX_crypto_kem_dec, ct, sk); } } - decap!(PQCLEAN_MCELIECE6688128F_VEC_crypto_kem_dec, ct, sk) + decap!(PQCLEAN_MCELIECE6688128F_CLEAN_crypto_kem_dec, ct, sk) } #[cfg(test)] diff --git a/pqcrypto-classicmceliece/src/mceliece6960119.rs b/pqcrypto-classicmceliece/src/mceliece6960119.rs index 70778c45..e605e58e 100644 --- a/pqcrypto-classicmceliece/src/mceliece6960119.rs +++ b/pqcrypto-classicmceliece/src/mceliece6960119.rs @@ -1,6 +1,6 @@ //! mceliece6960119 //! -//! These bindings use the vec version from [PQClean][pqc] +//! These bindings use the clean version from [PQClean][pqc] //! //! # Example //! ```no_run @@ -84,36 +84,39 @@ macro_rules! simple_struct { simple_struct!( PublicKey, - ffi::PQCLEAN_MCELIECE6960119_VEC_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_MCELIECE6960119_CLEAN_CRYPTO_PUBLICKEYBYTES ); simple_struct!( SecretKey, - ffi::PQCLEAN_MCELIECE6960119_VEC_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_MCELIECE6960119_CLEAN_CRYPTO_SECRETKEYBYTES ); simple_struct!( Ciphertext, - ffi::PQCLEAN_MCELIECE6960119_VEC_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_MCELIECE6960119_CLEAN_CRYPTO_CIPHERTEXTBYTES +); +simple_struct!( + SharedSecret, + ffi::PQCLEAN_MCELIECE6960119_CLEAN_CRYPTO_BYTES ); -simple_struct!(SharedSecret, ffi::PQCLEAN_MCELIECE6960119_VEC_CRYPTO_BYTES); /// Get the number of bytes for a public key pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_MCELIECE6960119_VEC_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_MCELIECE6960119_CLEAN_CRYPTO_PUBLICKEYBYTES } /// Get the number of bytes for a secret key pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_MCELIECE6960119_VEC_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_MCELIECE6960119_CLEAN_CRYPTO_SECRETKEYBYTES } /// Get the number of bytes for the encapsulated ciphertext pub const fn ciphertext_bytes() -> usize { - ffi::PQCLEAN_MCELIECE6960119_VEC_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_MCELIECE6960119_CLEAN_CRYPTO_CIPHERTEXTBYTES } /// Get the number of bytes for the shared secret pub const fn shared_secret_bytes() -> usize { - ffi::PQCLEAN_MCELIECE6960119_VEC_CRYPTO_BYTES + ffi::PQCLEAN_MCELIECE6960119_CLEAN_CRYPTO_BYTES } macro_rules! gen_keypair { @@ -136,7 +139,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { return gen_keypair!(PQCLEAN_MCELIECE6960119_AVX_crypto_kem_keypair); } } - gen_keypair!(PQCLEAN_MCELIECE6960119_VEC_crypto_kem_keypair) + gen_keypair!(PQCLEAN_MCELIECE6960119_CLEAN_crypto_kem_keypair) } macro_rules! encap { @@ -159,7 +162,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { return encap!(PQCLEAN_MCELIECE6960119_AVX_crypto_kem_enc, pk); } } - encap!(PQCLEAN_MCELIECE6960119_VEC_crypto_kem_enc, pk) + encap!(PQCLEAN_MCELIECE6960119_CLEAN_crypto_kem_enc, pk) } macro_rules! decap { @@ -181,7 +184,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { return decap!(PQCLEAN_MCELIECE6960119_AVX_crypto_kem_dec, ct, sk); } } - decap!(PQCLEAN_MCELIECE6960119_VEC_crypto_kem_dec, ct, sk) + decap!(PQCLEAN_MCELIECE6960119_CLEAN_crypto_kem_dec, ct, sk) } #[cfg(test)] diff --git a/pqcrypto-classicmceliece/src/mceliece6960119f.rs b/pqcrypto-classicmceliece/src/mceliece6960119f.rs index 3f74e1db..5cd3e186 100644 --- a/pqcrypto-classicmceliece/src/mceliece6960119f.rs +++ b/pqcrypto-classicmceliece/src/mceliece6960119f.rs @@ -1,6 +1,6 @@ //! mceliece6960119f //! -//! These bindings use the vec version from [PQClean][pqc] +//! These bindings use the clean version from [PQClean][pqc] //! //! # Example //! ```no_run @@ -84,36 +84,39 @@ macro_rules! simple_struct { simple_struct!( PublicKey, - ffi::PQCLEAN_MCELIECE6960119F_VEC_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_MCELIECE6960119F_CLEAN_CRYPTO_PUBLICKEYBYTES ); simple_struct!( SecretKey, - ffi::PQCLEAN_MCELIECE6960119F_VEC_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_MCELIECE6960119F_CLEAN_CRYPTO_SECRETKEYBYTES ); simple_struct!( Ciphertext, - ffi::PQCLEAN_MCELIECE6960119F_VEC_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_MCELIECE6960119F_CLEAN_CRYPTO_CIPHERTEXTBYTES +); +simple_struct!( + SharedSecret, + ffi::PQCLEAN_MCELIECE6960119F_CLEAN_CRYPTO_BYTES ); -simple_struct!(SharedSecret, ffi::PQCLEAN_MCELIECE6960119F_VEC_CRYPTO_BYTES); /// Get the number of bytes for a public key pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_MCELIECE6960119F_VEC_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_MCELIECE6960119F_CLEAN_CRYPTO_PUBLICKEYBYTES } /// Get the number of bytes for a secret key pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_MCELIECE6960119F_VEC_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_MCELIECE6960119F_CLEAN_CRYPTO_SECRETKEYBYTES } /// Get the number of bytes for the encapsulated ciphertext pub const fn ciphertext_bytes() -> usize { - ffi::PQCLEAN_MCELIECE6960119F_VEC_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_MCELIECE6960119F_CLEAN_CRYPTO_CIPHERTEXTBYTES } /// Get the number of bytes for the shared secret pub const fn shared_secret_bytes() -> usize { - ffi::PQCLEAN_MCELIECE6960119F_VEC_CRYPTO_BYTES + ffi::PQCLEAN_MCELIECE6960119F_CLEAN_CRYPTO_BYTES } macro_rules! gen_keypair { @@ -136,7 +139,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { return gen_keypair!(PQCLEAN_MCELIECE6960119F_AVX_crypto_kem_keypair); } } - gen_keypair!(PQCLEAN_MCELIECE6960119F_VEC_crypto_kem_keypair) + gen_keypair!(PQCLEAN_MCELIECE6960119F_CLEAN_crypto_kem_keypair) } macro_rules! encap { @@ -159,7 +162,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { return encap!(PQCLEAN_MCELIECE6960119F_AVX_crypto_kem_enc, pk); } } - encap!(PQCLEAN_MCELIECE6960119F_VEC_crypto_kem_enc, pk) + encap!(PQCLEAN_MCELIECE6960119F_CLEAN_crypto_kem_enc, pk) } macro_rules! decap { @@ -181,7 +184,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { return decap!(PQCLEAN_MCELIECE6960119F_AVX_crypto_kem_dec, ct, sk); } } - decap!(PQCLEAN_MCELIECE6960119F_VEC_crypto_kem_dec, ct, sk) + decap!(PQCLEAN_MCELIECE6960119F_CLEAN_crypto_kem_dec, ct, sk) } #[cfg(test)] diff --git a/pqcrypto-classicmceliece/src/mceliece8192128.rs b/pqcrypto-classicmceliece/src/mceliece8192128.rs index 042c40f7..3d53c120 100644 --- a/pqcrypto-classicmceliece/src/mceliece8192128.rs +++ b/pqcrypto-classicmceliece/src/mceliece8192128.rs @@ -1,6 +1,6 @@ //! mceliece8192128 //! -//! These bindings use the vec version from [PQClean][pqc] +//! These bindings use the clean version from [PQClean][pqc] //! //! # Example //! ```no_run @@ -84,36 +84,39 @@ macro_rules! simple_struct { simple_struct!( PublicKey, - ffi::PQCLEAN_MCELIECE8192128_VEC_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_MCELIECE8192128_CLEAN_CRYPTO_PUBLICKEYBYTES ); simple_struct!( SecretKey, - ffi::PQCLEAN_MCELIECE8192128_VEC_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_MCELIECE8192128_CLEAN_CRYPTO_SECRETKEYBYTES ); simple_struct!( Ciphertext, - ffi::PQCLEAN_MCELIECE8192128_VEC_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_MCELIECE8192128_CLEAN_CRYPTO_CIPHERTEXTBYTES +); +simple_struct!( + SharedSecret, + ffi::PQCLEAN_MCELIECE8192128_CLEAN_CRYPTO_BYTES ); -simple_struct!(SharedSecret, ffi::PQCLEAN_MCELIECE8192128_VEC_CRYPTO_BYTES); /// Get the number of bytes for a public key pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_MCELIECE8192128_VEC_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_MCELIECE8192128_CLEAN_CRYPTO_PUBLICKEYBYTES } /// Get the number of bytes for a secret key pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_MCELIECE8192128_VEC_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_MCELIECE8192128_CLEAN_CRYPTO_SECRETKEYBYTES } /// Get the number of bytes for the encapsulated ciphertext pub const fn ciphertext_bytes() -> usize { - ffi::PQCLEAN_MCELIECE8192128_VEC_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_MCELIECE8192128_CLEAN_CRYPTO_CIPHERTEXTBYTES } /// Get the number of bytes for the shared secret pub const fn shared_secret_bytes() -> usize { - ffi::PQCLEAN_MCELIECE8192128_VEC_CRYPTO_BYTES + ffi::PQCLEAN_MCELIECE8192128_CLEAN_CRYPTO_BYTES } macro_rules! gen_keypair { @@ -136,7 +139,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { return gen_keypair!(PQCLEAN_MCELIECE8192128_AVX_crypto_kem_keypair); } } - gen_keypair!(PQCLEAN_MCELIECE8192128_VEC_crypto_kem_keypair) + gen_keypair!(PQCLEAN_MCELIECE8192128_CLEAN_crypto_kem_keypair) } macro_rules! encap { @@ -159,7 +162,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { return encap!(PQCLEAN_MCELIECE8192128_AVX_crypto_kem_enc, pk); } } - encap!(PQCLEAN_MCELIECE8192128_VEC_crypto_kem_enc, pk) + encap!(PQCLEAN_MCELIECE8192128_CLEAN_crypto_kem_enc, pk) } macro_rules! decap { @@ -181,7 +184,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { return decap!(PQCLEAN_MCELIECE8192128_AVX_crypto_kem_dec, ct, sk); } } - decap!(PQCLEAN_MCELIECE8192128_VEC_crypto_kem_dec, ct, sk) + decap!(PQCLEAN_MCELIECE8192128_CLEAN_crypto_kem_dec, ct, sk) } #[cfg(test)] diff --git a/pqcrypto-classicmceliece/src/mceliece8192128f.rs b/pqcrypto-classicmceliece/src/mceliece8192128f.rs index 2309ec93..23ddbe63 100644 --- a/pqcrypto-classicmceliece/src/mceliece8192128f.rs +++ b/pqcrypto-classicmceliece/src/mceliece8192128f.rs @@ -1,6 +1,6 @@ //! mceliece8192128f //! -//! These bindings use the vec version from [PQClean][pqc] +//! These bindings use the clean version from [PQClean][pqc] //! //! # Example //! ```no_run @@ -84,36 +84,39 @@ macro_rules! simple_struct { simple_struct!( PublicKey, - ffi::PQCLEAN_MCELIECE8192128F_VEC_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_MCELIECE8192128F_CLEAN_CRYPTO_PUBLICKEYBYTES ); simple_struct!( SecretKey, - ffi::PQCLEAN_MCELIECE8192128F_VEC_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_MCELIECE8192128F_CLEAN_CRYPTO_SECRETKEYBYTES ); simple_struct!( Ciphertext, - ffi::PQCLEAN_MCELIECE8192128F_VEC_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_MCELIECE8192128F_CLEAN_CRYPTO_CIPHERTEXTBYTES +); +simple_struct!( + SharedSecret, + ffi::PQCLEAN_MCELIECE8192128F_CLEAN_CRYPTO_BYTES ); -simple_struct!(SharedSecret, ffi::PQCLEAN_MCELIECE8192128F_VEC_CRYPTO_BYTES); /// Get the number of bytes for a public key pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_MCELIECE8192128F_VEC_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_MCELIECE8192128F_CLEAN_CRYPTO_PUBLICKEYBYTES } /// Get the number of bytes for a secret key pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_MCELIECE8192128F_VEC_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_MCELIECE8192128F_CLEAN_CRYPTO_SECRETKEYBYTES } /// Get the number of bytes for the encapsulated ciphertext pub const fn ciphertext_bytes() -> usize { - ffi::PQCLEAN_MCELIECE8192128F_VEC_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_MCELIECE8192128F_CLEAN_CRYPTO_CIPHERTEXTBYTES } /// Get the number of bytes for the shared secret pub const fn shared_secret_bytes() -> usize { - ffi::PQCLEAN_MCELIECE8192128F_VEC_CRYPTO_BYTES + ffi::PQCLEAN_MCELIECE8192128F_CLEAN_CRYPTO_BYTES } macro_rules! gen_keypair { @@ -136,7 +139,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { return gen_keypair!(PQCLEAN_MCELIECE8192128F_AVX_crypto_kem_keypair); } } - gen_keypair!(PQCLEAN_MCELIECE8192128F_VEC_crypto_kem_keypair) + gen_keypair!(PQCLEAN_MCELIECE8192128F_CLEAN_crypto_kem_keypair) } macro_rules! encap { @@ -159,7 +162,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { return encap!(PQCLEAN_MCELIECE8192128F_AVX_crypto_kem_enc, pk); } } - encap!(PQCLEAN_MCELIECE8192128F_VEC_crypto_kem_enc, pk) + encap!(PQCLEAN_MCELIECE8192128F_CLEAN_crypto_kem_enc, pk) } macro_rules! decap { @@ -181,7 +184,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { return decap!(PQCLEAN_MCELIECE8192128F_AVX_crypto_kem_dec, ct, sk); } } - decap!(PQCLEAN_MCELIECE8192128F_VEC_crypto_kem_dec, ct, sk) + decap!(PQCLEAN_MCELIECE8192128F_CLEAN_crypto_kem_dec, ct, sk) } #[cfg(test)] diff --git a/pqcrypto-dilithium/Cargo.toml b/pqcrypto-dilithium/Cargo.toml index 899ba13c..a96cb2d8 100644 --- a/pqcrypto-dilithium/Cargo.toml +++ b/pqcrypto-dilithium/Cargo.toml @@ -2,7 +2,7 @@ name = "pqcrypto-dilithium" description = "Post-Quantum Signature Scheme dilithium" readme = "README.md" -version = "0.4.7" +version = "0.5.0" authors = ["Thom Wiggers "] edition = "2018" license = "MIT OR Apache-2.0" diff --git a/pqcrypto-dilithium/README.md b/pqcrypto-dilithium/README.md index b29a27c6..2a6df7bb 100644 --- a/pqcrypto-dilithium/README.md +++ b/pqcrypto-dilithium/README.md @@ -31,15 +31,6 @@ methods only. * ``clean`` * ``avx2`` (if supported) * ``aarch64`` (if supported) -* ``dilithium2aes`` - * ``clean`` - * ``avx2`` (if supported) -* ``dilithium3aes`` - * ``clean`` - * ``avx2`` (if supported) -* ``dilithium5aes`` - * ``clean`` - * ``avx2`` (if supported) ## License diff --git a/pqcrypto-dilithium/build.rs b/pqcrypto-dilithium/build.rs index 61168ad1..ef125f52 100644 --- a/pqcrypto-dilithium/build.rs +++ b/pqcrypto-dilithium/build.rs @@ -150,18 +150,6 @@ fn main() { if target_arch == "aarch64" && neon_enabled { build_aarch64!("dilithium5"); } - build_clean!("dilithium2aes"); - if target_arch == "x86_64" && avx2_enabled && !is_windows { - build_avx2!("dilithium2aes"); - } - build_clean!("dilithium3aes"); - if target_arch == "x86_64" && avx2_enabled && !is_windows { - build_avx2!("dilithium3aes"); - } - build_clean!("dilithium5aes"); - if target_arch == "x86_64" && avx2_enabled && !is_windows { - build_avx2!("dilithium5aes"); - } if target_arch == "x86_64" && avx2_enabled && !is_windows { // Print enableing flag for AVX2 implementation diff --git a/pqcrypto-dilithium/src/dilithium2aes.rs b/pqcrypto-dilithium/src/dilithium2aes.rs deleted file mode 100644 index e3cf3d66..00000000 --- a/pqcrypto-dilithium/src/dilithium2aes.rs +++ /dev/null @@ -1,358 +0,0 @@ -//! dilithium2aes -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-dilithium -//! use pqcrypto_dilithium::dilithium2aes::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::dilithium2aes::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_DILITHIUM2AES_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_DILITHIUM2AES_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_DILITHIUM2AES_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature([0u8; ffi::PQCLEAN_DILITHIUM2AES_CLEAN_CRYPTO_BYTES], 0) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_DILITHIUM2AES_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_DILITHIUM2AES_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_DILITHIUM2AES_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_DILITHIUM2AES_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_DILITHIUM2AES_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a dilithium2aes keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_DILITHIUM2AES_AVX2_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_DILITHIUM2AES_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_signature!(PQCLEAN_DILITHIUM2AES_AVX2_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_DILITHIUM2AES_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return open_signed!(PQCLEAN_DILITHIUM2AES_AVX2_crypto_sign_open, sm, pk); - } - } - open_signed!(PQCLEAN_DILITHIUM2AES_CLEAN_crypto_sign_open, sm, pk) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return detached_signature!(PQCLEAN_DILITHIUM2AES_AVX2_crypto_sign_signature, msg, sk); - } - } - detached_signature!(PQCLEAN_DILITHIUM2AES_CLEAN_crypto_sign_signature, msg, sk) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return verify_detached_sig!( - PQCLEAN_DILITHIUM2AES_AVX2_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!(PQCLEAN_DILITHIUM2AES_CLEAN_crypto_sign_verify, sig, msg, pk) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-dilithium/src/dilithium3aes.rs b/pqcrypto-dilithium/src/dilithium3aes.rs deleted file mode 100644 index 75a229f6..00000000 --- a/pqcrypto-dilithium/src/dilithium3aes.rs +++ /dev/null @@ -1,358 +0,0 @@ -//! dilithium3aes -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-dilithium -//! use pqcrypto_dilithium::dilithium3aes::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::dilithium3aes::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_DILITHIUM3AES_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_DILITHIUM3AES_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_DILITHIUM3AES_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature([0u8; ffi::PQCLEAN_DILITHIUM3AES_CLEAN_CRYPTO_BYTES], 0) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_DILITHIUM3AES_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_DILITHIUM3AES_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_DILITHIUM3AES_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_DILITHIUM3AES_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_DILITHIUM3AES_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a dilithium3aes keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_DILITHIUM3AES_AVX2_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_DILITHIUM3AES_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_signature!(PQCLEAN_DILITHIUM3AES_AVX2_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_DILITHIUM3AES_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return open_signed!(PQCLEAN_DILITHIUM3AES_AVX2_crypto_sign_open, sm, pk); - } - } - open_signed!(PQCLEAN_DILITHIUM3AES_CLEAN_crypto_sign_open, sm, pk) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return detached_signature!(PQCLEAN_DILITHIUM3AES_AVX2_crypto_sign_signature, msg, sk); - } - } - detached_signature!(PQCLEAN_DILITHIUM3AES_CLEAN_crypto_sign_signature, msg, sk) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return verify_detached_sig!( - PQCLEAN_DILITHIUM3AES_AVX2_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!(PQCLEAN_DILITHIUM3AES_CLEAN_crypto_sign_verify, sig, msg, pk) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-dilithium/src/dilithium5aes.rs b/pqcrypto-dilithium/src/dilithium5aes.rs deleted file mode 100644 index 55bd1e1b..00000000 --- a/pqcrypto-dilithium/src/dilithium5aes.rs +++ /dev/null @@ -1,358 +0,0 @@ -//! dilithium5aes -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-dilithium -//! use pqcrypto_dilithium::dilithium5aes::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::dilithium5aes::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_DILITHIUM5AES_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_DILITHIUM5AES_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_DILITHIUM5AES_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature([0u8; ffi::PQCLEAN_DILITHIUM5AES_CLEAN_CRYPTO_BYTES], 0) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_DILITHIUM5AES_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_DILITHIUM5AES_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_DILITHIUM5AES_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_DILITHIUM5AES_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_DILITHIUM5AES_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a dilithium5aes keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_DILITHIUM5AES_AVX2_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_DILITHIUM5AES_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_signature!(PQCLEAN_DILITHIUM5AES_AVX2_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_DILITHIUM5AES_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return open_signed!(PQCLEAN_DILITHIUM5AES_AVX2_crypto_sign_open, sm, pk); - } - } - open_signed!(PQCLEAN_DILITHIUM5AES_CLEAN_crypto_sign_open, sm, pk) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return detached_signature!(PQCLEAN_DILITHIUM5AES_AVX2_crypto_sign_signature, msg, sk); - } - } - detached_signature!(PQCLEAN_DILITHIUM5AES_CLEAN_crypto_sign_signature, msg, sk) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return verify_detached_sig!( - PQCLEAN_DILITHIUM5AES_AVX2_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!(PQCLEAN_DILITHIUM5AES_CLEAN_crypto_sign_verify, sig, msg, pk) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-dilithium/src/ffi.rs b/pqcrypto-dilithium/src/ffi.rs index 7e611150..b5ef3353 100644 --- a/pqcrypto-dilithium/src/ffi.rs +++ b/pqcrypto-dilithium/src/ffi.rs @@ -6,9 +6,6 @@ //! * dilithium2 //! * dilithium3 //! * dilithium5 -//! * dilithium2aes -//! * dilithium3aes -//! * dilithium5aes // This file has been generated from PQClean. // Find the templates in pqcrypto-template use libc::c_int; @@ -17,92 +14,59 @@ use libc::c_int; #[allow(unused_imports)] use pqcrypto_internals::*; -pub const PQCLEAN_DILITHIUM2_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 2528; +pub const PQCLEAN_DILITHIUM2_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 2560; pub const PQCLEAN_DILITHIUM2_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 1312; pub const PQCLEAN_DILITHIUM2_CLEAN_CRYPTO_BYTES: usize = 2420; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_DILITHIUM2_AVX2_CRYPTO_SECRETKEYBYTES: usize = 2528; +pub const PQCLEAN_DILITHIUM2_AVX2_CRYPTO_SECRETKEYBYTES: usize = 2560; #[cfg(enable_x86_avx2)] pub const PQCLEAN_DILITHIUM2_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 1312; #[cfg(enable_x86_avx2)] pub const PQCLEAN_DILITHIUM2_AVX2_CRYPTO_BYTES: usize = 2420; #[cfg(enable_aarch64_neon)] -pub const PQCLEAN_DILITHIUM2_AARCH64_CRYPTO_SECRETKEYBYTES: usize = 2528; +pub const PQCLEAN_DILITHIUM2_AARCH64_CRYPTO_SECRETKEYBYTES: usize = 2560; #[cfg(enable_aarch64_neon)] pub const PQCLEAN_DILITHIUM2_AARCH64_CRYPTO_PUBLICKEYBYTES: usize = 1312; #[cfg(enable_aarch64_neon)] pub const PQCLEAN_DILITHIUM2_AARCH64_CRYPTO_BYTES: usize = 2420; -pub const PQCLEAN_DILITHIUM3_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 4000; +pub const PQCLEAN_DILITHIUM3_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 4032; pub const PQCLEAN_DILITHIUM3_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 1952; -pub const PQCLEAN_DILITHIUM3_CLEAN_CRYPTO_BYTES: usize = 3293; +pub const PQCLEAN_DILITHIUM3_CLEAN_CRYPTO_BYTES: usize = 3309; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_DILITHIUM3_AVX2_CRYPTO_SECRETKEYBYTES: usize = 4000; +pub const PQCLEAN_DILITHIUM3_AVX2_CRYPTO_SECRETKEYBYTES: usize = 4032; #[cfg(enable_x86_avx2)] pub const PQCLEAN_DILITHIUM3_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 1952; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_DILITHIUM3_AVX2_CRYPTO_BYTES: usize = 3293; +pub const PQCLEAN_DILITHIUM3_AVX2_CRYPTO_BYTES: usize = 3309; #[cfg(enable_aarch64_neon)] -pub const PQCLEAN_DILITHIUM3_AARCH64_CRYPTO_SECRETKEYBYTES: usize = 4000; +pub const PQCLEAN_DILITHIUM3_AARCH64_CRYPTO_SECRETKEYBYTES: usize = 4032; #[cfg(enable_aarch64_neon)] pub const PQCLEAN_DILITHIUM3_AARCH64_CRYPTO_PUBLICKEYBYTES: usize = 1952; #[cfg(enable_aarch64_neon)] -pub const PQCLEAN_DILITHIUM3_AARCH64_CRYPTO_BYTES: usize = 3293; +pub const PQCLEAN_DILITHIUM3_AARCH64_CRYPTO_BYTES: usize = 3309; -pub const PQCLEAN_DILITHIUM5_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 4864; +pub const PQCLEAN_DILITHIUM5_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 4896; pub const PQCLEAN_DILITHIUM5_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 2592; -pub const PQCLEAN_DILITHIUM5_CLEAN_CRYPTO_BYTES: usize = 4595; +pub const PQCLEAN_DILITHIUM5_CLEAN_CRYPTO_BYTES: usize = 4627; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_DILITHIUM5_AVX2_CRYPTO_SECRETKEYBYTES: usize = 4864; +pub const PQCLEAN_DILITHIUM5_AVX2_CRYPTO_SECRETKEYBYTES: usize = 4896; #[cfg(enable_x86_avx2)] pub const PQCLEAN_DILITHIUM5_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 2592; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_DILITHIUM5_AVX2_CRYPTO_BYTES: usize = 4595; +pub const PQCLEAN_DILITHIUM5_AVX2_CRYPTO_BYTES: usize = 4627; #[cfg(enable_aarch64_neon)] -pub const PQCLEAN_DILITHIUM5_AARCH64_CRYPTO_SECRETKEYBYTES: usize = 4864; +pub const PQCLEAN_DILITHIUM5_AARCH64_CRYPTO_SECRETKEYBYTES: usize = 4896; #[cfg(enable_aarch64_neon)] pub const PQCLEAN_DILITHIUM5_AARCH64_CRYPTO_PUBLICKEYBYTES: usize = 2592; #[cfg(enable_aarch64_neon)] -pub const PQCLEAN_DILITHIUM5_AARCH64_CRYPTO_BYTES: usize = 4595; - -pub const PQCLEAN_DILITHIUM2AES_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 2528; -pub const PQCLEAN_DILITHIUM2AES_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 1312; -pub const PQCLEAN_DILITHIUM2AES_CLEAN_CRYPTO_BYTES: usize = 2420; - -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_DILITHIUM2AES_AVX2_CRYPTO_SECRETKEYBYTES: usize = 2528; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_DILITHIUM2AES_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 1312; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_DILITHIUM2AES_AVX2_CRYPTO_BYTES: usize = 2420; - -pub const PQCLEAN_DILITHIUM3AES_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 4000; -pub const PQCLEAN_DILITHIUM3AES_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 1952; -pub const PQCLEAN_DILITHIUM3AES_CLEAN_CRYPTO_BYTES: usize = 3293; - -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_DILITHIUM3AES_AVX2_CRYPTO_SECRETKEYBYTES: usize = 4000; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_DILITHIUM3AES_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 1952; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_DILITHIUM3AES_AVX2_CRYPTO_BYTES: usize = 3293; - -pub const PQCLEAN_DILITHIUM5AES_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 4864; -pub const PQCLEAN_DILITHIUM5AES_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 2592; -pub const PQCLEAN_DILITHIUM5AES_CLEAN_CRYPTO_BYTES: usize = 4595; - -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_DILITHIUM5AES_AVX2_CRYPTO_SECRETKEYBYTES: usize = 4864; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_DILITHIUM5AES_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 2592; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_DILITHIUM5AES_AVX2_CRYPTO_BYTES: usize = 4595; +pub const PQCLEAN_DILITHIUM5_AARCH64_CRYPTO_BYTES: usize = 4627; #[link(name = "dilithium2_clean")] extern "C" { @@ -437,222 +401,6 @@ extern "C" { ) -> c_int; } -#[link(name = "dilithium2aes_clean")] -extern "C" { - pub fn PQCLEAN_DILITHIUM2AES_CLEAN_crypto_sign_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - pub fn PQCLEAN_DILITHIUM2AES_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_DILITHIUM2AES_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_DILITHIUM2AES_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_DILITHIUM2AES_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "dilithium2aes_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_DILITHIUM2AES_AVX2_crypto_sign_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_DILITHIUM2AES_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_DILITHIUM2AES_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_DILITHIUM2AES_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_DILITHIUM2AES_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "dilithium3aes_clean")] -extern "C" { - pub fn PQCLEAN_DILITHIUM3AES_CLEAN_crypto_sign_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - pub fn PQCLEAN_DILITHIUM3AES_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_DILITHIUM3AES_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_DILITHIUM3AES_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_DILITHIUM3AES_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "dilithium3aes_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_DILITHIUM3AES_AVX2_crypto_sign_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_DILITHIUM3AES_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_DILITHIUM3AES_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_DILITHIUM3AES_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_DILITHIUM3AES_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "dilithium5aes_clean")] -extern "C" { - pub fn PQCLEAN_DILITHIUM5AES_CLEAN_crypto_sign_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - pub fn PQCLEAN_DILITHIUM5AES_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_DILITHIUM5AES_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_DILITHIUM5AES_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_DILITHIUM5AES_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "dilithium5aes_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_DILITHIUM5AES_AVX2_crypto_sign_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_DILITHIUM5AES_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_DILITHIUM5AES_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_DILITHIUM5AES_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_DILITHIUM5AES_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - #[cfg(test)] mod test_dilithium2_clean { use super::*; @@ -1717,720 +1465,3 @@ mod test_dilithium5_aarch64 { } } } - -#[cfg(test)] -mod test_dilithium2aes_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_DILITHIUM2AES_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_DILITHIUM2AES_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_DILITHIUM2AES_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_DILITHIUM2AES_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_DILITHIUM2AES_CLEAN_CRYPTO_BYTES]; - let mut sm = Vec::with_capacity(mlen + PQCLEAN_DILITHIUM2AES_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_DILITHIUM2AES_CLEAN_crypto_sign_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_DILITHIUM2AES_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_DILITHIUM2AES_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_DILITHIUM2AES_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_DILITHIUM2AES_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_DILITHIUM2AES_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_DILITHIUM2AES_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_DILITHIUM2AES_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_DILITHIUM2AES_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_DILITHIUM2AES_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_DILITHIUM2AES_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_dilithium2aes_avx2 { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("avx2") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_DILITHIUM2AES_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_DILITHIUM2AES_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_DILITHIUM2AES_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_DILITHIUM2AES_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_DILITHIUM2AES_AVX2_CRYPTO_BYTES]; - let mut sm = Vec::with_capacity(mlen + PQCLEAN_DILITHIUM2AES_AVX2_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_DILITHIUM2AES_AVX2_crypto_sign_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_DILITHIUM2AES_AVX2_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = Vec::with_capacity(mlen + PQCLEAN_DILITHIUM2AES_AVX2_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_DILITHIUM2AES_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_DILITHIUM2AES_AVX2_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_DILITHIUM2AES_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_DILITHIUM2AES_AVX2_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_DILITHIUM2AES_AVX2_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_DILITHIUM2AES_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_DILITHIUM2AES_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_DILITHIUM2AES_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_dilithium3aes_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_DILITHIUM3AES_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_DILITHIUM3AES_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_DILITHIUM3AES_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_DILITHIUM3AES_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_DILITHIUM3AES_CLEAN_CRYPTO_BYTES]; - let mut sm = Vec::with_capacity(mlen + PQCLEAN_DILITHIUM3AES_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_DILITHIUM3AES_CLEAN_crypto_sign_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_DILITHIUM3AES_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_DILITHIUM3AES_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_DILITHIUM3AES_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_DILITHIUM3AES_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_DILITHIUM3AES_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_DILITHIUM3AES_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_DILITHIUM3AES_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_DILITHIUM3AES_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_DILITHIUM3AES_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_DILITHIUM3AES_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_dilithium3aes_avx2 { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("avx2") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_DILITHIUM3AES_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_DILITHIUM3AES_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_DILITHIUM3AES_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_DILITHIUM3AES_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_DILITHIUM3AES_AVX2_CRYPTO_BYTES]; - let mut sm = Vec::with_capacity(mlen + PQCLEAN_DILITHIUM3AES_AVX2_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_DILITHIUM3AES_AVX2_crypto_sign_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_DILITHIUM3AES_AVX2_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = Vec::with_capacity(mlen + PQCLEAN_DILITHIUM3AES_AVX2_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_DILITHIUM3AES_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_DILITHIUM3AES_AVX2_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_DILITHIUM3AES_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_DILITHIUM3AES_AVX2_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_DILITHIUM3AES_AVX2_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_DILITHIUM3AES_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_DILITHIUM3AES_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_DILITHIUM3AES_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_dilithium5aes_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_DILITHIUM5AES_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_DILITHIUM5AES_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_DILITHIUM5AES_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_DILITHIUM5AES_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_DILITHIUM5AES_CLEAN_CRYPTO_BYTES]; - let mut sm = Vec::with_capacity(mlen + PQCLEAN_DILITHIUM5AES_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_DILITHIUM5AES_CLEAN_crypto_sign_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_DILITHIUM5AES_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_DILITHIUM5AES_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_DILITHIUM5AES_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_DILITHIUM5AES_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_DILITHIUM5AES_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_DILITHIUM5AES_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_DILITHIUM5AES_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_DILITHIUM5AES_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_DILITHIUM5AES_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_DILITHIUM5AES_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_dilithium5aes_avx2 { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("avx2") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_DILITHIUM5AES_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_DILITHIUM5AES_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_DILITHIUM5AES_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_DILITHIUM5AES_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_DILITHIUM5AES_AVX2_CRYPTO_BYTES]; - let mut sm = Vec::with_capacity(mlen + PQCLEAN_DILITHIUM5AES_AVX2_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_DILITHIUM5AES_AVX2_crypto_sign_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_DILITHIUM5AES_AVX2_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = Vec::with_capacity(mlen + PQCLEAN_DILITHIUM5AES_AVX2_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_DILITHIUM5AES_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_DILITHIUM5AES_AVX2_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_DILITHIUM5AES_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_DILITHIUM5AES_AVX2_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_DILITHIUM5AES_AVX2_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_DILITHIUM5AES_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_DILITHIUM5AES_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_DILITHIUM5AES_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} diff --git a/pqcrypto-dilithium/src/lib.rs b/pqcrypto-dilithium/src/lib.rs index 350b33d5..6913eb69 100644 --- a/pqcrypto-dilithium/src/lib.rs +++ b/pqcrypto-dilithium/src/lib.rs @@ -6,9 +6,6 @@ //! * dilithium2 - clean //! * dilithium3 - clean //! * dilithium5 - clean -//! * dilithium2aes - clean -//! * dilithium3aes - clean -//! * dilithium5aes - clean //! //! [pqc]: https://github.com/pqclean/pqclean/ //! @@ -24,11 +21,8 @@ extern crate alloc; extern crate std; pub mod dilithium2; -pub mod dilithium2aes; pub mod dilithium3; -pub mod dilithium3aes; pub mod dilithium5; -pub mod dilithium5aes; pub mod ffi; pub use crate::dilithium2::{ @@ -38,13 +32,6 @@ pub use crate::dilithium2::{ signature_bytes as dilithium2_signature_bytes, verify_detached_signature as dilithium2_verify_detached_signature, }; -pub use crate::dilithium2aes::{ - detached_sign as dilithium2aes_detached_sign, keypair as dilithium2aes_keypair, - open as dilithium2aes_open, public_key_bytes as dilithium2aes_public_key_bytes, - secret_key_bytes as dilithium2aes_secret_key_bytes, sign as dilithium2aes_sign, - signature_bytes as dilithium2aes_signature_bytes, - verify_detached_signature as dilithium2aes_verify_detached_signature, -}; pub use crate::dilithium3::{ detached_sign as dilithium3_detached_sign, keypair as dilithium3_keypair, open as dilithium3_open, public_key_bytes as dilithium3_public_key_bytes, @@ -52,13 +39,6 @@ pub use crate::dilithium3::{ signature_bytes as dilithium3_signature_bytes, verify_detached_signature as dilithium3_verify_detached_signature, }; -pub use crate::dilithium3aes::{ - detached_sign as dilithium3aes_detached_sign, keypair as dilithium3aes_keypair, - open as dilithium3aes_open, public_key_bytes as dilithium3aes_public_key_bytes, - secret_key_bytes as dilithium3aes_secret_key_bytes, sign as dilithium3aes_sign, - signature_bytes as dilithium3aes_signature_bytes, - verify_detached_signature as dilithium3aes_verify_detached_signature, -}; pub use crate::dilithium5::{ detached_sign as dilithium5_detached_sign, keypair as dilithium5_keypair, open as dilithium5_open, public_key_bytes as dilithium5_public_key_bytes, @@ -66,10 +46,3 @@ pub use crate::dilithium5::{ signature_bytes as dilithium5_signature_bytes, verify_detached_signature as dilithium5_verify_detached_signature, }; -pub use crate::dilithium5aes::{ - detached_sign as dilithium5aes_detached_sign, keypair as dilithium5aes_keypair, - open as dilithium5aes_open, public_key_bytes as dilithium5aes_public_key_bytes, - secret_key_bytes as dilithium5aes_secret_key_bytes, sign as dilithium5aes_sign, - signature_bytes as dilithium5aes_signature_bytes, - verify_detached_signature as dilithium5aes_verify_detached_signature, -}; diff --git a/pqcrypto-falcon/README.md b/pqcrypto-falcon/README.md index d3c0982d..371eb6c3 100644 --- a/pqcrypto-falcon/README.md +++ b/pqcrypto-falcon/README.md @@ -22,9 +22,11 @@ methods only. * ``falcon-512`` * ``clean`` * ``avx2`` (if supported) + * ``aarch64`` (if supported) * ``falcon-1024`` * ``clean`` * ``avx2`` (if supported) + * ``aarch64`` (if supported) ## License diff --git a/pqcrypto-falcon/build.rs b/pqcrypto-falcon/build.rs index 14e2ff7d..daf10751 100644 --- a/pqcrypto-falcon/build.rs +++ b/pqcrypto-falcon/build.rs @@ -100,10 +100,16 @@ fn main() { if target_arch == "x86_64" && avx2_enabled { build_avx2!("falcon-512"); } + if target_arch == "aarch64" && neon_enabled { + build_aarch64!("falcon-512"); + } build_clean!("falcon-1024"); if target_arch == "x86_64" && avx2_enabled { build_avx2!("falcon-1024"); } + if target_arch == "aarch64" && neon_enabled { + build_aarch64!("falcon-1024"); + } if target_arch == "x86_64" && avx2_enabled { // Print enableing flag for AVX2 implementation diff --git a/pqcrypto-falcon/src/falcon1024.rs b/pqcrypto-falcon/src/falcon1024.rs index 32ecbaba..5f40fd2d 100644 --- a/pqcrypto-falcon/src/falcon1024.rs +++ b/pqcrypto-falcon/src/falcon1024.rs @@ -190,6 +190,15 @@ pub fn keypair() -> (PublicKey, SecretKey) { return gen_keypair!(PQCLEAN_FALCON1024_AVX2_crypto_sign_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_FALCON1024_AARCH64_crypto_sign_keypair); + } + } gen_keypair!(PQCLEAN_FALCON1024_CLEAN_crypto_sign_keypair) } @@ -221,6 +230,12 @@ pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { return gen_signature!(PQCLEAN_FALCON1024_AVX2_crypto_sign, msg, sk); } } + #[cfg(all(enable_aarch64_neon, feature = "neon"))] + { + if true { + return gen_signature!(PQCLEAN_FALCON1024_AARCH64_crypto_sign, msg, sk); + } + } gen_signature!(PQCLEAN_FALCON1024_CLEAN_crypto_sign, msg, sk) } @@ -258,6 +273,12 @@ pub fn open( return open_signed!(PQCLEAN_FALCON1024_AVX2_crypto_sign_open, sm, pk); } } + #[cfg(all(enable_aarch64_neon, feature = "neon"))] + { + if true { + return open_signed!(PQCLEAN_FALCON1024_AARCH64_crypto_sign_open, sm, pk); + } + } open_signed!(PQCLEAN_FALCON1024_CLEAN_crypto_sign_open, sm, pk) } @@ -285,6 +306,12 @@ pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { return detached_signature!(PQCLEAN_FALCON1024_AVX2_crypto_sign_signature, msg, sk); } } + #[cfg(all(enable_aarch64_neon, feature = "neon"))] + { + if true { + return detached_signature!(PQCLEAN_FALCON1024_AARCH64_crypto_sign_signature, msg, sk); + } + } detached_signature!(PQCLEAN_FALCON1024_CLEAN_crypto_sign_signature, msg, sk) } @@ -319,6 +346,17 @@ pub fn verify_detached_signature( return verify_detached_sig!(PQCLEAN_FALCON1024_AVX2_crypto_sign_verify, sig, msg, pk); } } + #[cfg(all(enable_aarch64_neon, feature = "neon"))] + { + if true { + return verify_detached_sig!( + PQCLEAN_FALCON1024_AARCH64_crypto_sign_verify, + sig, + msg, + pk + ); + } + } verify_detached_sig!(PQCLEAN_FALCON1024_CLEAN_crypto_sign_verify, sig, msg, pk) } diff --git a/pqcrypto-falcon/src/falcon512.rs b/pqcrypto-falcon/src/falcon512.rs index adb839a7..e46c66f2 100644 --- a/pqcrypto-falcon/src/falcon512.rs +++ b/pqcrypto-falcon/src/falcon512.rs @@ -190,6 +190,15 @@ pub fn keypair() -> (PublicKey, SecretKey) { return gen_keypair!(PQCLEAN_FALCON512_AVX2_crypto_sign_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_FALCON512_AARCH64_crypto_sign_keypair); + } + } gen_keypair!(PQCLEAN_FALCON512_CLEAN_crypto_sign_keypair) } @@ -221,6 +230,12 @@ pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { return gen_signature!(PQCLEAN_FALCON512_AVX2_crypto_sign, msg, sk); } } + #[cfg(all(enable_aarch64_neon, feature = "neon"))] + { + if true { + return gen_signature!(PQCLEAN_FALCON512_AARCH64_crypto_sign, msg, sk); + } + } gen_signature!(PQCLEAN_FALCON512_CLEAN_crypto_sign, msg, sk) } @@ -258,6 +273,12 @@ pub fn open( return open_signed!(PQCLEAN_FALCON512_AVX2_crypto_sign_open, sm, pk); } } + #[cfg(all(enable_aarch64_neon, feature = "neon"))] + { + if true { + return open_signed!(PQCLEAN_FALCON512_AARCH64_crypto_sign_open, sm, pk); + } + } open_signed!(PQCLEAN_FALCON512_CLEAN_crypto_sign_open, sm, pk) } @@ -285,6 +306,12 @@ pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { return detached_signature!(PQCLEAN_FALCON512_AVX2_crypto_sign_signature, msg, sk); } } + #[cfg(all(enable_aarch64_neon, feature = "neon"))] + { + if true { + return detached_signature!(PQCLEAN_FALCON512_AARCH64_crypto_sign_signature, msg, sk); + } + } detached_signature!(PQCLEAN_FALCON512_CLEAN_crypto_sign_signature, msg, sk) } @@ -319,6 +346,17 @@ pub fn verify_detached_signature( return verify_detached_sig!(PQCLEAN_FALCON512_AVX2_crypto_sign_verify, sig, msg, pk); } } + #[cfg(all(enable_aarch64_neon, feature = "neon"))] + { + if true { + return verify_detached_sig!( + PQCLEAN_FALCON512_AARCH64_crypto_sign_verify, + sig, + msg, + pk + ); + } + } verify_detached_sig!(PQCLEAN_FALCON512_CLEAN_crypto_sign_verify, sig, msg, pk) } diff --git a/pqcrypto-falcon/src/ffi.rs b/pqcrypto-falcon/src/ffi.rs index fa6892ca..eddf6c31 100644 --- a/pqcrypto-falcon/src/ffi.rs +++ b/pqcrypto-falcon/src/ffi.rs @@ -24,6 +24,13 @@ pub const PQCLEAN_FALCON512_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 897; #[cfg(enable_x86_avx2)] pub const PQCLEAN_FALCON512_AVX2_CRYPTO_BYTES: usize = 666; +#[cfg(enable_aarch64_neon)] +pub const PQCLEAN_FALCON512_AARCH64_CRYPTO_SECRETKEYBYTES: usize = 1281; +#[cfg(enable_aarch64_neon)] +pub const PQCLEAN_FALCON512_AARCH64_CRYPTO_PUBLICKEYBYTES: usize = 897; +#[cfg(enable_aarch64_neon)] +pub const PQCLEAN_FALCON512_AARCH64_CRYPTO_BYTES: usize = 666; + pub const PQCLEAN_FALCON1024_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 2305; pub const PQCLEAN_FALCON1024_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 1793; pub const PQCLEAN_FALCON1024_CLEAN_CRYPTO_BYTES: usize = 1280; @@ -35,6 +42,13 @@ pub const PQCLEAN_FALCON1024_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 1793; #[cfg(enable_x86_avx2)] pub const PQCLEAN_FALCON1024_AVX2_CRYPTO_BYTES: usize = 1280; +#[cfg(enable_aarch64_neon)] +pub const PQCLEAN_FALCON1024_AARCH64_CRYPTO_SECRETKEYBYTES: usize = 2305; +#[cfg(enable_aarch64_neon)] +pub const PQCLEAN_FALCON1024_AARCH64_CRYPTO_PUBLICKEYBYTES: usize = 1793; +#[cfg(enable_aarch64_neon)] +pub const PQCLEAN_FALCON1024_AARCH64_CRYPTO_BYTES: usize = 1280; + #[link(name = "falcon-512_clean")] extern "C" { pub fn PQCLEAN_FALCON512_CLEAN_crypto_sign_keypair(pk: *mut u8, sk: *mut u8) -> c_int; @@ -107,6 +121,45 @@ extern "C" { ) -> c_int; } +#[cfg(enable_aarch64_neon)] +#[link(name = "falcon-512_aarch64")] +extern "C" { + #[cfg(enable_aarch64_neon)] + pub fn PQCLEAN_FALCON512_AARCH64_crypto_sign_keypair(pk: *mut u8, sk: *mut u8) -> c_int; + #[cfg(enable_aarch64_neon)] + pub fn PQCLEAN_FALCON512_AARCH64_crypto_sign( + sm: *mut u8, + smlen: *mut usize, + msg: *const u8, + len: usize, + sk: *const u8, + ) -> c_int; + #[cfg(enable_aarch64_neon)] + pub fn PQCLEAN_FALCON512_AARCH64_crypto_sign_open( + m: *mut u8, + mlen: *mut usize, + sm: *const u8, + smlen: usize, + pk: *const u8, + ) -> c_int; + #[cfg(enable_aarch64_neon)] + pub fn PQCLEAN_FALCON512_AARCH64_crypto_sign_signature( + sig: *mut u8, + siglen: *mut usize, + m: *const u8, + mlen: usize, + sk: *const u8, + ) -> c_int; + #[cfg(enable_aarch64_neon)] + pub fn PQCLEAN_FALCON512_AARCH64_crypto_sign_verify( + sig: *const u8, + siglen: usize, + m: *const u8, + mlen: usize, + pk: *const u8, + ) -> c_int; +} + #[link(name = "falcon-1024_clean")] extern "C" { pub fn PQCLEAN_FALCON1024_CLEAN_crypto_sign_keypair(pk: *mut u8, sk: *mut u8) -> c_int; @@ -179,6 +232,45 @@ extern "C" { ) -> c_int; } +#[cfg(enable_aarch64_neon)] +#[link(name = "falcon-1024_aarch64")] +extern "C" { + #[cfg(enable_aarch64_neon)] + pub fn PQCLEAN_FALCON1024_AARCH64_crypto_sign_keypair(pk: *mut u8, sk: *mut u8) -> c_int; + #[cfg(enable_aarch64_neon)] + pub fn PQCLEAN_FALCON1024_AARCH64_crypto_sign( + sm: *mut u8, + smlen: *mut usize, + msg: *const u8, + len: usize, + sk: *const u8, + ) -> c_int; + #[cfg(enable_aarch64_neon)] + pub fn PQCLEAN_FALCON1024_AARCH64_crypto_sign_open( + m: *mut u8, + mlen: *mut usize, + sm: *const u8, + smlen: usize, + pk: *const u8, + ) -> c_int; + #[cfg(enable_aarch64_neon)] + pub fn PQCLEAN_FALCON1024_AARCH64_crypto_sign_signature( + sig: *mut u8, + siglen: *mut usize, + m: *const u8, + mlen: usize, + sk: *const u8, + ) -> c_int; + #[cfg(enable_aarch64_neon)] + pub fn PQCLEAN_FALCON1024_AARCH64_crypto_sign_verify( + sig: *const u8, + siglen: usize, + m: *const u8, + mlen: usize, + pk: *const u8, + ) -> c_int; +} + #[cfg(test)] mod test_falcon512_clean { use super::*; @@ -417,6 +509,123 @@ mod test_falcon512_avx2 { } } +#[cfg(all(test, enable_aarch64_neon, feature = "neon"))] +mod test_falcon512_aarch64 { + use super::*; + use alloc::vec; + use alloc::vec::Vec; + use rand::prelude::*; + + #[test] + fn test_ffi() { + unsafe { + let mut rng = rand::thread_rng(); + let mut mlen: usize = rng.gen::() as usize; + let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); + + let mut pk = vec![0u8; PQCLEAN_FALCON512_AARCH64_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_FALCON512_AARCH64_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_FALCON512_AARCH64_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_FALCON512_AARCH64_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_FALCON512_AARCH64_CRYPTO_BYTES]; + let mut sm = Vec::with_capacity(mlen + PQCLEAN_FALCON512_AARCH64_CRYPTO_BYTES); + let mut smlen = 0; + assert_eq!( + 0, + PQCLEAN_FALCON512_AARCH64_crypto_sign_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) + ); + assert_eq!( + 0, + PQCLEAN_FALCON512_AARCH64_crypto_sign( + sm.as_mut_ptr(), + &mut smlen as *mut usize, + msg.as_ptr(), + mlen, + sk.as_ptr() + ) + ); + sm.set_len(smlen); + + let mut unpacked_m = Vec::with_capacity(mlen + PQCLEAN_FALCON512_AARCH64_CRYPTO_BYTES); + assert_eq!( + 0, + PQCLEAN_FALCON512_AARCH64_crypto_sign_open( + unpacked_m.as_mut_ptr(), + &mut mlen as *mut usize, + sm.as_ptr(), + sm.len(), + pk.as_ptr() + ) + ); + unpacked_m.set_len(mlen); + assert_eq!(unpacked_m, msg); + + // check verification fails with wrong pk + assert_eq!( + 0, + PQCLEAN_FALCON512_AARCH64_crypto_sign_keypair( + pk_alt.as_mut_ptr(), + sk_alt.as_mut_ptr() + ) + ); + assert_eq!( + -1, + PQCLEAN_FALCON512_AARCH64_crypto_sign_open( + unpacked_m.as_mut_ptr(), + &mut mlen as *mut usize, + sm.as_ptr(), + sm.len(), + pk_alt.as_ptr() + ) + ); + assert_eq!( + 0, + PQCLEAN_FALCON512_AARCH64_crypto_sign_signature( + detached_sig.as_mut_ptr(), + &mut smlen as *mut usize, + msg.as_ptr(), + msg.len(), + sk.as_ptr() + ) + ); + assert!( + smlen <= PQCLEAN_FALCON512_AARCH64_CRYPTO_BYTES, + "Signed message length should be ≤ CRYPTO_BYTES" + ); + assert_eq!( + 0, + PQCLEAN_FALCON512_AARCH64_crypto_sign_verify( + detached_sig.as_ptr(), + smlen, + msg.as_ptr(), + msg.len(), + pk.as_ptr() + ) + ); + assert_eq!( + -1, + PQCLEAN_FALCON512_AARCH64_crypto_sign_verify( + detached_sig.as_ptr(), + smlen, + msg.as_ptr(), + msg.len(), + pk_alt.as_ptr() + ) + ); + assert_eq!( + -1, + PQCLEAN_FALCON512_AARCH64_crypto_sign_verify( + detached_sig.as_ptr(), + smlen, + msg.as_ptr(), + msg.len() - 1, + pk.as_ptr() + ) + ); + } + } +} + #[cfg(test)] mod test_falcon1024_clean { use super::*; @@ -654,3 +863,120 @@ mod test_falcon1024_avx2 { } } } + +#[cfg(all(test, enable_aarch64_neon, feature = "neon"))] +mod test_falcon1024_aarch64 { + use super::*; + use alloc::vec; + use alloc::vec::Vec; + use rand::prelude::*; + + #[test] + fn test_ffi() { + unsafe { + let mut rng = rand::thread_rng(); + let mut mlen: usize = rng.gen::() as usize; + let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); + + let mut pk = vec![0u8; PQCLEAN_FALCON1024_AARCH64_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_FALCON1024_AARCH64_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_FALCON1024_AARCH64_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_FALCON1024_AARCH64_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_FALCON1024_AARCH64_CRYPTO_BYTES]; + let mut sm = Vec::with_capacity(mlen + PQCLEAN_FALCON1024_AARCH64_CRYPTO_BYTES); + let mut smlen = 0; + assert_eq!( + 0, + PQCLEAN_FALCON1024_AARCH64_crypto_sign_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) + ); + assert_eq!( + 0, + PQCLEAN_FALCON1024_AARCH64_crypto_sign( + sm.as_mut_ptr(), + &mut smlen as *mut usize, + msg.as_ptr(), + mlen, + sk.as_ptr() + ) + ); + sm.set_len(smlen); + + let mut unpacked_m = Vec::with_capacity(mlen + PQCLEAN_FALCON1024_AARCH64_CRYPTO_BYTES); + assert_eq!( + 0, + PQCLEAN_FALCON1024_AARCH64_crypto_sign_open( + unpacked_m.as_mut_ptr(), + &mut mlen as *mut usize, + sm.as_ptr(), + sm.len(), + pk.as_ptr() + ) + ); + unpacked_m.set_len(mlen); + assert_eq!(unpacked_m, msg); + + // check verification fails with wrong pk + assert_eq!( + 0, + PQCLEAN_FALCON1024_AARCH64_crypto_sign_keypair( + pk_alt.as_mut_ptr(), + sk_alt.as_mut_ptr() + ) + ); + assert_eq!( + -1, + PQCLEAN_FALCON1024_AARCH64_crypto_sign_open( + unpacked_m.as_mut_ptr(), + &mut mlen as *mut usize, + sm.as_ptr(), + sm.len(), + pk_alt.as_ptr() + ) + ); + assert_eq!( + 0, + PQCLEAN_FALCON1024_AARCH64_crypto_sign_signature( + detached_sig.as_mut_ptr(), + &mut smlen as *mut usize, + msg.as_ptr(), + msg.len(), + sk.as_ptr() + ) + ); + assert!( + smlen <= PQCLEAN_FALCON1024_AARCH64_CRYPTO_BYTES, + "Signed message length should be ≤ CRYPTO_BYTES" + ); + assert_eq!( + 0, + PQCLEAN_FALCON1024_AARCH64_crypto_sign_verify( + detached_sig.as_ptr(), + smlen, + msg.as_ptr(), + msg.len(), + pk.as_ptr() + ) + ); + assert_eq!( + -1, + PQCLEAN_FALCON1024_AARCH64_crypto_sign_verify( + detached_sig.as_ptr(), + smlen, + msg.as_ptr(), + msg.len(), + pk_alt.as_ptr() + ) + ); + assert_eq!( + -1, + PQCLEAN_FALCON1024_AARCH64_crypto_sign_verify( + detached_sig.as_ptr(), + smlen, + msg.as_ptr(), + msg.len() - 1, + pk.as_ptr() + ) + ); + } + } +} diff --git a/pqcrypto-hqc/Cargo.toml b/pqcrypto-hqc/Cargo.toml index 295a9a82..faa52691 100644 --- a/pqcrypto-hqc/Cargo.toml +++ b/pqcrypto-hqc/Cargo.toml @@ -2,7 +2,7 @@ name = "pqcrypto-hqc" description = "Post-Quantum Key-Encapsulation Mechanism hqc" readme = "README.md" -version = "0.1.7" +version = "0.2.0" authors = ["Thom Wiggers "] edition = "2018" license = "MIT OR Apache-2.0" diff --git a/pqcrypto-hqc/README.md b/pqcrypto-hqc/README.md index 052cafb4..0bf17a9f 100644 --- a/pqcrypto-hqc/README.md +++ b/pqcrypto-hqc/README.md @@ -19,11 +19,11 @@ sourced from [PQClean][pqclean]. The "default" implementation is used in the Rust-friendly interface, alternative implementations are exposed as ``ffi`` methods only. -* ``hqc-rmrs-128`` +* ``hqc-128`` * ``clean`` -* ``hqc-rmrs-192`` +* ``hqc-192`` * ``clean`` -* ``hqc-rmrs-256`` +* ``hqc-256`` * ``clean`` diff --git a/pqcrypto-hqc/build.rs b/pqcrypto-hqc/build.rs index 23efd999..57e3210e 100644 --- a/pqcrypto-hqc/build.rs +++ b/pqcrypto-hqc/build.rs @@ -52,7 +52,7 @@ fn main() { #[allow(unused_variables)] let is_macos = target_os == "macos"; - build_clean!("hqc-rmrs-128"); - build_clean!("hqc-rmrs-192"); - build_clean!("hqc-rmrs-256"); + build_clean!("hqc-128"); + build_clean!("hqc-192"); + build_clean!("hqc-256"); } diff --git a/pqcrypto-hqc/src/ffi.rs b/pqcrypto-hqc/src/ffi.rs index 73aada28..9eb95bc5 100644 --- a/pqcrypto-hqc/src/ffi.rs +++ b/pqcrypto-hqc/src/ffi.rs @@ -3,9 +3,9 @@ //! This module defines the foreign function interface for the following //! crypto implementations from PQClean: //! -//! * hqc-rmrs-128 -//! * hqc-rmrs-192 -//! * hqc-rmrs-256 +//! * hqc-128 +//! * hqc-192 +//! * hqc-256 // This file has been generated from PQClean. // Find the templates in pqcrypto-template use libc::c_int; @@ -14,95 +14,67 @@ use libc::c_int; #[allow(unused_imports)] use pqcrypto_internals::*; -pub const PQCLEAN_HQCRMRS128_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 2289; -pub const PQCLEAN_HQCRMRS128_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 2249; -pub const PQCLEAN_HQCRMRS128_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 4481; -pub const PQCLEAN_HQCRMRS128_CLEAN_CRYPTO_BYTES: usize = 64; +pub const PQCLEAN_HQC128_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 2305; +pub const PQCLEAN_HQC128_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 2249; +pub const PQCLEAN_HQC128_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 4433; +pub const PQCLEAN_HQC128_CLEAN_CRYPTO_BYTES: usize = 64; -pub const PQCLEAN_HQCRMRS192_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 4562; -pub const PQCLEAN_HQCRMRS192_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 4522; -pub const PQCLEAN_HQCRMRS192_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 9026; -pub const PQCLEAN_HQCRMRS192_CLEAN_CRYPTO_BYTES: usize = 64; +pub const PQCLEAN_HQC192_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 4586; +pub const PQCLEAN_HQC192_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 4522; +pub const PQCLEAN_HQC192_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 8978; +pub const PQCLEAN_HQC192_CLEAN_CRYPTO_BYTES: usize = 64; -pub const PQCLEAN_HQCRMRS256_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 7285; -pub const PQCLEAN_HQCRMRS256_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 7245; -pub const PQCLEAN_HQCRMRS256_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 14469; -pub const PQCLEAN_HQCRMRS256_CLEAN_CRYPTO_BYTES: usize = 64; +pub const PQCLEAN_HQC256_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 7317; +pub const PQCLEAN_HQC256_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 7245; +pub const PQCLEAN_HQC256_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 14421; +pub const PQCLEAN_HQC256_CLEAN_CRYPTO_BYTES: usize = 64; -#[link(name = "hqc-rmrs-128_clean")] +#[link(name = "hqc-128_clean")] extern "C" { - pub fn PQCLEAN_HQCRMRS128_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - pub fn PQCLEAN_HQCRMRS128_CLEAN_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_HQCRMRS128_CLEAN_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; + pub fn PQCLEAN_HQC128_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; + pub fn PQCLEAN_HQC128_CLEAN_crypto_kem_enc(ct: *mut u8, ss: *mut u8, pk: *const u8) -> c_int; + pub fn PQCLEAN_HQC128_CLEAN_crypto_kem_dec(ss: *mut u8, ct: *const u8, sk: *const u8) -> c_int; } -#[link(name = "hqc-rmrs-192_clean")] +#[link(name = "hqc-192_clean")] extern "C" { - pub fn PQCLEAN_HQCRMRS192_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - pub fn PQCLEAN_HQCRMRS192_CLEAN_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_HQCRMRS192_CLEAN_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; + pub fn PQCLEAN_HQC192_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; + pub fn PQCLEAN_HQC192_CLEAN_crypto_kem_enc(ct: *mut u8, ss: *mut u8, pk: *const u8) -> c_int; + pub fn PQCLEAN_HQC192_CLEAN_crypto_kem_dec(ss: *mut u8, ct: *const u8, sk: *const u8) -> c_int; } -#[link(name = "hqc-rmrs-256_clean")] +#[link(name = "hqc-256_clean")] extern "C" { - pub fn PQCLEAN_HQCRMRS256_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - pub fn PQCLEAN_HQCRMRS256_CLEAN_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_HQCRMRS256_CLEAN_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; + pub fn PQCLEAN_HQC256_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; + pub fn PQCLEAN_HQC256_CLEAN_crypto_kem_enc(ct: *mut u8, ss: *mut u8, pk: *const u8) -> c_int; + pub fn PQCLEAN_HQC256_CLEAN_crypto_kem_dec(ss: *mut u8, ct: *const u8, sk: *const u8) -> c_int; } #[cfg(test)] -mod test_hqcrmrs128_clean { +mod test_hqc128_clean { use super::*; use alloc::vec; #[test] fn test_ffi() { unsafe { - let mut pk = vec![0u8; PQCLEAN_HQCRMRS128_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_HQCRMRS128_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_HQCRMRS128_CLEAN_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_HQCRMRS128_CLEAN_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_HQCRMRS128_CLEAN_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_HQC128_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_HQC128_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut ct = vec![0u8; PQCLEAN_HQC128_CLEAN_CRYPTO_CIPHERTEXTBYTES]; + let mut ss1 = vec![0u8; PQCLEAN_HQC128_CLEAN_CRYPTO_BYTES]; + let mut ss2 = vec![0u8; PQCLEAN_HQC128_CLEAN_CRYPTO_BYTES]; assert_eq!( 0, - PQCLEAN_HQCRMRS128_CLEAN_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) + PQCLEAN_HQC128_CLEAN_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) ); assert_eq!( 0, - PQCLEAN_HQCRMRS128_CLEAN_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) + PQCLEAN_HQC128_CLEAN_crypto_kem_enc(ct.as_mut_ptr(), ss1.as_mut_ptr(), pk.as_ptr()) ); assert_eq!( 0, - PQCLEAN_HQCRMRS128_CLEAN_crypto_kem_dec(ss2.as_mut_ptr(), ct.as_ptr(), sk.as_ptr()) + PQCLEAN_HQC128_CLEAN_crypto_kem_dec(ss2.as_mut_ptr(), ct.as_ptr(), sk.as_ptr()) ); assert_eq!(&ss1[..], &ss2[..], "Shared secrets should be equal"); } @@ -110,34 +82,30 @@ mod test_hqcrmrs128_clean { } #[cfg(test)] -mod test_hqcrmrs192_clean { +mod test_hqc192_clean { use super::*; use alloc::vec; #[test] fn test_ffi() { unsafe { - let mut pk = vec![0u8; PQCLEAN_HQCRMRS192_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_HQCRMRS192_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_HQCRMRS192_CLEAN_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_HQCRMRS192_CLEAN_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_HQCRMRS192_CLEAN_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_HQC192_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_HQC192_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut ct = vec![0u8; PQCLEAN_HQC192_CLEAN_CRYPTO_CIPHERTEXTBYTES]; + let mut ss1 = vec![0u8; PQCLEAN_HQC192_CLEAN_CRYPTO_BYTES]; + let mut ss2 = vec![0u8; PQCLEAN_HQC192_CLEAN_CRYPTO_BYTES]; assert_eq!( 0, - PQCLEAN_HQCRMRS192_CLEAN_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) + PQCLEAN_HQC192_CLEAN_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) ); assert_eq!( 0, - PQCLEAN_HQCRMRS192_CLEAN_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) + PQCLEAN_HQC192_CLEAN_crypto_kem_enc(ct.as_mut_ptr(), ss1.as_mut_ptr(), pk.as_ptr()) ); assert_eq!( 0, - PQCLEAN_HQCRMRS192_CLEAN_crypto_kem_dec(ss2.as_mut_ptr(), ct.as_ptr(), sk.as_ptr()) + PQCLEAN_HQC192_CLEAN_crypto_kem_dec(ss2.as_mut_ptr(), ct.as_ptr(), sk.as_ptr()) ); assert_eq!(&ss1[..], &ss2[..], "Shared secrets should be equal"); } @@ -145,34 +113,30 @@ mod test_hqcrmrs192_clean { } #[cfg(test)] -mod test_hqcrmrs256_clean { +mod test_hqc256_clean { use super::*; use alloc::vec; #[test] fn test_ffi() { unsafe { - let mut pk = vec![0u8; PQCLEAN_HQCRMRS256_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_HQCRMRS256_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_HQCRMRS256_CLEAN_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_HQCRMRS256_CLEAN_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_HQCRMRS256_CLEAN_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_HQC256_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_HQC256_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut ct = vec![0u8; PQCLEAN_HQC256_CLEAN_CRYPTO_CIPHERTEXTBYTES]; + let mut ss1 = vec![0u8; PQCLEAN_HQC256_CLEAN_CRYPTO_BYTES]; + let mut ss2 = vec![0u8; PQCLEAN_HQC256_CLEAN_CRYPTO_BYTES]; assert_eq!( 0, - PQCLEAN_HQCRMRS256_CLEAN_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) + PQCLEAN_HQC256_CLEAN_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) ); assert_eq!( 0, - PQCLEAN_HQCRMRS256_CLEAN_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) + PQCLEAN_HQC256_CLEAN_crypto_kem_enc(ct.as_mut_ptr(), ss1.as_mut_ptr(), pk.as_ptr()) ); assert_eq!( 0, - PQCLEAN_HQCRMRS256_CLEAN_crypto_kem_dec(ss2.as_mut_ptr(), ct.as_ptr(), sk.as_ptr()) + PQCLEAN_HQC256_CLEAN_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-hqc/src/hqcrmrs192.rs b/pqcrypto-hqc/src/hqc128.rs similarity index 80% rename from pqcrypto-hqc/src/hqcrmrs192.rs rename to pqcrypto-hqc/src/hqc128.rs index 5ab36357..119daaf3 100644 --- a/pqcrypto-hqc/src/hqcrmrs192.rs +++ b/pqcrypto-hqc/src/hqc128.rs @@ -1,13 +1,13 @@ -//! hqc-rmrs-192 +//! hqc-128 //! //! These bindings use the clean version from [PQClean][pqc] //! //! # Example //! ``` //! // if using pqcrypto-hqc -//! use pqcrypto_hqc::hqcrmrs192::*; +//! use pqcrypto_hqc::hqc128::*; //! // or if using the pqcrypto crate: -//! // use pqcrypto::kem::hqcrmrs192::*; +//! // use pqcrypto::kem::hqc128::*; //! let (pk, sk) = keypair(); //! let (ss1, ct) = encapsulate(&pk); //! let ss2 = decapsulate(&ct, &sk); @@ -82,38 +82,29 @@ macro_rules! simple_struct { }; } -simple_struct!( - PublicKey, - ffi::PQCLEAN_HQCRMRS192_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_HQCRMRS192_CLEAN_CRYPTO_SECRETKEYBYTES -); -simple_struct!( - Ciphertext, - ffi::PQCLEAN_HQCRMRS192_CLEAN_CRYPTO_CIPHERTEXTBYTES -); -simple_struct!(SharedSecret, ffi::PQCLEAN_HQCRMRS192_CLEAN_CRYPTO_BYTES); +simple_struct!(PublicKey, ffi::PQCLEAN_HQC128_CLEAN_CRYPTO_PUBLICKEYBYTES); +simple_struct!(SecretKey, ffi::PQCLEAN_HQC128_CLEAN_CRYPTO_SECRETKEYBYTES); +simple_struct!(Ciphertext, ffi::PQCLEAN_HQC128_CLEAN_CRYPTO_CIPHERTEXTBYTES); +simple_struct!(SharedSecret, ffi::PQCLEAN_HQC128_CLEAN_CRYPTO_BYTES); /// Get the number of bytes for a public key pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_HQCRMRS192_CLEAN_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_HQC128_CLEAN_CRYPTO_PUBLICKEYBYTES } /// Get the number of bytes for a secret key pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_HQCRMRS192_CLEAN_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_HQC128_CLEAN_CRYPTO_SECRETKEYBYTES } /// Get the number of bytes for the encapsulated ciphertext pub const fn ciphertext_bytes() -> usize { - ffi::PQCLEAN_HQCRMRS192_CLEAN_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_HQC128_CLEAN_CRYPTO_CIPHERTEXTBYTES } /// Get the number of bytes for the shared secret pub const fn shared_secret_bytes() -> usize { - ffi::PQCLEAN_HQCRMRS192_CLEAN_CRYPTO_BYTES + ffi::PQCLEAN_HQC128_CLEAN_CRYPTO_BYTES } macro_rules! gen_keypair { @@ -128,9 +119,9 @@ macro_rules! gen_keypair { }}; } -/// Generate a hqc-rmrs-192 keypair +/// Generate a hqc-128 keypair pub fn keypair() -> (PublicKey, SecretKey) { - gen_keypair!(PQCLEAN_HQCRMRS192_CLEAN_crypto_kem_keypair) + gen_keypair!(PQCLEAN_HQC128_CLEAN_crypto_kem_keypair) } macro_rules! encap { @@ -145,9 +136,9 @@ macro_rules! encap { }}; } -/// Encapsulate to a hqc-rmrs-192 public key +/// Encapsulate to a hqc-128 public key pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { - encap!(PQCLEAN_HQCRMRS192_CLEAN_crypto_kem_enc, pk) + encap!(PQCLEAN_HQC128_CLEAN_crypto_kem_enc, pk) } macro_rules! decap { @@ -161,9 +152,9 @@ macro_rules! decap { }}; } -/// Decapsulate the received hqc-rmrs-192 ciphertext +/// Decapsulate the received hqc-128 ciphertext pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { - decap!(PQCLEAN_HQCRMRS192_CLEAN_crypto_kem_dec, ct, sk) + decap!(PQCLEAN_HQC128_CLEAN_crypto_kem_dec, ct, sk) } #[cfg(test)] diff --git a/pqcrypto-hqc/src/hqcrmrs256.rs b/pqcrypto-hqc/src/hqc192.rs similarity index 80% rename from pqcrypto-hqc/src/hqcrmrs256.rs rename to pqcrypto-hqc/src/hqc192.rs index f929fdae..98479e02 100644 --- a/pqcrypto-hqc/src/hqcrmrs256.rs +++ b/pqcrypto-hqc/src/hqc192.rs @@ -1,13 +1,13 @@ -//! hqc-rmrs-256 +//! hqc-192 //! //! These bindings use the clean version from [PQClean][pqc] //! //! # Example //! ``` //! // if using pqcrypto-hqc -//! use pqcrypto_hqc::hqcrmrs256::*; +//! use pqcrypto_hqc::hqc192::*; //! // or if using the pqcrypto crate: -//! // use pqcrypto::kem::hqcrmrs256::*; +//! // use pqcrypto::kem::hqc192::*; //! let (pk, sk) = keypair(); //! let (ss1, ct) = encapsulate(&pk); //! let ss2 = decapsulate(&ct, &sk); @@ -82,38 +82,29 @@ macro_rules! simple_struct { }; } -simple_struct!( - PublicKey, - ffi::PQCLEAN_HQCRMRS256_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_HQCRMRS256_CLEAN_CRYPTO_SECRETKEYBYTES -); -simple_struct!( - Ciphertext, - ffi::PQCLEAN_HQCRMRS256_CLEAN_CRYPTO_CIPHERTEXTBYTES -); -simple_struct!(SharedSecret, ffi::PQCLEAN_HQCRMRS256_CLEAN_CRYPTO_BYTES); +simple_struct!(PublicKey, ffi::PQCLEAN_HQC192_CLEAN_CRYPTO_PUBLICKEYBYTES); +simple_struct!(SecretKey, ffi::PQCLEAN_HQC192_CLEAN_CRYPTO_SECRETKEYBYTES); +simple_struct!(Ciphertext, ffi::PQCLEAN_HQC192_CLEAN_CRYPTO_CIPHERTEXTBYTES); +simple_struct!(SharedSecret, ffi::PQCLEAN_HQC192_CLEAN_CRYPTO_BYTES); /// Get the number of bytes for a public key pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_HQCRMRS256_CLEAN_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_HQC192_CLEAN_CRYPTO_PUBLICKEYBYTES } /// Get the number of bytes for a secret key pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_HQCRMRS256_CLEAN_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_HQC192_CLEAN_CRYPTO_SECRETKEYBYTES } /// Get the number of bytes for the encapsulated ciphertext pub const fn ciphertext_bytes() -> usize { - ffi::PQCLEAN_HQCRMRS256_CLEAN_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_HQC192_CLEAN_CRYPTO_CIPHERTEXTBYTES } /// Get the number of bytes for the shared secret pub const fn shared_secret_bytes() -> usize { - ffi::PQCLEAN_HQCRMRS256_CLEAN_CRYPTO_BYTES + ffi::PQCLEAN_HQC192_CLEAN_CRYPTO_BYTES } macro_rules! gen_keypair { @@ -128,9 +119,9 @@ macro_rules! gen_keypair { }}; } -/// Generate a hqc-rmrs-256 keypair +/// Generate a hqc-192 keypair pub fn keypair() -> (PublicKey, SecretKey) { - gen_keypair!(PQCLEAN_HQCRMRS256_CLEAN_crypto_kem_keypair) + gen_keypair!(PQCLEAN_HQC192_CLEAN_crypto_kem_keypair) } macro_rules! encap { @@ -145,9 +136,9 @@ macro_rules! encap { }}; } -/// Encapsulate to a hqc-rmrs-256 public key +/// Encapsulate to a hqc-192 public key pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { - encap!(PQCLEAN_HQCRMRS256_CLEAN_crypto_kem_enc, pk) + encap!(PQCLEAN_HQC192_CLEAN_crypto_kem_enc, pk) } macro_rules! decap { @@ -161,9 +152,9 @@ macro_rules! decap { }}; } -/// Decapsulate the received hqc-rmrs-256 ciphertext +/// Decapsulate the received hqc-192 ciphertext pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { - decap!(PQCLEAN_HQCRMRS256_CLEAN_crypto_kem_dec, ct, sk) + decap!(PQCLEAN_HQC192_CLEAN_crypto_kem_dec, ct, sk) } #[cfg(test)] diff --git a/pqcrypto-hqc/src/hqcrmrs128.rs b/pqcrypto-hqc/src/hqc256.rs similarity index 80% rename from pqcrypto-hqc/src/hqcrmrs128.rs rename to pqcrypto-hqc/src/hqc256.rs index 2a92b841..7a862f18 100644 --- a/pqcrypto-hqc/src/hqcrmrs128.rs +++ b/pqcrypto-hqc/src/hqc256.rs @@ -1,13 +1,13 @@ -//! hqc-rmrs-128 +//! hqc-256 //! //! These bindings use the clean version from [PQClean][pqc] //! //! # Example //! ``` //! // if using pqcrypto-hqc -//! use pqcrypto_hqc::hqcrmrs128::*; +//! use pqcrypto_hqc::hqc256::*; //! // or if using the pqcrypto crate: -//! // use pqcrypto::kem::hqcrmrs128::*; +//! // use pqcrypto::kem::hqc256::*; //! let (pk, sk) = keypair(); //! let (ss1, ct) = encapsulate(&pk); //! let ss2 = decapsulate(&ct, &sk); @@ -82,38 +82,29 @@ macro_rules! simple_struct { }; } -simple_struct!( - PublicKey, - ffi::PQCLEAN_HQCRMRS128_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_HQCRMRS128_CLEAN_CRYPTO_SECRETKEYBYTES -); -simple_struct!( - Ciphertext, - ffi::PQCLEAN_HQCRMRS128_CLEAN_CRYPTO_CIPHERTEXTBYTES -); -simple_struct!(SharedSecret, ffi::PQCLEAN_HQCRMRS128_CLEAN_CRYPTO_BYTES); +simple_struct!(PublicKey, ffi::PQCLEAN_HQC256_CLEAN_CRYPTO_PUBLICKEYBYTES); +simple_struct!(SecretKey, ffi::PQCLEAN_HQC256_CLEAN_CRYPTO_SECRETKEYBYTES); +simple_struct!(Ciphertext, ffi::PQCLEAN_HQC256_CLEAN_CRYPTO_CIPHERTEXTBYTES); +simple_struct!(SharedSecret, ffi::PQCLEAN_HQC256_CLEAN_CRYPTO_BYTES); /// Get the number of bytes for a public key pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_HQCRMRS128_CLEAN_CRYPTO_PUBLICKEYBYTES + ffi::PQCLEAN_HQC256_CLEAN_CRYPTO_PUBLICKEYBYTES } /// Get the number of bytes for a secret key pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_HQCRMRS128_CLEAN_CRYPTO_SECRETKEYBYTES + ffi::PQCLEAN_HQC256_CLEAN_CRYPTO_SECRETKEYBYTES } /// Get the number of bytes for the encapsulated ciphertext pub const fn ciphertext_bytes() -> usize { - ffi::PQCLEAN_HQCRMRS128_CLEAN_CRYPTO_CIPHERTEXTBYTES + ffi::PQCLEAN_HQC256_CLEAN_CRYPTO_CIPHERTEXTBYTES } /// Get the number of bytes for the shared secret pub const fn shared_secret_bytes() -> usize { - ffi::PQCLEAN_HQCRMRS128_CLEAN_CRYPTO_BYTES + ffi::PQCLEAN_HQC256_CLEAN_CRYPTO_BYTES } macro_rules! gen_keypair { @@ -128,9 +119,9 @@ macro_rules! gen_keypair { }}; } -/// Generate a hqc-rmrs-128 keypair +/// Generate a hqc-256 keypair pub fn keypair() -> (PublicKey, SecretKey) { - gen_keypair!(PQCLEAN_HQCRMRS128_CLEAN_crypto_kem_keypair) + gen_keypair!(PQCLEAN_HQC256_CLEAN_crypto_kem_keypair) } macro_rules! encap { @@ -145,9 +136,9 @@ macro_rules! encap { }}; } -/// Encapsulate to a hqc-rmrs-128 public key +/// Encapsulate to a hqc-256 public key pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { - encap!(PQCLEAN_HQCRMRS128_CLEAN_crypto_kem_enc, pk) + encap!(PQCLEAN_HQC256_CLEAN_crypto_kem_enc, pk) } macro_rules! decap { @@ -161,9 +152,9 @@ macro_rules! decap { }}; } -/// Decapsulate the received hqc-rmrs-128 ciphertext +/// Decapsulate the received hqc-256 ciphertext pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { - decap!(PQCLEAN_HQCRMRS128_CLEAN_crypto_kem_dec, ct, sk) + decap!(PQCLEAN_HQC256_CLEAN_crypto_kem_dec, ct, sk) } #[cfg(test)] diff --git a/pqcrypto-hqc/src/lib.rs b/pqcrypto-hqc/src/lib.rs index f62cd69e..7d263eb0 100644 --- a/pqcrypto-hqc/src/lib.rs +++ b/pqcrypto-hqc/src/lib.rs @@ -3,9 +3,9 @@ //! This crate provides bindings to and wrappers around the following //! implementations from [PQClean][pqc]: //! -//! * hqc-rmrs-128 - clean -//! * hqc-rmrs-192 - clean -//! * hqc-rmrs-256 - clean +//! * hqc-128 - clean +//! * hqc-192 - clean +//! * hqc-256 - clean //! //! [pqc]: https://github.com/pqclean/pqclean/ //! @@ -21,28 +21,25 @@ extern crate alloc; extern crate std; pub mod ffi; -pub mod hqcrmrs128; -pub mod hqcrmrs192; -pub mod hqcrmrs256; +pub mod hqc128; +pub mod hqc192; +pub mod hqc256; -pub use crate::hqcrmrs128::{ - ciphertext_bytes as hqcrmrs128_ciphertext_bytes, decapsulate as hqcrmrs128_decapsulate, - encapsulate as hqcrmrs128_encapsulate, keypair as hqcrmrs128_keypair, - public_key_bytes as hqcrmrs128_public_key_bytes, - secret_key_bytes as hqcrmrs128_secret_key_bytes, - shared_secret_bytes as hqcrmrs128_shared_secret_bytes, +pub use crate::hqc128::{ + ciphertext_bytes as hqc128_ciphertext_bytes, decapsulate as hqc128_decapsulate, + encapsulate as hqc128_encapsulate, keypair as hqc128_keypair, + public_key_bytes as hqc128_public_key_bytes, secret_key_bytes as hqc128_secret_key_bytes, + shared_secret_bytes as hqc128_shared_secret_bytes, }; -pub use crate::hqcrmrs192::{ - ciphertext_bytes as hqcrmrs192_ciphertext_bytes, decapsulate as hqcrmrs192_decapsulate, - encapsulate as hqcrmrs192_encapsulate, keypair as hqcrmrs192_keypair, - public_key_bytes as hqcrmrs192_public_key_bytes, - secret_key_bytes as hqcrmrs192_secret_key_bytes, - shared_secret_bytes as hqcrmrs192_shared_secret_bytes, +pub use crate::hqc192::{ + ciphertext_bytes as hqc192_ciphertext_bytes, decapsulate as hqc192_decapsulate, + encapsulate as hqc192_encapsulate, keypair as hqc192_keypair, + public_key_bytes as hqc192_public_key_bytes, secret_key_bytes as hqc192_secret_key_bytes, + shared_secret_bytes as hqc192_shared_secret_bytes, }; -pub use crate::hqcrmrs256::{ - ciphertext_bytes as hqcrmrs256_ciphertext_bytes, decapsulate as hqcrmrs256_decapsulate, - encapsulate as hqcrmrs256_encapsulate, keypair as hqcrmrs256_keypair, - public_key_bytes as hqcrmrs256_public_key_bytes, - secret_key_bytes as hqcrmrs256_secret_key_bytes, - shared_secret_bytes as hqcrmrs256_shared_secret_bytes, +pub use crate::hqc256::{ + ciphertext_bytes as hqc256_ciphertext_bytes, decapsulate as hqc256_decapsulate, + encapsulate as hqc256_encapsulate, keypair as hqc256_keypair, + public_key_bytes as hqc256_public_key_bytes, secret_key_bytes as hqc256_secret_key_bytes, + shared_secret_bytes as hqc256_shared_secret_bytes, }; diff --git a/pqcrypto-kyber/README.md b/pqcrypto-kyber/README.md index 49776f7a..b261eafa 100644 --- a/pqcrypto-kyber/README.md +++ b/pqcrypto-kyber/README.md @@ -31,15 +31,6 @@ methods only. * ``clean`` * ``avx2`` (if supported) * ``aarch64`` (if supported) -* ``kyber512-90s`` - * ``clean`` - * ``avx2`` (if supported) -* ``kyber768-90s`` - * ``clean`` - * ``avx2`` (if supported) -* ``kyber1024-90s`` - * ``clean`` - * ``avx2`` (if supported) ## License diff --git a/pqcrypto-kyber/build.rs b/pqcrypto-kyber/build.rs index ca3b0226..a86b3061 100644 --- a/pqcrypto-kyber/build.rs +++ b/pqcrypto-kyber/build.rs @@ -148,18 +148,6 @@ fn main() { if target_arch == "aarch64" && neon_enabled { build_aarch64!("kyber1024"); } - build_clean!("kyber512-90s"); - if target_arch == "x86_64" && avx2_enabled && !is_windows && !is_macos { - build_avx2!("kyber512-90s"); - } - build_clean!("kyber768-90s"); - if target_arch == "x86_64" && avx2_enabled && !is_windows && !is_macos { - build_avx2!("kyber768-90s"); - } - build_clean!("kyber1024-90s"); - if target_arch == "x86_64" && avx2_enabled && !is_windows && !is_macos { - build_avx2!("kyber1024-90s"); - } if target_arch == "x86_64" && avx2_enabled && !is_windows && !is_macos { // Print enableing flag for AVX2 implementation diff --git a/pqcrypto-kyber/src/ffi.rs b/pqcrypto-kyber/src/ffi.rs index c614adad..6e64777a 100644 --- a/pqcrypto-kyber/src/ffi.rs +++ b/pqcrypto-kyber/src/ffi.rs @@ -6,9 +6,6 @@ //! * kyber512 //! * kyber768 //! * kyber1024 -//! * kyber512-90s -//! * kyber768-90s -//! * kyber1024-90s // This file has been generated from PQClean. // Find the templates in pqcrypto-template use libc::c_int; @@ -86,48 +83,6 @@ pub const PQCLEAN_KYBER1024_AARCH64_CRYPTO_CIPHERTEXTBYTES: usize = 1568; #[cfg(enable_aarch64_neon)] pub const PQCLEAN_KYBER1024_AARCH64_CRYPTO_BYTES: usize = 32; -pub const PQCLEAN_KYBER51290S_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 1632; -pub const PQCLEAN_KYBER51290S_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 800; -pub const PQCLEAN_KYBER51290S_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 768; -pub const PQCLEAN_KYBER51290S_CLEAN_CRYPTO_BYTES: usize = 32; - -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_KYBER51290S_AVX2_CRYPTO_SECRETKEYBYTES: usize = 1632; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_KYBER51290S_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 800; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_KYBER51290S_AVX2_CRYPTO_CIPHERTEXTBYTES: usize = 768; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_KYBER51290S_AVX2_CRYPTO_BYTES: usize = 32; - -pub const PQCLEAN_KYBER76890S_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 2400; -pub const PQCLEAN_KYBER76890S_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 1184; -pub const PQCLEAN_KYBER76890S_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 1088; -pub const PQCLEAN_KYBER76890S_CLEAN_CRYPTO_BYTES: usize = 32; - -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_KYBER76890S_AVX2_CRYPTO_SECRETKEYBYTES: usize = 2400; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_KYBER76890S_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 1184; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_KYBER76890S_AVX2_CRYPTO_CIPHERTEXTBYTES: usize = 1088; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_KYBER76890S_AVX2_CRYPTO_BYTES: usize = 32; - -pub const PQCLEAN_KYBER102490S_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 3168; -pub const PQCLEAN_KYBER102490S_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 1568; -pub const PQCLEAN_KYBER102490S_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 1568; -pub const PQCLEAN_KYBER102490S_CLEAN_CRYPTO_BYTES: usize = 32; - -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_KYBER102490S_AVX2_CRYPTO_SECRETKEYBYTES: usize = 3168; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_KYBER102490S_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 1568; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_KYBER102490S_AVX2_CRYPTO_CIPHERTEXTBYTES: usize = 1568; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_KYBER102490S_AVX2_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; @@ -258,108 +213,6 @@ extern "C" { ) -> c_int; } -#[link(name = "kyber512-90s_clean")] -extern "C" { - pub fn PQCLEAN_KYBER51290S_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - pub fn PQCLEAN_KYBER51290S_CLEAN_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_KYBER51290S_CLEAN_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "kyber512-90s_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_KYBER51290S_AVX2_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_KYBER51290S_AVX2_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_KYBER51290S_AVX2_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; -} - -#[link(name = "kyber768-90s_clean")] -extern "C" { - pub fn PQCLEAN_KYBER76890S_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - pub fn PQCLEAN_KYBER76890S_CLEAN_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_KYBER76890S_CLEAN_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "kyber768-90s_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_KYBER76890S_AVX2_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_KYBER76890S_AVX2_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_KYBER76890S_AVX2_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; -} - -#[link(name = "kyber1024-90s_clean")] -extern "C" { - pub fn PQCLEAN_KYBER102490S_CLEAN_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - pub fn PQCLEAN_KYBER102490S_CLEAN_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_KYBER102490S_CLEAN_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "kyber1024-90s_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_KYBER102490S_AVX2_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_KYBER102490S_AVX2_crypto_kem_enc( - ct: *mut u8, - ss: *mut u8, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_KYBER102490S_AVX2_crypto_kem_dec( - ss: *mut u8, - ct: *const u8, - sk: *const u8, - ) -> c_int; -} - #[cfg(test)] mod test_kyber512_clean { use super::*; @@ -690,241 +543,3 @@ mod test_kyber1024_aarch64 { } } } - -#[cfg(test)] -mod test_kyber51290s_clean { - use super::*; - use alloc::vec; - - #[test] - fn test_ffi() { - unsafe { - let mut pk = vec![0u8; PQCLEAN_KYBER51290S_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_KYBER51290S_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_KYBER51290S_CLEAN_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_KYBER51290S_CLEAN_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_KYBER51290S_CLEAN_CRYPTO_BYTES]; - - assert_eq!( - 0, - PQCLEAN_KYBER51290S_CLEAN_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_KYBER51290S_CLEAN_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_KYBER51290S_CLEAN_crypto_kem_dec( - ss2.as_mut_ptr(), - ct.as_ptr(), - sk.as_ptr() - ) - ); - assert_eq!(&ss1[..], &ss2[..], "Shared secrets should be equal"); - } - } -} - -#[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_kyber51290s_avx2 { - use super::*; - use alloc::vec; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("avx2") { - return; - } - unsafe { - let mut pk = vec![0u8; PQCLEAN_KYBER51290S_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_KYBER51290S_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_KYBER51290S_AVX2_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_KYBER51290S_AVX2_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_KYBER51290S_AVX2_CRYPTO_BYTES]; - - assert_eq!( - 0, - PQCLEAN_KYBER51290S_AVX2_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_KYBER51290S_AVX2_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_KYBER51290S_AVX2_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_kyber76890s_clean { - use super::*; - use alloc::vec; - - #[test] - fn test_ffi() { - unsafe { - let mut pk = vec![0u8; PQCLEAN_KYBER76890S_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_KYBER76890S_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_KYBER76890S_CLEAN_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_KYBER76890S_CLEAN_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_KYBER76890S_CLEAN_CRYPTO_BYTES]; - - assert_eq!( - 0, - PQCLEAN_KYBER76890S_CLEAN_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_KYBER76890S_CLEAN_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_KYBER76890S_CLEAN_crypto_kem_dec( - ss2.as_mut_ptr(), - ct.as_ptr(), - sk.as_ptr() - ) - ); - assert_eq!(&ss1[..], &ss2[..], "Shared secrets should be equal"); - } - } -} - -#[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_kyber76890s_avx2 { - use super::*; - use alloc::vec; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("avx2") { - return; - } - unsafe { - let mut pk = vec![0u8; PQCLEAN_KYBER76890S_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_KYBER76890S_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_KYBER76890S_AVX2_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_KYBER76890S_AVX2_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_KYBER76890S_AVX2_CRYPTO_BYTES]; - - assert_eq!( - 0, - PQCLEAN_KYBER76890S_AVX2_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_KYBER76890S_AVX2_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_KYBER76890S_AVX2_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_kyber102490s_clean { - use super::*; - use alloc::vec; - - #[test] - fn test_ffi() { - unsafe { - let mut pk = vec![0u8; PQCLEAN_KYBER102490S_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_KYBER102490S_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_KYBER102490S_CLEAN_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_KYBER102490S_CLEAN_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_KYBER102490S_CLEAN_CRYPTO_BYTES]; - - assert_eq!( - 0, - PQCLEAN_KYBER102490S_CLEAN_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_KYBER102490S_CLEAN_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_KYBER102490S_CLEAN_crypto_kem_dec( - ss2.as_mut_ptr(), - ct.as_ptr(), - sk.as_ptr() - ) - ); - assert_eq!(&ss1[..], &ss2[..], "Shared secrets should be equal"); - } - } -} - -#[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_kyber102490s_avx2 { - use super::*; - use alloc::vec; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("avx2") { - return; - } - unsafe { - let mut pk = vec![0u8; PQCLEAN_KYBER102490S_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_KYBER102490S_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_KYBER102490S_AVX2_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_KYBER102490S_AVX2_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_KYBER102490S_AVX2_CRYPTO_BYTES]; - - assert_eq!( - 0, - PQCLEAN_KYBER102490S_AVX2_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) - ); - assert_eq!( - 0, - PQCLEAN_KYBER102490S_AVX2_crypto_kem_enc( - ct.as_mut_ptr(), - ss1.as_mut_ptr(), - pk.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_KYBER102490S_AVX2_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/kyber102490s.rs b/pqcrypto-kyber/src/kyber102490s.rs deleted file mode 100644 index 4e51d085..00000000 --- a/pqcrypto-kyber/src/kyber102490s.rs +++ /dev/null @@ -1,198 +0,0 @@ -//! kyber1024-90s -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-kyber -//! use pqcrypto_kyber::kyber102490s::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::kem::kyber102490s::*; -//! let (pk, sk) = keypair(); -//! let (ss1, ct) = encapsulate(&pk); -//! let ss2 = decapsulate(&ct, &sk); -//! assert!(ss1 == ss2); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use pqcrypto_traits::kem as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_KYBER102490S_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_KYBER102490S_CLEAN_CRYPTO_SECRETKEYBYTES -); -simple_struct!( - Ciphertext, - ffi::PQCLEAN_KYBER102490S_CLEAN_CRYPTO_CIPHERTEXTBYTES -); -simple_struct!(SharedSecret, ffi::PQCLEAN_KYBER102490S_CLEAN_CRYPTO_BYTES); - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_KYBER102490S_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_KYBER102490S_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes for the encapsulated ciphertext -pub const fn ciphertext_bytes() -> usize { - ffi::PQCLEAN_KYBER102490S_CLEAN_CRYPTO_CIPHERTEXTBYTES -} - -/// Get the number of bytes for the shared secret -pub const fn shared_secret_bytes() -> usize { - ffi::PQCLEAN_KYBER102490S_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a kyber1024-90s keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_KYBER102490S_AVX2_crypto_kem_keypair); - } - } - gen_keypair!(PQCLEAN_KYBER102490S_CLEAN_crypto_kem_keypair) -} - -macro_rules! encap { - ($variant:ident, $pk:ident) => {{ - let mut ss = SharedSecret::new(); - let mut ct = Ciphertext::new(); - assert_eq!( - unsafe { ffi::$variant(ct.0.as_mut_ptr(), ss.0.as_mut_ptr(), $pk.0.as_ptr()) }, - 0, - ); - (ss, ct) - }}; -} - -/// Encapsulate to a kyber1024-90s public key -pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return encap!(PQCLEAN_KYBER102490S_AVX2_crypto_kem_enc, pk); - } - } - encap!(PQCLEAN_KYBER102490S_CLEAN_crypto_kem_enc, pk) -} - -macro_rules! decap { - ($variant:ident, $ct:ident, $sk:ident) => {{ - let mut ss = SharedSecret::new(); - assert_eq!( - unsafe { ffi::$variant(ss.0.as_mut_ptr(), $ct.0.as_ptr(), $sk.0.as_ptr(),) }, - 0 - ); - ss - }}; -} - -/// Decapsulate the received kyber1024-90s ciphertext -pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return decap!(PQCLEAN_KYBER102490S_AVX2_crypto_kem_dec, ct, sk); - } - } - decap!(PQCLEAN_KYBER102490S_CLEAN_crypto_kem_dec, ct, sk) -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - pub fn test_kem() { - let (pk, sk) = keypair(); - let (ss1, ct) = encapsulate(&pk); - let ss2 = decapsulate(&ct, &sk); - assert_eq!(&ss1.0[..], &ss2.0[..], "Difference in shared secrets!"); - } -} diff --git a/pqcrypto-kyber/src/kyber51290s.rs b/pqcrypto-kyber/src/kyber51290s.rs deleted file mode 100644 index 943f00ec..00000000 --- a/pqcrypto-kyber/src/kyber51290s.rs +++ /dev/null @@ -1,198 +0,0 @@ -//! kyber512-90s -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-kyber -//! use pqcrypto_kyber::kyber51290s::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::kem::kyber51290s::*; -//! let (pk, sk) = keypair(); -//! let (ss1, ct) = encapsulate(&pk); -//! let ss2 = decapsulate(&ct, &sk); -//! assert!(ss1 == ss2); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use pqcrypto_traits::kem as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_KYBER51290S_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_KYBER51290S_CLEAN_CRYPTO_SECRETKEYBYTES -); -simple_struct!( - Ciphertext, - ffi::PQCLEAN_KYBER51290S_CLEAN_CRYPTO_CIPHERTEXTBYTES -); -simple_struct!(SharedSecret, ffi::PQCLEAN_KYBER51290S_CLEAN_CRYPTO_BYTES); - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_KYBER51290S_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_KYBER51290S_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes for the encapsulated ciphertext -pub const fn ciphertext_bytes() -> usize { - ffi::PQCLEAN_KYBER51290S_CLEAN_CRYPTO_CIPHERTEXTBYTES -} - -/// Get the number of bytes for the shared secret -pub const fn shared_secret_bytes() -> usize { - ffi::PQCLEAN_KYBER51290S_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a kyber512-90s keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_KYBER51290S_AVX2_crypto_kem_keypair); - } - } - gen_keypair!(PQCLEAN_KYBER51290S_CLEAN_crypto_kem_keypair) -} - -macro_rules! encap { - ($variant:ident, $pk:ident) => {{ - let mut ss = SharedSecret::new(); - let mut ct = Ciphertext::new(); - assert_eq!( - unsafe { ffi::$variant(ct.0.as_mut_ptr(), ss.0.as_mut_ptr(), $pk.0.as_ptr()) }, - 0, - ); - (ss, ct) - }}; -} - -/// Encapsulate to a kyber512-90s public key -pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return encap!(PQCLEAN_KYBER51290S_AVX2_crypto_kem_enc, pk); - } - } - encap!(PQCLEAN_KYBER51290S_CLEAN_crypto_kem_enc, pk) -} - -macro_rules! decap { - ($variant:ident, $ct:ident, $sk:ident) => {{ - let mut ss = SharedSecret::new(); - assert_eq!( - unsafe { ffi::$variant(ss.0.as_mut_ptr(), $ct.0.as_ptr(), $sk.0.as_ptr(),) }, - 0 - ); - ss - }}; -} - -/// Decapsulate the received kyber512-90s ciphertext -pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return decap!(PQCLEAN_KYBER51290S_AVX2_crypto_kem_dec, ct, sk); - } - } - decap!(PQCLEAN_KYBER51290S_CLEAN_crypto_kem_dec, ct, sk) -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - pub fn test_kem() { - let (pk, sk) = keypair(); - let (ss1, ct) = encapsulate(&pk); - let ss2 = decapsulate(&ct, &sk); - assert_eq!(&ss1.0[..], &ss2.0[..], "Difference in shared secrets!"); - } -} diff --git a/pqcrypto-kyber/src/kyber76890s.rs b/pqcrypto-kyber/src/kyber76890s.rs deleted file mode 100644 index 7bf11cdb..00000000 --- a/pqcrypto-kyber/src/kyber76890s.rs +++ /dev/null @@ -1,198 +0,0 @@ -//! kyber768-90s -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-kyber -//! use pqcrypto_kyber::kyber76890s::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::kem::kyber76890s::*; -//! let (pk, sk) = keypair(); -//! let (ss1, ct) = encapsulate(&pk); -//! let ss2 = decapsulate(&ct, &sk); -//! assert!(ss1 == ss2); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use pqcrypto_traits::kem as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_KYBER76890S_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_KYBER76890S_CLEAN_CRYPTO_SECRETKEYBYTES -); -simple_struct!( - Ciphertext, - ffi::PQCLEAN_KYBER76890S_CLEAN_CRYPTO_CIPHERTEXTBYTES -); -simple_struct!(SharedSecret, ffi::PQCLEAN_KYBER76890S_CLEAN_CRYPTO_BYTES); - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_KYBER76890S_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_KYBER76890S_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes for the encapsulated ciphertext -pub const fn ciphertext_bytes() -> usize { - ffi::PQCLEAN_KYBER76890S_CLEAN_CRYPTO_CIPHERTEXTBYTES -} - -/// Get the number of bytes for the shared secret -pub const fn shared_secret_bytes() -> usize { - ffi::PQCLEAN_KYBER76890S_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a kyber768-90s keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_KYBER76890S_AVX2_crypto_kem_keypair); - } - } - gen_keypair!(PQCLEAN_KYBER76890S_CLEAN_crypto_kem_keypair) -} - -macro_rules! encap { - ($variant:ident, $pk:ident) => {{ - let mut ss = SharedSecret::new(); - let mut ct = Ciphertext::new(); - assert_eq!( - unsafe { ffi::$variant(ct.0.as_mut_ptr(), ss.0.as_mut_ptr(), $pk.0.as_ptr()) }, - 0, - ); - (ss, ct) - }}; -} - -/// Encapsulate to a kyber768-90s public key -pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return encap!(PQCLEAN_KYBER76890S_AVX2_crypto_kem_enc, pk); - } - } - encap!(PQCLEAN_KYBER76890S_CLEAN_crypto_kem_enc, pk) -} - -macro_rules! decap { - ($variant:ident, $ct:ident, $sk:ident) => {{ - let mut ss = SharedSecret::new(); - assert_eq!( - unsafe { ffi::$variant(ss.0.as_mut_ptr(), $ct.0.as_ptr(), $sk.0.as_ptr(),) }, - 0 - ); - ss - }}; -} - -/// Decapsulate the received kyber768-90s ciphertext -pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return decap!(PQCLEAN_KYBER76890S_AVX2_crypto_kem_dec, ct, sk); - } - } - decap!(PQCLEAN_KYBER76890S_CLEAN_crypto_kem_dec, ct, sk) -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - pub fn test_kem() { - let (pk, sk) = keypair(); - let (ss1, ct) = encapsulate(&pk); - let ss2 = decapsulate(&ct, &sk); - assert_eq!(&ss1.0[..], &ss2.0[..], "Difference in shared secrets!"); - } -} diff --git a/pqcrypto-kyber/src/lib.rs b/pqcrypto-kyber/src/lib.rs index ae4c6c48..ab8295cd 100644 --- a/pqcrypto-kyber/src/lib.rs +++ b/pqcrypto-kyber/src/lib.rs @@ -6,9 +6,6 @@ //! * kyber512 - clean //! * kyber768 - clean //! * kyber1024 - clean -//! * kyber512-90s - clean -//! * kyber768-90s - clean -//! * kyber1024-90s - clean //! //! [pqc]: https://github.com/pqclean/pqclean/ //! @@ -25,11 +22,8 @@ extern crate std; pub mod ffi; pub mod kyber1024; -pub mod kyber102490s; pub mod kyber512; -pub mod kyber51290s; pub mod kyber768; -pub mod kyber76890s; pub use crate::kyber1024::{ ciphertext_bytes as kyber1024_ciphertext_bytes, decapsulate as kyber1024_decapsulate, @@ -37,36 +31,15 @@ pub use crate::kyber1024::{ public_key_bytes as kyber1024_public_key_bytes, secret_key_bytes as kyber1024_secret_key_bytes, shared_secret_bytes as kyber1024_shared_secret_bytes, }; -pub use crate::kyber102490s::{ - ciphertext_bytes as kyber102490s_ciphertext_bytes, decapsulate as kyber102490s_decapsulate, - encapsulate as kyber102490s_encapsulate, keypair as kyber102490s_keypair, - public_key_bytes as kyber102490s_public_key_bytes, - secret_key_bytes as kyber102490s_secret_key_bytes, - shared_secret_bytes as kyber102490s_shared_secret_bytes, -}; pub use crate::kyber512::{ ciphertext_bytes as kyber512_ciphertext_bytes, decapsulate as kyber512_decapsulate, encapsulate as kyber512_encapsulate, keypair as kyber512_keypair, public_key_bytes as kyber512_public_key_bytes, secret_key_bytes as kyber512_secret_key_bytes, shared_secret_bytes as kyber512_shared_secret_bytes, }; -pub use crate::kyber51290s::{ - ciphertext_bytes as kyber51290s_ciphertext_bytes, decapsulate as kyber51290s_decapsulate, - encapsulate as kyber51290s_encapsulate, keypair as kyber51290s_keypair, - public_key_bytes as kyber51290s_public_key_bytes, - secret_key_bytes as kyber51290s_secret_key_bytes, - shared_secret_bytes as kyber51290s_shared_secret_bytes, -}; pub use crate::kyber768::{ ciphertext_bytes as kyber768_ciphertext_bytes, decapsulate as kyber768_decapsulate, encapsulate as kyber768_encapsulate, keypair as kyber768_keypair, public_key_bytes as kyber768_public_key_bytes, secret_key_bytes as kyber768_secret_key_bytes, shared_secret_bytes as kyber768_shared_secret_bytes, }; -pub use crate::kyber76890s::{ - ciphertext_bytes as kyber76890s_ciphertext_bytes, decapsulate as kyber76890s_decapsulate, - encapsulate as kyber76890s_encapsulate, keypair as kyber76890s_keypair, - public_key_bytes as kyber76890s_public_key_bytes, - secret_key_bytes as kyber76890s_secret_key_bytes, - shared_secret_bytes as kyber76890s_shared_secret_bytes, -}; diff --git a/pqcrypto-sphincsplus/README.md b/pqcrypto-sphincsplus/README.md index 7dec2899..7a365a06 100644 --- a/pqcrypto-sphincsplus/README.md +++ b/pqcrypto-sphincsplus/README.md @@ -19,111 +19,39 @@ sourced from [PQClean][pqclean]. The "default" implementation is used in the Rust-friendly interface, alternative implementations are exposed as ``ffi`` methods only. -* ``sphincs-haraka-128f-robust`` - * ``clean`` - * ``aesni`` (if supported) -* ``sphincs-haraka-128f-simple`` - * ``clean`` - * ``aesni`` (if supported) -* ``sphincs-haraka-128s-robust`` - * ``clean`` - * ``aesni`` (if supported) -* ``sphincs-haraka-128s-simple`` - * ``clean`` - * ``aesni`` (if supported) -* ``sphincs-haraka-192f-robust`` - * ``clean`` - * ``aesni`` (if supported) -* ``sphincs-haraka-192f-simple`` - * ``clean`` - * ``aesni`` (if supported) -* ``sphincs-haraka-192s-robust`` - * ``clean`` - * ``aesni`` (if supported) -* ``sphincs-haraka-192s-simple`` - * ``clean`` - * ``aesni`` (if supported) -* ``sphincs-haraka-256f-robust`` - * ``clean`` - * ``aesni`` (if supported) -* ``sphincs-haraka-256f-simple`` - * ``clean`` - * ``aesni`` (if supported) -* ``sphincs-haraka-256s-robust`` - * ``clean`` - * ``aesni`` (if supported) -* ``sphincs-haraka-256s-simple`` - * ``clean`` - * ``aesni`` (if supported) -* ``sphincs-shake-128f-robust`` - * ``clean`` - * ``avx2`` (if supported) * ``sphincs-shake-128f-simple`` * ``clean`` * ``avx2`` (if supported) -* ``sphincs-shake-128s-robust`` - * ``clean`` - * ``avx2`` (if supported) * ``sphincs-shake-128s-simple`` * ``clean`` * ``avx2`` (if supported) -* ``sphincs-shake-192f-robust`` - * ``clean`` - * ``avx2`` (if supported) * ``sphincs-shake-192f-simple`` * ``clean`` * ``avx2`` (if supported) -* ``sphincs-shake-192s-robust`` - * ``clean`` - * ``avx2`` (if supported) * ``sphincs-shake-192s-simple`` * ``clean`` * ``avx2`` (if supported) -* ``sphincs-shake-256f-robust`` - * ``clean`` - * ``avx2`` (if supported) * ``sphincs-shake-256f-simple`` * ``clean`` * ``avx2`` (if supported) -* ``sphincs-shake-256s-robust`` - * ``clean`` - * ``avx2`` (if supported) * ``sphincs-shake-256s-simple`` * ``clean`` * ``avx2`` (if supported) -* ``sphincs-sha2-128f-robust`` - * ``clean`` - * ``avx2`` (if supported) * ``sphincs-sha2-128f-simple`` * ``clean`` * ``avx2`` (if supported) -* ``sphincs-sha2-128s-robust`` - * ``clean`` - * ``avx2`` (if supported) * ``sphincs-sha2-128s-simple`` * ``clean`` * ``avx2`` (if supported) -* ``sphincs-sha2-192f-robust`` - * ``clean`` - * ``avx2`` (if supported) * ``sphincs-sha2-192f-simple`` * ``clean`` * ``avx2`` (if supported) -* ``sphincs-sha2-192s-robust`` - * ``clean`` - * ``avx2`` (if supported) * ``sphincs-sha2-192s-simple`` * ``clean`` * ``avx2`` (if supported) -* ``sphincs-sha2-256f-robust`` - * ``clean`` - * ``avx2`` (if supported) * ``sphincs-sha2-256f-simple`` * ``clean`` * ``avx2`` (if supported) -* ``sphincs-sha2-256s-robust`` - * ``clean`` - * ``avx2`` (if supported) * ``sphincs-sha2-256s-simple`` * ``clean`` * ``avx2`` (if supported) diff --git a/pqcrypto-sphincsplus/build.rs b/pqcrypto-sphincsplus/build.rs index fc5a3a29..d768de53 100644 --- a/pqcrypto-sphincsplus/build.rs +++ b/pqcrypto-sphincsplus/build.rs @@ -134,146 +134,50 @@ fn main() { #[allow(unused_variables)] let is_macos = target_os == "macos"; - build_clean!("sphincs-haraka-128f-robust"); - if target_arch == "x86_64" && aes_enabled { - build_aesni!("sphincs-haraka-128f-robust"); - } - build_clean!("sphincs-haraka-128f-simple"); - if target_arch == "x86_64" && aes_enabled { - build_aesni!("sphincs-haraka-128f-simple"); - } - build_clean!("sphincs-haraka-128s-robust"); - if target_arch == "x86_64" && aes_enabled { - build_aesni!("sphincs-haraka-128s-robust"); - } - build_clean!("sphincs-haraka-128s-simple"); - if target_arch == "x86_64" && aes_enabled { - build_aesni!("sphincs-haraka-128s-simple"); - } - build_clean!("sphincs-haraka-192f-robust"); - if target_arch == "x86_64" && aes_enabled { - build_aesni!("sphincs-haraka-192f-robust"); - } - build_clean!("sphincs-haraka-192f-simple"); - if target_arch == "x86_64" && aes_enabled { - build_aesni!("sphincs-haraka-192f-simple"); - } - build_clean!("sphincs-haraka-192s-robust"); - if target_arch == "x86_64" && aes_enabled { - build_aesni!("sphincs-haraka-192s-robust"); - } - build_clean!("sphincs-haraka-192s-simple"); - if target_arch == "x86_64" && aes_enabled { - build_aesni!("sphincs-haraka-192s-simple"); - } - build_clean!("sphincs-haraka-256f-robust"); - if target_arch == "x86_64" && aes_enabled { - build_aesni!("sphincs-haraka-256f-robust"); - } - build_clean!("sphincs-haraka-256f-simple"); - if target_arch == "x86_64" && aes_enabled { - build_aesni!("sphincs-haraka-256f-simple"); - } - build_clean!("sphincs-haraka-256s-robust"); - if target_arch == "x86_64" && aes_enabled { - build_aesni!("sphincs-haraka-256s-robust"); - } - build_clean!("sphincs-haraka-256s-simple"); - if target_arch == "x86_64" && aes_enabled { - build_aesni!("sphincs-haraka-256s-simple"); - } - build_clean!("sphincs-shake-128f-robust"); - if target_arch == "x86_64" && avx2_enabled { - build_avx2!("sphincs-shake-128f-robust"); - } build_clean!("sphincs-shake-128f-simple"); if target_arch == "x86_64" && avx2_enabled { build_avx2!("sphincs-shake-128f-simple"); } - build_clean!("sphincs-shake-128s-robust"); - if target_arch == "x86_64" && avx2_enabled { - build_avx2!("sphincs-shake-128s-robust"); - } build_clean!("sphincs-shake-128s-simple"); if target_arch == "x86_64" && avx2_enabled { build_avx2!("sphincs-shake-128s-simple"); } - build_clean!("sphincs-shake-192f-robust"); - if target_arch == "x86_64" && avx2_enabled { - build_avx2!("sphincs-shake-192f-robust"); - } build_clean!("sphincs-shake-192f-simple"); if target_arch == "x86_64" && avx2_enabled { build_avx2!("sphincs-shake-192f-simple"); } - build_clean!("sphincs-shake-192s-robust"); - if target_arch == "x86_64" && avx2_enabled { - build_avx2!("sphincs-shake-192s-robust"); - } build_clean!("sphincs-shake-192s-simple"); if target_arch == "x86_64" && avx2_enabled { build_avx2!("sphincs-shake-192s-simple"); } - build_clean!("sphincs-shake-256f-robust"); - if target_arch == "x86_64" && avx2_enabled { - build_avx2!("sphincs-shake-256f-robust"); - } build_clean!("sphincs-shake-256f-simple"); if target_arch == "x86_64" && avx2_enabled { build_avx2!("sphincs-shake-256f-simple"); } - build_clean!("sphincs-shake-256s-robust"); - if target_arch == "x86_64" && avx2_enabled { - build_avx2!("sphincs-shake-256s-robust"); - } build_clean!("sphincs-shake-256s-simple"); if target_arch == "x86_64" && avx2_enabled { build_avx2!("sphincs-shake-256s-simple"); } - build_clean!("sphincs-sha2-128f-robust"); - if target_arch == "x86_64" && avx2_enabled { - build_avx2!("sphincs-sha2-128f-robust"); - } build_clean!("sphincs-sha2-128f-simple"); if target_arch == "x86_64" && avx2_enabled { build_avx2!("sphincs-sha2-128f-simple"); } - build_clean!("sphincs-sha2-128s-robust"); - if target_arch == "x86_64" && avx2_enabled { - build_avx2!("sphincs-sha2-128s-robust"); - } build_clean!("sphincs-sha2-128s-simple"); if target_arch == "x86_64" && avx2_enabled { build_avx2!("sphincs-sha2-128s-simple"); } - build_clean!("sphincs-sha2-192f-robust"); - if target_arch == "x86_64" && avx2_enabled { - build_avx2!("sphincs-sha2-192f-robust"); - } build_clean!("sphincs-sha2-192f-simple"); if target_arch == "x86_64" && avx2_enabled { build_avx2!("sphincs-sha2-192f-simple"); } - build_clean!("sphincs-sha2-192s-robust"); - if target_arch == "x86_64" && avx2_enabled { - build_avx2!("sphincs-sha2-192s-robust"); - } build_clean!("sphincs-sha2-192s-simple"); if target_arch == "x86_64" && avx2_enabled { build_avx2!("sphincs-sha2-192s-simple"); } - build_clean!("sphincs-sha2-256f-robust"); - if target_arch == "x86_64" && avx2_enabled { - build_avx2!("sphincs-sha2-256f-robust"); - } build_clean!("sphincs-sha2-256f-simple"); if target_arch == "x86_64" && avx2_enabled { build_avx2!("sphincs-sha2-256f-simple"); } - build_clean!("sphincs-sha2-256s-robust"); - if target_arch == "x86_64" && avx2_enabled { - build_avx2!("sphincs-sha2-256s-robust"); - } build_clean!("sphincs-sha2-256s-simple"); if target_arch == "x86_64" && avx2_enabled { build_avx2!("sphincs-sha2-256s-simple"); diff --git a/pqcrypto-sphincsplus/src/ffi.rs b/pqcrypto-sphincsplus/src/ffi.rs index f1474900..94554687 100644 --- a/pqcrypto-sphincsplus/src/ffi.rs +++ b/pqcrypto-sphincsplus/src/ffi.rs @@ -3,41 +3,17 @@ //! This module defines the foreign function interface for the following //! crypto implementations from PQClean: //! -//! * sphincs-haraka-128f-robust -//! * sphincs-haraka-128f-simple -//! * sphincs-haraka-128s-robust -//! * sphincs-haraka-128s-simple -//! * sphincs-haraka-192f-robust -//! * sphincs-haraka-192f-simple -//! * sphincs-haraka-192s-robust -//! * sphincs-haraka-192s-simple -//! * sphincs-haraka-256f-robust -//! * sphincs-haraka-256f-simple -//! * sphincs-haraka-256s-robust -//! * sphincs-haraka-256s-simple -//! * sphincs-shake-128f-robust //! * sphincs-shake-128f-simple -//! * sphincs-shake-128s-robust //! * sphincs-shake-128s-simple -//! * sphincs-shake-192f-robust //! * sphincs-shake-192f-simple -//! * sphincs-shake-192s-robust //! * sphincs-shake-192s-simple -//! * sphincs-shake-256f-robust //! * sphincs-shake-256f-simple -//! * sphincs-shake-256s-robust //! * sphincs-shake-256s-simple -//! * sphincs-sha2-128f-robust //! * sphincs-sha2-128f-simple -//! * sphincs-sha2-128s-robust //! * sphincs-sha2-128s-simple -//! * sphincs-sha2-192f-robust //! * sphincs-sha2-192f-simple -//! * sphincs-sha2-192s-robust //! * sphincs-sha2-192s-simple -//! * sphincs-sha2-256f-robust //! * sphincs-sha2-256f-simple -//! * sphincs-sha2-256s-robust //! * sphincs-sha2-256s-simple // This file has been generated from PQClean. // Find the templates in pqcrypto-template @@ -47,149 +23,6 @@ use libc::c_int; #[allow(unused_imports)] use pqcrypto_internals::*; -pub const PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 64; -pub const PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 32; -pub const PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_CRYPTO_BYTES: usize = 17088; - -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_CRYPTO_SECRETKEYBYTES: usize = 64; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_CRYPTO_PUBLICKEYBYTES: usize = 32; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_CRYPTO_BYTES: usize = 17088; - -pub const PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 64; -pub const PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 32; -pub const PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_CRYPTO_BYTES: usize = 17088; - -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_CRYPTO_SECRETKEYBYTES: usize = 64; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_CRYPTO_PUBLICKEYBYTES: usize = 32; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_CRYPTO_BYTES: usize = 17088; - -pub const PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 64; -pub const PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 32; -pub const PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_CRYPTO_BYTES: usize = 7856; - -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_CRYPTO_SECRETKEYBYTES: usize = 64; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_CRYPTO_PUBLICKEYBYTES: usize = 32; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_CRYPTO_BYTES: usize = 7856; - -pub const PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 64; -pub const PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 32; -pub const PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_CRYPTO_BYTES: usize = 7856; - -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_CRYPTO_SECRETKEYBYTES: usize = 64; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_CRYPTO_PUBLICKEYBYTES: usize = 32; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_CRYPTO_BYTES: usize = 7856; - -pub const PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 96; -pub const PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 48; -pub const PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_CRYPTO_BYTES: usize = 35664; - -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_CRYPTO_SECRETKEYBYTES: usize = 96; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_CRYPTO_PUBLICKEYBYTES: usize = 48; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_CRYPTO_BYTES: usize = 35664; - -pub const PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 96; -pub const PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 48; -pub const PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_CRYPTO_BYTES: usize = 35664; - -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_CRYPTO_SECRETKEYBYTES: usize = 96; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_CRYPTO_PUBLICKEYBYTES: usize = 48; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_CRYPTO_BYTES: usize = 35664; - -pub const PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 96; -pub const PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 48; -pub const PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_CRYPTO_BYTES: usize = 16224; - -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_CRYPTO_SECRETKEYBYTES: usize = 96; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_CRYPTO_PUBLICKEYBYTES: usize = 48; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_CRYPTO_BYTES: usize = 16224; - -pub const PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 96; -pub const PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 48; -pub const PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_CRYPTO_BYTES: usize = 16224; - -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_CRYPTO_SECRETKEYBYTES: usize = 96; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_CRYPTO_PUBLICKEYBYTES: usize = 48; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_CRYPTO_BYTES: usize = 16224; - -pub const PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 128; -pub const PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 64; -pub const PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_CRYPTO_BYTES: usize = 49856; - -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_CRYPTO_SECRETKEYBYTES: usize = 128; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_CRYPTO_PUBLICKEYBYTES: usize = 64; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_CRYPTO_BYTES: usize = 49856; - -pub const PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 128; -pub const PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 64; -pub const PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_CRYPTO_BYTES: usize = 49856; - -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_CRYPTO_SECRETKEYBYTES: usize = 128; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_CRYPTO_PUBLICKEYBYTES: usize = 64; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_CRYPTO_BYTES: usize = 49856; - -pub const PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 128; -pub const PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 64; -pub const PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_CRYPTO_BYTES: usize = 29792; - -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_CRYPTO_SECRETKEYBYTES: usize = 128; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_CRYPTO_PUBLICKEYBYTES: usize = 64; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_CRYPTO_BYTES: usize = 29792; - -pub const PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 128; -pub const PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 64; -pub const PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_CRYPTO_BYTES: usize = 29792; - -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_CRYPTO_SECRETKEYBYTES: usize = 128; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_CRYPTO_PUBLICKEYBYTES: usize = 64; -#[cfg(enable_x86_aes)] -pub const PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_CRYPTO_BYTES: usize = 29792; - -pub const PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 64; -pub const PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 32; -pub const PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_CRYPTO_BYTES: usize = 17088; - -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_CRYPTO_SECRETKEYBYTES: usize = 64; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 32; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_CRYPTO_BYTES: usize = 17088; - pub const PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 64; pub const PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 32; pub const PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_CRYPTO_BYTES: usize = 17088; @@ -201,17 +34,6 @@ pub const PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 32; #[cfg(enable_x86_avx2)] pub const PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_CRYPTO_BYTES: usize = 17088; -pub const PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 64; -pub const PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 32; -pub const PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_CRYPTO_BYTES: usize = 7856; - -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_CRYPTO_SECRETKEYBYTES: usize = 64; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 32; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_CRYPTO_BYTES: usize = 7856; - pub const PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 64; pub const PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 32; pub const PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_CRYPTO_BYTES: usize = 7856; @@ -223,17 +45,6 @@ pub const PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 32; #[cfg(enable_x86_avx2)] pub const PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_CRYPTO_BYTES: usize = 7856; -pub const PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 96; -pub const PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 48; -pub const PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_CRYPTO_BYTES: usize = 35664; - -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_CRYPTO_SECRETKEYBYTES: usize = 96; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 48; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_CRYPTO_BYTES: usize = 35664; - pub const PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 96; pub const PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 48; pub const PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_CRYPTO_BYTES: usize = 35664; @@ -245,17 +56,6 @@ pub const PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 48; #[cfg(enable_x86_avx2)] pub const PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_CRYPTO_BYTES: usize = 35664; -pub const PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 96; -pub const PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 48; -pub const PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_CRYPTO_BYTES: usize = 16224; - -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_CRYPTO_SECRETKEYBYTES: usize = 96; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 48; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_CRYPTO_BYTES: usize = 16224; - pub const PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 96; pub const PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 48; pub const PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_CRYPTO_BYTES: usize = 16224; @@ -267,17 +67,6 @@ pub const PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 48; #[cfg(enable_x86_avx2)] pub const PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_CRYPTO_BYTES: usize = 16224; -pub const PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 128; -pub const PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 64; -pub const PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_CRYPTO_BYTES: usize = 49856; - -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_CRYPTO_SECRETKEYBYTES: usize = 128; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 64; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_CRYPTO_BYTES: usize = 49856; - pub const PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 128; pub const PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 64; pub const PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_CRYPTO_BYTES: usize = 49856; @@ -289,17 +78,6 @@ pub const PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 64; #[cfg(enable_x86_avx2)] pub const PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_CRYPTO_BYTES: usize = 49856; -pub const PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 128; -pub const PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 64; -pub const PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_CRYPTO_BYTES: usize = 29792; - -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_CRYPTO_SECRETKEYBYTES: usize = 128; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 64; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_CRYPTO_BYTES: usize = 29792; - pub const PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 128; pub const PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 64; pub const PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_CRYPTO_BYTES: usize = 29792; @@ -311,17 +89,6 @@ pub const PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 64; #[cfg(enable_x86_avx2)] pub const PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_CRYPTO_BYTES: usize = 29792; -pub const PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 64; -pub const PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 32; -pub const PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_CRYPTO_BYTES: usize = 17088; - -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_CRYPTO_SECRETKEYBYTES: usize = 64; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 32; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_CRYPTO_BYTES: usize = 17088; - pub const PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 64; pub const PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 32; pub const PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_CRYPTO_BYTES: usize = 17088; @@ -333,17 +100,6 @@ pub const PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 32; #[cfg(enable_x86_avx2)] pub const PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_CRYPTO_BYTES: usize = 17088; -pub const PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 64; -pub const PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 32; -pub const PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_CRYPTO_BYTES: usize = 7856; - -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_CRYPTO_SECRETKEYBYTES: usize = 64; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 32; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_CRYPTO_BYTES: usize = 7856; - pub const PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 64; pub const PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 32; pub const PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_CRYPTO_BYTES: usize = 7856; @@ -355,17 +111,6 @@ pub const PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 32; #[cfg(enable_x86_avx2)] pub const PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_CRYPTO_BYTES: usize = 7856; -pub const PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 96; -pub const PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 48; -pub const PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_CRYPTO_BYTES: usize = 35664; - -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_CRYPTO_SECRETKEYBYTES: usize = 96; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 48; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_CRYPTO_BYTES: usize = 35664; - pub const PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 96; pub const PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 48; pub const PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_CRYPTO_BYTES: usize = 35664; @@ -377,17 +122,6 @@ pub const PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 48; #[cfg(enable_x86_avx2)] pub const PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_CRYPTO_BYTES: usize = 35664; -pub const PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 96; -pub const PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 48; -pub const PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_CRYPTO_BYTES: usize = 16224; - -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_CRYPTO_SECRETKEYBYTES: usize = 96; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 48; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_CRYPTO_BYTES: usize = 16224; - pub const PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 96; pub const PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 48; pub const PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_CRYPTO_BYTES: usize = 16224; @@ -399,17 +133,6 @@ pub const PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 48; #[cfg(enable_x86_avx2)] pub const PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_CRYPTO_BYTES: usize = 16224; -pub const PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 128; -pub const PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 64; -pub const PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_CRYPTO_BYTES: usize = 49856; - -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_CRYPTO_SECRETKEYBYTES: usize = 128; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 64; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_CRYPTO_BYTES: usize = 49856; - pub const PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 128; pub const PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 64; pub const PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_CRYPTO_BYTES: usize = 49856; @@ -421,17 +144,6 @@ pub const PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 64; #[cfg(enable_x86_avx2)] pub const PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_CRYPTO_BYTES: usize = 49856; -pub const PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 128; -pub const PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 64; -pub const PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_CRYPTO_BYTES: usize = 29792; - -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_CRYPTO_SECRETKEYBYTES: usize = 128; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 64; -#[cfg(enable_x86_avx2)] -pub const PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_CRYPTO_BYTES: usize = 29792; - pub const PQCLEAN_SPHINCSSHA2256SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 128; pub const PQCLEAN_SPHINCSSHA2256SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 64; pub const PQCLEAN_SPHINCSSHA2256SSIMPLE_CLEAN_CRYPTO_BYTES: usize = 29792; @@ -443,34 +155,34 @@ pub const PQCLEAN_SPHINCSSHA2256SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 64; #[cfg(enable_x86_avx2)] pub const PQCLEAN_SPHINCSSHA2256SSIMPLE_AVX2_CRYPTO_BYTES: usize = 29792; -#[link(name = "sphincs-haraka-128f-robust_clean")] +#[link(name = "sphincs-shake-128f-simple_clean")] extern "C" { - pub fn PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_crypto_sign_keypair( + pub fn PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_crypto_sign( + pub fn PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_crypto_sign_open( + pub fn PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_crypto_sign_signature( + pub fn PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_crypto_sign_verify( + pub fn PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_verify( sig: *const u8, siglen: usize, m: *const u8, @@ -479,40 +191,40 @@ extern "C" { ) -> c_int; } -#[cfg(enable_x86_aes)] -#[link(name = "sphincs-haraka-128f-robust_aesni")] +#[cfg(enable_x86_avx2)] +#[link(name = "sphincs-shake-128f-simple_avx2")] extern "C" { - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_crypto_sign_keypair( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_crypto_sign( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_crypto_sign_open( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_crypto_sign_signature( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_crypto_sign_verify( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_verify( sig: *const u8, siglen: usize, m: *const u8, @@ -521,34 +233,34 @@ extern "C" { ) -> c_int; } -#[link(name = "sphincs-haraka-128f-simple_clean")] +#[link(name = "sphincs-shake-128s-simple_clean")] extern "C" { - pub fn PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_crypto_sign_keypair( + pub fn PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_crypto_sign( + pub fn PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_crypto_sign_open( + pub fn PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_crypto_sign_signature( + pub fn PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_crypto_sign_verify( + pub fn PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_verify( sig: *const u8, siglen: usize, m: *const u8, @@ -557,40 +269,40 @@ extern "C" { ) -> c_int; } -#[cfg(enable_x86_aes)] -#[link(name = "sphincs-haraka-128f-simple_aesni")] +#[cfg(enable_x86_avx2)] +#[link(name = "sphincs-shake-128s-simple_avx2")] extern "C" { - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_crypto_sign_keypair( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_crypto_sign( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_crypto_sign_open( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_crypto_sign_signature( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_crypto_sign_verify( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_verify( sig: *const u8, siglen: usize, m: *const u8, @@ -599,34 +311,34 @@ extern "C" { ) -> c_int; } -#[link(name = "sphincs-haraka-128s-robust_clean")] +#[link(name = "sphincs-shake-192f-simple_clean")] extern "C" { - pub fn PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_crypto_sign_keypair( + pub fn PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_crypto_sign( + pub fn PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_crypto_sign_open( + pub fn PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_crypto_sign_signature( + pub fn PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_crypto_sign_verify( + pub fn PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_verify( sig: *const u8, siglen: usize, m: *const u8, @@ -635,40 +347,40 @@ extern "C" { ) -> c_int; } -#[cfg(enable_x86_aes)] -#[link(name = "sphincs-haraka-128s-robust_aesni")] +#[cfg(enable_x86_avx2)] +#[link(name = "sphincs-shake-192f-simple_avx2")] extern "C" { - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_crypto_sign_keypair( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_crypto_sign( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_crypto_sign_open( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_crypto_sign_signature( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_crypto_sign_verify( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_verify( sig: *const u8, siglen: usize, m: *const u8, @@ -677,34 +389,34 @@ extern "C" { ) -> c_int; } -#[link(name = "sphincs-haraka-128s-simple_clean")] +#[link(name = "sphincs-shake-192s-simple_clean")] extern "C" { - pub fn PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_crypto_sign_keypair( + pub fn PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_crypto_sign( + pub fn PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_crypto_sign_open( + pub fn PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_crypto_sign_signature( + pub fn PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_crypto_sign_verify( + pub fn PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_verify( sig: *const u8, siglen: usize, m: *const u8, @@ -713,40 +425,40 @@ extern "C" { ) -> c_int; } -#[cfg(enable_x86_aes)] -#[link(name = "sphincs-haraka-128s-simple_aesni")] +#[cfg(enable_x86_avx2)] +#[link(name = "sphincs-shake-192s-simple_avx2")] extern "C" { - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_crypto_sign_keypair( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_crypto_sign( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_crypto_sign_open( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_crypto_sign_signature( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_crypto_sign_verify( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_verify( sig: *const u8, siglen: usize, m: *const u8, @@ -755,34 +467,34 @@ extern "C" { ) -> c_int; } -#[link(name = "sphincs-haraka-192f-robust_clean")] +#[link(name = "sphincs-shake-256f-simple_clean")] extern "C" { - pub fn PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_crypto_sign_keypair( + pub fn PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_crypto_sign( + pub fn PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_crypto_sign_open( + pub fn PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_crypto_sign_signature( + pub fn PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_crypto_sign_verify( + pub fn PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_verify( sig: *const u8, siglen: usize, m: *const u8, @@ -791,40 +503,40 @@ extern "C" { ) -> c_int; } -#[cfg(enable_x86_aes)] -#[link(name = "sphincs-haraka-192f-robust_aesni")] +#[cfg(enable_x86_avx2)] +#[link(name = "sphincs-shake-256f-simple_avx2")] extern "C" { - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_crypto_sign_keypair( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_crypto_sign( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_crypto_sign_open( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_crypto_sign_signature( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_crypto_sign_verify( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_verify( sig: *const u8, siglen: usize, m: *const u8, @@ -833,34 +545,34 @@ extern "C" { ) -> c_int; } -#[link(name = "sphincs-haraka-192f-simple_clean")] +#[link(name = "sphincs-shake-256s-simple_clean")] extern "C" { - pub fn PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_crypto_sign_keypair( + pub fn PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_crypto_sign( + pub fn PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_crypto_sign_open( + pub fn PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_crypto_sign_signature( + pub fn PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_crypto_sign_verify( + pub fn PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_verify( sig: *const u8, siglen: usize, m: *const u8, @@ -869,40 +581,40 @@ extern "C" { ) -> c_int; } -#[cfg(enable_x86_aes)] -#[link(name = "sphincs-haraka-192f-simple_aesni")] +#[cfg(enable_x86_avx2)] +#[link(name = "sphincs-shake-256s-simple_avx2")] extern "C" { - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_crypto_sign_keypair( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_crypto_sign( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_crypto_sign_open( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_crypto_sign_signature( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_crypto_sign_verify( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_verify( sig: *const u8, siglen: usize, m: *const u8, @@ -911,34 +623,34 @@ extern "C" { ) -> c_int; } -#[link(name = "sphincs-haraka-192s-robust_clean")] +#[link(name = "sphincs-sha2-128f-simple_clean")] extern "C" { - pub fn PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_crypto_sign_keypair( + pub fn PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_crypto_sign( + pub fn PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_crypto_sign_open( + pub fn PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_crypto_sign_signature( + pub fn PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_crypto_sign_verify( + pub fn PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_verify( sig: *const u8, siglen: usize, m: *const u8, @@ -947,40 +659,40 @@ extern "C" { ) -> c_int; } -#[cfg(enable_x86_aes)] -#[link(name = "sphincs-haraka-192s-robust_aesni")] +#[cfg(enable_x86_avx2)] +#[link(name = "sphincs-sha2-128f-simple_avx2")] extern "C" { - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_crypto_sign_keypair( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_crypto_sign( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_crypto_sign_open( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_crypto_sign_signature( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_crypto_sign_verify( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_verify( sig: *const u8, siglen: usize, m: *const u8, @@ -989,34 +701,34 @@ extern "C" { ) -> c_int; } -#[link(name = "sphincs-haraka-192s-simple_clean")] +#[link(name = "sphincs-sha2-128s-simple_clean")] extern "C" { - pub fn PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_crypto_sign_keypair( + pub fn PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_crypto_sign( + pub fn PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_crypto_sign_open( + pub fn PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_crypto_sign_signature( + pub fn PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_crypto_sign_verify( + pub fn PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_verify( sig: *const u8, siglen: usize, m: *const u8, @@ -1025,40 +737,40 @@ extern "C" { ) -> c_int; } -#[cfg(enable_x86_aes)] -#[link(name = "sphincs-haraka-192s-simple_aesni")] +#[cfg(enable_x86_avx2)] +#[link(name = "sphincs-sha2-128s-simple_avx2")] extern "C" { - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_crypto_sign_keypair( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_crypto_sign( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_crypto_sign_open( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_crypto_sign_signature( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_crypto_sign_verify( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_verify( sig: *const u8, siglen: usize, m: *const u8, @@ -1067,34 +779,34 @@ extern "C" { ) -> c_int; } -#[link(name = "sphincs-haraka-256f-robust_clean")] +#[link(name = "sphincs-sha2-192f-simple_clean")] extern "C" { - pub fn PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_crypto_sign_keypair( + pub fn PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_crypto_sign( + pub fn PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_crypto_sign_open( + pub fn PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_crypto_sign_signature( + pub fn PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_crypto_sign_verify( + pub fn PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_verify( sig: *const u8, siglen: usize, m: *const u8, @@ -1103,40 +815,40 @@ extern "C" { ) -> c_int; } -#[cfg(enable_x86_aes)] -#[link(name = "sphincs-haraka-256f-robust_aesni")] +#[cfg(enable_x86_avx2)] +#[link(name = "sphincs-sha2-192f-simple_avx2")] extern "C" { - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_crypto_sign_keypair( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_crypto_sign( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_crypto_sign_open( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_crypto_sign_signature( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_crypto_sign_verify( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_verify( sig: *const u8, siglen: usize, m: *const u8, @@ -1145,34 +857,34 @@ extern "C" { ) -> c_int; } -#[link(name = "sphincs-haraka-256f-simple_clean")] +#[link(name = "sphincs-sha2-192s-simple_clean")] extern "C" { - pub fn PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_crypto_sign_keypair( + pub fn PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_crypto_sign( + pub fn PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_crypto_sign_open( + pub fn PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_crypto_sign_signature( + pub fn PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_crypto_sign_verify( + pub fn PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_verify( sig: *const u8, siglen: usize, m: *const u8, @@ -1181,40 +893,40 @@ extern "C" { ) -> c_int; } -#[cfg(enable_x86_aes)] -#[link(name = "sphincs-haraka-256f-simple_aesni")] +#[cfg(enable_x86_avx2)] +#[link(name = "sphincs-sha2-192s-simple_avx2")] extern "C" { - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_crypto_sign_keypair( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_crypto_sign( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_crypto_sign_open( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_crypto_sign_signature( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_crypto_sign_verify( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_verify( sig: *const u8, siglen: usize, m: *const u8, @@ -1223,34 +935,34 @@ extern "C" { ) -> c_int; } -#[link(name = "sphincs-haraka-256s-robust_clean")] +#[link(name = "sphincs-sha2-256f-simple_clean")] extern "C" { - pub fn PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_crypto_sign_keypair( + pub fn PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_crypto_sign( + pub fn PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_crypto_sign_open( + pub fn PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_crypto_sign_signature( + pub fn PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_crypto_sign_verify( + pub fn PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_verify( sig: *const u8, siglen: usize, m: *const u8, @@ -1259,7952 +971,128 @@ extern "C" { ) -> c_int; } -#[cfg(enable_x86_aes)] -#[link(name = "sphincs-haraka-256s-robust_aesni")] +#[cfg(enable_x86_avx2)] +#[link(name = "sphincs-sha2-256f-simple_avx2")] extern "C" { - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_crypto_sign_keypair( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_keypair( pk: *mut u8, sk: *mut u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_crypto_sign( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign( sm: *mut u8, smlen: *mut usize, msg: *const u8, len: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_crypto_sign_open( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_open( m: *mut u8, mlen: *mut usize, sm: *const u8, smlen: usize, pk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_crypto_sign_signature( + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_signature( sig: *mut u8, siglen: *mut usize, m: *const u8, mlen: usize, sk: *const u8, ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-haraka-256s-simple_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_aes)] -#[link(name = "sphincs-haraka-256s-simple_aesni")] -extern "C" { - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_aes)] - pub fn PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-shake-128f-robust_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-shake-128f-robust_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-shake-128f-simple_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-shake-128f-simple_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-shake-128s-robust_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-shake-128s-robust_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-shake-128s-simple_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-shake-128s-simple_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-shake-192f-robust_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-shake-192f-robust_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-shake-192f-simple_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-shake-192f-simple_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-shake-192s-robust_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-shake-192s-robust_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-shake-192s-simple_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-shake-192s-simple_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-shake-256f-robust_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-shake-256f-robust_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-shake-256f-simple_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-shake-256f-simple_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-shake-256s-robust_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-shake-256s-robust_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-shake-256s-simple_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-shake-256s-simple_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-sha2-128f-robust_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-sha2-128f-robust_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-sha2-128f-simple_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-sha2-128f-simple_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-sha2-128s-robust_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-sha2-128s-robust_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-sha2-128s-simple_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-sha2-128s-simple_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-sha2-192f-robust_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-sha2-192f-robust_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-sha2-192f-simple_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-sha2-192f-simple_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-sha2-192s-robust_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-sha2-192s-robust_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-sha2-192s-simple_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-sha2-192s-simple_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-sha2-256f-robust_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-sha2-256f-robust_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-sha2-256f-simple_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-sha2-256f-simple_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-sha2-256s-robust_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-sha2-256s-robust_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[link(name = "sphincs-sha2-256s-simple_clean")] -extern "C" { - pub fn PQCLEAN_SPHINCSSHA2256SSIMPLE_CLEAN_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2256SSIMPLE_CLEAN_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2256SSIMPLE_CLEAN_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2256SSIMPLE_CLEAN_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - pub fn PQCLEAN_SPHINCSSHA2256SSIMPLE_CLEAN_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(enable_x86_avx2)] -#[link(name = "sphincs-sha2-256s-simple_avx2")] -extern "C" { - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2256SSIMPLE_AVX2_crypto_sign_keypair( - pk: *mut u8, - sk: *mut u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2256SSIMPLE_AVX2_crypto_sign( - sm: *mut u8, - smlen: *mut usize, - msg: *const u8, - len: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2256SSIMPLE_AVX2_crypto_sign_open( - m: *mut u8, - mlen: *mut usize, - sm: *const u8, - smlen: usize, - pk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2256SSIMPLE_AVX2_crypto_sign_signature( - sig: *mut u8, - siglen: *mut usize, - m: *const u8, - mlen: usize, - sk: *const u8, - ) -> c_int; - #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_SPHINCSSHA2256SSIMPLE_AVX2_crypto_sign_verify( - sig: *const u8, - siglen: usize, - m: *const u8, - mlen: usize, - pk: *const u8, - ) -> c_int; -} - -#[cfg(test)] -mod test_sphincsharaka128frobust_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_aes, feature = "aes"))] -mod test_sphincsharaka128frobust_aesni { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("aes") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsharaka128fsimple_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_aes, feature = "aes"))] -mod test_sphincsharaka128fsimple_aesni { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("aes") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsharaka128srobust_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_aes, feature = "aes"))] -mod test_sphincsharaka128srobust_aesni { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("aes") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsharaka128ssimple_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_aes, feature = "aes"))] -mod test_sphincsharaka128ssimple_aesni { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("aes") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsharaka192frobust_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_aes, feature = "aes"))] -mod test_sphincsharaka192frobust_aesni { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("aes") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsharaka192fsimple_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_aes, feature = "aes"))] -mod test_sphincsharaka192fsimple_aesni { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("aes") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsharaka192srobust_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_aes, feature = "aes"))] -mod test_sphincsharaka192srobust_aesni { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("aes") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsharaka192ssimple_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_aes, feature = "aes"))] -mod test_sphincsharaka192ssimple_aesni { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("aes") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsharaka256frobust_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_aes, feature = "aes"))] -mod test_sphincsharaka256frobust_aesni { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("aes") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsharaka256fsimple_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_aes, feature = "aes"))] -mod test_sphincsharaka256fsimple_aesni { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("aes") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsharaka256srobust_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_aes, feature = "aes"))] -mod test_sphincsharaka256srobust_aesni { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("aes") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsharaka256ssimple_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_aes, feature = "aes"))] -mod test_sphincsharaka256ssimple_aesni { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("aes") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsshake128frobust_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincsshake128frobust_avx2 { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("avx2") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsshake128fsimple_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincsshake128fsimple_avx2 { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("avx2") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsshake128srobust_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincsshake128srobust_avx2 { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("avx2") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsshake128ssimple_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincsshake128ssimple_avx2 { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("avx2") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsshake192frobust_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincsshake192frobust_avx2 { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("avx2") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsshake192fsimple_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincsshake192fsimple_avx2 { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("avx2") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsshake192srobust_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincsshake192srobust_avx2 { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("avx2") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsshake192ssimple_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincsshake192ssimple_avx2 { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("avx2") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsshake256frobust_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincsshake256frobust_avx2 { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("avx2") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsshake256fsimple_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincsshake256fsimple_avx2 { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("avx2") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsshake256srobust_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincsshake256srobust_avx2 { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("avx2") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(test)] -mod test_sphincsshake256ssimple_clean { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - - #[test] - fn test_ffi() { - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); - - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); - - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } -} - -#[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincsshake256ssimple_avx2 { - use super::*; - use alloc::vec; - use alloc::vec::Vec; - use rand::prelude::*; - use std::is_x86_feature_detected; - - #[test] - fn test_ffi() { - if !is_x86_feature_detected!("avx2") { - return; - } - unsafe { - let mut rng = rand::thread_rng(); - let mut mlen: usize = rng.gen::() as usize; - let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_CRYPTO_BYTES]; - let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_CRYPTO_BYTES); - let mut smlen = 0; - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_keypair( - pk.as_mut_ptr(), - sk.as_mut_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign( - sm.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - mlen, - sk.as_ptr() - ) - ); - sm.set_len(smlen); + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_verify( + sig: *const u8, + siglen: usize, + m: *const u8, + mlen: usize, + pk: *const u8, + ) -> c_int; +} - let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_CRYPTO_BYTES); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk.as_ptr() - ) - ); - unpacked_m.set_len(mlen); - assert_eq!(unpacked_m, msg); +#[link(name = "sphincs-sha2-256s-simple_clean")] +extern "C" { + pub fn PQCLEAN_SPHINCSSHA2256SSIMPLE_CLEAN_crypto_sign_keypair( + pk: *mut u8, + sk: *mut u8, + ) -> c_int; + pub fn PQCLEAN_SPHINCSSHA2256SSIMPLE_CLEAN_crypto_sign( + sm: *mut u8, + smlen: *mut usize, + msg: *const u8, + len: usize, + sk: *const u8, + ) -> c_int; + pub fn PQCLEAN_SPHINCSSHA2256SSIMPLE_CLEAN_crypto_sign_open( + m: *mut u8, + mlen: *mut usize, + sm: *const u8, + smlen: usize, + pk: *const u8, + ) -> c_int; + pub fn PQCLEAN_SPHINCSSHA2256SSIMPLE_CLEAN_crypto_sign_signature( + sig: *mut u8, + siglen: *mut usize, + m: *const u8, + mlen: usize, + sk: *const u8, + ) -> c_int; + pub fn PQCLEAN_SPHINCSSHA2256SSIMPLE_CLEAN_crypto_sign_verify( + sig: *const u8, + siglen: usize, + m: *const u8, + mlen: usize, + pk: *const u8, + ) -> c_int; +} - // check verification fails with wrong pk - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_keypair( - pk_alt.as_mut_ptr(), - sk_alt.as_mut_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_open( - unpacked_m.as_mut_ptr(), - &mut mlen as *mut usize, - sm.as_ptr(), - sm.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_signature( - detached_sig.as_mut_ptr(), - &mut smlen as *mut usize, - msg.as_ptr(), - msg.len(), - sk.as_ptr() - ) - ); - assert!( - smlen <= PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_CRYPTO_BYTES, - "Signed message length should be ≤ CRYPTO_BYTES" - ); - assert_eq!( - 0, - PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len(), - pk_alt.as_ptr() - ) - ); - assert_eq!( - -1, - PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_verify( - detached_sig.as_ptr(), - smlen, - msg.as_ptr(), - msg.len() - 1, - pk.as_ptr() - ) - ); - } - } +#[cfg(enable_x86_avx2)] +#[link(name = "sphincs-sha2-256s-simple_avx2")] +extern "C" { + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2256SSIMPLE_AVX2_crypto_sign_keypair( + pk: *mut u8, + sk: *mut u8, + ) -> c_int; + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2256SSIMPLE_AVX2_crypto_sign( + sm: *mut u8, + smlen: *mut usize, + msg: *const u8, + len: usize, + sk: *const u8, + ) -> c_int; + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2256SSIMPLE_AVX2_crypto_sign_open( + m: *mut u8, + mlen: *mut usize, + sm: *const u8, + smlen: usize, + pk: *const u8, + ) -> c_int; + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2256SSIMPLE_AVX2_crypto_sign_signature( + sig: *mut u8, + siglen: *mut usize, + m: *const u8, + mlen: usize, + sk: *const u8, + ) -> c_int; + #[cfg(enable_x86_avx2)] + pub fn PQCLEAN_SPHINCSSHA2256SSIMPLE_AVX2_crypto_sign_verify( + sig: *const u8, + siglen: usize, + m: *const u8, + mlen: usize, + pk: *const u8, + ) -> c_int; } #[cfg(test)] -mod test_sphincssha2128frobust_clean { +mod test_sphincsshake128fsimple_clean { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -9217,24 +1105,24 @@ mod test_sphincssha2128frobust_clean { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_CRYPTO_BYTES]; let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_crypto_sign( + PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -9245,10 +1133,10 @@ mod test_sphincssha2128frobust_clean { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -9262,14 +1150,14 @@ mod test_sphincssha2128frobust_clean { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -9279,7 +1167,7 @@ mod test_sphincssha2128frobust_clean { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_crypto_sign_signature( + PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -9288,12 +1176,12 @@ mod test_sphincssha2128frobust_clean { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -9303,7 +1191,7 @@ mod test_sphincssha2128frobust_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -9313,7 +1201,7 @@ mod test_sphincssha2128frobust_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE128FSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -9326,7 +1214,7 @@ mod test_sphincssha2128frobust_clean { } #[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincssha2128frobust_avx2 { +mod test_sphincsshake128fsimple_avx2 { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -9343,23 +1231,24 @@ mod test_sphincssha2128frobust_avx2 { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_CRYPTO_BYTES]; - let mut sm = Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_CRYPTO_BYTES); + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_CRYPTO_BYTES]; + let mut sm = + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_crypto_sign( + PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -9370,10 +1259,10 @@ mod test_sphincssha2128frobust_avx2 { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -9387,14 +1276,14 @@ mod test_sphincssha2128frobust_avx2 { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -9404,7 +1293,7 @@ mod test_sphincssha2128frobust_avx2 { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_crypto_sign_signature( + PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -9413,12 +1302,12 @@ mod test_sphincssha2128frobust_avx2 { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -9428,7 +1317,7 @@ mod test_sphincssha2128frobust_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -9438,7 +1327,7 @@ mod test_sphincssha2128frobust_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE128FSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -9451,7 +1340,7 @@ mod test_sphincssha2128frobust_avx2 { } #[cfg(test)] -mod test_sphincssha2128fsimple_clean { +mod test_sphincsshake128ssimple_clean { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -9464,24 +1353,24 @@ mod test_sphincssha2128fsimple_clean { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_CRYPTO_BYTES]; let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign( + PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -9492,10 +1381,10 @@ mod test_sphincssha2128fsimple_clean { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -9509,14 +1398,14 @@ mod test_sphincssha2128fsimple_clean { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -9526,7 +1415,7 @@ mod test_sphincssha2128fsimple_clean { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_signature( + PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -9535,12 +1424,12 @@ mod test_sphincssha2128fsimple_clean { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -9550,7 +1439,7 @@ mod test_sphincssha2128fsimple_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -9560,7 +1449,7 @@ mod test_sphincssha2128fsimple_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE128SSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -9573,7 +1462,7 @@ mod test_sphincssha2128fsimple_clean { } #[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincssha2128fsimple_avx2 { +mod test_sphincsshake128ssimple_avx2 { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -9590,23 +1479,24 @@ mod test_sphincssha2128fsimple_avx2 { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_CRYPTO_BYTES]; - let mut sm = Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_CRYPTO_BYTES); + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_CRYPTO_BYTES]; + let mut sm = + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign( + PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -9617,10 +1507,10 @@ mod test_sphincssha2128fsimple_avx2 { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -9634,14 +1524,14 @@ mod test_sphincssha2128fsimple_avx2 { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -9651,7 +1541,7 @@ mod test_sphincssha2128fsimple_avx2 { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_signature( + PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -9660,12 +1550,12 @@ mod test_sphincssha2128fsimple_avx2 { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -9675,7 +1565,7 @@ mod test_sphincssha2128fsimple_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -9685,7 +1575,7 @@ mod test_sphincssha2128fsimple_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE128SSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -9698,7 +1588,7 @@ mod test_sphincssha2128fsimple_avx2 { } #[cfg(test)] -mod test_sphincssha2128srobust_clean { +mod test_sphincsshake192fsimple_clean { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -9711,24 +1601,24 @@ mod test_sphincssha2128srobust_clean { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_CRYPTO_BYTES]; let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_crypto_sign( + PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -9739,10 +1629,10 @@ mod test_sphincssha2128srobust_clean { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -9756,14 +1646,14 @@ mod test_sphincssha2128srobust_clean { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -9773,7 +1663,7 @@ mod test_sphincssha2128srobust_clean { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_crypto_sign_signature( + PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -9782,12 +1672,12 @@ mod test_sphincssha2128srobust_clean { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -9797,7 +1687,7 @@ mod test_sphincssha2128srobust_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -9807,7 +1697,7 @@ mod test_sphincssha2128srobust_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE192FSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -9820,7 +1710,7 @@ mod test_sphincssha2128srobust_clean { } #[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincssha2128srobust_avx2 { +mod test_sphincsshake192fsimple_avx2 { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -9837,23 +1727,24 @@ mod test_sphincssha2128srobust_avx2 { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_CRYPTO_BYTES]; - let mut sm = Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_CRYPTO_BYTES); + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_CRYPTO_BYTES]; + let mut sm = + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_crypto_sign( + PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -9864,10 +1755,10 @@ mod test_sphincssha2128srobust_avx2 { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -9881,14 +1772,14 @@ mod test_sphincssha2128srobust_avx2 { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -9898,7 +1789,7 @@ mod test_sphincssha2128srobust_avx2 { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_crypto_sign_signature( + PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -9907,12 +1798,12 @@ mod test_sphincssha2128srobust_avx2 { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -9922,7 +1813,7 @@ mod test_sphincssha2128srobust_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -9932,7 +1823,7 @@ mod test_sphincssha2128srobust_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE192FSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -9945,7 +1836,7 @@ mod test_sphincssha2128srobust_avx2 { } #[cfg(test)] -mod test_sphincssha2128ssimple_clean { +mod test_sphincsshake192ssimple_clean { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -9958,24 +1849,24 @@ mod test_sphincssha2128ssimple_clean { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_CRYPTO_BYTES]; let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign( + PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -9986,10 +1877,10 @@ mod test_sphincssha2128ssimple_clean { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -10003,14 +1894,14 @@ mod test_sphincssha2128ssimple_clean { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -10020,7 +1911,7 @@ mod test_sphincssha2128ssimple_clean { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_signature( + PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -10029,12 +1920,12 @@ mod test_sphincssha2128ssimple_clean { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10044,7 +1935,7 @@ mod test_sphincssha2128ssimple_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10054,7 +1945,7 @@ mod test_sphincssha2128ssimple_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE192SSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10067,7 +1958,7 @@ mod test_sphincssha2128ssimple_clean { } #[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincssha2128ssimple_avx2 { +mod test_sphincsshake192ssimple_avx2 { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -10084,23 +1975,24 @@ mod test_sphincssha2128ssimple_avx2 { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_CRYPTO_BYTES]; - let mut sm = Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_CRYPTO_BYTES); + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_CRYPTO_BYTES]; + let mut sm = + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign( + PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -10111,10 +2003,10 @@ mod test_sphincssha2128ssimple_avx2 { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -10128,14 +2020,14 @@ mod test_sphincssha2128ssimple_avx2 { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -10145,7 +2037,7 @@ mod test_sphincssha2128ssimple_avx2 { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_signature( + PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -10154,12 +2046,12 @@ mod test_sphincssha2128ssimple_avx2 { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10169,7 +2061,7 @@ mod test_sphincssha2128ssimple_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10179,7 +2071,7 @@ mod test_sphincssha2128ssimple_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE192SSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10192,7 +2084,7 @@ mod test_sphincssha2128ssimple_avx2 { } #[cfg(test)] -mod test_sphincssha2192frobust_clean { +mod test_sphincsshake256fsimple_clean { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -10205,24 +2097,24 @@ mod test_sphincssha2192frobust_clean { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_CRYPTO_BYTES]; let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_crypto_sign( + PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -10233,10 +2125,10 @@ mod test_sphincssha2192frobust_clean { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -10250,14 +2142,14 @@ mod test_sphincssha2192frobust_clean { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -10267,7 +2159,7 @@ mod test_sphincssha2192frobust_clean { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_crypto_sign_signature( + PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -10276,12 +2168,12 @@ mod test_sphincssha2192frobust_clean { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10291,7 +2183,7 @@ mod test_sphincssha2192frobust_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10301,7 +2193,7 @@ mod test_sphincssha2192frobust_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE256FSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10314,7 +2206,7 @@ mod test_sphincssha2192frobust_clean { } #[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincssha2192frobust_avx2 { +mod test_sphincsshake256fsimple_avx2 { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -10331,23 +2223,24 @@ mod test_sphincssha2192frobust_avx2 { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_CRYPTO_BYTES]; - let mut sm = Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_CRYPTO_BYTES); + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_CRYPTO_BYTES]; + let mut sm = + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_crypto_sign( + PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -10358,10 +2251,10 @@ mod test_sphincssha2192frobust_avx2 { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -10375,14 +2268,14 @@ mod test_sphincssha2192frobust_avx2 { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -10392,7 +2285,7 @@ mod test_sphincssha2192frobust_avx2 { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_crypto_sign_signature( + PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -10401,12 +2294,12 @@ mod test_sphincssha2192frobust_avx2 { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10416,7 +2309,7 @@ mod test_sphincssha2192frobust_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10426,7 +2319,7 @@ mod test_sphincssha2192frobust_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE256FSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10439,7 +2332,7 @@ mod test_sphincssha2192frobust_avx2 { } #[cfg(test)] -mod test_sphincssha2192fsimple_clean { +mod test_sphincsshake256ssimple_clean { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -10452,24 +2345,24 @@ mod test_sphincssha2192fsimple_clean { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_CRYPTO_BYTES]; let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign( + PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -10480,10 +2373,10 @@ mod test_sphincssha2192fsimple_clean { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -10497,14 +2390,14 @@ mod test_sphincssha2192fsimple_clean { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -10514,7 +2407,7 @@ mod test_sphincssha2192fsimple_clean { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_signature( + PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -10523,12 +2416,12 @@ mod test_sphincssha2192fsimple_clean { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10538,7 +2431,7 @@ mod test_sphincssha2192fsimple_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10548,7 +2441,7 @@ mod test_sphincssha2192fsimple_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE256SSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10561,7 +2454,7 @@ mod test_sphincssha2192fsimple_clean { } #[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincssha2192fsimple_avx2 { +mod test_sphincsshake256ssimple_avx2 { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -10578,23 +2471,24 @@ mod test_sphincssha2192fsimple_avx2 { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_CRYPTO_BYTES]; - let mut sm = Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_CRYPTO_BYTES); + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_CRYPTO_BYTES]; + let mut sm = + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign( + PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -10605,10 +2499,10 @@ mod test_sphincssha2192fsimple_avx2 { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -10622,14 +2516,14 @@ mod test_sphincssha2192fsimple_avx2 { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -10639,7 +2533,7 @@ mod test_sphincssha2192fsimple_avx2 { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_signature( + PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -10648,12 +2542,12 @@ mod test_sphincssha2192fsimple_avx2 { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10663,7 +2557,7 @@ mod test_sphincssha2192fsimple_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10673,7 +2567,7 @@ mod test_sphincssha2192fsimple_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHAKE256SSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10686,7 +2580,7 @@ mod test_sphincssha2192fsimple_avx2 { } #[cfg(test)] -mod test_sphincssha2192srobust_clean { +mod test_sphincssha2128fsimple_clean { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -10699,24 +2593,24 @@ mod test_sphincssha2192srobust_clean { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_CRYPTO_BYTES]; let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_crypto_sign( + PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -10727,10 +2621,10 @@ mod test_sphincssha2192srobust_clean { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -10744,14 +2638,14 @@ mod test_sphincssha2192srobust_clean { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -10761,7 +2655,7 @@ mod test_sphincssha2192srobust_clean { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_crypto_sign_signature( + PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -10770,12 +2664,12 @@ mod test_sphincssha2192srobust_clean { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10785,7 +2679,7 @@ mod test_sphincssha2192srobust_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10795,7 +2689,7 @@ mod test_sphincssha2192srobust_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2128FSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10808,7 +2702,7 @@ mod test_sphincssha2192srobust_clean { } #[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincssha2192srobust_avx2 { +mod test_sphincssha2128fsimple_avx2 { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -10825,23 +2719,23 @@ mod test_sphincssha2192srobust_avx2 { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_CRYPTO_BYTES]; - let mut sm = Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_CRYPTO_BYTES); + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_CRYPTO_BYTES]; + let mut sm = Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_crypto_sign( + PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -10852,10 +2746,10 @@ mod test_sphincssha2192srobust_avx2 { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -10869,14 +2763,14 @@ mod test_sphincssha2192srobust_avx2 { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -10886,7 +2780,7 @@ mod test_sphincssha2192srobust_avx2 { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_crypto_sign_signature( + PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -10895,12 +2789,12 @@ mod test_sphincssha2192srobust_avx2 { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10910,7 +2804,7 @@ mod test_sphincssha2192srobust_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10920,7 +2814,7 @@ mod test_sphincssha2192srobust_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2128FSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -10933,7 +2827,7 @@ mod test_sphincssha2192srobust_avx2 { } #[cfg(test)] -mod test_sphincssha2192ssimple_clean { +mod test_sphincssha2128ssimple_clean { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -10946,24 +2840,24 @@ mod test_sphincssha2192ssimple_clean { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_CRYPTO_BYTES]; let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign( + PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -10974,10 +2868,10 @@ mod test_sphincssha2192ssimple_clean { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -10991,14 +2885,14 @@ mod test_sphincssha2192ssimple_clean { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -11008,7 +2902,7 @@ mod test_sphincssha2192ssimple_clean { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_signature( + PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -11017,12 +2911,12 @@ mod test_sphincssha2192ssimple_clean { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11032,7 +2926,7 @@ mod test_sphincssha2192ssimple_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11042,7 +2936,7 @@ mod test_sphincssha2192ssimple_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2128SSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11055,7 +2949,7 @@ mod test_sphincssha2192ssimple_clean { } #[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincssha2192ssimple_avx2 { +mod test_sphincssha2128ssimple_avx2 { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -11072,23 +2966,23 @@ mod test_sphincssha2192ssimple_avx2 { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_CRYPTO_BYTES]; - let mut sm = Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_CRYPTO_BYTES); + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_CRYPTO_BYTES]; + let mut sm = Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign( + PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -11099,10 +2993,10 @@ mod test_sphincssha2192ssimple_avx2 { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -11116,14 +3010,14 @@ mod test_sphincssha2192ssimple_avx2 { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -11133,7 +3027,7 @@ mod test_sphincssha2192ssimple_avx2 { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_signature( + PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -11142,12 +3036,12 @@ mod test_sphincssha2192ssimple_avx2 { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11157,7 +3051,7 @@ mod test_sphincssha2192ssimple_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11167,7 +3061,7 @@ mod test_sphincssha2192ssimple_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2128SSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11180,7 +3074,7 @@ mod test_sphincssha2192ssimple_avx2 { } #[cfg(test)] -mod test_sphincssha2256frobust_clean { +mod test_sphincssha2192fsimple_clean { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -11193,24 +3087,24 @@ mod test_sphincssha2256frobust_clean { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_CRYPTO_BYTES]; let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_crypto_sign( + PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -11221,10 +3115,10 @@ mod test_sphincssha2256frobust_clean { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -11238,14 +3132,14 @@ mod test_sphincssha2256frobust_clean { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -11255,7 +3149,7 @@ mod test_sphincssha2256frobust_clean { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_crypto_sign_signature( + PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -11264,12 +3158,12 @@ mod test_sphincssha2256frobust_clean { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11279,7 +3173,7 @@ mod test_sphincssha2256frobust_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11289,7 +3183,7 @@ mod test_sphincssha2256frobust_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2192FSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11302,7 +3196,7 @@ mod test_sphincssha2256frobust_clean { } #[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincssha2256frobust_avx2 { +mod test_sphincssha2192fsimple_avx2 { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -11319,23 +3213,23 @@ mod test_sphincssha2256frobust_avx2 { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_CRYPTO_BYTES]; - let mut sm = Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_CRYPTO_BYTES); + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_CRYPTO_BYTES]; + let mut sm = Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_crypto_sign( + PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -11346,10 +3240,10 @@ mod test_sphincssha2256frobust_avx2 { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -11363,14 +3257,14 @@ mod test_sphincssha2256frobust_avx2 { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -11380,7 +3274,7 @@ mod test_sphincssha2256frobust_avx2 { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_crypto_sign_signature( + PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -11389,12 +3283,12 @@ mod test_sphincssha2256frobust_avx2 { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11404,7 +3298,7 @@ mod test_sphincssha2256frobust_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11414,7 +3308,7 @@ mod test_sphincssha2256frobust_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2192FSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11427,7 +3321,7 @@ mod test_sphincssha2256frobust_avx2 { } #[cfg(test)] -mod test_sphincssha2256fsimple_clean { +mod test_sphincssha2192ssimple_clean { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -11440,24 +3334,24 @@ mod test_sphincssha2256fsimple_clean { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_CRYPTO_BYTES]; let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign( + PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -11468,10 +3362,10 @@ mod test_sphincssha2256fsimple_clean { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -11485,14 +3379,14 @@ mod test_sphincssha2256fsimple_clean { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -11502,7 +3396,7 @@ mod test_sphincssha2256fsimple_clean { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_signature( + PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -11511,12 +3405,12 @@ mod test_sphincssha2256fsimple_clean { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11526,7 +3420,7 @@ mod test_sphincssha2256fsimple_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11536,7 +3430,7 @@ mod test_sphincssha2256fsimple_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2192SSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11549,7 +3443,7 @@ mod test_sphincssha2256fsimple_clean { } #[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincssha2256fsimple_avx2 { +mod test_sphincssha2192ssimple_avx2 { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -11566,23 +3460,23 @@ mod test_sphincssha2256fsimple_avx2 { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_CRYPTO_BYTES]; - let mut sm = Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_CRYPTO_BYTES); + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_CRYPTO_BYTES]; + let mut sm = Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign( + PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -11593,10 +3487,10 @@ mod test_sphincssha2256fsimple_avx2 { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -11610,14 +3504,14 @@ mod test_sphincssha2256fsimple_avx2 { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -11627,7 +3521,7 @@ mod test_sphincssha2256fsimple_avx2 { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_signature( + PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -11636,12 +3530,12 @@ mod test_sphincssha2256fsimple_avx2 { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11651,7 +3545,7 @@ mod test_sphincssha2256fsimple_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11661,7 +3555,7 @@ mod test_sphincssha2256fsimple_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2192SSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11674,7 +3568,7 @@ mod test_sphincssha2256fsimple_avx2 { } #[cfg(test)] -mod test_sphincssha2256srobust_clean { +mod test_sphincssha2256fsimple_clean { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -11687,24 +3581,24 @@ mod test_sphincssha2256srobust_clean { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_CRYPTO_BYTES]; let mut sm = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_crypto_sign( + PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -11715,10 +3609,10 @@ mod test_sphincssha2256srobust_clean { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -11732,14 +3626,14 @@ mod test_sphincssha2256srobust_clean { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_crypto_sign_keypair( + PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_crypto_sign_open( + PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -11749,7 +3643,7 @@ mod test_sphincssha2256srobust_clean { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_crypto_sign_signature( + PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -11758,12 +3652,12 @@ mod test_sphincssha2256srobust_clean { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11773,7 +3667,7 @@ mod test_sphincssha2256srobust_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11783,7 +3677,7 @@ mod test_sphincssha2256srobust_clean { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2256FSIMPLE_CLEAN_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11796,7 +3690,7 @@ mod test_sphincssha2256srobust_clean { } #[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_sphincssha2256srobust_avx2 { +mod test_sphincssha2256fsimple_avx2 { use super::*; use alloc::vec; use alloc::vec::Vec; @@ -11813,23 +3707,23 @@ mod test_sphincssha2256srobust_avx2 { let mut mlen: usize = rng.gen::() as usize; let msg: Vec = (0..mlen).map(|_| rng.gen()).collect(); - let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_CRYPTO_PUBLICKEYBYTES]; - let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_CRYPTO_SECRETKEYBYTES]; - let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_CRYPTO_BYTES]; - let mut sm = Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_CRYPTO_BYTES); + let mut pk = vec![0u8; PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut pk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk_alt = vec![0u8; PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut detached_sig = vec![0u8; PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_CRYPTO_BYTES]; + let mut sm = Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_CRYPTO_BYTES); let mut smlen = 0; assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_keypair( pk.as_mut_ptr(), sk.as_mut_ptr() ) ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_crypto_sign( + PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign( sm.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -11840,10 +3734,10 @@ mod test_sphincssha2256srobust_avx2 { sm.set_len(smlen); let mut unpacked_m = - Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_CRYPTO_BYTES); + Vec::with_capacity(mlen + PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_CRYPTO_BYTES); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -11857,14 +3751,14 @@ mod test_sphincssha2256srobust_avx2 { // check verification fails with wrong pk assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_crypto_sign_keypair( + PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_keypair( pk_alt.as_mut_ptr(), sk_alt.as_mut_ptr() ) ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_crypto_sign_open( + PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_open( unpacked_m.as_mut_ptr(), &mut mlen as *mut usize, sm.as_ptr(), @@ -11874,7 +3768,7 @@ mod test_sphincssha2256srobust_avx2 { ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_crypto_sign_signature( + PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_signature( detached_sig.as_mut_ptr(), &mut smlen as *mut usize, msg.as_ptr(), @@ -11883,12 +3777,12 @@ mod test_sphincssha2256srobust_avx2 { ) ); assert!( - smlen <= PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_CRYPTO_BYTES, + smlen <= PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_CRYPTO_BYTES, "Signed message length should be ≤ CRYPTO_BYTES" ); assert_eq!( 0, - PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11898,7 +3792,7 @@ mod test_sphincssha2256srobust_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), @@ -11908,7 +3802,7 @@ mod test_sphincssha2256srobust_avx2 { ); assert_eq!( -1, - PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_crypto_sign_verify( + PQCLEAN_SPHINCSSHA2256FSIMPLE_AVX2_crypto_sign_verify( detached_sig.as_ptr(), smlen, msg.as_ptr(), diff --git a/pqcrypto-sphincsplus/src/lib.rs b/pqcrypto-sphincsplus/src/lib.rs index 900b20ef..3ff1daec 100644 --- a/pqcrypto-sphincsplus/src/lib.rs +++ b/pqcrypto-sphincsplus/src/lib.rs @@ -3,41 +3,17 @@ //! This crate provides bindings to and wrappers around the following //! implementations from [PQClean][pqc]: //! -//! * sphincs-haraka-128f-robust - clean -//! * sphincs-haraka-128f-simple - clean -//! * sphincs-haraka-128s-robust - clean -//! * sphincs-haraka-128s-simple - clean -//! * sphincs-haraka-192f-robust - clean -//! * sphincs-haraka-192f-simple - clean -//! * sphincs-haraka-192s-robust - clean -//! * sphincs-haraka-192s-simple - clean -//! * sphincs-haraka-256f-robust - clean -//! * sphincs-haraka-256f-simple - clean -//! * sphincs-haraka-256s-robust - clean -//! * sphincs-haraka-256s-simple - clean -//! * sphincs-shake-128f-robust - clean //! * sphincs-shake-128f-simple - clean -//! * sphincs-shake-128s-robust - clean //! * sphincs-shake-128s-simple - clean -//! * sphincs-shake-192f-robust - clean //! * sphincs-shake-192f-simple - clean -//! * sphincs-shake-192s-robust - clean //! * sphincs-shake-192s-simple - clean -//! * sphincs-shake-256f-robust - clean //! * sphincs-shake-256f-simple - clean -//! * sphincs-shake-256s-robust - clean //! * sphincs-shake-256s-simple - clean -//! * sphincs-sha2-128f-robust - clean //! * sphincs-sha2-128f-simple - clean -//! * sphincs-sha2-128s-robust - clean //! * sphincs-sha2-128s-simple - clean -//! * sphincs-sha2-192f-robust - clean //! * sphincs-sha2-192f-simple - clean -//! * sphincs-sha2-192s-robust - clean //! * sphincs-sha2-192s-simple - clean -//! * sphincs-sha2-256f-robust - clean //! * sphincs-sha2-256f-simple - clean -//! * sphincs-sha2-256s-robust - clean //! * sphincs-sha2-256s-simple - clean //! //! [pqc]: https://github.com/pqclean/pqclean/ @@ -54,158 +30,19 @@ extern crate alloc; extern crate std; pub mod ffi; -pub mod sphincsharaka128frobust; -pub mod sphincsharaka128fsimple; -pub mod sphincsharaka128srobust; -pub mod sphincsharaka128ssimple; -pub mod sphincsharaka192frobust; -pub mod sphincsharaka192fsimple; -pub mod sphincsharaka192srobust; -pub mod sphincsharaka192ssimple; -pub mod sphincsharaka256frobust; -pub mod sphincsharaka256fsimple; -pub mod sphincsharaka256srobust; -pub mod sphincsharaka256ssimple; -pub mod sphincssha2128frobust; pub mod sphincssha2128fsimple; -pub mod sphincssha2128srobust; pub mod sphincssha2128ssimple; -pub mod sphincssha2192frobust; pub mod sphincssha2192fsimple; -pub mod sphincssha2192srobust; pub mod sphincssha2192ssimple; -pub mod sphincssha2256frobust; pub mod sphincssha2256fsimple; -pub mod sphincssha2256srobust; pub mod sphincssha2256ssimple; -pub mod sphincsshake128frobust; pub mod sphincsshake128fsimple; -pub mod sphincsshake128srobust; pub mod sphincsshake128ssimple; -pub mod sphincsshake192frobust; pub mod sphincsshake192fsimple; -pub mod sphincsshake192srobust; pub mod sphincsshake192ssimple; -pub mod sphincsshake256frobust; pub mod sphincsshake256fsimple; -pub mod sphincsshake256srobust; pub mod sphincsshake256ssimple; -pub use crate::sphincsharaka128frobust::{ - detached_sign as sphincsharaka128frobust_detached_sign, - keypair as sphincsharaka128frobust_keypair, open as sphincsharaka128frobust_open, - public_key_bytes as sphincsharaka128frobust_public_key_bytes, - secret_key_bytes as sphincsharaka128frobust_secret_key_bytes, - sign as sphincsharaka128frobust_sign, - signature_bytes as sphincsharaka128frobust_signature_bytes, - verify_detached_signature as sphincsharaka128frobust_verify_detached_signature, -}; -pub use crate::sphincsharaka128fsimple::{ - detached_sign as sphincsharaka128fsimple_detached_sign, - keypair as sphincsharaka128fsimple_keypair, open as sphincsharaka128fsimple_open, - public_key_bytes as sphincsharaka128fsimple_public_key_bytes, - secret_key_bytes as sphincsharaka128fsimple_secret_key_bytes, - sign as sphincsharaka128fsimple_sign, - signature_bytes as sphincsharaka128fsimple_signature_bytes, - verify_detached_signature as sphincsharaka128fsimple_verify_detached_signature, -}; -pub use crate::sphincsharaka128srobust::{ - detached_sign as sphincsharaka128srobust_detached_sign, - keypair as sphincsharaka128srobust_keypair, open as sphincsharaka128srobust_open, - public_key_bytes as sphincsharaka128srobust_public_key_bytes, - secret_key_bytes as sphincsharaka128srobust_secret_key_bytes, - sign as sphincsharaka128srobust_sign, - signature_bytes as sphincsharaka128srobust_signature_bytes, - verify_detached_signature as sphincsharaka128srobust_verify_detached_signature, -}; -pub use crate::sphincsharaka128ssimple::{ - detached_sign as sphincsharaka128ssimple_detached_sign, - keypair as sphincsharaka128ssimple_keypair, open as sphincsharaka128ssimple_open, - public_key_bytes as sphincsharaka128ssimple_public_key_bytes, - secret_key_bytes as sphincsharaka128ssimple_secret_key_bytes, - sign as sphincsharaka128ssimple_sign, - signature_bytes as sphincsharaka128ssimple_signature_bytes, - verify_detached_signature as sphincsharaka128ssimple_verify_detached_signature, -}; -pub use crate::sphincsharaka192frobust::{ - detached_sign as sphincsharaka192frobust_detached_sign, - keypair as sphincsharaka192frobust_keypair, open as sphincsharaka192frobust_open, - public_key_bytes as sphincsharaka192frobust_public_key_bytes, - secret_key_bytes as sphincsharaka192frobust_secret_key_bytes, - sign as sphincsharaka192frobust_sign, - signature_bytes as sphincsharaka192frobust_signature_bytes, - verify_detached_signature as sphincsharaka192frobust_verify_detached_signature, -}; -pub use crate::sphincsharaka192fsimple::{ - detached_sign as sphincsharaka192fsimple_detached_sign, - keypair as sphincsharaka192fsimple_keypair, open as sphincsharaka192fsimple_open, - public_key_bytes as sphincsharaka192fsimple_public_key_bytes, - secret_key_bytes as sphincsharaka192fsimple_secret_key_bytes, - sign as sphincsharaka192fsimple_sign, - signature_bytes as sphincsharaka192fsimple_signature_bytes, - verify_detached_signature as sphincsharaka192fsimple_verify_detached_signature, -}; -pub use crate::sphincsharaka192srobust::{ - detached_sign as sphincsharaka192srobust_detached_sign, - keypair as sphincsharaka192srobust_keypair, open as sphincsharaka192srobust_open, - public_key_bytes as sphincsharaka192srobust_public_key_bytes, - secret_key_bytes as sphincsharaka192srobust_secret_key_bytes, - sign as sphincsharaka192srobust_sign, - signature_bytes as sphincsharaka192srobust_signature_bytes, - verify_detached_signature as sphincsharaka192srobust_verify_detached_signature, -}; -pub use crate::sphincsharaka192ssimple::{ - detached_sign as sphincsharaka192ssimple_detached_sign, - keypair as sphincsharaka192ssimple_keypair, open as sphincsharaka192ssimple_open, - public_key_bytes as sphincsharaka192ssimple_public_key_bytes, - secret_key_bytes as sphincsharaka192ssimple_secret_key_bytes, - sign as sphincsharaka192ssimple_sign, - signature_bytes as sphincsharaka192ssimple_signature_bytes, - verify_detached_signature as sphincsharaka192ssimple_verify_detached_signature, -}; -pub use crate::sphincsharaka256frobust::{ - detached_sign as sphincsharaka256frobust_detached_sign, - keypair as sphincsharaka256frobust_keypair, open as sphincsharaka256frobust_open, - public_key_bytes as sphincsharaka256frobust_public_key_bytes, - secret_key_bytes as sphincsharaka256frobust_secret_key_bytes, - sign as sphincsharaka256frobust_sign, - signature_bytes as sphincsharaka256frobust_signature_bytes, - verify_detached_signature as sphincsharaka256frobust_verify_detached_signature, -}; -pub use crate::sphincsharaka256fsimple::{ - detached_sign as sphincsharaka256fsimple_detached_sign, - keypair as sphincsharaka256fsimple_keypair, open as sphincsharaka256fsimple_open, - public_key_bytes as sphincsharaka256fsimple_public_key_bytes, - secret_key_bytes as sphincsharaka256fsimple_secret_key_bytes, - sign as sphincsharaka256fsimple_sign, - signature_bytes as sphincsharaka256fsimple_signature_bytes, - verify_detached_signature as sphincsharaka256fsimple_verify_detached_signature, -}; -pub use crate::sphincsharaka256srobust::{ - detached_sign as sphincsharaka256srobust_detached_sign, - keypair as sphincsharaka256srobust_keypair, open as sphincsharaka256srobust_open, - public_key_bytes as sphincsharaka256srobust_public_key_bytes, - secret_key_bytes as sphincsharaka256srobust_secret_key_bytes, - sign as sphincsharaka256srobust_sign, - signature_bytes as sphincsharaka256srobust_signature_bytes, - verify_detached_signature as sphincsharaka256srobust_verify_detached_signature, -}; -pub use crate::sphincsharaka256ssimple::{ - detached_sign as sphincsharaka256ssimple_detached_sign, - keypair as sphincsharaka256ssimple_keypair, open as sphincsharaka256ssimple_open, - public_key_bytes as sphincsharaka256ssimple_public_key_bytes, - secret_key_bytes as sphincsharaka256ssimple_secret_key_bytes, - sign as sphincsharaka256ssimple_sign, - signature_bytes as sphincsharaka256ssimple_signature_bytes, - verify_detached_signature as sphincsharaka256ssimple_verify_detached_signature, -}; -pub use crate::sphincssha2128frobust::{ - detached_sign as sphincssha2128frobust_detached_sign, keypair as sphincssha2128frobust_keypair, - open as sphincssha2128frobust_open, public_key_bytes as sphincssha2128frobust_public_key_bytes, - secret_key_bytes as sphincssha2128frobust_secret_key_bytes, sign as sphincssha2128frobust_sign, - signature_bytes as sphincssha2128frobust_signature_bytes, - verify_detached_signature as sphincssha2128frobust_verify_detached_signature, -}; pub use crate::sphincssha2128fsimple::{ detached_sign as sphincssha2128fsimple_detached_sign, keypair as sphincssha2128fsimple_keypair, open as sphincssha2128fsimple_open, public_key_bytes as sphincssha2128fsimple_public_key_bytes, @@ -213,13 +50,6 @@ pub use crate::sphincssha2128fsimple::{ signature_bytes as sphincssha2128fsimple_signature_bytes, verify_detached_signature as sphincssha2128fsimple_verify_detached_signature, }; -pub use crate::sphincssha2128srobust::{ - detached_sign as sphincssha2128srobust_detached_sign, keypair as sphincssha2128srobust_keypair, - open as sphincssha2128srobust_open, public_key_bytes as sphincssha2128srobust_public_key_bytes, - secret_key_bytes as sphincssha2128srobust_secret_key_bytes, sign as sphincssha2128srobust_sign, - signature_bytes as sphincssha2128srobust_signature_bytes, - verify_detached_signature as sphincssha2128srobust_verify_detached_signature, -}; pub use crate::sphincssha2128ssimple::{ detached_sign as sphincssha2128ssimple_detached_sign, keypair as sphincssha2128ssimple_keypair, open as sphincssha2128ssimple_open, public_key_bytes as sphincssha2128ssimple_public_key_bytes, @@ -227,13 +57,6 @@ pub use crate::sphincssha2128ssimple::{ signature_bytes as sphincssha2128ssimple_signature_bytes, verify_detached_signature as sphincssha2128ssimple_verify_detached_signature, }; -pub use crate::sphincssha2192frobust::{ - detached_sign as sphincssha2192frobust_detached_sign, keypair as sphincssha2192frobust_keypair, - open as sphincssha2192frobust_open, public_key_bytes as sphincssha2192frobust_public_key_bytes, - secret_key_bytes as sphincssha2192frobust_secret_key_bytes, sign as sphincssha2192frobust_sign, - signature_bytes as sphincssha2192frobust_signature_bytes, - verify_detached_signature as sphincssha2192frobust_verify_detached_signature, -}; pub use crate::sphincssha2192fsimple::{ detached_sign as sphincssha2192fsimple_detached_sign, keypair as sphincssha2192fsimple_keypair, open as sphincssha2192fsimple_open, public_key_bytes as sphincssha2192fsimple_public_key_bytes, @@ -241,13 +64,6 @@ pub use crate::sphincssha2192fsimple::{ signature_bytes as sphincssha2192fsimple_signature_bytes, verify_detached_signature as sphincssha2192fsimple_verify_detached_signature, }; -pub use crate::sphincssha2192srobust::{ - detached_sign as sphincssha2192srobust_detached_sign, keypair as sphincssha2192srobust_keypair, - open as sphincssha2192srobust_open, public_key_bytes as sphincssha2192srobust_public_key_bytes, - secret_key_bytes as sphincssha2192srobust_secret_key_bytes, sign as sphincssha2192srobust_sign, - signature_bytes as sphincssha2192srobust_signature_bytes, - verify_detached_signature as sphincssha2192srobust_verify_detached_signature, -}; pub use crate::sphincssha2192ssimple::{ detached_sign as sphincssha2192ssimple_detached_sign, keypair as sphincssha2192ssimple_keypair, open as sphincssha2192ssimple_open, public_key_bytes as sphincssha2192ssimple_public_key_bytes, @@ -255,13 +71,6 @@ pub use crate::sphincssha2192ssimple::{ signature_bytes as sphincssha2192ssimple_signature_bytes, verify_detached_signature as sphincssha2192ssimple_verify_detached_signature, }; -pub use crate::sphincssha2256frobust::{ - detached_sign as sphincssha2256frobust_detached_sign, keypair as sphincssha2256frobust_keypair, - open as sphincssha2256frobust_open, public_key_bytes as sphincssha2256frobust_public_key_bytes, - secret_key_bytes as sphincssha2256frobust_secret_key_bytes, sign as sphincssha2256frobust_sign, - signature_bytes as sphincssha2256frobust_signature_bytes, - verify_detached_signature as sphincssha2256frobust_verify_detached_signature, -}; pub use crate::sphincssha2256fsimple::{ detached_sign as sphincssha2256fsimple_detached_sign, keypair as sphincssha2256fsimple_keypair, open as sphincssha2256fsimple_open, public_key_bytes as sphincssha2256fsimple_public_key_bytes, @@ -269,13 +78,6 @@ pub use crate::sphincssha2256fsimple::{ signature_bytes as sphincssha2256fsimple_signature_bytes, verify_detached_signature as sphincssha2256fsimple_verify_detached_signature, }; -pub use crate::sphincssha2256srobust::{ - detached_sign as sphincssha2256srobust_detached_sign, keypair as sphincssha2256srobust_keypair, - open as sphincssha2256srobust_open, public_key_bytes as sphincssha2256srobust_public_key_bytes, - secret_key_bytes as sphincssha2256srobust_secret_key_bytes, sign as sphincssha2256srobust_sign, - signature_bytes as sphincssha2256srobust_signature_bytes, - verify_detached_signature as sphincssha2256srobust_verify_detached_signature, -}; pub use crate::sphincssha2256ssimple::{ detached_sign as sphincssha2256ssimple_detached_sign, keypair as sphincssha2256ssimple_keypair, open as sphincssha2256ssimple_open, public_key_bytes as sphincssha2256ssimple_public_key_bytes, @@ -283,14 +85,6 @@ pub use crate::sphincssha2256ssimple::{ signature_bytes as sphincssha2256ssimple_signature_bytes, verify_detached_signature as sphincssha2256ssimple_verify_detached_signature, }; -pub use crate::sphincsshake128frobust::{ - detached_sign as sphincsshake128frobust_detached_sign, - keypair as sphincsshake128frobust_keypair, open as sphincsshake128frobust_open, - public_key_bytes as sphincsshake128frobust_public_key_bytes, - secret_key_bytes as sphincsshake128frobust_secret_key_bytes, - sign as sphincsshake128frobust_sign, signature_bytes as sphincsshake128frobust_signature_bytes, - verify_detached_signature as sphincsshake128frobust_verify_detached_signature, -}; pub use crate::sphincsshake128fsimple::{ detached_sign as sphincsshake128fsimple_detached_sign, keypair as sphincsshake128fsimple_keypair, open as sphincsshake128fsimple_open, @@ -299,14 +93,6 @@ pub use crate::sphincsshake128fsimple::{ sign as sphincsshake128fsimple_sign, signature_bytes as sphincsshake128fsimple_signature_bytes, verify_detached_signature as sphincsshake128fsimple_verify_detached_signature, }; -pub use crate::sphincsshake128srobust::{ - detached_sign as sphincsshake128srobust_detached_sign, - keypair as sphincsshake128srobust_keypair, open as sphincsshake128srobust_open, - public_key_bytes as sphincsshake128srobust_public_key_bytes, - secret_key_bytes as sphincsshake128srobust_secret_key_bytes, - sign as sphincsshake128srobust_sign, signature_bytes as sphincsshake128srobust_signature_bytes, - verify_detached_signature as sphincsshake128srobust_verify_detached_signature, -}; pub use crate::sphincsshake128ssimple::{ detached_sign as sphincsshake128ssimple_detached_sign, keypair as sphincsshake128ssimple_keypair, open as sphincsshake128ssimple_open, @@ -315,14 +101,6 @@ pub use crate::sphincsshake128ssimple::{ sign as sphincsshake128ssimple_sign, signature_bytes as sphincsshake128ssimple_signature_bytes, verify_detached_signature as sphincsshake128ssimple_verify_detached_signature, }; -pub use crate::sphincsshake192frobust::{ - detached_sign as sphincsshake192frobust_detached_sign, - keypair as sphincsshake192frobust_keypair, open as sphincsshake192frobust_open, - public_key_bytes as sphincsshake192frobust_public_key_bytes, - secret_key_bytes as sphincsshake192frobust_secret_key_bytes, - sign as sphincsshake192frobust_sign, signature_bytes as sphincsshake192frobust_signature_bytes, - verify_detached_signature as sphincsshake192frobust_verify_detached_signature, -}; pub use crate::sphincsshake192fsimple::{ detached_sign as sphincsshake192fsimple_detached_sign, keypair as sphincsshake192fsimple_keypair, open as sphincsshake192fsimple_open, @@ -331,14 +109,6 @@ pub use crate::sphincsshake192fsimple::{ sign as sphincsshake192fsimple_sign, signature_bytes as sphincsshake192fsimple_signature_bytes, verify_detached_signature as sphincsshake192fsimple_verify_detached_signature, }; -pub use crate::sphincsshake192srobust::{ - detached_sign as sphincsshake192srobust_detached_sign, - keypair as sphincsshake192srobust_keypair, open as sphincsshake192srobust_open, - public_key_bytes as sphincsshake192srobust_public_key_bytes, - secret_key_bytes as sphincsshake192srobust_secret_key_bytes, - sign as sphincsshake192srobust_sign, signature_bytes as sphincsshake192srobust_signature_bytes, - verify_detached_signature as sphincsshake192srobust_verify_detached_signature, -}; pub use crate::sphincsshake192ssimple::{ detached_sign as sphincsshake192ssimple_detached_sign, keypair as sphincsshake192ssimple_keypair, open as sphincsshake192ssimple_open, @@ -347,14 +117,6 @@ pub use crate::sphincsshake192ssimple::{ sign as sphincsshake192ssimple_sign, signature_bytes as sphincsshake192ssimple_signature_bytes, verify_detached_signature as sphincsshake192ssimple_verify_detached_signature, }; -pub use crate::sphincsshake256frobust::{ - detached_sign as sphincsshake256frobust_detached_sign, - keypair as sphincsshake256frobust_keypair, open as sphincsshake256frobust_open, - public_key_bytes as sphincsshake256frobust_public_key_bytes, - secret_key_bytes as sphincsshake256frobust_secret_key_bytes, - sign as sphincsshake256frobust_sign, signature_bytes as sphincsshake256frobust_signature_bytes, - verify_detached_signature as sphincsshake256frobust_verify_detached_signature, -}; pub use crate::sphincsshake256fsimple::{ detached_sign as sphincsshake256fsimple_detached_sign, keypair as sphincsshake256fsimple_keypair, open as sphincsshake256fsimple_open, @@ -363,14 +125,6 @@ pub use crate::sphincsshake256fsimple::{ sign as sphincsshake256fsimple_sign, signature_bytes as sphincsshake256fsimple_signature_bytes, verify_detached_signature as sphincsshake256fsimple_verify_detached_signature, }; -pub use crate::sphincsshake256srobust::{ - detached_sign as sphincsshake256srobust_detached_sign, - keypair as sphincsshake256srobust_keypair, open as sphincsshake256srobust_open, - public_key_bytes as sphincsshake256srobust_public_key_bytes, - secret_key_bytes as sphincsshake256srobust_secret_key_bytes, - sign as sphincsshake256srobust_sign, signature_bytes as sphincsshake256srobust_signature_bytes, - verify_detached_signature as sphincsshake256srobust_verify_detached_signature, -}; pub use crate::sphincsshake256ssimple::{ detached_sign as sphincsshake256ssimple_detached_sign, keypair as sphincsshake256ssimple_keypair, open as sphincsshake256ssimple_open, diff --git a/pqcrypto-sphincsplus/src/sphincsharaka128frobust.rs b/pqcrypto-sphincsplus/src/sphincsharaka128frobust.rs deleted file mode 100644 index b43a92bd..00000000 --- a/pqcrypto-sphincsplus/src/sphincsharaka128frobust.rs +++ /dev/null @@ -1,382 +0,0 @@ -//! sphincs-haraka-128f-robust -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincsharaka128frobust::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincsharaka128frobust::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-haraka-128f-robust keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_keypair!(PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_signature!(PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return open_signed!( - PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_crypto_sign_open, - sm, - pk - ); - } - } - open_signed!( - PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_crypto_sign_open, - sm, - pk - ) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return detached_signature!( - PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA128FROBUST_AESNI_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA128FROBUST_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincsharaka128fsimple.rs b/pqcrypto-sphincsplus/src/sphincsharaka128fsimple.rs deleted file mode 100644 index 141f77ca..00000000 --- a/pqcrypto-sphincsplus/src/sphincsharaka128fsimple.rs +++ /dev/null @@ -1,382 +0,0 @@ -//! sphincs-haraka-128f-simple -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincsharaka128fsimple::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincsharaka128fsimple::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-haraka-128f-simple keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_keypair!(PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_signature!(PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return open_signed!( - PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_crypto_sign_open, - sm, - pk - ); - } - } - open_signed!( - PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_crypto_sign_open, - sm, - pk - ) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return detached_signature!( - PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA128FSIMPLE_AESNI_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA128FSIMPLE_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincsharaka128srobust.rs b/pqcrypto-sphincsplus/src/sphincsharaka128srobust.rs deleted file mode 100644 index 4f72e35a..00000000 --- a/pqcrypto-sphincsplus/src/sphincsharaka128srobust.rs +++ /dev/null @@ -1,382 +0,0 @@ -//! sphincs-haraka-128s-robust -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincsharaka128srobust::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincsharaka128srobust::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-haraka-128s-robust keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_keypair!(PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_signature!(PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return open_signed!( - PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_crypto_sign_open, - sm, - pk - ); - } - } - open_signed!( - PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_crypto_sign_open, - sm, - pk - ) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return detached_signature!( - PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA128SROBUST_AESNI_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA128SROBUST_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincsharaka128ssimple.rs b/pqcrypto-sphincsplus/src/sphincsharaka128ssimple.rs deleted file mode 100644 index 0b08a83f..00000000 --- a/pqcrypto-sphincsplus/src/sphincsharaka128ssimple.rs +++ /dev/null @@ -1,382 +0,0 @@ -//! sphincs-haraka-128s-simple -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincsharaka128ssimple::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincsharaka128ssimple::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-haraka-128s-simple keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_keypair!(PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_signature!(PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return open_signed!( - PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_crypto_sign_open, - sm, - pk - ); - } - } - open_signed!( - PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_crypto_sign_open, - sm, - pk - ) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return detached_signature!( - PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA128SSIMPLE_AESNI_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA128SSIMPLE_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincsharaka192frobust.rs b/pqcrypto-sphincsplus/src/sphincsharaka192frobust.rs deleted file mode 100644 index 6d971f43..00000000 --- a/pqcrypto-sphincsplus/src/sphincsharaka192frobust.rs +++ /dev/null @@ -1,382 +0,0 @@ -//! sphincs-haraka-192f-robust -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincsharaka192frobust::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincsharaka192frobust::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-haraka-192f-robust keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_keypair!(PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_signature!(PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return open_signed!( - PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_crypto_sign_open, - sm, - pk - ); - } - } - open_signed!( - PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_crypto_sign_open, - sm, - pk - ) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return detached_signature!( - PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA192FROBUST_AESNI_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA192FROBUST_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincsharaka192fsimple.rs b/pqcrypto-sphincsplus/src/sphincsharaka192fsimple.rs deleted file mode 100644 index 1d1b04b4..00000000 --- a/pqcrypto-sphincsplus/src/sphincsharaka192fsimple.rs +++ /dev/null @@ -1,382 +0,0 @@ -//! sphincs-haraka-192f-simple -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincsharaka192fsimple::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincsharaka192fsimple::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-haraka-192f-simple keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_keypair!(PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_signature!(PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return open_signed!( - PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_crypto_sign_open, - sm, - pk - ); - } - } - open_signed!( - PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_crypto_sign_open, - sm, - pk - ) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return detached_signature!( - PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA192FSIMPLE_AESNI_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA192FSIMPLE_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincsharaka192srobust.rs b/pqcrypto-sphincsplus/src/sphincsharaka192srobust.rs deleted file mode 100644 index 175e1531..00000000 --- a/pqcrypto-sphincsplus/src/sphincsharaka192srobust.rs +++ /dev/null @@ -1,382 +0,0 @@ -//! sphincs-haraka-192s-robust -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincsharaka192srobust::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincsharaka192srobust::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-haraka-192s-robust keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_keypair!(PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_signature!(PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return open_signed!( - PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_crypto_sign_open, - sm, - pk - ); - } - } - open_signed!( - PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_crypto_sign_open, - sm, - pk - ) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return detached_signature!( - PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA192SROBUST_AESNI_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA192SROBUST_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincsharaka192ssimple.rs b/pqcrypto-sphincsplus/src/sphincsharaka192ssimple.rs deleted file mode 100644 index 668494d1..00000000 --- a/pqcrypto-sphincsplus/src/sphincsharaka192ssimple.rs +++ /dev/null @@ -1,382 +0,0 @@ -//! sphincs-haraka-192s-simple -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincsharaka192ssimple::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincsharaka192ssimple::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-haraka-192s-simple keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_keypair!(PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_signature!(PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return open_signed!( - PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_crypto_sign_open, - sm, - pk - ); - } - } - open_signed!( - PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_crypto_sign_open, - sm, - pk - ) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return detached_signature!( - PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA192SSIMPLE_AESNI_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA192SSIMPLE_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincsharaka256frobust.rs b/pqcrypto-sphincsplus/src/sphincsharaka256frobust.rs deleted file mode 100644 index f39bb6db..00000000 --- a/pqcrypto-sphincsplus/src/sphincsharaka256frobust.rs +++ /dev/null @@ -1,382 +0,0 @@ -//! sphincs-haraka-256f-robust -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincsharaka256frobust::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincsharaka256frobust::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-haraka-256f-robust keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_keypair!(PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_signature!(PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return open_signed!( - PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_crypto_sign_open, - sm, - pk - ); - } - } - open_signed!( - PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_crypto_sign_open, - sm, - pk - ) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return detached_signature!( - PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA256FROBUST_AESNI_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA256FROBUST_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincsharaka256fsimple.rs b/pqcrypto-sphincsplus/src/sphincsharaka256fsimple.rs deleted file mode 100644 index 0bc35e5d..00000000 --- a/pqcrypto-sphincsplus/src/sphincsharaka256fsimple.rs +++ /dev/null @@ -1,382 +0,0 @@ -//! sphincs-haraka-256f-simple -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincsharaka256fsimple::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincsharaka256fsimple::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-haraka-256f-simple keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_keypair!(PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_signature!(PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return open_signed!( - PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_crypto_sign_open, - sm, - pk - ); - } - } - open_signed!( - PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_crypto_sign_open, - sm, - pk - ) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return detached_signature!( - PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA256FSIMPLE_AESNI_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA256FSIMPLE_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincsharaka256srobust.rs b/pqcrypto-sphincsplus/src/sphincsharaka256srobust.rs deleted file mode 100644 index 63aa896e..00000000 --- a/pqcrypto-sphincsplus/src/sphincsharaka256srobust.rs +++ /dev/null @@ -1,382 +0,0 @@ -//! sphincs-haraka-256s-robust -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincsharaka256srobust::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincsharaka256srobust::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-haraka-256s-robust keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_keypair!(PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_signature!(PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return open_signed!( - PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_crypto_sign_open, - sm, - pk - ); - } - } - open_signed!( - PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_crypto_sign_open, - sm, - pk - ) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return detached_signature!( - PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA256SROBUST_AESNI_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA256SROBUST_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincsharaka256ssimple.rs b/pqcrypto-sphincsplus/src/sphincsharaka256ssimple.rs deleted file mode 100644 index 13e1824a..00000000 --- a/pqcrypto-sphincsplus/src/sphincsharaka256ssimple.rs +++ /dev/null @@ -1,382 +0,0 @@ -//! sphincs-haraka-256s-simple -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincsharaka256ssimple::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincsharaka256ssimple::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-haraka-256s-simple keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_keypair!(PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return gen_signature!(PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return open_signed!( - PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_crypto_sign_open, - sm, - pk - ); - } - } - open_signed!( - PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_crypto_sign_open, - sm, - pk - ) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return detached_signature!( - PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_aes, feature = "aes"))] - { - if std::is_x86_feature_detected!("aes") { - return verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA256SSIMPLE_AESNI_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSHARAKA256SSIMPLE_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincssha2128frobust.rs b/pqcrypto-sphincsplus/src/sphincssha2128frobust.rs deleted file mode 100644 index bdbd86e6..00000000 --- a/pqcrypto-sphincsplus/src/sphincssha2128frobust.rs +++ /dev/null @@ -1,374 +0,0 @@ -//! sphincs-sha2-128f-robust -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincssha2128frobust::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincssha2128frobust::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-sha2-128f-robust keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_signature!(PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return open_signed!(PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_crypto_sign_open, sm, pk); - } - } - open_signed!(PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_crypto_sign_open, sm, pk) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return detached_signature!( - PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return verify_detached_sig!( - PQCLEAN_SPHINCSSHA2128FROBUST_AVX2_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSSHA2128FROBUST_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincssha2128srobust.rs b/pqcrypto-sphincsplus/src/sphincssha2128srobust.rs deleted file mode 100644 index 89c572d6..00000000 --- a/pqcrypto-sphincsplus/src/sphincssha2128srobust.rs +++ /dev/null @@ -1,374 +0,0 @@ -//! sphincs-sha2-128s-robust -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincssha2128srobust::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincssha2128srobust::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-sha2-128s-robust keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_signature!(PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return open_signed!(PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_crypto_sign_open, sm, pk); - } - } - open_signed!(PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_crypto_sign_open, sm, pk) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return detached_signature!( - PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return verify_detached_sig!( - PQCLEAN_SPHINCSSHA2128SROBUST_AVX2_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSSHA2128SROBUST_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincssha2192frobust.rs b/pqcrypto-sphincsplus/src/sphincssha2192frobust.rs deleted file mode 100644 index a021b70a..00000000 --- a/pqcrypto-sphincsplus/src/sphincssha2192frobust.rs +++ /dev/null @@ -1,374 +0,0 @@ -//! sphincs-sha2-192f-robust -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincssha2192frobust::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincssha2192frobust::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-sha2-192f-robust keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_signature!(PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return open_signed!(PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_crypto_sign_open, sm, pk); - } - } - open_signed!(PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_crypto_sign_open, sm, pk) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return detached_signature!( - PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return verify_detached_sig!( - PQCLEAN_SPHINCSSHA2192FROBUST_AVX2_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSSHA2192FROBUST_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincssha2192srobust.rs b/pqcrypto-sphincsplus/src/sphincssha2192srobust.rs deleted file mode 100644 index 6944ac37..00000000 --- a/pqcrypto-sphincsplus/src/sphincssha2192srobust.rs +++ /dev/null @@ -1,374 +0,0 @@ -//! sphincs-sha2-192s-robust -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincssha2192srobust::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincssha2192srobust::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-sha2-192s-robust keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_signature!(PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return open_signed!(PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_crypto_sign_open, sm, pk); - } - } - open_signed!(PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_crypto_sign_open, sm, pk) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return detached_signature!( - PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return verify_detached_sig!( - PQCLEAN_SPHINCSSHA2192SROBUST_AVX2_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSSHA2192SROBUST_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincssha2256frobust.rs b/pqcrypto-sphincsplus/src/sphincssha2256frobust.rs deleted file mode 100644 index cab0090e..00000000 --- a/pqcrypto-sphincsplus/src/sphincssha2256frobust.rs +++ /dev/null @@ -1,374 +0,0 @@ -//! sphincs-sha2-256f-robust -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincssha2256frobust::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincssha2256frobust::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-sha2-256f-robust keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_signature!(PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return open_signed!(PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_crypto_sign_open, sm, pk); - } - } - open_signed!(PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_crypto_sign_open, sm, pk) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return detached_signature!( - PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return verify_detached_sig!( - PQCLEAN_SPHINCSSHA2256FROBUST_AVX2_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSSHA2256FROBUST_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincssha2256srobust.rs b/pqcrypto-sphincsplus/src/sphincssha2256srobust.rs deleted file mode 100644 index 519322ff..00000000 --- a/pqcrypto-sphincsplus/src/sphincssha2256srobust.rs +++ /dev/null @@ -1,374 +0,0 @@ -//! sphincs-sha2-256s-robust -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincssha2256srobust::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincssha2256srobust::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-sha2-256s-robust keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_signature!(PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return open_signed!(PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_crypto_sign_open, sm, pk); - } - } - open_signed!(PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_crypto_sign_open, sm, pk) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return detached_signature!( - PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return verify_detached_sig!( - PQCLEAN_SPHINCSSHA2256SROBUST_AVX2_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSSHA2256SROBUST_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincsshake128frobust.rs b/pqcrypto-sphincsplus/src/sphincsshake128frobust.rs deleted file mode 100644 index fcaa36ed..00000000 --- a/pqcrypto-sphincsplus/src/sphincsshake128frobust.rs +++ /dev/null @@ -1,378 +0,0 @@ -//! sphincs-shake-128f-robust -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincsshake128frobust::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincsshake128frobust::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-shake-128f-robust keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_signature!(PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return open_signed!(PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_crypto_sign_open, sm, pk); - } - } - open_signed!( - PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_crypto_sign_open, - sm, - pk - ) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return detached_signature!( - PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return verify_detached_sig!( - PQCLEAN_SPHINCSSHAKE128FROBUST_AVX2_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSSHAKE128FROBUST_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincsshake128srobust.rs b/pqcrypto-sphincsplus/src/sphincsshake128srobust.rs deleted file mode 100644 index 792906d4..00000000 --- a/pqcrypto-sphincsplus/src/sphincsshake128srobust.rs +++ /dev/null @@ -1,378 +0,0 @@ -//! sphincs-shake-128s-robust -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincsshake128srobust::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincsshake128srobust::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-shake-128s-robust keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_signature!(PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return open_signed!(PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_crypto_sign_open, sm, pk); - } - } - open_signed!( - PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_crypto_sign_open, - sm, - pk - ) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return detached_signature!( - PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return verify_detached_sig!( - PQCLEAN_SPHINCSSHAKE128SROBUST_AVX2_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSSHAKE128SROBUST_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincsshake192frobust.rs b/pqcrypto-sphincsplus/src/sphincsshake192frobust.rs deleted file mode 100644 index 1e4822ce..00000000 --- a/pqcrypto-sphincsplus/src/sphincsshake192frobust.rs +++ /dev/null @@ -1,378 +0,0 @@ -//! sphincs-shake-192f-robust -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincsshake192frobust::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincsshake192frobust::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-shake-192f-robust keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_signature!(PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return open_signed!(PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_crypto_sign_open, sm, pk); - } - } - open_signed!( - PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_crypto_sign_open, - sm, - pk - ) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return detached_signature!( - PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return verify_detached_sig!( - PQCLEAN_SPHINCSSHAKE192FROBUST_AVX2_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSSHAKE192FROBUST_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincsshake192srobust.rs b/pqcrypto-sphincsplus/src/sphincsshake192srobust.rs deleted file mode 100644 index 2afa2976..00000000 --- a/pqcrypto-sphincsplus/src/sphincsshake192srobust.rs +++ /dev/null @@ -1,378 +0,0 @@ -//! sphincs-shake-192s-robust -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincsshake192srobust::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincsshake192srobust::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-shake-192s-robust keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_signature!(PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return open_signed!(PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_crypto_sign_open, sm, pk); - } - } - open_signed!( - PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_crypto_sign_open, - sm, - pk - ) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return detached_signature!( - PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return verify_detached_sig!( - PQCLEAN_SPHINCSSHAKE192SROBUST_AVX2_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSSHAKE192SROBUST_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincsshake256frobust.rs b/pqcrypto-sphincsplus/src/sphincsshake256frobust.rs deleted file mode 100644 index 40eabbf6..00000000 --- a/pqcrypto-sphincsplus/src/sphincsshake256frobust.rs +++ /dev/null @@ -1,378 +0,0 @@ -//! sphincs-shake-256f-robust -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincsshake256frobust::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincsshake256frobust::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-shake-256f-robust keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_signature!(PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return open_signed!(PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_crypto_sign_open, sm, pk); - } - } - open_signed!( - PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_crypto_sign_open, - sm, - pk - ) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return detached_signature!( - PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return verify_detached_sig!( - PQCLEAN_SPHINCSSHAKE256FROBUST_AVX2_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSSHAKE256FROBUST_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto-sphincsplus/src/sphincsshake256srobust.rs b/pqcrypto-sphincsplus/src/sphincsshake256srobust.rs deleted file mode 100644 index 1a9d3060..00000000 --- a/pqcrypto-sphincsplus/src/sphincsshake256srobust.rs +++ /dev/null @@ -1,378 +0,0 @@ -//! sphincs-shake-256s-robust -//! -//! These bindings use the clean version from [PQClean][pqc] -//! -//! # Example -//! ``` -//! // if using pqcrypto-sphincsplus -//! use pqcrypto_sphincsplus::sphincsshake256srobust::*; -//! // or if using the pqcrypto crate: -//! // use pqcrypto::sign::sphincsshake256srobust::*; -//! let message = vec![0, 1, 2, 3, 4, 5]; -//! let (pk, sk) = keypair(); -//! let sm = sign(&message, &sk); -//! let verifiedmsg = open(&sm, &pk).unwrap(); -//! assert!(verifiedmsg == message); -//! ``` -//! -//! [pqc]: https://github.com/pqclean/pqclean/ - -// This file is generated. - -#[cfg(feature = "serialization")] -use serde::{Deserialize, Serialize}; -#[cfg(feature = "serialization")] -use serde_big_array::BigArray; - -use crate::ffi; -use alloc::vec::Vec; -use pqcrypto_traits::sign as primitive; -use pqcrypto_traits::{Error, Result}; - -macro_rules! simple_struct { - ($type: ident, $size: expr) => { - #[derive(Clone, Copy)] - #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] - pub struct $type( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] [u8; $size], - ); - - impl $type { - /// Generates an uninitialized object - /// - /// Used to pass to ``ffi`` interfaces. - /// - /// Internal use only! - fn new() -> Self { - $type([0u8; $size]) - } - } - - impl primitive::$type for $type { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0 - } - - /// Construct this object from a byte slice - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != $size { - Err(Error::BadLength { - name: stringify!($type), - actual: bytes.len(), - expected: $size, - }) - } else { - let mut array = [0u8; $size]; - array.copy_from_slice(bytes); - Ok($type(array)) - } - } - } - - impl PartialEq for $type { - /// By no means constant time comparison - fn eq(&self, other: &Self) -> bool { - self.0 - .iter() - .zip(other.0.iter()) - .try_for_each(|(a, b)| if a == b { Ok(()) } else { Err(()) }) - .is_ok() - } - } - }; -} - -simple_struct!( - PublicKey, - ffi::PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -); -simple_struct!( - SecretKey, - ffi::PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -); - -#[derive(Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct DetachedSignature( - #[cfg_attr(feature = "serialization", serde(with = "BigArray"))] - [u8; ffi::PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_CRYPTO_BYTES], - usize, -); - -// for internal use -impl DetachedSignature { - fn new() -> Self { - DetachedSignature( - [0u8; ffi::PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_CRYPTO_BYTES], - 0, - ) - } -} - -impl primitive::DetachedSignature for DetachedSignature { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - &self.0[..self.1] - } - - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - let actual = bytes.len(); - let expected = ffi::PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_CRYPTO_BYTES; - if actual > expected { - return Err(Error::BadLength { - name: "DetachedSignature", - actual, - expected, - }); - } - let mut array = [0u8; ffi::PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_CRYPTO_BYTES]; - array[..bytes.len()].copy_from_slice(bytes); - Ok(DetachedSignature(array, actual)) - } -} - -#[derive(Clone)] -#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] -pub struct SignedMessage(Vec); -impl primitive::SignedMessage for SignedMessage { - /// Get this object as a byte slice - #[inline] - fn as_bytes(&self) -> &[u8] { - self.0.as_slice() - } - - /// Construct this object from a byte slice - #[inline] - fn from_bytes(bytes: &[u8]) -> Result { - Ok(SignedMessage(bytes.to_vec())) - } -} - -impl SignedMessage { - pub fn len(&self) -> usize { - self.0.len() - } -} - -/// Get the number of bytes for a public key -pub const fn public_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_CRYPTO_PUBLICKEYBYTES -} - -/// Get the number of bytes for a secret key -pub const fn secret_key_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_CRYPTO_SECRETKEYBYTES -} - -/// Get the number of bytes that a signature occupies -pub const fn signature_bytes() -> usize { - ffi::PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_CRYPTO_BYTES -} - -macro_rules! gen_keypair { - ($variant:ident) => {{ - let mut pk = PublicKey::new(); - let mut sk = SecretKey::new(); - assert_eq!( - unsafe { ffi::$variant(pk.0.as_mut_ptr(), sk.0.as_mut_ptr()) }, - 0 - ); - (pk, sk) - }}; -} - -/// Generate a sphincs-shake-256s-robust keypair -pub fn keypair() -> (PublicKey, SecretKey) { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_crypto_sign_keypair); - } - } - gen_keypair!(PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_crypto_sign_keypair) -} - -macro_rules! gen_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let max_len = $msg.len() + signature_bytes(); - let mut signed_msg = Vec::with_capacity(max_len); - let mut smlen: usize = 0; - unsafe { - ffi::$variant( - signed_msg.as_mut_ptr(), - &mut smlen as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - debug_assert!(smlen <= max_len, "exceeded vector capacity"); - signed_msg.set_len(smlen); - } - SignedMessage(signed_msg) - }}; -} - -/// Sign the message and return the signed message. -pub fn sign(msg: &[u8], sk: &SecretKey) -> SignedMessage { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return gen_signature!(PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_crypto_sign, msg, sk); - } - } - gen_signature!(PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_crypto_sign, msg, sk) -} - -macro_rules! open_signed { - ($variant:ident, $sm:ident, $pk:ident) => {{ - let mut m: Vec = Vec::with_capacity($sm.len()); - let mut mlen: usize = 0; - match unsafe { - ffi::$variant( - m.as_mut_ptr(), - &mut mlen as *mut usize, - $sm.0.as_ptr(), - $sm.len(), - $pk.0.as_ptr(), - ) - } { - 0 => { - unsafe { m.set_len(mlen) }; - Ok(m) - } - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Open the signed message and if verification succeeds return the message -pub fn open( - sm: &SignedMessage, - pk: &PublicKey, -) -> core::result::Result, primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return open_signed!(PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_crypto_sign_open, sm, pk); - } - } - open_signed!( - PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_crypto_sign_open, - sm, - pk - ) -} - -macro_rules! detached_signature { - ($variant:ident, $msg:ident, $sk:ident) => {{ - let mut sig = DetachedSignature::new(); - unsafe { - ffi::$variant( - sig.0.as_mut_ptr(), - &mut sig.1 as *mut usize, - $msg.as_ptr(), - $msg.len(), - $sk.0.as_ptr(), - ); - } - sig - }}; -} - -/// Create a detached signature on the message -pub fn detached_sign(msg: &[u8], sk: &SecretKey) -> DetachedSignature { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return detached_signature!( - PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_crypto_sign_signature, - msg, - sk - ); - } - } - detached_signature!( - PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_crypto_sign_signature, - msg, - sk - ) -} - -macro_rules! verify_detached_sig { - ($variant:ident, $sig:ident, $msg:ident, $pk:ident) => {{ - let res = unsafe { - ffi::$variant( - $sig.0.as_ptr(), - $sig.1, - $msg.as_ptr(), - $msg.len(), - $pk.0.as_ptr(), - ) - }; - match res { - 0 => Ok(()), - -1 => Err(primitive::VerificationError::InvalidSignature), - _ => Err(primitive::VerificationError::UnknownVerificationError), - } - }}; -} - -/// Verify the detached signature -pub fn verify_detached_signature( - sig: &DetachedSignature, - msg: &[u8], - pk: &PublicKey, -) -> core::result::Result<(), primitive::VerificationError> { - #[cfg(all(enable_x86_avx2, feature = "avx2"))] - { - if std::is_x86_feature_detected!("avx2") { - return verify_detached_sig!( - PQCLEAN_SPHINCSSHAKE256SROBUST_AVX2_crypto_sign_verify, - sig, - msg, - pk - ); - } - } - verify_detached_sig!( - PQCLEAN_SPHINCSSHAKE256SROBUST_CLEAN_crypto_sign_verify, - sig, - msg, - pk - ) -} - -#[cfg(test)] -mod test { - use super::*; - use rand::prelude::*; - - #[test] - pub fn test_sign() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - - let message = (0..len).map(|_| rng.gen::()).collect::>(); - let (pk, sk) = keypair(); - let sm = sign(&message, &sk); - let verifiedmsg = open(&sm, &pk).unwrap(); - assert!(verifiedmsg == message); - } - - #[test] - pub fn test_sign_detached() { - let mut rng = rand::thread_rng(); - let len: u16 = rng.gen(); - let message = (0..len).map(|_| rng.gen::()).collect::>(); - - let (pk, sk) = keypair(); - let sig = detached_sign(&message, &sk); - assert!(verify_detached_signature(&sig, &message, &pk).is_ok()); - assert!(!verify_detached_signature(&sig, &message[..message.len() - 1], &pk).is_ok()); - } -} diff --git a/pqcrypto/Cargo.toml b/pqcrypto/Cargo.toml index 2e0226af..6e73e3e1 100644 --- a/pqcrypto/Cargo.toml +++ b/pqcrypto/Cargo.toml @@ -14,9 +14,9 @@ categories = ["cryptography"] [dependencies] pqcrypto-traits = { path = "../pqcrypto-traits", version = "0.3.5" } pqcrypto-kyber = { path = "../pqcrypto-kyber", version = "0.7.7", optional = true } -pqcrypto-classicmceliece = { path = "../pqcrypto-classicmceliece", version = "0.1.8", optional = true } -pqcrypto-hqc = { path = "../pqcrypto-hqc", version = "0.1.7", optional = true } -pqcrypto-dilithium = { path = "../pqcrypto-dilithium", version = "0.4.7", optional = true } +pqcrypto-classicmceliece = { path = "../pqcrypto-classicmceliece", version = "0.2.0", optional = true } +pqcrypto-hqc = { path = "../pqcrypto-hqc", version = "0.2.0", optional = true } +pqcrypto-dilithium = { path = "../pqcrypto-dilithium", version = "0.5.0", optional = true } pqcrypto-falcon = { path = "../pqcrypto-falcon", version = "0.3.0", optional = true } pqcrypto-sphincsplus = { path = "../pqcrypto-sphincsplus", version = "0.7.0", optional = true } diff --git a/pqcrypto/src/lib.rs b/pqcrypto/src/lib.rs index e94c798d..750db923 100644 --- a/pqcrypto/src/lib.rs +++ b/pqcrypto/src/lib.rs @@ -21,32 +21,21 @@ pub mod kem { mceliece6688128f, mceliece6960119, mceliece6960119f, mceliece8192128, mceliece8192128f, }; #[cfg(feature = "pqcrypto-hqc")] - pub use pqcrypto_hqc::{hqcrmrs128, hqcrmrs192, hqcrmrs256}; + pub use pqcrypto_hqc::{hqc128, hqc192, hqc256}; #[cfg(feature = "pqcrypto-kyber")] - pub use pqcrypto_kyber::{ - kyber1024, kyber102490s, kyber512, kyber51290s, kyber768, kyber76890s, - }; + pub use pqcrypto_kyber::{kyber1024, kyber512, kyber768}; } pub mod sign { #[cfg(feature = "pqcrypto-dilithium")] - pub use pqcrypto_dilithium::{ - dilithium2, dilithium2aes, dilithium3, dilithium3aes, dilithium5, dilithium5aes, - }; + pub use pqcrypto_dilithium::{dilithium2, dilithium3, dilithium5}; #[cfg(feature = "pqcrypto-falcon")] pub use pqcrypto_falcon::{falcon1024, falcon512}; #[cfg(feature = "pqcrypto-sphincsplus")] pub use pqcrypto_sphincsplus::{ - sphincsharaka128frobust, sphincsharaka128fsimple, sphincsharaka128srobust, - sphincsharaka128ssimple, sphincsharaka192frobust, sphincsharaka192fsimple, - sphincsharaka192srobust, sphincsharaka192ssimple, sphincsharaka256frobust, - sphincsharaka256fsimple, sphincsharaka256srobust, sphincsharaka256ssimple, - sphincssha2128frobust, sphincssha2128fsimple, sphincssha2128srobust, sphincssha2128ssimple, - sphincssha2192frobust, sphincssha2192fsimple, sphincssha2192srobust, sphincssha2192ssimple, - sphincssha2256frobust, sphincssha2256fsimple, sphincssha2256srobust, sphincssha2256ssimple, - sphincsshake128frobust, sphincsshake128fsimple, sphincsshake128srobust, - sphincsshake128ssimple, sphincsshake192frobust, sphincsshake192fsimple, - sphincsshake192srobust, sphincsshake192ssimple, sphincsshake256frobust, - sphincsshake256fsimple, sphincsshake256srobust, sphincsshake256ssimple, + sphincssha2128fsimple, sphincssha2128ssimple, sphincssha2192fsimple, sphincssha2192ssimple, + sphincssha2256fsimple, sphincssha2256ssimple, sphincsshake128fsimple, + sphincsshake128ssimple, sphincsshake192fsimple, sphincsshake192ssimple, + sphincsshake256fsimple, sphincsshake256ssimple, }; } From b00207b1d5c060bac2cd9835078eee7ea15adc0b Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Mon, 16 Oct 2023 16:19:17 +0200 Subject: [PATCH 2/7] Only render info about insecure impls if we have them --- generate-implementations.py | 3 +++ pqcrypto-template/pqcrypto/README.md.j2 | 2 ++ pqcrypto/README.md | 7 ------- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/generate-implementations.py b/generate-implementations.py index 65ac68ba..ba31f1ac 100755 --- a/generate-implementations.py +++ b/generate-implementations.py @@ -135,6 +135,8 @@ def generate_pqcrypto_crate(implementations): target_dir = 'pqcrypto' shutil.rmtree(target_dir) os.makedirs(os.path.join(target_dir, 'src')) + any_insecure = any(kem.get('insecure') for (_name, kem) in implementations['kems'].items()) + any_insecure |= any(sig.get('insecure') for (_name, sig) in implementations['signs'].items()) render_template( target_dir, 'Cargo.toml', "pqcrypto/Cargo.toml.j2", @@ -152,6 +154,7 @@ def generate_pqcrypto_crate(implementations): target_dir, 'README.md', 'pqcrypto/README.md.j2', kems=implementations['kems'], signs=implementations['signs'], + any_insecure=any_insecure, ) shutil.copytree( "pqcrypto-template/pqcrypto/examples", diff --git a/pqcrypto-template/pqcrypto/README.md.j2 b/pqcrypto-template/pqcrypto/README.md.j2 index 5b87abd5..234de10b 100644 --- a/pqcrypto-template/pqcrypto/README.md.j2 +++ b/pqcrypto-template/pqcrypto/README.md.j2 @@ -4,6 +4,7 @@ This project contains Post-Quantum cryptographic algorithms that participate in the [NIST PQC standardization effort][nistpqc]. It is currently a collection of wrappers around C implementations from the [PQClean][pqclean] project. +{% if any_insecure %} ## Insecure algorithms This crate contains optional support for insecure algorithms. They can be enabled via the @@ -11,6 +12,7 @@ This crate contains optional support for insecure algorithms. They can be enable This crate also contains algorithms that have non-constant time implementations. Always check the relevant algorithms for their security details. +{% endif %} ## Included algorithms diff --git a/pqcrypto/README.md b/pqcrypto/README.md index 01d7b0ff..7e0d726a 100644 --- a/pqcrypto/README.md +++ b/pqcrypto/README.md @@ -4,13 +4,6 @@ This project contains Post-Quantum cryptographic algorithms that participate in the [NIST PQC standardization effort][nistpqc]. It is currently a collection of wrappers around C implementations from the [PQClean][pqclean] project. -## Insecure algorithms - -This crate contains optional support for insecure algorithms. They can be enabled via the -``cryptographically-insecure`` flag. - -This crate also contains algorithms that have non-constant time implementations. -Always check the relevant algorithms for their security details. ## Included algorithms From 71eb8399bb7a3399c84a80f3d7769ba4cf202dc3 Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Mon, 16 Oct 2023 16:27:02 +0200 Subject: [PATCH 3/7] Fix build~ --- implementations.yaml | 26 +- pqcrypto-classicmceliece/README.md | 20 +- pqcrypto-classicmceliece/build.rs | 26 +- pqcrypto-classicmceliece/src/ffi.rs | 340 +++++++++--------- .../src/mceliece348864.rs | 6 +- .../src/mceliece348864f.rs | 6 +- .../src/mceliece460896.rs | 6 +- .../src/mceliece460896f.rs | 6 +- .../src/mceliece6688128.rs | 6 +- .../src/mceliece6688128f.rs | 6 +- .../src/mceliece6960119.rs | 6 +- .../src/mceliece6960119f.rs | 6 +- .../src/mceliece8192128.rs | 6 +- .../src/mceliece8192128f.rs | 6 +- pqcrypto-falcon/Cargo.toml | 3 +- pqcrypto-falcon/build.rs | 37 ++ pqcrypto-sphincsplus/Cargo.toml | 3 +- pqcrypto-sphincsplus/build.rs | 42 --- 18 files changed, 276 insertions(+), 281 deletions(-) diff --git a/implementations.yaml b/implementations.yaml index ffc9e35b..4d6d2db5 100644 --- a/implementations.yaml +++ b/implementations.yaml @@ -21,33 +21,33 @@ kems: This implementation requires a lot of stack space. You need to specify ``RUST_MIN_STACK=800000000``, probably. x86_avx2_guard: 'target_arch == "x86_64" && avx2_enabled && !is_windows' - implementations: [clean, avx] + implementations: [clean, avx2] schemes: - name: mceliece348864 - implementations: [clean, avx] + implementations: [clean, avx2] - name: mceliece348864f - implementations: [clean, avx] + implementations: [clean, avx2] - name: mceliece460896 - implementations: [clean, avx] + implementations: [clean, avx2] - name: mceliece460896f - implementations: [clean, avx] + implementations: [clean, avx2] - name: mceliece6688128 - implementations: [clean, avx] + implementations: [clean, avx2] doctest: no - name: mceliece6688128f - implementations: [clean, avx] + implementations: [clean, avx2] doctest: no - name: mceliece6960119 - implementations: [clean, avx] + implementations: [clean, avx2] doctest: no - name: mceliece6960119f - implementations: [clean, avx] + implementations: [clean, avx2] doctest: no - name: mceliece8192128 - implementations: [clean, avx] + implementations: [clean, avx2] doctest: no - name: mceliece8192128f - implementations: [clean, avx] + implementations: [clean, avx2] doctest: no hqc: version: 0.2.0 @@ -75,7 +75,7 @@ signs: implementations: [clean, avx2, aarch64] falcon: version: 0.3.0 - implementations: [clean, avx2] + implementations: [clean, avx2, aarch64] schemes: - name: falcon-512 implementations: [clean, avx2, aarch64] @@ -83,7 +83,7 @@ signs: implementations: [clean, avx2, aarch64] sphincsplus: version: 0.7.0 - implementations: [clean, aesni, avx2] + implementations: [clean, avx2] schemes: - name: sphincs-shake-128f-simple implementations: [clean, avx2] diff --git a/pqcrypto-classicmceliece/README.md b/pqcrypto-classicmceliece/README.md index 018c95e2..93a485b2 100644 --- a/pqcrypto-classicmceliece/README.md +++ b/pqcrypto-classicmceliece/README.md @@ -21,34 +21,34 @@ methods only. * ``mceliece348864`` * ``clean`` - * ``avx`` (if supported) + * ``avx2`` (if supported) * ``mceliece348864f`` * ``clean`` - * ``avx`` (if supported) + * ``avx2`` (if supported) * ``mceliece460896`` * ``clean`` - * ``avx`` (if supported) + * ``avx2`` (if supported) * ``mceliece460896f`` * ``clean`` - * ``avx`` (if supported) + * ``avx2`` (if supported) * ``mceliece6688128`` * ``clean`` - * ``avx`` (if supported) + * ``avx2`` (if supported) * ``mceliece6688128f`` * ``clean`` - * ``avx`` (if supported) + * ``avx2`` (if supported) * ``mceliece6960119`` * ``clean`` - * ``avx`` (if supported) + * ``avx2`` (if supported) * ``mceliece6960119f`` * ``clean`` - * ``avx`` (if supported) + * ``avx2`` (if supported) * ``mceliece8192128`` * ``clean`` - * ``avx`` (if supported) + * ``avx2`` (if supported) * ``mceliece8192128f`` * ``clean`` - * ``avx`` (if supported) + * ``avx2`` (if supported) ## Notes diff --git a/pqcrypto-classicmceliece/build.rs b/pqcrypto-classicmceliece/build.rs index d386f587..8167ef3d 100644 --- a/pqcrypto-classicmceliece/build.rs +++ b/pqcrypto-classicmceliece/build.rs @@ -36,13 +36,13 @@ macro_rules! build_clean { }; } -macro_rules! build_avx { +macro_rules! build_avx2 { ($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, "avx"].iter().collect(); + let target_dir: PathBuf = ["pqclean", "crypto_kem", $variant, "avx2"].iter().collect(); let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); if target_os == "wasi" { @@ -74,7 +74,7 @@ macro_rules! build_avx { .into_iter() .map(|p| p.unwrap().to_string_lossy().into_owned()), ); - builder.compile(format!("{}_avx", $variant).as_str()); + builder.compile(format!("{}_avx2", $variant).as_str()); }; } @@ -96,43 +96,43 @@ fn main() { build_clean!("mceliece348864"); if target_arch == "x86_64" && avx2_enabled && !is_windows { - build_avx!("mceliece348864"); + build_avx2!("mceliece348864"); } build_clean!("mceliece348864f"); if target_arch == "x86_64" && avx2_enabled && !is_windows { - build_avx!("mceliece348864f"); + build_avx2!("mceliece348864f"); } build_clean!("mceliece460896"); if target_arch == "x86_64" && avx2_enabled && !is_windows { - build_avx!("mceliece460896"); + build_avx2!("mceliece460896"); } build_clean!("mceliece460896f"); if target_arch == "x86_64" && avx2_enabled && !is_windows { - build_avx!("mceliece460896f"); + build_avx2!("mceliece460896f"); } build_clean!("mceliece6688128"); if target_arch == "x86_64" && avx2_enabled && !is_windows { - build_avx!("mceliece6688128"); + build_avx2!("mceliece6688128"); } build_clean!("mceliece6688128f"); if target_arch == "x86_64" && avx2_enabled && !is_windows { - build_avx!("mceliece6688128f"); + build_avx2!("mceliece6688128f"); } build_clean!("mceliece6960119"); if target_arch == "x86_64" && avx2_enabled && !is_windows { - build_avx!("mceliece6960119"); + build_avx2!("mceliece6960119"); } build_clean!("mceliece6960119f"); if target_arch == "x86_64" && avx2_enabled && !is_windows { - build_avx!("mceliece6960119f"); + build_avx2!("mceliece6960119f"); } build_clean!("mceliece8192128"); if target_arch == "x86_64" && avx2_enabled && !is_windows { - build_avx!("mceliece8192128"); + build_avx2!("mceliece8192128"); } build_clean!("mceliece8192128f"); if target_arch == "x86_64" && avx2_enabled && !is_windows { - build_avx!("mceliece8192128f"); + build_avx2!("mceliece8192128f"); } if target_arch == "x86_64" && avx2_enabled && !is_windows { diff --git a/pqcrypto-classicmceliece/src/ffi.rs b/pqcrypto-classicmceliece/src/ffi.rs index c3827c9a..615cbcb0 100644 --- a/pqcrypto-classicmceliece/src/ffi.rs +++ b/pqcrypto-classicmceliece/src/ffi.rs @@ -27,13 +27,13 @@ pub const PQCLEAN_MCELIECE348864_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 96; pub const PQCLEAN_MCELIECE348864_CLEAN_CRYPTO_BYTES: usize = 32; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE348864_AVX_CRYPTO_SECRETKEYBYTES: usize = 6492; +pub const PQCLEAN_MCELIECE348864_AVX2_CRYPTO_SECRETKEYBYTES: usize = 6492; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE348864_AVX_CRYPTO_PUBLICKEYBYTES: usize = 261120; +pub const PQCLEAN_MCELIECE348864_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 261120; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE348864_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 96; +pub const PQCLEAN_MCELIECE348864_AVX2_CRYPTO_CIPHERTEXTBYTES: usize = 96; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE348864_AVX_CRYPTO_BYTES: usize = 32; +pub const PQCLEAN_MCELIECE348864_AVX2_CRYPTO_BYTES: usize = 32; pub const PQCLEAN_MCELIECE348864F_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 6492; pub const PQCLEAN_MCELIECE348864F_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 261120; @@ -41,13 +41,13 @@ pub const PQCLEAN_MCELIECE348864F_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 96; pub const PQCLEAN_MCELIECE348864F_CLEAN_CRYPTO_BYTES: usize = 32; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE348864F_AVX_CRYPTO_SECRETKEYBYTES: usize = 6492; +pub const PQCLEAN_MCELIECE348864F_AVX2_CRYPTO_SECRETKEYBYTES: usize = 6492; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE348864F_AVX_CRYPTO_PUBLICKEYBYTES: usize = 261120; +pub const PQCLEAN_MCELIECE348864F_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 261120; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE348864F_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 96; +pub const PQCLEAN_MCELIECE348864F_AVX2_CRYPTO_CIPHERTEXTBYTES: usize = 96; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE348864F_AVX_CRYPTO_BYTES: usize = 32; +pub const PQCLEAN_MCELIECE348864F_AVX2_CRYPTO_BYTES: usize = 32; pub const PQCLEAN_MCELIECE460896_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 13608; pub const PQCLEAN_MCELIECE460896_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 524160; @@ -55,13 +55,13 @@ pub const PQCLEAN_MCELIECE460896_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 156; pub const PQCLEAN_MCELIECE460896_CLEAN_CRYPTO_BYTES: usize = 32; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE460896_AVX_CRYPTO_SECRETKEYBYTES: usize = 13608; +pub const PQCLEAN_MCELIECE460896_AVX2_CRYPTO_SECRETKEYBYTES: usize = 13608; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE460896_AVX_CRYPTO_PUBLICKEYBYTES: usize = 524160; +pub const PQCLEAN_MCELIECE460896_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 524160; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE460896_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 156; +pub const PQCLEAN_MCELIECE460896_AVX2_CRYPTO_CIPHERTEXTBYTES: usize = 156; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE460896_AVX_CRYPTO_BYTES: usize = 32; +pub const PQCLEAN_MCELIECE460896_AVX2_CRYPTO_BYTES: usize = 32; pub const PQCLEAN_MCELIECE460896F_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 13608; pub const PQCLEAN_MCELIECE460896F_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 524160; @@ -69,13 +69,13 @@ pub const PQCLEAN_MCELIECE460896F_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 156; pub const PQCLEAN_MCELIECE460896F_CLEAN_CRYPTO_BYTES: usize = 32; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE460896F_AVX_CRYPTO_SECRETKEYBYTES: usize = 13608; +pub const PQCLEAN_MCELIECE460896F_AVX2_CRYPTO_SECRETKEYBYTES: usize = 13608; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE460896F_AVX_CRYPTO_PUBLICKEYBYTES: usize = 524160; +pub const PQCLEAN_MCELIECE460896F_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 524160; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE460896F_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 156; +pub const PQCLEAN_MCELIECE460896F_AVX2_CRYPTO_CIPHERTEXTBYTES: usize = 156; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE460896F_AVX_CRYPTO_BYTES: usize = 32; +pub const PQCLEAN_MCELIECE460896F_AVX2_CRYPTO_BYTES: usize = 32; pub const PQCLEAN_MCELIECE6688128_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 13932; pub const PQCLEAN_MCELIECE6688128_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 1044992; @@ -83,13 +83,13 @@ pub const PQCLEAN_MCELIECE6688128_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 208; pub const PQCLEAN_MCELIECE6688128_CLEAN_CRYPTO_BYTES: usize = 32; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6688128_AVX_CRYPTO_SECRETKEYBYTES: usize = 13932; +pub const PQCLEAN_MCELIECE6688128_AVX2_CRYPTO_SECRETKEYBYTES: usize = 13932; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6688128_AVX_CRYPTO_PUBLICKEYBYTES: usize = 1044992; +pub const PQCLEAN_MCELIECE6688128_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 1044992; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6688128_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 208; +pub const PQCLEAN_MCELIECE6688128_AVX2_CRYPTO_CIPHERTEXTBYTES: usize = 208; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6688128_AVX_CRYPTO_BYTES: usize = 32; +pub const PQCLEAN_MCELIECE6688128_AVX2_CRYPTO_BYTES: usize = 32; pub const PQCLEAN_MCELIECE6688128F_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 13932; pub const PQCLEAN_MCELIECE6688128F_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 1044992; @@ -97,13 +97,13 @@ pub const PQCLEAN_MCELIECE6688128F_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 208; pub const PQCLEAN_MCELIECE6688128F_CLEAN_CRYPTO_BYTES: usize = 32; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6688128F_AVX_CRYPTO_SECRETKEYBYTES: usize = 13932; +pub const PQCLEAN_MCELIECE6688128F_AVX2_CRYPTO_SECRETKEYBYTES: usize = 13932; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6688128F_AVX_CRYPTO_PUBLICKEYBYTES: usize = 1044992; +pub const PQCLEAN_MCELIECE6688128F_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 1044992; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6688128F_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 208; +pub const PQCLEAN_MCELIECE6688128F_AVX2_CRYPTO_CIPHERTEXTBYTES: usize = 208; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6688128F_AVX_CRYPTO_BYTES: usize = 32; +pub const PQCLEAN_MCELIECE6688128F_AVX2_CRYPTO_BYTES: usize = 32; pub const PQCLEAN_MCELIECE6960119_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 13948; pub const PQCLEAN_MCELIECE6960119_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 1047319; @@ -111,13 +111,13 @@ pub const PQCLEAN_MCELIECE6960119_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 194; pub const PQCLEAN_MCELIECE6960119_CLEAN_CRYPTO_BYTES: usize = 32; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6960119_AVX_CRYPTO_SECRETKEYBYTES: usize = 13948; +pub const PQCLEAN_MCELIECE6960119_AVX2_CRYPTO_SECRETKEYBYTES: usize = 13948; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6960119_AVX_CRYPTO_PUBLICKEYBYTES: usize = 1047319; +pub const PQCLEAN_MCELIECE6960119_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 1047319; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6960119_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 194; +pub const PQCLEAN_MCELIECE6960119_AVX2_CRYPTO_CIPHERTEXTBYTES: usize = 194; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6960119_AVX_CRYPTO_BYTES: usize = 32; +pub const PQCLEAN_MCELIECE6960119_AVX2_CRYPTO_BYTES: usize = 32; pub const PQCLEAN_MCELIECE6960119F_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 13948; pub const PQCLEAN_MCELIECE6960119F_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 1047319; @@ -125,13 +125,13 @@ pub const PQCLEAN_MCELIECE6960119F_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 194; pub const PQCLEAN_MCELIECE6960119F_CLEAN_CRYPTO_BYTES: usize = 32; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6960119F_AVX_CRYPTO_SECRETKEYBYTES: usize = 13948; +pub const PQCLEAN_MCELIECE6960119F_AVX2_CRYPTO_SECRETKEYBYTES: usize = 13948; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6960119F_AVX_CRYPTO_PUBLICKEYBYTES: usize = 1047319; +pub const PQCLEAN_MCELIECE6960119F_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 1047319; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6960119F_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 194; +pub const PQCLEAN_MCELIECE6960119F_AVX2_CRYPTO_CIPHERTEXTBYTES: usize = 194; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE6960119F_AVX_CRYPTO_BYTES: usize = 32; +pub const PQCLEAN_MCELIECE6960119F_AVX2_CRYPTO_BYTES: usize = 32; pub const PQCLEAN_MCELIECE8192128_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 14120; pub const PQCLEAN_MCELIECE8192128_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 1357824; @@ -139,13 +139,13 @@ pub const PQCLEAN_MCELIECE8192128_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 208; pub const PQCLEAN_MCELIECE8192128_CLEAN_CRYPTO_BYTES: usize = 32; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE8192128_AVX_CRYPTO_SECRETKEYBYTES: usize = 14120; +pub const PQCLEAN_MCELIECE8192128_AVX2_CRYPTO_SECRETKEYBYTES: usize = 14120; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE8192128_AVX_CRYPTO_PUBLICKEYBYTES: usize = 1357824; +pub const PQCLEAN_MCELIECE8192128_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 1357824; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE8192128_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 208; +pub const PQCLEAN_MCELIECE8192128_AVX2_CRYPTO_CIPHERTEXTBYTES: usize = 208; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE8192128_AVX_CRYPTO_BYTES: usize = 32; +pub const PQCLEAN_MCELIECE8192128_AVX2_CRYPTO_BYTES: usize = 32; pub const PQCLEAN_MCELIECE8192128F_CLEAN_CRYPTO_SECRETKEYBYTES: usize = 14120; pub const PQCLEAN_MCELIECE8192128F_CLEAN_CRYPTO_PUBLICKEYBYTES: usize = 1357824; @@ -153,13 +153,13 @@ pub const PQCLEAN_MCELIECE8192128F_CLEAN_CRYPTO_CIPHERTEXTBYTES: usize = 208; pub const PQCLEAN_MCELIECE8192128F_CLEAN_CRYPTO_BYTES: usize = 32; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE8192128F_AVX_CRYPTO_SECRETKEYBYTES: usize = 14120; +pub const PQCLEAN_MCELIECE8192128F_AVX2_CRYPTO_SECRETKEYBYTES: usize = 14120; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE8192128F_AVX_CRYPTO_PUBLICKEYBYTES: usize = 1357824; +pub const PQCLEAN_MCELIECE8192128F_AVX2_CRYPTO_PUBLICKEYBYTES: usize = 1357824; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE8192128F_AVX_CRYPTO_CIPHERTEXTBYTES: usize = 208; +pub const PQCLEAN_MCELIECE8192128F_AVX2_CRYPTO_CIPHERTEXTBYTES: usize = 208; #[cfg(enable_x86_avx2)] -pub const PQCLEAN_MCELIECE8192128F_AVX_CRYPTO_BYTES: usize = 32; +pub const PQCLEAN_MCELIECE8192128F_AVX2_CRYPTO_BYTES: usize = 32; #[link(name = "mceliece348864_clean")] extern "C" { @@ -177,18 +177,18 @@ extern "C" { } #[cfg(enable_x86_avx2)] -#[link(name = "mceliece348864_avx")] +#[link(name = "mceliece348864_avx2")] extern "C" { #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE348864_AVX_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; + pub fn PQCLEAN_MCELIECE348864_AVX2_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE348864_AVX_crypto_kem_enc( + pub fn PQCLEAN_MCELIECE348864_AVX2_crypto_kem_enc( ct: *mut u8, ss: *mut u8, pk: *const u8, ) -> c_int; #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE348864_AVX_crypto_kem_dec( + pub fn PQCLEAN_MCELIECE348864_AVX2_crypto_kem_dec( ss: *mut u8, ct: *const u8, sk: *const u8, @@ -211,18 +211,18 @@ extern "C" { } #[cfg(enable_x86_avx2)] -#[link(name = "mceliece348864f_avx")] +#[link(name = "mceliece348864f_avx2")] extern "C" { #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE348864F_AVX_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; + pub fn PQCLEAN_MCELIECE348864F_AVX2_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE348864F_AVX_crypto_kem_enc( + pub fn PQCLEAN_MCELIECE348864F_AVX2_crypto_kem_enc( ct: *mut u8, ss: *mut u8, pk: *const u8, ) -> c_int; #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE348864F_AVX_crypto_kem_dec( + pub fn PQCLEAN_MCELIECE348864F_AVX2_crypto_kem_dec( ss: *mut u8, ct: *const u8, sk: *const u8, @@ -245,18 +245,18 @@ extern "C" { } #[cfg(enable_x86_avx2)] -#[link(name = "mceliece460896_avx")] +#[link(name = "mceliece460896_avx2")] extern "C" { #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE460896_AVX_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; + pub fn PQCLEAN_MCELIECE460896_AVX2_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE460896_AVX_crypto_kem_enc( + pub fn PQCLEAN_MCELIECE460896_AVX2_crypto_kem_enc( ct: *mut u8, ss: *mut u8, pk: *const u8, ) -> c_int; #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE460896_AVX_crypto_kem_dec( + pub fn PQCLEAN_MCELIECE460896_AVX2_crypto_kem_dec( ss: *mut u8, ct: *const u8, sk: *const u8, @@ -279,18 +279,18 @@ extern "C" { } #[cfg(enable_x86_avx2)] -#[link(name = "mceliece460896f_avx")] +#[link(name = "mceliece460896f_avx2")] extern "C" { #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE460896F_AVX_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; + pub fn PQCLEAN_MCELIECE460896F_AVX2_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE460896F_AVX_crypto_kem_enc( + pub fn PQCLEAN_MCELIECE460896F_AVX2_crypto_kem_enc( ct: *mut u8, ss: *mut u8, pk: *const u8, ) -> c_int; #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE460896F_AVX_crypto_kem_dec( + pub fn PQCLEAN_MCELIECE460896F_AVX2_crypto_kem_dec( ss: *mut u8, ct: *const u8, sk: *const u8, @@ -313,18 +313,18 @@ extern "C" { } #[cfg(enable_x86_avx2)] -#[link(name = "mceliece6688128_avx")] +#[link(name = "mceliece6688128_avx2")] extern "C" { #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE6688128_AVX_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; + pub fn PQCLEAN_MCELIECE6688128_AVX2_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE6688128_AVX_crypto_kem_enc( + pub fn PQCLEAN_MCELIECE6688128_AVX2_crypto_kem_enc( ct: *mut u8, ss: *mut u8, pk: *const u8, ) -> c_int; #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE6688128_AVX_crypto_kem_dec( + pub fn PQCLEAN_MCELIECE6688128_AVX2_crypto_kem_dec( ss: *mut u8, ct: *const u8, sk: *const u8, @@ -347,18 +347,18 @@ extern "C" { } #[cfg(enable_x86_avx2)] -#[link(name = "mceliece6688128f_avx")] +#[link(name = "mceliece6688128f_avx2")] extern "C" { #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE6688128F_AVX_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; + pub fn PQCLEAN_MCELIECE6688128F_AVX2_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE6688128F_AVX_crypto_kem_enc( + pub fn PQCLEAN_MCELIECE6688128F_AVX2_crypto_kem_enc( ct: *mut u8, ss: *mut u8, pk: *const u8, ) -> c_int; #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE6688128F_AVX_crypto_kem_dec( + pub fn PQCLEAN_MCELIECE6688128F_AVX2_crypto_kem_dec( ss: *mut u8, ct: *const u8, sk: *const u8, @@ -381,18 +381,18 @@ extern "C" { } #[cfg(enable_x86_avx2)] -#[link(name = "mceliece6960119_avx")] +#[link(name = "mceliece6960119_avx2")] extern "C" { #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE6960119_AVX_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; + pub fn PQCLEAN_MCELIECE6960119_AVX2_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE6960119_AVX_crypto_kem_enc( + pub fn PQCLEAN_MCELIECE6960119_AVX2_crypto_kem_enc( ct: *mut u8, ss: *mut u8, pk: *const u8, ) -> c_int; #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE6960119_AVX_crypto_kem_dec( + pub fn PQCLEAN_MCELIECE6960119_AVX2_crypto_kem_dec( ss: *mut u8, ct: *const u8, sk: *const u8, @@ -415,18 +415,18 @@ extern "C" { } #[cfg(enable_x86_avx2)] -#[link(name = "mceliece6960119f_avx")] +#[link(name = "mceliece6960119f_avx2")] extern "C" { #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE6960119F_AVX_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; + pub fn PQCLEAN_MCELIECE6960119F_AVX2_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE6960119F_AVX_crypto_kem_enc( + pub fn PQCLEAN_MCELIECE6960119F_AVX2_crypto_kem_enc( ct: *mut u8, ss: *mut u8, pk: *const u8, ) -> c_int; #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE6960119F_AVX_crypto_kem_dec( + pub fn PQCLEAN_MCELIECE6960119F_AVX2_crypto_kem_dec( ss: *mut u8, ct: *const u8, sk: *const u8, @@ -449,18 +449,18 @@ extern "C" { } #[cfg(enable_x86_avx2)] -#[link(name = "mceliece8192128_avx")] +#[link(name = "mceliece8192128_avx2")] extern "C" { #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE8192128_AVX_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; + pub fn PQCLEAN_MCELIECE8192128_AVX2_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE8192128_AVX_crypto_kem_enc( + pub fn PQCLEAN_MCELIECE8192128_AVX2_crypto_kem_enc( ct: *mut u8, ss: *mut u8, pk: *const u8, ) -> c_int; #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE8192128_AVX_crypto_kem_dec( + pub fn PQCLEAN_MCELIECE8192128_AVX2_crypto_kem_dec( ss: *mut u8, ct: *const u8, sk: *const u8, @@ -483,18 +483,18 @@ extern "C" { } #[cfg(enable_x86_avx2)] -#[link(name = "mceliece8192128f_avx")] +#[link(name = "mceliece8192128f_avx2")] extern "C" { #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE8192128F_AVX_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; + pub fn PQCLEAN_MCELIECE8192128F_AVX2_crypto_kem_keypair(pk: *mut u8, sk: *mut u8) -> c_int; #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE8192128F_AVX_crypto_kem_enc( + pub fn PQCLEAN_MCELIECE8192128F_AVX2_crypto_kem_enc( ct: *mut u8, ss: *mut u8, pk: *const u8, ) -> c_int; #[cfg(enable_x86_avx2)] - pub fn PQCLEAN_MCELIECE8192128F_AVX_crypto_kem_dec( + pub fn PQCLEAN_MCELIECE8192128F_AVX2_crypto_kem_dec( ss: *mut u8, ct: *const u8, sk: *const u8, @@ -541,7 +541,7 @@ mod test_mceliece348864_clean { } #[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_mceliece348864_avx { +mod test_mceliece348864_avx2 { use super::*; use alloc::vec; use std::is_x86_feature_detected; @@ -552,19 +552,19 @@ mod test_mceliece348864_avx { return; } unsafe { - let mut pk = vec![0u8; PQCLEAN_MCELIECE348864_AVX_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_MCELIECE348864_AVX_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_MCELIECE348864_AVX_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_MCELIECE348864_AVX_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_MCELIECE348864_AVX_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_MCELIECE348864_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_MCELIECE348864_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut ct = vec![0u8; PQCLEAN_MCELIECE348864_AVX2_CRYPTO_CIPHERTEXTBYTES]; + let mut ss1 = vec![0u8; PQCLEAN_MCELIECE348864_AVX2_CRYPTO_BYTES]; + let mut ss2 = vec![0u8; PQCLEAN_MCELIECE348864_AVX2_CRYPTO_BYTES]; assert_eq!( 0, - PQCLEAN_MCELIECE348864_AVX_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) + PQCLEAN_MCELIECE348864_AVX2_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) ); assert_eq!( 0, - PQCLEAN_MCELIECE348864_AVX_crypto_kem_enc( + PQCLEAN_MCELIECE348864_AVX2_crypto_kem_enc( ct.as_mut_ptr(), ss1.as_mut_ptr(), pk.as_ptr() @@ -572,7 +572,7 @@ mod test_mceliece348864_avx { ); assert_eq!( 0, - PQCLEAN_MCELIECE348864_AVX_crypto_kem_dec( + PQCLEAN_MCELIECE348864_AVX2_crypto_kem_dec( ss2.as_mut_ptr(), ct.as_ptr(), sk.as_ptr() @@ -623,7 +623,7 @@ mod test_mceliece348864f_clean { } #[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_mceliece348864f_avx { +mod test_mceliece348864f_avx2 { use super::*; use alloc::vec; use std::is_x86_feature_detected; @@ -634,19 +634,19 @@ mod test_mceliece348864f_avx { return; } unsafe { - let mut pk = vec![0u8; PQCLEAN_MCELIECE348864F_AVX_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_MCELIECE348864F_AVX_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_MCELIECE348864F_AVX_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_MCELIECE348864F_AVX_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_MCELIECE348864F_AVX_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_MCELIECE348864F_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_MCELIECE348864F_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut ct = vec![0u8; PQCLEAN_MCELIECE348864F_AVX2_CRYPTO_CIPHERTEXTBYTES]; + let mut ss1 = vec![0u8; PQCLEAN_MCELIECE348864F_AVX2_CRYPTO_BYTES]; + let mut ss2 = vec![0u8; PQCLEAN_MCELIECE348864F_AVX2_CRYPTO_BYTES]; assert_eq!( 0, - PQCLEAN_MCELIECE348864F_AVX_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) + PQCLEAN_MCELIECE348864F_AVX2_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) ); assert_eq!( 0, - PQCLEAN_MCELIECE348864F_AVX_crypto_kem_enc( + PQCLEAN_MCELIECE348864F_AVX2_crypto_kem_enc( ct.as_mut_ptr(), ss1.as_mut_ptr(), pk.as_ptr() @@ -654,7 +654,7 @@ mod test_mceliece348864f_avx { ); assert_eq!( 0, - PQCLEAN_MCELIECE348864F_AVX_crypto_kem_dec( + PQCLEAN_MCELIECE348864F_AVX2_crypto_kem_dec( ss2.as_mut_ptr(), ct.as_ptr(), sk.as_ptr() @@ -705,7 +705,7 @@ mod test_mceliece460896_clean { } #[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_mceliece460896_avx { +mod test_mceliece460896_avx2 { use super::*; use alloc::vec; use std::is_x86_feature_detected; @@ -716,19 +716,19 @@ mod test_mceliece460896_avx { return; } unsafe { - let mut pk = vec![0u8; PQCLEAN_MCELIECE460896_AVX_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_MCELIECE460896_AVX_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_MCELIECE460896_AVX_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_MCELIECE460896_AVX_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_MCELIECE460896_AVX_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_MCELIECE460896_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_MCELIECE460896_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut ct = vec![0u8; PQCLEAN_MCELIECE460896_AVX2_CRYPTO_CIPHERTEXTBYTES]; + let mut ss1 = vec![0u8; PQCLEAN_MCELIECE460896_AVX2_CRYPTO_BYTES]; + let mut ss2 = vec![0u8; PQCLEAN_MCELIECE460896_AVX2_CRYPTO_BYTES]; assert_eq!( 0, - PQCLEAN_MCELIECE460896_AVX_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) + PQCLEAN_MCELIECE460896_AVX2_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) ); assert_eq!( 0, - PQCLEAN_MCELIECE460896_AVX_crypto_kem_enc( + PQCLEAN_MCELIECE460896_AVX2_crypto_kem_enc( ct.as_mut_ptr(), ss1.as_mut_ptr(), pk.as_ptr() @@ -736,7 +736,7 @@ mod test_mceliece460896_avx { ); assert_eq!( 0, - PQCLEAN_MCELIECE460896_AVX_crypto_kem_dec( + PQCLEAN_MCELIECE460896_AVX2_crypto_kem_dec( ss2.as_mut_ptr(), ct.as_ptr(), sk.as_ptr() @@ -787,7 +787,7 @@ mod test_mceliece460896f_clean { } #[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_mceliece460896f_avx { +mod test_mceliece460896f_avx2 { use super::*; use alloc::vec; use std::is_x86_feature_detected; @@ -798,19 +798,19 @@ mod test_mceliece460896f_avx { return; } unsafe { - let mut pk = vec![0u8; PQCLEAN_MCELIECE460896F_AVX_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_MCELIECE460896F_AVX_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_MCELIECE460896F_AVX_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_MCELIECE460896F_AVX_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_MCELIECE460896F_AVX_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_MCELIECE460896F_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_MCELIECE460896F_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut ct = vec![0u8; PQCLEAN_MCELIECE460896F_AVX2_CRYPTO_CIPHERTEXTBYTES]; + let mut ss1 = vec![0u8; PQCLEAN_MCELIECE460896F_AVX2_CRYPTO_BYTES]; + let mut ss2 = vec![0u8; PQCLEAN_MCELIECE460896F_AVX2_CRYPTO_BYTES]; assert_eq!( 0, - PQCLEAN_MCELIECE460896F_AVX_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) + PQCLEAN_MCELIECE460896F_AVX2_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) ); assert_eq!( 0, - PQCLEAN_MCELIECE460896F_AVX_crypto_kem_enc( + PQCLEAN_MCELIECE460896F_AVX2_crypto_kem_enc( ct.as_mut_ptr(), ss1.as_mut_ptr(), pk.as_ptr() @@ -818,7 +818,7 @@ mod test_mceliece460896f_avx { ); assert_eq!( 0, - PQCLEAN_MCELIECE460896F_AVX_crypto_kem_dec( + PQCLEAN_MCELIECE460896F_AVX2_crypto_kem_dec( ss2.as_mut_ptr(), ct.as_ptr(), sk.as_ptr() @@ -869,7 +869,7 @@ mod test_mceliece6688128_clean { } #[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_mceliece6688128_avx { +mod test_mceliece6688128_avx2 { use super::*; use alloc::vec; use std::is_x86_feature_detected; @@ -880,19 +880,19 @@ mod test_mceliece6688128_avx { return; } unsafe { - let mut pk = vec![0u8; PQCLEAN_MCELIECE6688128_AVX_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_MCELIECE6688128_AVX_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_MCELIECE6688128_AVX_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_MCELIECE6688128_AVX_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_MCELIECE6688128_AVX_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_MCELIECE6688128_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_MCELIECE6688128_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut ct = vec![0u8; PQCLEAN_MCELIECE6688128_AVX2_CRYPTO_CIPHERTEXTBYTES]; + let mut ss1 = vec![0u8; PQCLEAN_MCELIECE6688128_AVX2_CRYPTO_BYTES]; + let mut ss2 = vec![0u8; PQCLEAN_MCELIECE6688128_AVX2_CRYPTO_BYTES]; assert_eq!( 0, - PQCLEAN_MCELIECE6688128_AVX_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) + PQCLEAN_MCELIECE6688128_AVX2_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) ); assert_eq!( 0, - PQCLEAN_MCELIECE6688128_AVX_crypto_kem_enc( + PQCLEAN_MCELIECE6688128_AVX2_crypto_kem_enc( ct.as_mut_ptr(), ss1.as_mut_ptr(), pk.as_ptr() @@ -900,7 +900,7 @@ mod test_mceliece6688128_avx { ); assert_eq!( 0, - PQCLEAN_MCELIECE6688128_AVX_crypto_kem_dec( + PQCLEAN_MCELIECE6688128_AVX2_crypto_kem_dec( ss2.as_mut_ptr(), ct.as_ptr(), sk.as_ptr() @@ -951,7 +951,7 @@ mod test_mceliece6688128f_clean { } #[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_mceliece6688128f_avx { +mod test_mceliece6688128f_avx2 { use super::*; use alloc::vec; use std::is_x86_feature_detected; @@ -962,19 +962,19 @@ mod test_mceliece6688128f_avx { return; } unsafe { - let mut pk = vec![0u8; PQCLEAN_MCELIECE6688128F_AVX_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_MCELIECE6688128F_AVX_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_MCELIECE6688128F_AVX_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_MCELIECE6688128F_AVX_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_MCELIECE6688128F_AVX_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_MCELIECE6688128F_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_MCELIECE6688128F_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut ct = vec![0u8; PQCLEAN_MCELIECE6688128F_AVX2_CRYPTO_CIPHERTEXTBYTES]; + let mut ss1 = vec![0u8; PQCLEAN_MCELIECE6688128F_AVX2_CRYPTO_BYTES]; + let mut ss2 = vec![0u8; PQCLEAN_MCELIECE6688128F_AVX2_CRYPTO_BYTES]; assert_eq!( 0, - PQCLEAN_MCELIECE6688128F_AVX_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) + PQCLEAN_MCELIECE6688128F_AVX2_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) ); assert_eq!( 0, - PQCLEAN_MCELIECE6688128F_AVX_crypto_kem_enc( + PQCLEAN_MCELIECE6688128F_AVX2_crypto_kem_enc( ct.as_mut_ptr(), ss1.as_mut_ptr(), pk.as_ptr() @@ -982,7 +982,7 @@ mod test_mceliece6688128f_avx { ); assert_eq!( 0, - PQCLEAN_MCELIECE6688128F_AVX_crypto_kem_dec( + PQCLEAN_MCELIECE6688128F_AVX2_crypto_kem_dec( ss2.as_mut_ptr(), ct.as_ptr(), sk.as_ptr() @@ -1033,7 +1033,7 @@ mod test_mceliece6960119_clean { } #[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_mceliece6960119_avx { +mod test_mceliece6960119_avx2 { use super::*; use alloc::vec; use std::is_x86_feature_detected; @@ -1044,19 +1044,19 @@ mod test_mceliece6960119_avx { return; } unsafe { - let mut pk = vec![0u8; PQCLEAN_MCELIECE6960119_AVX_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_MCELIECE6960119_AVX_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_MCELIECE6960119_AVX_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_MCELIECE6960119_AVX_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_MCELIECE6960119_AVX_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_MCELIECE6960119_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_MCELIECE6960119_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut ct = vec![0u8; PQCLEAN_MCELIECE6960119_AVX2_CRYPTO_CIPHERTEXTBYTES]; + let mut ss1 = vec![0u8; PQCLEAN_MCELIECE6960119_AVX2_CRYPTO_BYTES]; + let mut ss2 = vec![0u8; PQCLEAN_MCELIECE6960119_AVX2_CRYPTO_BYTES]; assert_eq!( 0, - PQCLEAN_MCELIECE6960119_AVX_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) + PQCLEAN_MCELIECE6960119_AVX2_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) ); assert_eq!( 0, - PQCLEAN_MCELIECE6960119_AVX_crypto_kem_enc( + PQCLEAN_MCELIECE6960119_AVX2_crypto_kem_enc( ct.as_mut_ptr(), ss1.as_mut_ptr(), pk.as_ptr() @@ -1064,7 +1064,7 @@ mod test_mceliece6960119_avx { ); assert_eq!( 0, - PQCLEAN_MCELIECE6960119_AVX_crypto_kem_dec( + PQCLEAN_MCELIECE6960119_AVX2_crypto_kem_dec( ss2.as_mut_ptr(), ct.as_ptr(), sk.as_ptr() @@ -1115,7 +1115,7 @@ mod test_mceliece6960119f_clean { } #[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_mceliece6960119f_avx { +mod test_mceliece6960119f_avx2 { use super::*; use alloc::vec; use std::is_x86_feature_detected; @@ -1126,19 +1126,19 @@ mod test_mceliece6960119f_avx { return; } unsafe { - let mut pk = vec![0u8; PQCLEAN_MCELIECE6960119F_AVX_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_MCELIECE6960119F_AVX_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_MCELIECE6960119F_AVX_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_MCELIECE6960119F_AVX_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_MCELIECE6960119F_AVX_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_MCELIECE6960119F_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_MCELIECE6960119F_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut ct = vec![0u8; PQCLEAN_MCELIECE6960119F_AVX2_CRYPTO_CIPHERTEXTBYTES]; + let mut ss1 = vec![0u8; PQCLEAN_MCELIECE6960119F_AVX2_CRYPTO_BYTES]; + let mut ss2 = vec![0u8; PQCLEAN_MCELIECE6960119F_AVX2_CRYPTO_BYTES]; assert_eq!( 0, - PQCLEAN_MCELIECE6960119F_AVX_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) + PQCLEAN_MCELIECE6960119F_AVX2_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) ); assert_eq!( 0, - PQCLEAN_MCELIECE6960119F_AVX_crypto_kem_enc( + PQCLEAN_MCELIECE6960119F_AVX2_crypto_kem_enc( ct.as_mut_ptr(), ss1.as_mut_ptr(), pk.as_ptr() @@ -1146,7 +1146,7 @@ mod test_mceliece6960119f_avx { ); assert_eq!( 0, - PQCLEAN_MCELIECE6960119F_AVX_crypto_kem_dec( + PQCLEAN_MCELIECE6960119F_AVX2_crypto_kem_dec( ss2.as_mut_ptr(), ct.as_ptr(), sk.as_ptr() @@ -1197,7 +1197,7 @@ mod test_mceliece8192128_clean { } #[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_mceliece8192128_avx { +mod test_mceliece8192128_avx2 { use super::*; use alloc::vec; use std::is_x86_feature_detected; @@ -1208,19 +1208,19 @@ mod test_mceliece8192128_avx { return; } unsafe { - let mut pk = vec![0u8; PQCLEAN_MCELIECE8192128_AVX_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_MCELIECE8192128_AVX_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_MCELIECE8192128_AVX_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_MCELIECE8192128_AVX_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_MCELIECE8192128_AVX_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_MCELIECE8192128_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_MCELIECE8192128_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut ct = vec![0u8; PQCLEAN_MCELIECE8192128_AVX2_CRYPTO_CIPHERTEXTBYTES]; + let mut ss1 = vec![0u8; PQCLEAN_MCELIECE8192128_AVX2_CRYPTO_BYTES]; + let mut ss2 = vec![0u8; PQCLEAN_MCELIECE8192128_AVX2_CRYPTO_BYTES]; assert_eq!( 0, - PQCLEAN_MCELIECE8192128_AVX_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) + PQCLEAN_MCELIECE8192128_AVX2_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) ); assert_eq!( 0, - PQCLEAN_MCELIECE8192128_AVX_crypto_kem_enc( + PQCLEAN_MCELIECE8192128_AVX2_crypto_kem_enc( ct.as_mut_ptr(), ss1.as_mut_ptr(), pk.as_ptr() @@ -1228,7 +1228,7 @@ mod test_mceliece8192128_avx { ); assert_eq!( 0, - PQCLEAN_MCELIECE8192128_AVX_crypto_kem_dec( + PQCLEAN_MCELIECE8192128_AVX2_crypto_kem_dec( ss2.as_mut_ptr(), ct.as_ptr(), sk.as_ptr() @@ -1279,7 +1279,7 @@ mod test_mceliece8192128f_clean { } #[cfg(all(test, enable_x86_avx2, feature = "avx2"))] -mod test_mceliece8192128f_avx { +mod test_mceliece8192128f_avx2 { use super::*; use alloc::vec; use std::is_x86_feature_detected; @@ -1290,19 +1290,19 @@ mod test_mceliece8192128f_avx { return; } unsafe { - let mut pk = vec![0u8; PQCLEAN_MCELIECE8192128F_AVX_CRYPTO_PUBLICKEYBYTES]; - let mut sk = vec![0u8; PQCLEAN_MCELIECE8192128F_AVX_CRYPTO_SECRETKEYBYTES]; - let mut ct = vec![0u8; PQCLEAN_MCELIECE8192128F_AVX_CRYPTO_CIPHERTEXTBYTES]; - let mut ss1 = vec![0u8; PQCLEAN_MCELIECE8192128F_AVX_CRYPTO_BYTES]; - let mut ss2 = vec![0u8; PQCLEAN_MCELIECE8192128F_AVX_CRYPTO_BYTES]; + let mut pk = vec![0u8; PQCLEAN_MCELIECE8192128F_AVX2_CRYPTO_PUBLICKEYBYTES]; + let mut sk = vec![0u8; PQCLEAN_MCELIECE8192128F_AVX2_CRYPTO_SECRETKEYBYTES]; + let mut ct = vec![0u8; PQCLEAN_MCELIECE8192128F_AVX2_CRYPTO_CIPHERTEXTBYTES]; + let mut ss1 = vec![0u8; PQCLEAN_MCELIECE8192128F_AVX2_CRYPTO_BYTES]; + let mut ss2 = vec![0u8; PQCLEAN_MCELIECE8192128F_AVX2_CRYPTO_BYTES]; assert_eq!( 0, - PQCLEAN_MCELIECE8192128F_AVX_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) + PQCLEAN_MCELIECE8192128F_AVX2_crypto_kem_keypair(pk.as_mut_ptr(), sk.as_mut_ptr()) ); assert_eq!( 0, - PQCLEAN_MCELIECE8192128F_AVX_crypto_kem_enc( + PQCLEAN_MCELIECE8192128F_AVX2_crypto_kem_enc( ct.as_mut_ptr(), ss1.as_mut_ptr(), pk.as_ptr() @@ -1310,7 +1310,7 @@ mod test_mceliece8192128f_avx { ); assert_eq!( 0, - PQCLEAN_MCELIECE8192128F_AVX_crypto_kem_dec( + PQCLEAN_MCELIECE8192128F_AVX2_crypto_kem_dec( ss2.as_mut_ptr(), ct.as_ptr(), sk.as_ptr() diff --git a/pqcrypto-classicmceliece/src/mceliece348864.rs b/pqcrypto-classicmceliece/src/mceliece348864.rs index b9eb6c51..bb24e41a 100644 --- a/pqcrypto-classicmceliece/src/mceliece348864.rs +++ b/pqcrypto-classicmceliece/src/mceliece348864.rs @@ -133,7 +133,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_MCELIECE348864_AVX_crypto_kem_keypair); + return gen_keypair!(PQCLEAN_MCELIECE348864_AVX2_crypto_kem_keypair); } } gen_keypair!(PQCLEAN_MCELIECE348864_CLEAN_crypto_kem_keypair) @@ -156,7 +156,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return encap!(PQCLEAN_MCELIECE348864_AVX_crypto_kem_enc, pk); + return encap!(PQCLEAN_MCELIECE348864_AVX2_crypto_kem_enc, pk); } } encap!(PQCLEAN_MCELIECE348864_CLEAN_crypto_kem_enc, pk) @@ -178,7 +178,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return decap!(PQCLEAN_MCELIECE348864_AVX_crypto_kem_dec, ct, sk); + return decap!(PQCLEAN_MCELIECE348864_AVX2_crypto_kem_dec, ct, sk); } } decap!(PQCLEAN_MCELIECE348864_CLEAN_crypto_kem_dec, ct, sk) diff --git a/pqcrypto-classicmceliece/src/mceliece348864f.rs b/pqcrypto-classicmceliece/src/mceliece348864f.rs index 801e74de..56b463da 100644 --- a/pqcrypto-classicmceliece/src/mceliece348864f.rs +++ b/pqcrypto-classicmceliece/src/mceliece348864f.rs @@ -136,7 +136,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_MCELIECE348864F_AVX_crypto_kem_keypair); + return gen_keypair!(PQCLEAN_MCELIECE348864F_AVX2_crypto_kem_keypair); } } gen_keypair!(PQCLEAN_MCELIECE348864F_CLEAN_crypto_kem_keypair) @@ -159,7 +159,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return encap!(PQCLEAN_MCELIECE348864F_AVX_crypto_kem_enc, pk); + return encap!(PQCLEAN_MCELIECE348864F_AVX2_crypto_kem_enc, pk); } } encap!(PQCLEAN_MCELIECE348864F_CLEAN_crypto_kem_enc, pk) @@ -181,7 +181,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return decap!(PQCLEAN_MCELIECE348864F_AVX_crypto_kem_dec, ct, sk); + return decap!(PQCLEAN_MCELIECE348864F_AVX2_crypto_kem_dec, ct, sk); } } decap!(PQCLEAN_MCELIECE348864F_CLEAN_crypto_kem_dec, ct, sk) diff --git a/pqcrypto-classicmceliece/src/mceliece460896.rs b/pqcrypto-classicmceliece/src/mceliece460896.rs index 8db83632..09e038d8 100644 --- a/pqcrypto-classicmceliece/src/mceliece460896.rs +++ b/pqcrypto-classicmceliece/src/mceliece460896.rs @@ -133,7 +133,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_MCELIECE460896_AVX_crypto_kem_keypair); + return gen_keypair!(PQCLEAN_MCELIECE460896_AVX2_crypto_kem_keypair); } } gen_keypair!(PQCLEAN_MCELIECE460896_CLEAN_crypto_kem_keypair) @@ -156,7 +156,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return encap!(PQCLEAN_MCELIECE460896_AVX_crypto_kem_enc, pk); + return encap!(PQCLEAN_MCELIECE460896_AVX2_crypto_kem_enc, pk); } } encap!(PQCLEAN_MCELIECE460896_CLEAN_crypto_kem_enc, pk) @@ -178,7 +178,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return decap!(PQCLEAN_MCELIECE460896_AVX_crypto_kem_dec, ct, sk); + return decap!(PQCLEAN_MCELIECE460896_AVX2_crypto_kem_dec, ct, sk); } } decap!(PQCLEAN_MCELIECE460896_CLEAN_crypto_kem_dec, ct, sk) diff --git a/pqcrypto-classicmceliece/src/mceliece460896f.rs b/pqcrypto-classicmceliece/src/mceliece460896f.rs index dbce7bc4..7bb9a28b 100644 --- a/pqcrypto-classicmceliece/src/mceliece460896f.rs +++ b/pqcrypto-classicmceliece/src/mceliece460896f.rs @@ -136,7 +136,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_MCELIECE460896F_AVX_crypto_kem_keypair); + return gen_keypair!(PQCLEAN_MCELIECE460896F_AVX2_crypto_kem_keypair); } } gen_keypair!(PQCLEAN_MCELIECE460896F_CLEAN_crypto_kem_keypair) @@ -159,7 +159,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return encap!(PQCLEAN_MCELIECE460896F_AVX_crypto_kem_enc, pk); + return encap!(PQCLEAN_MCELIECE460896F_AVX2_crypto_kem_enc, pk); } } encap!(PQCLEAN_MCELIECE460896F_CLEAN_crypto_kem_enc, pk) @@ -181,7 +181,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return decap!(PQCLEAN_MCELIECE460896F_AVX_crypto_kem_dec, ct, sk); + return decap!(PQCLEAN_MCELIECE460896F_AVX2_crypto_kem_dec, ct, sk); } } decap!(PQCLEAN_MCELIECE460896F_CLEAN_crypto_kem_dec, ct, sk) diff --git a/pqcrypto-classicmceliece/src/mceliece6688128.rs b/pqcrypto-classicmceliece/src/mceliece6688128.rs index bd462e2f..673aabd5 100644 --- a/pqcrypto-classicmceliece/src/mceliece6688128.rs +++ b/pqcrypto-classicmceliece/src/mceliece6688128.rs @@ -136,7 +136,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_MCELIECE6688128_AVX_crypto_kem_keypair); + return gen_keypair!(PQCLEAN_MCELIECE6688128_AVX2_crypto_kem_keypair); } } gen_keypair!(PQCLEAN_MCELIECE6688128_CLEAN_crypto_kem_keypair) @@ -159,7 +159,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return encap!(PQCLEAN_MCELIECE6688128_AVX_crypto_kem_enc, pk); + return encap!(PQCLEAN_MCELIECE6688128_AVX2_crypto_kem_enc, pk); } } encap!(PQCLEAN_MCELIECE6688128_CLEAN_crypto_kem_enc, pk) @@ -181,7 +181,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return decap!(PQCLEAN_MCELIECE6688128_AVX_crypto_kem_dec, ct, sk); + return decap!(PQCLEAN_MCELIECE6688128_AVX2_crypto_kem_dec, ct, sk); } } decap!(PQCLEAN_MCELIECE6688128_CLEAN_crypto_kem_dec, ct, sk) diff --git a/pqcrypto-classicmceliece/src/mceliece6688128f.rs b/pqcrypto-classicmceliece/src/mceliece6688128f.rs index 2b177871..ffbffcdd 100644 --- a/pqcrypto-classicmceliece/src/mceliece6688128f.rs +++ b/pqcrypto-classicmceliece/src/mceliece6688128f.rs @@ -136,7 +136,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_MCELIECE6688128F_AVX_crypto_kem_keypair); + return gen_keypair!(PQCLEAN_MCELIECE6688128F_AVX2_crypto_kem_keypair); } } gen_keypair!(PQCLEAN_MCELIECE6688128F_CLEAN_crypto_kem_keypair) @@ -159,7 +159,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return encap!(PQCLEAN_MCELIECE6688128F_AVX_crypto_kem_enc, pk); + return encap!(PQCLEAN_MCELIECE6688128F_AVX2_crypto_kem_enc, pk); } } encap!(PQCLEAN_MCELIECE6688128F_CLEAN_crypto_kem_enc, pk) @@ -181,7 +181,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return decap!(PQCLEAN_MCELIECE6688128F_AVX_crypto_kem_dec, ct, sk); + return decap!(PQCLEAN_MCELIECE6688128F_AVX2_crypto_kem_dec, ct, sk); } } decap!(PQCLEAN_MCELIECE6688128F_CLEAN_crypto_kem_dec, ct, sk) diff --git a/pqcrypto-classicmceliece/src/mceliece6960119.rs b/pqcrypto-classicmceliece/src/mceliece6960119.rs index e605e58e..83a3c996 100644 --- a/pqcrypto-classicmceliece/src/mceliece6960119.rs +++ b/pqcrypto-classicmceliece/src/mceliece6960119.rs @@ -136,7 +136,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_MCELIECE6960119_AVX_crypto_kem_keypair); + return gen_keypair!(PQCLEAN_MCELIECE6960119_AVX2_crypto_kem_keypair); } } gen_keypair!(PQCLEAN_MCELIECE6960119_CLEAN_crypto_kem_keypair) @@ -159,7 +159,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return encap!(PQCLEAN_MCELIECE6960119_AVX_crypto_kem_enc, pk); + return encap!(PQCLEAN_MCELIECE6960119_AVX2_crypto_kem_enc, pk); } } encap!(PQCLEAN_MCELIECE6960119_CLEAN_crypto_kem_enc, pk) @@ -181,7 +181,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return decap!(PQCLEAN_MCELIECE6960119_AVX_crypto_kem_dec, ct, sk); + return decap!(PQCLEAN_MCELIECE6960119_AVX2_crypto_kem_dec, ct, sk); } } decap!(PQCLEAN_MCELIECE6960119_CLEAN_crypto_kem_dec, ct, sk) diff --git a/pqcrypto-classicmceliece/src/mceliece6960119f.rs b/pqcrypto-classicmceliece/src/mceliece6960119f.rs index 5cd3e186..8f1e7207 100644 --- a/pqcrypto-classicmceliece/src/mceliece6960119f.rs +++ b/pqcrypto-classicmceliece/src/mceliece6960119f.rs @@ -136,7 +136,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_MCELIECE6960119F_AVX_crypto_kem_keypair); + return gen_keypair!(PQCLEAN_MCELIECE6960119F_AVX2_crypto_kem_keypair); } } gen_keypair!(PQCLEAN_MCELIECE6960119F_CLEAN_crypto_kem_keypair) @@ -159,7 +159,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return encap!(PQCLEAN_MCELIECE6960119F_AVX_crypto_kem_enc, pk); + return encap!(PQCLEAN_MCELIECE6960119F_AVX2_crypto_kem_enc, pk); } } encap!(PQCLEAN_MCELIECE6960119F_CLEAN_crypto_kem_enc, pk) @@ -181,7 +181,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return decap!(PQCLEAN_MCELIECE6960119F_AVX_crypto_kem_dec, ct, sk); + return decap!(PQCLEAN_MCELIECE6960119F_AVX2_crypto_kem_dec, ct, sk); } } decap!(PQCLEAN_MCELIECE6960119F_CLEAN_crypto_kem_dec, ct, sk) diff --git a/pqcrypto-classicmceliece/src/mceliece8192128.rs b/pqcrypto-classicmceliece/src/mceliece8192128.rs index 3d53c120..6820380b 100644 --- a/pqcrypto-classicmceliece/src/mceliece8192128.rs +++ b/pqcrypto-classicmceliece/src/mceliece8192128.rs @@ -136,7 +136,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_MCELIECE8192128_AVX_crypto_kem_keypair); + return gen_keypair!(PQCLEAN_MCELIECE8192128_AVX2_crypto_kem_keypair); } } gen_keypair!(PQCLEAN_MCELIECE8192128_CLEAN_crypto_kem_keypair) @@ -159,7 +159,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return encap!(PQCLEAN_MCELIECE8192128_AVX_crypto_kem_enc, pk); + return encap!(PQCLEAN_MCELIECE8192128_AVX2_crypto_kem_enc, pk); } } encap!(PQCLEAN_MCELIECE8192128_CLEAN_crypto_kem_enc, pk) @@ -181,7 +181,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return decap!(PQCLEAN_MCELIECE8192128_AVX_crypto_kem_dec, ct, sk); + return decap!(PQCLEAN_MCELIECE8192128_AVX2_crypto_kem_dec, ct, sk); } } decap!(PQCLEAN_MCELIECE8192128_CLEAN_crypto_kem_dec, ct, sk) diff --git a/pqcrypto-classicmceliece/src/mceliece8192128f.rs b/pqcrypto-classicmceliece/src/mceliece8192128f.rs index 23ddbe63..e247b5c0 100644 --- a/pqcrypto-classicmceliece/src/mceliece8192128f.rs +++ b/pqcrypto-classicmceliece/src/mceliece8192128f.rs @@ -136,7 +136,7 @@ pub fn keypair() -> (PublicKey, SecretKey) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return gen_keypair!(PQCLEAN_MCELIECE8192128F_AVX_crypto_kem_keypair); + return gen_keypair!(PQCLEAN_MCELIECE8192128F_AVX2_crypto_kem_keypair); } } gen_keypair!(PQCLEAN_MCELIECE8192128F_CLEAN_crypto_kem_keypair) @@ -159,7 +159,7 @@ pub fn encapsulate(pk: &PublicKey) -> (SharedSecret, Ciphertext) { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return encap!(PQCLEAN_MCELIECE8192128F_AVX_crypto_kem_enc, pk); + return encap!(PQCLEAN_MCELIECE8192128F_AVX2_crypto_kem_enc, pk); } } encap!(PQCLEAN_MCELIECE8192128F_CLEAN_crypto_kem_enc, pk) @@ -181,7 +181,7 @@ pub fn decapsulate(ct: &Ciphertext, sk: &SecretKey) -> SharedSecret { #[cfg(all(enable_x86_avx2, feature = "avx2"))] { if std::is_x86_feature_detected!("avx2") { - return decap!(PQCLEAN_MCELIECE8192128F_AVX_crypto_kem_dec, ct, sk); + return decap!(PQCLEAN_MCELIECE8192128F_AVX2_crypto_kem_dec, ct, sk); } } decap!(PQCLEAN_MCELIECE8192128F_CLEAN_crypto_kem_dec, ct, sk) diff --git a/pqcrypto-falcon/Cargo.toml b/pqcrypto-falcon/Cargo.toml index 26c0b44f..57858b26 100644 --- a/pqcrypto-falcon/Cargo.toml +++ b/pqcrypto-falcon/Cargo.toml @@ -19,8 +19,9 @@ serde = { version = "1.0", features = ["derive"], optional = true } serde-big-array = { version = "0.5.1", optional = true } [features] -default = ["avx2", "std"] +default = ["avx2", "neon", "std"] avx2 = ["std"] +neon = ["std"] std = ["pqcrypto-traits/std"] serialization = ["serde", "serde-big-array"] diff --git a/pqcrypto-falcon/build.rs b/pqcrypto-falcon/build.rs index daf10751..763f50aa 100644 --- a/pqcrypto-falcon/build.rs +++ b/pqcrypto-falcon/build.rs @@ -80,6 +80,39 @@ 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_sign", $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(); @@ -115,4 +148,8 @@ fn main() { // 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-sphincsplus/Cargo.toml b/pqcrypto-sphincsplus/Cargo.toml index c2ec3675..eef71e0d 100644 --- a/pqcrypto-sphincsplus/Cargo.toml +++ b/pqcrypto-sphincsplus/Cargo.toml @@ -19,9 +19,8 @@ serde = { version = "1.0", features = ["derive"], optional = true } serde-big-array = { version = "0.5.1", optional = true } [features] -default = ["avx2", "aes", "std"] +default = ["avx2", "std"] avx2 = ["std"] -aes = ["std"] std = ["pqcrypto-traits/std"] serialization = ["serde", "serde-big-array"] diff --git a/pqcrypto-sphincsplus/build.rs b/pqcrypto-sphincsplus/build.rs index d768de53..17530615 100644 --- a/pqcrypto-sphincsplus/build.rs +++ b/pqcrypto-sphincsplus/build.rs @@ -36,44 +36,6 @@ macro_rules! build_clean { }; } -macro_rules! build_aesni { - ($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_sign", $variant, "aesni"] - .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(); - let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap(); - if target_env == "msvc" { - builder.flag("/arch:AVX2"); - } else { - builder.flag("-maes"); - } - - 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!("{}_aesni", $variant).as_str()); - }; -} - macro_rules! build_avx2 { ($variant:expr) => { let internals_include_path = &std::env::var("DEP_PQCRYPTO_INTERNALS_INCLUDEPATH").unwrap(); @@ -187,8 +149,4 @@ fn main() { // Print enableing flag for AVX2 implementation println!("cargo:rustc-cfg=enable_x86_avx2"); } - if target_arch == "x86_64" && aes_enabled { - // Print enableing flag for AES implementation - println!("cargo:rustc-cfg=enable_x86_aes"); - } } From 28eda65b9286e8912344939264ba9ab92b0f6276 Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Mon, 16 Oct 2023 16:29:01 +0200 Subject: [PATCH 4/7] Update changelog [skip ci] --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8f9f6df..0be84a0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,12 @@ ## 2023-10-16 * Update Kyber to draft FIPS standard + * Remove 90s variants * Update Dilithium to draft FIPS standard + * Remove 90s variants * Update McEliece implementation + * Remove Vec variants +* Bring SPHINCS+ to closer to FIPS variants by removing -robust and Haraka variants * Small fix in Falcon * Add Falcon NEON implementation From f3c75309a5d692e1062dab92e7da84457554788d Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Mon, 16 Oct 2023 16:33:48 +0200 Subject: [PATCH 5/7] Small clippy fix --- pqcrypto-internals/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pqcrypto-internals/build.rs b/pqcrypto-internals/build.rs index 3b594abc..83ecf7fa 100644 --- a/pqcrypto-internals/build.rs +++ b/pqcrypto-internals/build.rs @@ -28,7 +28,7 @@ fn main() { build .include(&includepath) - .files(common_files.into_iter()) + .files(common_files) .compile("pqclean_common"); println!("cargo:rustc-link-lib=pqclean_common"); From 12edfcb5a4107677dc4f1b0ef90a8b1f3f6caacd Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Mon, 16 Oct 2023 16:35:53 +0200 Subject: [PATCH 6/7] Fix examples --- pqcrypto-template/pqcrypto/examples/keygen.rs | 2 +- pqcrypto-template/pqcrypto/examples/signer.rs | 2 +- pqcrypto-template/pqcrypto/examples/verifier.rs | 2 +- pqcrypto/examples/keygen.rs | 2 +- pqcrypto/examples/signer.rs | 2 +- pqcrypto/examples/verifier.rs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pqcrypto-template/pqcrypto/examples/keygen.rs b/pqcrypto-template/pqcrypto/examples/keygen.rs index d1cc82ee..39582219 100644 --- a/pqcrypto-template/pqcrypto/examples/keygen.rs +++ b/pqcrypto-template/pqcrypto/examples/keygen.rs @@ -2,7 +2,7 @@ use std::fs::File; use std::io::prelude::*; use pqcrypto::prelude::*; -use pqcrypto::sign::sphincsharaka128frobust::*; +use pqcrypto::sign::dilithium2::*; fn main() -> std::io::Result<()> { diff --git a/pqcrypto-template/pqcrypto/examples/signer.rs b/pqcrypto-template/pqcrypto/examples/signer.rs index 0d388732..574c01bf 100644 --- a/pqcrypto-template/pqcrypto/examples/signer.rs +++ b/pqcrypto-template/pqcrypto/examples/signer.rs @@ -2,7 +2,7 @@ use std::fs::{self, File}; use std::io::prelude::*; use pqcrypto::prelude::*; -use pqcrypto::sign::sphincsharaka128frobust::*; +use pqcrypto::sign::dilithium2::*; fn parseargs() -> (String, String, String) { let args: Vec = std::env::args().collect(); diff --git a/pqcrypto-template/pqcrypto/examples/verifier.rs b/pqcrypto-template/pqcrypto/examples/verifier.rs index a4631645..08444b80 100644 --- a/pqcrypto-template/pqcrypto/examples/verifier.rs +++ b/pqcrypto-template/pqcrypto/examples/verifier.rs @@ -1,7 +1,7 @@ use std::fs; use pqcrypto::prelude::*; -use pqcrypto::sign::sphincsharaka128frobust::*; +use pqcrypto::sign::dilithium2::*; fn parseargs() -> (String, String, String) { let args: Vec = std::env::args().collect(); diff --git a/pqcrypto/examples/keygen.rs b/pqcrypto/examples/keygen.rs index 94f8c3cb..486b28ba 100644 --- a/pqcrypto/examples/keygen.rs +++ b/pqcrypto/examples/keygen.rs @@ -2,7 +2,7 @@ use std::fs::File; use std::io::prelude::*; use pqcrypto::prelude::*; -use pqcrypto::sign::sphincsharaka128frobust::*; +use pqcrypto::sign::dilithium2::*; fn main() -> std::io::Result<()> { let mut pubfile = File::create("publickey.bin")?; diff --git a/pqcrypto/examples/signer.rs b/pqcrypto/examples/signer.rs index b3e2422d..2d06302d 100644 --- a/pqcrypto/examples/signer.rs +++ b/pqcrypto/examples/signer.rs @@ -2,7 +2,7 @@ use std::fs::{self, File}; use std::io::prelude::*; use pqcrypto::prelude::*; -use pqcrypto::sign::sphincsharaka128frobust::*; +use pqcrypto::sign::dilithium2::*; fn parseargs() -> (String, String, String) { let args: Vec = std::env::args().collect(); diff --git a/pqcrypto/examples/verifier.rs b/pqcrypto/examples/verifier.rs index a4631645..08444b80 100644 --- a/pqcrypto/examples/verifier.rs +++ b/pqcrypto/examples/verifier.rs @@ -1,7 +1,7 @@ use std::fs; use pqcrypto::prelude::*; -use pqcrypto::sign::sphincsharaka128frobust::*; +use pqcrypto::sign::dilithium2::*; fn parseargs() -> (String, String, String) { let args: Vec = std::env::args().collect(); From 80d389d88754b6accef031ef226c7deb5e4e3c5e Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Mon, 16 Oct 2023 16:37:55 +0200 Subject: [PATCH 7/7] update rust edition --- CHANGELOG.md | 1 + Cargo.toml | 3 ++- pqcrypto-classicmceliece/Cargo.toml | 2 +- pqcrypto-dilithium/Cargo.toml | 2 +- pqcrypto-falcon/Cargo.toml | 2 +- pqcrypto-hqc/Cargo.toml | 2 +- pqcrypto-kyber/Cargo.toml | 2 +- pqcrypto-sphincsplus/Cargo.toml | 2 +- pqcrypto-template/scheme/Cargo.toml.j2 | 2 +- pqcrypto-template/workspace-Cargo.toml.j2 | 1 + 10 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0be84a0b..e39c273c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * Bring SPHINCS+ to closer to FIPS variants by removing -robust and Haraka variants * Small fix in Falcon * Add Falcon NEON implementation +* Update Rust edition to 2021 ## 2023-04-26 diff --git a/Cargo.toml b/Cargo.toml index b1af8d83..2e0565c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,5 @@ members=[ "pqcrypto-dilithium", "pqcrypto-falcon", "pqcrypto-sphincsplus", -] \ No newline at end of file +] +resolver="2" \ No newline at end of file diff --git a/pqcrypto-classicmceliece/Cargo.toml b/pqcrypto-classicmceliece/Cargo.toml index 912afee8..3b8eee8c 100644 --- a/pqcrypto-classicmceliece/Cargo.toml +++ b/pqcrypto-classicmceliece/Cargo.toml @@ -4,7 +4,7 @@ description = "Post-Quantum Key-Encapsulation Mechanism classicmceliece" readme = "README.md" version = "0.2.0" authors = ["Thom Wiggers "] -edition = "2018" +edition = "2021" license = "MIT OR Apache-2.0" homepage = "https://github.com/rustpq/" repository = "https://github.com/rustpq/pqcrypto/" diff --git a/pqcrypto-dilithium/Cargo.toml b/pqcrypto-dilithium/Cargo.toml index a96cb2d8..835d2e40 100644 --- a/pqcrypto-dilithium/Cargo.toml +++ b/pqcrypto-dilithium/Cargo.toml @@ -4,7 +4,7 @@ description = "Post-Quantum Signature Scheme dilithium" readme = "README.md" version = "0.5.0" authors = ["Thom Wiggers "] -edition = "2018" +edition = "2021" license = "MIT OR Apache-2.0" homepage = "https://github.com/rustpq/" repository = "https://github.com/rustpq/pqcrypto/" diff --git a/pqcrypto-falcon/Cargo.toml b/pqcrypto-falcon/Cargo.toml index 57858b26..269d16d5 100644 --- a/pqcrypto-falcon/Cargo.toml +++ b/pqcrypto-falcon/Cargo.toml @@ -4,7 +4,7 @@ description = "Post-Quantum Signature Scheme falcon" readme = "README.md" version = "0.3.0" authors = ["Thom Wiggers "] -edition = "2018" +edition = "2021" license = "MIT OR Apache-2.0" homepage = "https://github.com/rustpq/" repository = "https://github.com/rustpq/pqcrypto/" diff --git a/pqcrypto-hqc/Cargo.toml b/pqcrypto-hqc/Cargo.toml index faa52691..1b89217b 100644 --- a/pqcrypto-hqc/Cargo.toml +++ b/pqcrypto-hqc/Cargo.toml @@ -4,7 +4,7 @@ description = "Post-Quantum Key-Encapsulation Mechanism hqc" readme = "README.md" version = "0.2.0" authors = ["Thom Wiggers "] -edition = "2018" +edition = "2021" license = "MIT OR Apache-2.0" homepage = "https://github.com/rustpq/" repository = "https://github.com/rustpq/pqcrypto/" diff --git a/pqcrypto-kyber/Cargo.toml b/pqcrypto-kyber/Cargo.toml index c850a8eb..41fc6f5d 100644 --- a/pqcrypto-kyber/Cargo.toml +++ b/pqcrypto-kyber/Cargo.toml @@ -4,7 +4,7 @@ description = "Post-Quantum Key-Encapsulation Mechanism kyber" readme = "README.md" version = "0.7.7" authors = ["Thom Wiggers "] -edition = "2018" +edition = "2021" license = "MIT OR Apache-2.0" homepage = "https://github.com/rustpq/" repository = "https://github.com/rustpq/pqcrypto/" diff --git a/pqcrypto-sphincsplus/Cargo.toml b/pqcrypto-sphincsplus/Cargo.toml index eef71e0d..d2b373f7 100644 --- a/pqcrypto-sphincsplus/Cargo.toml +++ b/pqcrypto-sphincsplus/Cargo.toml @@ -4,7 +4,7 @@ description = "Post-Quantum Signature Scheme sphincsplus" readme = "README.md" version = "0.7.0" authors = ["Thom Wiggers "] -edition = "2018" +edition = "2021" license = "MIT OR Apache-2.0" homepage = "https://github.com/rustpq/" repository = "https://github.com/rustpq/pqcrypto/" diff --git a/pqcrypto-template/scheme/Cargo.toml.j2 b/pqcrypto-template/scheme/Cargo.toml.j2 index 79826aa3..1e144e7a 100644 --- a/pqcrypto-template/scheme/Cargo.toml.j2 +++ b/pqcrypto-template/scheme/Cargo.toml.j2 @@ -4,7 +4,7 @@ description = "Post-Quantum {% if type == "kem" %}Key-Encapsulation Mechanism{% readme = "README.md" version = "{{ version }}" authors = ["Thom Wiggers "] -edition = "2018" +edition = "2021" license = "MIT OR Apache-2.0" homepage = "https://github.com/rustpq/" repository = "https://github.com/rustpq/pqcrypto/" diff --git a/pqcrypto-template/workspace-Cargo.toml.j2 b/pqcrypto-template/workspace-Cargo.toml.j2 index a9f5c3d9..3922be8b 100644 --- a/pqcrypto-template/workspace-Cargo.toml.j2 +++ b/pqcrypto-template/workspace-Cargo.toml.j2 @@ -8,3 +8,4 @@ members=[ "{{ name }}", {% endfor %} ] +resolver="2"