class

Beryl::Crypto::V1::AdvancedEncryptionStandardInGaloisCounterMode

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

AES-GCM (FIPS 197 and NIST SP 800-38D): authenticated encryption under a 16, 24 or 32-byte key. It is the cipher of TLS 1.3's TLS_AES_128_GCM_SHA256 and TLS_AES_256_GCM_SHA384.

cipher = Beryl::Crypto::V1::AESGCM.new(key) # AES-256-GCM for a 32-byte key
sealed = cipher.encrypt(body, nonce: nonce, associated_data: header)
cipher.decrypt(sealed, nonce: nonce, associated_data: header) # => body, or nil

Use a 12-byte nonce, and count it: one repeated nonce under one key gives away the authentication key. A nonce of another length is accepted, as the standard defines, for formats that already use one.

On a processor with AES and carry-less multiply instructions (ARMv8 aese and pmull, x86-64 AES-NI and pclmulqdq), both run on those instructions, eight blocks at a time, and on x86-64 with VAES and VPCLMULQDQ four or two blocks to an instruction (GaloisCounterModeWithProcessorInstructions). Elsewhere AES runs as a Boolean circuit and GHASH as carry-less multiplies built from integer ones, with no table (BitslicedAdvancedEncryptionStandard and GaloisHash). Either way the running time is the same for every key and every message.

Constants

LIST_OF_TAG_BYTESIZES = [16, 15, 14, 13, 12, 8, 4]

The tag sizes SP 800-38D ยง5.2.1.2 defines, in bytes. Sizes under 12 exist for formats that already use them; a short tag is easy to forge.

NONCE_BYTESIZE = 12

The nonce size SP 800-38D recommends, in bytes.

Constructors

new(key : Bytes, *, tag_bytesize : Int32 = FULL_TAG_BYTESIZE)

Creates the cipher under key (16, 24 or 32 bytes). tag_bytesize is the number of tag bytes kept on each message.

Source

Instance methods

nonce_bytesize

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

Source