Noise. CipherState
(Noise Protocol v0.3.0)
View Source
A CipherState (spec §5.1): a 32-byte key k and a 64-bit nonce n.
Produced in pairs by Noise.split/1 once a handshake completes; used for
transport messages through Noise.encrypt/3 and Noise.decrypt/3.
Spec rules enforced here:
nis never incremented on a failed decryption.- Once
nreaches2^64-1(reserved forrekey/1) every further encrypt/decrypt returns{:error, :nonce_exhausted}.
The key is redacted from inspect/1 output.
Summary
Functions
DECRYPT(k, n, ad, ciphertext) then n++; n is unchanged on failure (spec §5.1).
ENCRYPT(k, n, ad, plaintext) then n++ (spec §5.1).
A CipherState without a key; encrypt/decrypt pass data through unchanged (spec §5.1).
Sets a 32-byte key and resets the nonce to 0.
REKEY(k) (spec §4.2 / §11.3). The nonce is not reset.
Sets the nonce explicitly (spec §11.4, out-of-order transport messages).
Types
Functions
DECRYPT(k, n, ad, ciphertext) then n++; n is unchanged on failure (spec §5.1).
ENCRYPT(k, n, ad, plaintext) then n++ (spec §5.1).
@spec initialize(Noise.Protocol.t()) :: t()
A CipherState without a key; encrypt/decrypt pass data through unchanged (spec §5.1).
@spec initialize_key(t(), Noise.Crypto.Cipher.key()) :: t()
Sets a 32-byte key and resets the nonce to 0.
@spec nonce(t()) :: non_neg_integer()
REKEY(k) (spec §4.2 / §11.3). The nonce is not reset.
@spec set_nonce(t(), non_neg_integer()) :: t()
Sets the nonce explicitly (spec §11.4, out-of-order transport messages).
Raises ArgumentError for values outside 0..2^64-2.