Support for WebAssembly
mmihaipreda opened this issue · 5 comments
What is the problem you want to solve and can not with the current version?
I tried to build with
wasm-pack build
and I receive the following error:
error[E0658]: use of unstable library feature 'stdsimd'
--> /home/mihai/.cargo/registry/src/github.com-1ecc6299db9ec823/concrete-csprng-0.1.7/src/aesni.rs:21:12
|
21 | if is_x86_feature_detected!("aes")
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #27731 <https://github.com/rust-lang/rust/issues/27731> for more information
error:
is_x86_feature_detected can only be used on x86 and x86_64 targets.
You can prevent it from being used in other architectures by
guarding it behind a cfg(target_arch) as follows:
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
if is_x86_feature_detected(...) { ... }
}
--> /home/mihai/.cargo/registry/src/github.com-1ecc6299db9ec823/concrete-csprng-0.1.7/src/aesni.rs:21:12
|
21 | if is_x86_feature_detected!("aes")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `is_x86_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0658]: use of unstable library feature 'stdsimd'
--> /home/mihai/.cargo/registry/src/github.com-1ecc6299db9ec823/concrete-csprng-0.1.7/src/aesni.rs:22:16
|
22 | && is_x86_feature_detected!("rdseed")
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #27731 <https://github.com/rust-lang/rust/issues/27731> for more information
error:
is_x86_feature_detected can only be used on x86 and x86_64 targets.
You can prevent it from being used in other architectures by
guarding it behind a cfg(target_arch) as follows:
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
if is_x86_feature_detected(...) { ... }
}
--> /home/mihai/.cargo/registry/src/github.com-1ecc6299db9ec823/concrete-csprng-0.1.7/src/aesni.rs:22:16
|
22 | && is_x86_feature_detected!("rdseed")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `is_x86_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0658]: use of unstable library feature 'stdsimd'
--> /home/mihai/.cargo/registry/src/github.com-1ecc6299db9ec823/concrete-csprng-0.1.7/src/aesni.rs:23:16
|
23 | && is_x86_feature_detected!("sse2")
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #27731 <https://github.com/rust-lang/rust/issues/27731> for more information
error:
is_x86_feature_detected can only be used on x86 and x86_64 targets.
You can prevent it from being used in other architectures by
guarding it behind a cfg(target_arch) as follows:
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
if is_x86_feature_detected(...) { ... }
}
--> /home/mihai/.cargo/registry/src/github.com-1ecc6299db9ec823/concrete-csprng-0.1.7/src/aesni.rs:23:16
|
23 | && is_x86_feature_detected!("sse2")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `is_x86_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0658]: use of unstable library feature 'stdsimd'
--> /home/mihai/.cargo/registry/src/github.com-1ecc6299db9ec823/concrete-csprng-0.1.7/src/lib.rs:54:13
|
54 | if !is_x86_feature_detected!("aes")
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #27731 <https://github.com/rust-lang/rust/issues/27731> for more information
error:
is_x86_feature_detected can only be used on x86 and x86_64 targets.
You can prevent it from being used in other architectures by
guarding it behind a cfg(target_arch) as follows:
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
if is_x86_feature_detected(...) { ... }
}
--> /home/mihai/.cargo/registry/src/github.com-1ecc6299db9ec823/concrete-csprng-0.1.7/src/lib.rs:54:13
|
54 | if !is_x86_feature_detected!("aes")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `is_x86_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0658]: use of unstable library feature 'stdsimd'
--> /home/mihai/.cargo/registry/src/github.com-1ecc6299db9ec823/concrete-csprng-0.1.7/src/lib.rs:55:17
|
55 | || !is_x86_feature_detected!("rdseed")
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #27731 <https://github.com/rust-lang/rust/issues/27731> for more information
error:
is_x86_feature_detected can only be used on x86 and x86_64 targets.
You can prevent it from being used in other architectures by
guarding it behind a cfg(target_arch) as follows:
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
if is_x86_feature_detected(...) { ... }
}
--> /home/mihai/.cargo/registry/src/github.com-1ecc6299db9ec823/concrete-csprng-0.1.7/src/lib.rs:55:17
|
55 | || !is_x86_feature_detected!("rdseed")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `is_x86_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0658]: use of unstable library feature 'stdsimd'
--> /home/mihai/.cargo/registry/src/github.com-1ecc6299db9ec823/concrete-csprng-0.1.7/src/lib.rs:56:17
|
56 | || !is_x86_feature_detected!("sse2")
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #27731 <https://github.com/rust-lang/rust/issues/27731> for more information
error:
is_x86_feature_detected can only be used on x86 and x86_64 targets.
You can prevent it from being used in other architectures by
guarding it behind a cfg(target_arch) as follows:
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
if is_x86_feature_detected(...) { ... }
}
--> /home/mihai/.cargo/registry/src/github.com-1ecc6299db9ec823/concrete-csprng-0.1.7/src/lib.rs:56:17
|
56 | || !is_x86_feature_detected!("sse2")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `is_x86_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0432]: unresolved import `std::arch::x86_64`
--> /home/mihai/.cargo/registry/src/github.com-1ecc6299db9ec823/concrete-csprng-0.1.7/src/aesni.rs:7:16
|
7 | use std::arch::x86_64::{
| ^^^^^^ could not find `x86_64` in `arch`
error[E0433]: failed to resolve: could not find `x86_64` in `arch`
--> /home/mihai/.cargo/registry/src/github.com-1ecc6299db9ec823/concrete-csprng-0.1.7/src/aesni.rs:70:28
|
70 | if core::arch::x86_64::_rdseed64_step(&mut rand1) == 1 {
| ^^^^^^ could not find `x86_64` in `arch`
error[E0433]: failed to resolve: could not find `x86_64` in `arch`
--> /home/mihai/.cargo/registry/src/github.com-1ecc6299db9ec823/concrete-csprng-0.1.7/src/aesni.rs:75:28
|
75 | if core::arch::x86_64::_rdseed64_step(&mut rand2) == 1 {
| ^^^^^^ could not find `x86_64` in `arch`
Describe the solution you'd like
A possible solution ( I'm not sure) is to have a mapping between core::arch::x86_64
to core::arch::wasm32
For example
use std::arch::x86_64:: __m128i;
https://doc.rust-lang.org/core/arch/x86_64/struct.__m128i.html
From documentation they say that :
Internally this type may be viewed as:
i8x16 - sixteen i8 variables packed together
i16x8 - eight i16 variables packed together
i32x4 - four i32 variables packed together
i64x2 - two i64 variables packed together
So for core::arch::x86_64::__m128
can be mapped to core::arch::wasm32::i8x16
/ core::arch::wasm32::i16x8
/ core::arch::wasm32::i32x4
/ core::arch::wasm32::i64x2
Later edit :
Besides those mappings, I see that are specialized CPU intrinsics like _mm_aeskeygenassist_si128
.
So you can't do anything until WASM fully supports SIMD.
So if you know any other Rust library that can be compiled to wasm and offers at least basic arithmetic operation (addition, substitution, division and multiplication) for at least integers please tell me.
Thanks
Hello @mmihaipreda 👋 ,
Thanks for your interest for concrete
, and for coming up with a potential solution :)
A webassembly api is something we definitely would like to have in the future. As a matter of fact, our current codebase was developed with x86 as main target in mind, and it requires a substantial work to enable a wasm api. We are in the process of reverting that, but it requires quite a lot of work, and we are not there yet.
Could you tell us more about your usecase ? Maybe with more understanding of your situation, we could help better ?
Best,
Alex
@aPere3 Thank you for the quick response,
My use-case is the following: I wanted to use concrete to make a WASM module with modular functions like add, substract, multiply and so on for my dissertation thesis to process some encrypted data directly into the browser.
After some research I found a library made by Facebook researchers named Cupcake
which I could build with wasm-pack build
. At the first glance it isn't as generic as concrete
( it supports addition, substraction, multiplication, division for integer types but it is okey for a proof-of-concept)
Hello,
I am also very interested in developing schemes/applications with wasm compilable/enabled homomorphic encryption libraries (for my Diss/for my Work also). Another (possible) alternative to concrete and Cupcake I found is :
https://github.com/golemfactory/gmorph
For now, I am playing/implementing (attribute and geospatial encryption schemes) in parallel with all three libraries. Unfortunately concrete is not yet wasm compilable, therefore installation-less (i.e. browser based/ wasm based) decryption/encryption software clients are not possible (yet =) ?
Hopefully this will change. I'm waiting for it, also ;)
Greetings
Hi,
even though it might be a little bit late (and potentially off-topic w.r.t. concrete). I still want to add my input.
In the past, we successfully worked on a project with WebAssembly and Microsoft SEAL. We used node-seal for wasm, encrypted data in the browser and communicated/exchanged the resulting ciphertexts with a server running a Python Port of Microsoft SEAL.
Best,
Jan
Hi,
even though it might be a little bit late (and potentially off-topic w.r.t. concrete). I still want to add my input.
In the past, we successfully worked on a project with WebAssembly and Microsoft SEAL. We used node-seal for wasm, encrypted data in the browser and communicated/exchanged the resulting ciphertexts with a server running a Python Port of Microsoft SEAL.
Best,
Jan
In the end I have use Microsoft SEAL and node-seal a little backwards :)).
I have created a bindings.js file in which I have imported node-seal, then I have written functions which uses node-seal API and exported them.
Then in a Rust project I used [wasm_bindgen='path/to/bindings/file']
with extern C. This allowed me to run all the needed functions directly in Rust.
From here I create a mini-library based on those APIs, but with simplified parameters.
Then I was able to build the wasm bundle and after that I have made a Typescript wrapper for it