class

Beryl::Crypto::V1::AuthenticatedEncryptionWithExtendedNonceChaCha20AndPoly1305

Inherits Beryl::Crypto::V1::AuthenticatedEncryption < Reference < Object

XChaCha20-Poly1305 (draft-irtf-cfrg-xchacha-03): ChaCha20-Poly1305 with a 24-byte nonce, long enough to pick at random for every message. This is the cipher behind Beryl::Crypto.encrypt.

cipher = Beryl::Crypto::V1::XChaCha20Poly1305.new(key)
nonce = Random::Secure.random_bytes(24)
sealed = cipher.encrypt(body, nonce: nonce)
cipher.decrypt(sealed, nonce: nonce) # => body, or nil

The first 16 nonce bytes and the key give a one-message key (HChaCha20); the last 8 nonce bytes are the nonce of an ordinary ChaCha20-Poly1305 under that key.

Constants

KEY_BYTESIZE = 32
NONCE_BYTESIZE = 24

Constructors

new(key : Bytes)

Creates the cipher under key (32 bytes), which is copied.

Source

Instance methods

nonce_bytesize

Returns the nonce size this cipher is meant to be used with, in bytes.

Source