A small demonstration of building liboqs for WebAssembly using Emscripten, and then using it in a browser.
!!! THIS IS NOT MEANT FOR PRODUCTION USE !!!
./addons
- Contains 2 small C files that have a small main()
function to appease Emscripten and also a bunch of accessor methods that allow JS code to access the fields of OQS_KEM
and OQS_SIG
structs.
./docker-builder
- Contains the Dockerfile for the build container, and also a build script that builds the final JS/WASM files. It builds the static version of liboqs, and then adds the accessor methods from above. Please check the env vars there to see how it's behavior can be changed.
./test-website
- Contains the test HTML page. Also contains a high-level wrapper script liboqs_wrapper.mjs
that allows for conventient access and use of the relevant functions of liboqs. Also has a small script server.py
that starts a webserver allowing to interact with the static website.
./out
- Empty directory where the relevant JS and WASM files should be placed. ./test-website
contains symlinks to this directory.
- Clone the repo
- Build the docker image. From the
./docker-builder
directory:docker build -t oqs-wasm .
. This will create theoqs-wasm
image with the toolchain. - From the same directory, run
docker run -it --rm -e OQS_GIT_TAG="0.10.0" -v "$(pwd)/../out:/out:rw" -v "$(pwd)/../addons:/addons:ro" oqs-wasm
. You can build from whatever tag is in the repo. If the var is not defined, the script will build from main. - Check that no errors are shown and that now, there are files
liboqs.js
andliboqs.wasm
in the./out
directory. - Go to the
./test-website
directory. From this directory, runpython server.py
to start the server. - In your browser (I tested on the last Chrome Beta) go to http://127.0.0.1:8000/ and play with the algorithms there.