Chacha20 (Chacha20 v1.0.4)
View SourceChacha20 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
Return an arbitrary block
The crypt function suitable for a complete message.
The crypt function suitable for streaming
Types
@type chacha_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
To start from block 0, the initial state is {k,n,0,""}
@type key() :: binary()
The shared encryption key.
@type nonce() :: binary()
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
@spec block(key(), nonce(), non_neg_integer()) :: binary()
Return an arbitrary block
This is probably most useful in fast-forwarding a stream.
@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,n) = c
, then crypt(c,k,n) = m
@spec 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.