Implementing the SHA256 Hash Algorithm in WebAssembly Text
Table of Contents
- SHA256 Algorithm Overview
- WebAssembly Does Not Have A “raw binary” Data Type
- WebAssembly Program Architecture
- WebAssembly Implementation
- Unit Testing WebAssembly Functions
- JavaScript Host Environment
- Summary
Development Objectives
- See how small a binary can be produced when the SHA256 digest algorithm is implemented directly in WebAssembly Text
- Compare the runtime performance of the WebAssembly module with the native
sha256sum
program supplied with macOS
The Git repo containing the working software can be found here
Development Challenges
Two challenges had to be overcome during development:
- The SHA256 algorithm expects to handle data in network byte order, but WebAssembly only has numeric data types that automatically rearrange a value’s byte order according to the CPU’s endianness.
- Unit testing WASM functions within a module is an entirely manual process. This presented an interesting challenge - especially when writing unit tests for private WASM functions