View Source Salsa20 (Salsa20 v1.0.4)

Salsa20 symmetric stream cipher

As specified in http://cr.yp.to/snuffle/spec.pdf.

Also includes the HSalsa20 hashing function as specified in http://cr.yp.to/highspeed/naclcrypto-20090310.pdf

Summary

Types

The shared encryption key.

The shared per-session nonce.

The parameters and state of the current session

Functions

The crypt function suitable for a complete message.

The crypt function suitable for streaming

HSalsa20 hash

Types

@type key() :: binary()

The shared encryption key.

32-byte values are to be preferred over 16-byte ones where possible.

@type nonce() :: binary()

The shared per-session nonce.

By spec, this nonce may be used to encrypt a stream of up to 2^70 bytes.

@type salsa_parameters() :: {key(), nonce(), non_neg_integer(), binary()}

The parameters and state of the current session

  • The shared key
  • The session nonce
  • The next block number
  • The unused portion of the current block

Starting from block 0 the initial state is {k,v,0,""}

Functions

@spec crypt(binary(), key(), nonce(), non_neg_integer()) :: binary()

The crypt function suitable for a complete message.

This is a convenience wrapper when the full message is ready for processing.

The operations are symmetric, so if crypt(m,k,v) = c, then crypt(c,k,v) = m

@spec crypt_bytes(binary(), salsa_parameters(), [binary()]) ::
  {binary(), salsa_parameters()}

The crypt function suitable for streaming

Use an initial state of {k,v,0,""} The returned parameters can be used for the next available bytes. Any previous emitted binary can be included in the acc, if desired.

@spec hash(key(), nonce()) :: binary()

HSalsa20 hash

The strict specification requires a 32-byte key, but the defined expansion function can be used with a 16-byte key.