Command Palette

Search for a command to run...

sha3 package icon
chriswhealy/sha3
Public
wasmer run chriswhealy/sha3

SHA3 Implementation in WebAssembly Text

An algorithmically compliant implementation of SHA3 based on the specification published as NIST FIPS 202. Implemented in WebAssembly Text.

The resulting binary is 5.3 Kb 😎

Table of Contents

Overview

The SHA3 algorithm can be used in two modes:

  • As a drop-in replacement for SHA2, or in
  • Extendible Output Function (XOF) mode

Drop-In Replacement Mode for SHA2

When used as a drop-in replacement for SHA2, the length of the generated digest d must exacly match the digest lengths generated by SHA2. Therefore, d may only be one of 224, 256, 384, or 512 bits.

Extendible Output Function (XOF) Mode

When used in XOF mode, the SHA3 function can produce an arbitrary quantity of pseudo-random output data.

§6.2 in the above NIST FIPS 202 document defines two XOF mode functions known as SHAKE128 and SHAKE256.

How Does Drop-In Mode Differ From XOF Mode?

Internally, the same hashing function is used in both modes; but with the following differences:

ModeData In Last BlockTerminated WithOutput Length
Drop-in0x06One of 224, 256, 384 or 512 bits
XOF0x1111Any length between 1 and 16,777,216

Run The Published Version

Assuming you have wasmer installed, you can run the published version of this program as follows:

wasmer run chriswhealy/sha3 --volume=<local_directory>:/. --command-name=<cmd> <output-length> <filename>
ArgPossible ValuesDescription
<local_directory>A local directory on your machineThe directory to be preopened for WASM
<cmd>224 , 256, 384 or 512Run SHA3 in SHA2 drop-in replacement mode and produce a digest this many bits long
<cmd>shake128 , shake256Run SHA3 in XOF mode and produce <output-length> bytes of pseudo-random data
<output-length>An integer between 1 and 16777216Only relevant when using the shake128 and shake256 commands
<filename>The filename to be hashedThis file must live in or below the <local_directory>

Calculates the SHA3 hash of a local file, implemented in WebAssembly Text


Github