I've been working on getting my custom hash functions - 'Rainstorm' and 'Rainbow', to run on the web using Emscripten, and I've got to tell you, the journey has been equal parts challenging and fascinating.
The first step was to compile my C/C++ code to WASM with Emscripten. emcc's flags are a crucial part of this process. Here's how I defined mine:
The ASSERTIONS flag was useful during debugging, but I removed it for the production version for better performance. Along the way, I learned that you need to be careful with shell variable expansion - shell was replacing '$_malloc' with something else, leading to confusion.
The next step was integrating the generated WASM with my custom HTML/JS. I initially tried using Emscripten's -o option to generate an HTML, but it didn't fit my needs as I wanted to integrate the output into my custom page.
Eventually, I figured out how to load the WASM file as a module in my JavaScript, assign it to a variable, and call the functions exported by the WASM from my JavaScript.
It's not always smooth sailing - JavaScript promises can sometimes reject and I had to set up handlers for unhandled rejections and exceptions, but the result is a working in-browser implementation of my 'Rainstorm' and 'Rainbow' hash functions.
Now anyone can use their web browser to compute Rainstorm and Rainbow hashes, check against test vectors, or input their own data. I'm really proud of the work, and I learned so much during this process!
The first step was to compile my C/C++ code to WASM with Emscripten. emcc's flags are a crucial part of this process. Here's how I defined mine:
```sh EMCCFLAGS = -O3 -s WASM=1 -s EXPORTED_FUNCTIONS="['_rainstormHash64', '_rainstormHash128', '_rainstormHash256', '_rainstormHash512', 'stringToUTF8', 'lengthBytesUTF8', '_malloc', '_free']" -s EXPORTED_RUNTIME_METHODS="['ccall', 'cwrap']" -s WASM_BIGINT=1 -s ALLOW_MEMORY_GROWTH=1 ```
The ASSERTIONS flag was useful during debugging, but I removed it for the production version for better performance. Along the way, I learned that you need to be careful with shell variable expansion - shell was replacing '$_malloc' with something else, leading to confusion.
The next step was integrating the generated WASM with my custom HTML/JS. I initially tried using Emscripten's -o option to generate an HTML, but it didn't fit my needs as I wanted to integrate the output into my custom page.
Eventually, I figured out how to load the WASM file as a module in my JavaScript, assign it to a variable, and call the functions exported by the WASM from my JavaScript.
It's not always smooth sailing - JavaScript promises can sometimes reject and I had to set up handlers for unhandled rejections and exceptions, but the result is a working in-browser implementation of my 'Rainstorm' and 'Rainbow' hash functions.
Now anyone can use their web browser to compute Rainstorm and Rainbow hashes, check against test vectors, or input their own data. I'm really proud of the work, and I learned so much during this process!