rustpq / pqcrypto

Rust Post-Quantum cryptography
212 stars 38 forks source link

Added support for WebAssembly that targets wasm32-wasi - quantum crypto on the browser here we come... #22

Closed john-sharratt closed 2 years ago

john-sharratt commented 2 years ago

As a part of a project I am working on there is a heavy use of quantum resistant crypto.

Now that I am porting the library (https://github.com/john-sharratt/ate) over to WebAssembly so that it can run in a web browser I need the same crypto functions to work in wasm32 under wasi however there are no known libraries in rust that support such routines other than pqcrypto - hence I started porting it.

Given that pqcrypto does not yet work I forked it to add support for compiling to wasm32-wasi (https://github.com/john-sharratt/pqcrypto-wasi) - most of it compiles except for the random generator which is runtime specific thus I have added a function within WASI.

The new function only impacts builds that target wasi hence it is fully forwards and backwards compatible.

In order to test simply run: cargo build --target wasm32-wasi

Once another pull request is accepted over at pqclean we should be able to remove the reference to pqclean-wasi and go back to a reference just for pqclean. Once it is accepted ill make these changes and submit another pull request - below is the pull request we are waiting on:

https://github.com/PQClean/PQClean/pull/405

thomwiggers commented 2 years ago

It would probably be better if we don't import pqclean's common files anymore and instead provide randombytes via getrandom from Rust.

john-sharratt commented 2 years ago

resolved the merge conflicts - will test them locally and get back to you

john-sharratt commented 2 years ago

It would probably be better if we don't import pqclean's common files anymore and instead provide randombytes via getrandom from Rust.

Yeah this would be better for pqcrypto for sure and would improve long term maintainability however the pqclean source will still need it right? otherwise those compiling from pqclean would run into the same problem.

Perhaps we should do both changes still?

john-sharratt commented 2 years ago

resolved the merge conflicts - will test them locally and get back to you

Tested again after the merge, both x86 and wasm targets compile but not yet run regression tests - will run those later today

thomwiggers commented 2 years ago

I don't think I'll be merging this. It would be better if randombytes.c from PQClean is not used and instead we use the getrandom crate (which should in turn handle API differences between platforms); but this PR also pulls in the entire WASI sysroot and that seems out of scope.

john-sharratt commented 2 years ago

I will take a look at removing the WASI sysroot from this PR and instead just referencing it - will also take a look at the getrandom crate too but no promises as my coding time is overbooked at the moment.

john-sharratt commented 2 years ago

Update on the status...

Looked into doing the random byte generation from rust instead of c... it is simply too much work with time I don't have spare to invest so this isn't possible from my end unfortunately. If I were to go down that route I would look at porting the routines themselves to pure rust code instead but thats too big a project

So what I have prepared now then...

The situation for me in the next day or so is that I now need to publish my crate (ate) on cargo.io which needs this pqcrypto with wasi support - so looking for you to decide if you will merge or not so I can proceed.

Let me know what you want to do.

Cheers

john-sharratt commented 2 years ago

I will resubmit the pull request - this is now too messed up.