class

Beryl::Crypto::V1::AuthenticatedEncryptionWithChaCha20AndPoly1305

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

ChaCha20-Poly1305 (RFC 8439 ยง2.8): authenticated encryption under a 32-byte key and a 12-byte nonce. It is the cipher of COSE algorithm 24 and of TLS 1.3's TLS_CHACHA20_POLY1305_SHA256.

cipher = Beryl::Crypto::V1::ChaCha20Poly1305.new(key)
sealed = cipher.encrypt(body, nonce: nonce, associated_data: header)
cipher.decrypt(sealed, nonce: nonce, associated_data: header) # => body, or nil

A 12-byte nonce is too short to pick at random for many messages under one key; count it, or use XChaCha20Poly1305, whose 24-byte nonce may be random.

Constants

KEY_BYTESIZE = 32
NONCE_BYTESIZE = 12

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