class
Crypto::AeadChacha20Poly1305
- Crypto::AeadChacha20Poly1305
- Reference
- Object
Overview
AEAD_CHACHA20_POLY1305 is an authenticated encryption with additional data algorithm.
Defined in:
crypto/aead.crConstructors
-
.new(key : Bytes, nonce : Bytes, io : IO)
The inputs to AEAD_CHACHA20_POLY1305 are: * key: A 256-bit key * nonce: A 96-bit nonce -- different for each invocation with the same key * io: the buffer to write the authenticated plain and ciphertext to
Class Method Summary
-
.decrypt(key : Bytes, nonce : Bytes, aad : Bytes, ciphertext : Bytes, tag : Bytes) : Bytes
The inverse of
.encrypt. -
.encrypt(key : Bytes, nonce : Bytes, aad : Bytes, plaintext : Bytes) : Tuple(Bytes, Bytes)
One-shot form of AEAD_CHACHA20_POLY1305 as specified in RFC 8439 section 2.8, as an alternative to the streaming/IO based instance interface above.
Instance Method Summary
-
#aad(data : Bytes)
Arbitrary length additional authenticated data (AAD).
-
#decrypt(data : Bytes, tag : Bytes) : Bytes
decrpyt parses the data and verifies the data with the tag returns the additional authenticated data.
-
#final : Bytes
write final footer
-
#update(data : Bytes)
An arbitrary length plaintext, has to be multiples of 16 bytes last call might be with less then 16 bytes
Constructor Detail
The inputs to AEAD_CHACHA20_POLY1305 are:
- key: A 256-bit key
- nonce: A 96-bit nonce -- different for each invocation with the same key
- io: the buffer to write the authenticated plain and ciphertext to
Class Method Detail
The inverse of .encrypt. Verifies tag against #aad and
ciphertext before decrypting, raising TagException when it does
not match.
One-shot form of AEAD_CHACHA20_POLY1305 as specified in RFC 8439
section 2.8, as an alternative to the streaming/IO based instance
interface above. Useful whenever a protocol needs a plain
encrypt(plaintext, aad) -> {ciphertext, tag} call per message,
such as protecting a single TLS 1.3 record (RFC 8446 section 5.2).
This method does not construct the per-record nonce for you: per RFC 8446 section 5.3 it is the connection's fixed IV XORed with the big-endian, zero left-padded 64-bit record sequence number.
Returns the ciphertext (same length as plaintext) and the 16-byte authentication tag.
Instance Method Detail
Arbitrary length additional authenticated data (AAD). Needs to be written before the plaintext. Can be called multiple times, but only the last block can be less then 16 bytes.
decrpyt parses the data and verifies the data with the tag returns the additional authenticated data. The plaintext is written to the provided mem, in case the tag is not validating the data an exception is raised.
An arbitrary length plaintext, has to be multiples of 16 bytes last call might be with less then 16 bytes