prozacchiwawa/elm-keccak/2.0.0

Keccak

Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby denoted as "the implementer".

For more information, feedback or questions, please refer to our websites:

To the extent possible under law, the implementer has waived all copyright and related or neighboring rights to the source code in this file. http://creativecommons.org/publicdomain/zero/1.0/

Ported to elm by Art Yerkes.

ethereum_keccak_256 is the hash function used in many places related to the ethereum cryptocurrency. It is different from sha3 in the padding used.

Elm 0.19 update by Coury Ditch https://github.com/cmditch

Functions

type State

The state of the keccak hasher.

type Config

A configuration for a keccak hasher.

Configuration for SHA3-224

Configuration for SHA3-256

Configuration for SHA3-384

Configuration for SHA3-512

Configuration for ethereum 256 bit hashes

Prepare a keccak instance to do hashing with the given configuration.

update : Bytes -> State -> State

Include the given bytes in the hash.

finish : State -> List Int

Consume the given hash state and return a list of ints representing the hash.

For a replacement for the original version of this library,

-- Exposes fips_202_sha3_224 etc with int list inputs
import Keccak.Int as Keccak 

For slightly better versions of the originals using elm/bytes,

-- Exposes fips202_sha3_224 etc with Bytes
import Keccak.Bytes as Keccak
import Bytes.Encode as BEnc
import String
import Hex


hexify l = String.concat (List.map (Hex.toString >> String.padLeft 2 '0') l)


hexify (Keccak.ethereum_keccak_256 (BEnc.string "baz(uint32,bool)")) -- "cdcd77c0992ec5bbfc459984220f8c45084cc24d9b6efed1fae540db8de801d2"

This library exposes configurations named by their respective exports as well as general hashing functions:

-- Initialize a hasher state.
init config
-- Add bytes to hash.
update bytes state
-- Return the hash value.
finish state

They can be used together like:

init ethereum_keccak_256 
|> update (BEnc.encode (BEnc.string "1"))
|> update (Benc.encode (Benc.string "2"))
|> finish