SipHash v1.0.0 SipHash.State

Module for representing state and state transformations of a digest whilst moving through the hasing pipeline.

Summary

Functions

Applies a block (an 8-byte chunk) to the digest, and returns the state after transformation. If a binary chunk is passed in, it’s converted to a number (as little endian) before being passed to the main body. First we XOR v3 before compressing the state twice. Once complete, we then XOR v0, and return the final state

Performs the equivalent of SipRound on the provided state, making sure to mask numbers as it goes (because Elixir precision gets too large). Once all steps are completed, the new state is returned

Provides a recursive wrapper around SipHash.Util.compress/1. Used to easily modify the c-d values of the SipHash algorithm

Finalizes a digest by XOR’ing v2 and performing SipRound d times. After the rotation, all properties of the state are XOR’d from left to right

Initializes a state based on an input key, using the technique defined in the SipHash specifications. First we take the input key, split it in two, and convert to the little endian version of the bytes. We then create a struct using the magic numbers and XOR them against the two key words created

Rotates an input number val left by shift number of bits. Bits which are pushed off to the left are rotated back onto the right, making this a left rotation (a circular shift)

Types

s :: %SipHash.State{v0: term, v1: term, v2: term, v3: term}

Functions

apply_block(state, m, c)

Specs

apply_block(s, binary | number, number) :: s

Applies a block (an 8-byte chunk) to the digest, and returns the state after transformation. If a binary chunk is passed in, it’s converted to a number (as little endian) before being passed to the main body. First we XOR v3 before compressing the state twice. Once complete, we then XOR v0, and return the final state.

compress(state)

Specs

compress(s) :: s

Performs the equivalent of SipRound on the provided state, making sure to mask numbers as it goes (because Elixir precision gets too large). Once all steps are completed, the new state is returned.

Incidentally, this function is named SipHash.State.compress/1 rather than SipHash.State.round/1 to avoid clashing with Kernel.round/1 internally.

compress(state, n)

Specs

compress(s, number) :: s

Provides a recursive wrapper around SipHash.Util.compress/1. Used to easily modify the c-d values of the SipHash algorithm.

finalize(state, d)

Specs

finalize(s, number) :: s

Finalizes a digest by XOR’ing v2 and performing SipRound d times. After the rotation, all properties of the state are XOR’d from left to right.

initialize(key)

Specs

initialize(binary) :: s

Initializes a state based on an input key, using the technique defined in the SipHash specifications. First we take the input key, split it in two, and convert to the little endian version of the bytes. We then create a struct using the magic numbers and XOR them against the two key words created.

rotate_left(val, shift)

Specs

rotate_left(number, number) :: number

Rotates an input number val left by shift number of bits. Bits which are pushed off to the left are rotated back onto the right, making this a left rotation (a circular shift).

Examples

iex> SipHash.State.rotate_left(8, 3)
64

iex> SipHash.State.rotate_left(3, 8)
768