Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,33 @@ jobs:
cargo install cargo-ndk
cargo ndk -t aarch64-linux-android build

wasm32-unknown-unknown:
name: wasm32-unknown-unknown
runs-on: ubuntu-latest
strategy:
matrix:
rust: [ stable, beta, nightly ]
steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Install Rust
run: |
rustup toolchain install ${{ matrix.rust }} --profile minimal --component clippy
rustup default ${{ matrix.rust }}
rustup target add wasm32-unknown-unknown

- name: Check workspace (all crates except classicmceliece & umbrella)
run: |
cargo check --workspace --target wasm32-unknown-unknown --features getrandom_wasm_js \
--exclude pqcrypto-classicmceliece \
--exclude pqcrypto

- name: Check umbrella crate (explicitly enable only supported wasm crates)
run: |
cargo check --target wasm32-unknown-unknown \
-p pqcrypto --no-default-features -F pqcrypto-mlkem,pqcrypto-hqc,pqcrypto-mldsa,pqcrypto-falcon,pqcrypto-sphincsplus,serialization,getrandom_wasm_js
# wasi:
# name: wasi
# runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion pqcrypto-classicmceliece/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ categories = ["cryptography", "no-std"]
[dependencies]
pqcrypto-internals = { path = "../pqcrypto-internals", version = "0.2.6" }
pqcrypto-traits = { path = "../pqcrypto-traits", version = "0.3.5", default-features = false }
libc = "0.2.0"
serde = { version = "1.0", features = ["derive"], optional = true }
serde-big-array = { version = "0.5.1", optional = true }

[target.wasm32-unknown-unknown.dependencies]
wasm32-unknown-unknown-openbsd-libc = "0.2"

[features]
default = ["avx2", "std"]
avx2 = ["std"]
std = ["pqcrypto-traits/std"]
serialization = ["serde", "serde-big-array"]
getrandom_wasm_js = ["pqcrypto-internals/getrandom_wasm_js"]

[dev-dependencies]

Expand Down
34 changes: 22 additions & 12 deletions pqcrypto-classicmceliece/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ macro_rules! build_clean {
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()),
);
.include(target_dir);
if let Some(libc) = std::env::var_os("DEP_WASM32_UNKNOWN_UNKNOWN_OPENBSD_LIBC_INCLUDE") {
builder.include(libc);
println!("cargo::rustc-link-lib=wasm32-unknown-unknown-openbsd-libc");
}

builder.files(
scheme_files
.into_iter()
.map(|p| p.unwrap().to_string_lossy().into_owned()),
);
builder.compile(format!("{}_clean", $variant).as_str());
};
}
Expand Down Expand Up @@ -68,12 +73,17 @@ macro_rules! build_avx2 {
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()),
);
.include(target_dir);
if let Some(libc) = std::env::var_os("DEP_WASM32_UNKNOWN_UNKNOWN_OPENBSD_LIBC_INCLUDE") {
builder.include(libc);
println!("cargo::rustc-link-lib=wasm32-unknown-unknown-openbsd-libc");
}

builder.files(
scheme_files
.into_iter()
.map(|p| p.unwrap().to_string_lossy().into_owned()),
);
builder.compile(format!("{}_avx2", $variant).as_str());
};
}
Expand Down
2 changes: 1 addition & 1 deletion pqcrypto-classicmceliece/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! * mceliece8192128f
// This file has been generated from PQClean.
// Find the templates in pqcrypto-template
use libc::c_int;
use core::ffi::c_int;

// ensures we link correctly
#[allow(unused_imports)]
Expand Down
5 changes: 4 additions & 1 deletion pqcrypto-falcon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ categories = ["cryptography", "no-std"]
[dependencies]
pqcrypto-internals = { path = "../pqcrypto-internals", version = "0.2.6" }
pqcrypto-traits = { path = "../pqcrypto-traits", version = "0.3.5", default-features = false }
libc = "0.2.0"
serde = { version = "1.0", features = ["derive"], optional = true }
serde-big-array = { version = "0.5.1", optional = true }

[target.wasm32-unknown-unknown.dependencies]
wasm32-unknown-unknown-openbsd-libc = "0.2"

[features]
default = ["avx2", "neon", "std"]
avx2 = ["std"]
neon = ["std"]
std = ["pqcrypto-traits/std"]
serialization = ["serde", "serde-big-array"]
getrandom_wasm_js = ["pqcrypto-internals/getrandom_wasm_js"]

[dev-dependencies]
rand = "0.9"
Expand Down
51 changes: 33 additions & 18 deletions pqcrypto-falcon/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ macro_rules! build_clean {
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()),
);
.include(target_dir);
if let Some(libc) = std::env::var_os("DEP_WASM32_UNKNOWN_UNKNOWN_OPENBSD_LIBC_INCLUDE") {
builder.include(libc);
println!("cargo::rustc-link-lib=wasm32-unknown-unknown-openbsd-libc");
}

builder.files(
scheme_files
.into_iter()
.map(|p| p.unwrap().to_string_lossy().into_owned()),
);
builder.compile(format!("{}_clean", $variant).as_str());
};
}
Expand Down Expand Up @@ -70,12 +75,17 @@ macro_rules! build_avx2 {
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()),
);
.include(target_dir);
if let Some(libc) = std::env::var_os("DEP_WASM32_UNKNOWN_UNKNOWN_OPENBSD_LIBC_INCLUDE") {
builder.include(libc);
println!("cargo::rustc-link-lib=wasm32-unknown-unknown-openbsd-libc");
}

builder.files(
scheme_files
.into_iter()
.map(|p| p.unwrap().to_string_lossy().into_owned()),
);
builder.compile(format!("{}_avx2", $variant).as_str());
};
}
Expand Down Expand Up @@ -103,12 +113,17 @@ macro_rules! build_aarch64 {
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()),
);
.include(target_dir);
if let Some(libc) = std::env::var_os("DEP_WASM32_UNKNOWN_UNKNOWN_OPENBSD_LIBC_INCLUDE") {
builder.include(libc);
println!("cargo::rustc-link-lib=wasm32-unknown-unknown-openbsd-libc");
}

builder.files(
scheme_files
.into_iter()
.map(|p| p.unwrap().to_string_lossy().into_owned()),
);
builder.compile(format!("{}_aarch64", $variant).as_str());
};
}
Expand Down
2 changes: 1 addition & 1 deletion pqcrypto-falcon/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! * falcon-padded-1024
// This file has been generated from PQClean.
// Find the templates in pqcrypto-template
use libc::c_int;
use core::ffi::c_int;

// ensures we link correctly
#[allow(unused_imports)]
Expand Down
5 changes: 4 additions & 1 deletion pqcrypto-hqc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ categories = ["cryptography", "no-std"]
[dependencies]
pqcrypto-internals = { path = "../pqcrypto-internals", version = "0.2.6" }
pqcrypto-traits = { path = "../pqcrypto-traits", version = "0.3.5", default-features = false }
libc = "0.2.0"
serde = { version = "1.0", features = ["derive"], optional = true }
serde-big-array = { version = "0.5.1", optional = true }

[target.wasm32-unknown-unknown.dependencies]
wasm32-unknown-unknown-openbsd-libc = "0.2"

[features]
default = ["std"]
std = ["pqcrypto-traits/std"]
serialization = ["serde", "serde-big-array"]
getrandom_wasm_js = ["pqcrypto-internals/getrandom_wasm_js"]

[dev-dependencies]

Expand Down
17 changes: 11 additions & 6 deletions pqcrypto-hqc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ macro_rules! build_clean {
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()),
);
.include(target_dir);
if let Some(libc) = std::env::var_os("DEP_WASM32_UNKNOWN_UNKNOWN_OPENBSD_LIBC_INCLUDE") {
builder.include(libc);
println!("cargo::rustc-link-lib=wasm32-unknown-unknown-openbsd-libc");
}

builder.files(
scheme_files
.into_iter()
.map(|p| p.unwrap().to_string_lossy().into_owned()),
);
builder.compile(format!("{}_clean", $variant).as_str());
};
}
Expand Down
2 changes: 1 addition & 1 deletion pqcrypto-hqc/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! * hqc-256
// This file has been generated from PQClean.
// Find the templates in pqcrypto-template
use libc::c_int;
use core::ffi::c_int;

// ensures we link correctly
#[allow(unused_imports)]
Expand Down
7 changes: 6 additions & 1 deletion pqcrypto-internals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ links = "pqcrypto_internals"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
getrandom_wasm_js = ["getrandom/wasm_js"]

[build-dependencies]
cc = { version = "1.0", features = ["parallel"] }
dunce = "1.0"

[dependencies]
getrandom = "0.3"
libc = "0.2"

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm32-unknown-unknown-openbsd-libc = "0.2"
12 changes: 8 additions & 4 deletions pqcrypto-internals/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ fn main() {
build.flag(format!("--sysroot={wasi_sdk_path}").as_str());
}

build
.include(&includepath)
.files(common_files)
.compile("pqclean_common");
build.include(&includepath);

if let Some(libc) = std::env::var_os("DEP_WASM32_UNKNOWN_UNKNOWN_OPENBSD_LIBC_INCLUDE") {
build.include(libc);
println!("cargo::rustc-link-lib=wasm32-unknown-unknown-openbsd-libc");
}

build.files(common_files).compile("pqclean_common");
println!("cargo:rustc-link-lib=pqclean_common");

let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
Expand Down
6 changes: 5 additions & 1 deletion pqcrypto-internals/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

use core::slice;

#[allow(nonstandard_style)]
type size_t = usize;
use core::ffi::c_int;

/// Get random bytes; exposed for PQClean implementations.
///
/// # Safety
Expand All @@ -16,7 +20,7 @@ use core::slice;
/// }
/// ```
#[no_mangle]
pub unsafe extern "C" fn PQCRYPTO_RUST_randombytes(buf: *mut u8, len: libc::size_t) -> libc::c_int {
pub unsafe extern "C" fn PQCRYPTO_RUST_randombytes(buf: *mut u8, len: size_t) -> c_int {
let buf = slice::from_raw_parts_mut(buf, len);
getrandom::fill(buf).expect("RNG Failed");
0
Expand Down
5 changes: 4 additions & 1 deletion pqcrypto-mldsa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ categories = ["cryptography", "no-std"]
[dependencies]
pqcrypto-internals = { path = "../pqcrypto-internals", version = "0.2.6" }
pqcrypto-traits = { path = "../pqcrypto-traits", version = "0.3.5", default-features = false }
libc = "0.2.0"
serde = { version = "1.0", features = ["derive"], optional = true }
serde-big-array = { version = "0.5.1", optional = true }
paste = "1.0"

[target.wasm32-unknown-unknown.dependencies]
wasm32-unknown-unknown-openbsd-libc = "0.2"

[features]
default = ["avx2", "neon", "std"]
avx2 = ["std"]
neon = ["std"]
std = ["pqcrypto-traits/std"]
serialization = ["serde", "serde-big-array"]
getrandom_wasm_js = ["pqcrypto-internals/getrandom_wasm_js"]

[dev-dependencies]
rand = "0.9"
Expand Down
Loading