liboqs-rust
liboqs-rust copied to clipboard
WASM compatibility
In the conversation thread here, we discussed how to make oqs's C library compile to WASM. The build script and anything else internal should be modified to support compilation to the common WASM targets here for the rust crate, that way no modification is needed for users of this library.
I've got some WASM support in the pqcrypto crates since PR rustpq/pqcrypto#26. I have no idea how WASM works though, so I would appreciate it if those that would like to see it open a PR and propose some suggestions for testing it in CI (so I don't break it accidentally).
Plus one on this
So far, got liboqs rust to build with cargo build --target=wasm32-unknown-emscripten after supplying a few -I include paths - which I guessed, and might be part of the trouble. I used musl ones in emscripted compiler version 3.1.61 (on mac).
Then I setup a project to build with liboqs rust and get the benefit of all the brains behind the rust bindings.
I took the .a from the step above and made a liboqs.pc for a static link.
Here is where problems begin - and they are first compile problems.
When I build with target=wasm32-unknown-unknown (even using nightly and --Z wasm_c_abi=spec, I get
.../out/sig_bindings.rs:261:52
261 | pub fn OQS_SIG_new(method_name: *const ::libc::c_char) -> *mut OQS_SIG;
| ^^^^^^ not found in `libc`
with the suggestion
help: consider importing this type alias
--> /.../oqs-sys-0.9.1+liboqs-0.9.0/src/lib.rs:35:5
|
35 + use core::ffi::c_char;
In addition, there are also errors like
error[E0308]: mismatched types
--> /.../.cargo/registry/src/index.crates.io-6f17d22bba15001f/oqs-0.9.0/src/kem.rs:229:44
|
229 | let cstr = unsafe { CStr::from_ptr(kem.alg_version) };
| -------------- ^^^^^^^^^^^^^^^ expected `*const u8`, found `*const i8`
| |
| arguments to this function are incorrect
|
= note: expected raw pointer `*const u8`
found raw pointer `*const i8`
note: associated function defined here
--> /.../.cargo/registry/src/index.crates.io-6f17d22bba15001f/cstr_core-0.2.6/src/lib.rs:1025:19
|
1025 | pub unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a CStr {
| ^^^^^^^^
which involve library crates - code I cannot edit, so I imagine there is configuration that can help.
With wasm32-unknown-emscripten only the second error shows up. Following the suggestion for the first error to use the alias solves the instances that I can affect (files in the target folder, but also has the errors indicated for some crate files.
According to lib.rs in libc it seems c_int and friends are defined for emscripten only, but c_char is not defined (and appears to default to i8 instead of u8.