Chacha20 v0.2.0 Chacha20
Chacha20 symmetric stream cipher
https://tools.ietf.org/html/rfc7539
The calling semantics are still sub-optimal and no performance tuning has been done.
Summary
Types
The parameters and state of the current session
The shared encryption key
The shared per-session nonce
Functions
The crypt function suitable for a complete message
The crypt function suitable for streaming
Types
chacha_parameters :: {key, nonce, non_neg_integer, binary}
The parameters and state of the current session
- The shared key
- The session nonce
- The last used block number
- The unused portion of the above block number
Note that block 0 is undefined, so the initial state is {k,n,0,""}
key :: <<_::32 * 8>>
The shared encryption key.
nonce :: <<_::12 * 8>> | <<_::8 * 8>>
The shared per-session nonce.
By spec, this nonce may be used to encrypt a stream of up to 256GiB
An eight-byte nonce is compatible with the original reference implementation.
Functions
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,n) = c
, then crypt(c,k,n) = m
Specs
crypt_bytes(binary, chacha_parameters, [binary]) :: {binary, chacha_parameters}
The crypt function suitable for streaming
Use an initial state of {k,n,0,""}
The returned parameters can be used for the next available bytes.
Any previous emitted binary can be included in the acc
, if desired.