The `AES` block cipher and some common modes. See: - [[ https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.197-upd1.pdf ]] - [[ https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf ]] - [[ https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf ]]

Collection Info

View Source
Collection
core
Path
crypto/aes
Entries
26

Source Files

Constants

9

BLOCK_SIZE #

Source
BLOCK_SIZE :: _aes.BLOCK_SIZE

BLOCK_SIZE is the AES block size in bytes.

CTR_IV_SIZE #

Source
CTR_IV_SIZE :: 16

CTR_IV_SIZE is the size of the CTR mode IV in bytes.

DEFAULT_IMPLEMENTATION #

Source
DEFAULT_IMPLEMENTATION :: Implementation.Hardware

DEFAULT_IMPLEMENTATION is the implementation that will be used by default if possible.

GCM_IV_SIZE #

Source
GCM_IV_SIZE :: 12

GCM_IV_SIZE is the default size of the GCM IV in bytes.

GCM_IV_SIZE_MAX #

Source
GCM_IV_SIZE_MAX :: 0x2000000000000000

GCM_IV_SIZE_MAX is the maximum size of the GCM IV in bytes.

GCM_TAG_SIZE #

Source
GCM_TAG_SIZE :: _aes.GHASH_TAG_SIZE

GCM_TAG_SIZE is the size of a GCM tag in bytes.

KEY_SIZE_128 #

Source
KEY_SIZE_128 :: _aes.KEY_SIZE_128

KEY_SIZE_128 is the AES-128 key size in bytes.

KEY_SIZE_192 #

Source
KEY_SIZE_192 :: _aes.KEY_SIZE_192

KEY_SIZE_192 is the AES-192 key size in bytes.

KEY_SIZE_256 #

Source
KEY_SIZE_256 :: _aes.KEY_SIZE_256

KEY_SIZE_256 is the AES-256 key size in bytes.

Types

4

Context_ECB #

Source
Context_ECB :: Context_ECB

Context_ECB is a keyed AES-ECB instance. WARNING: Using ECB mode is strongly discouraged unless it is being used to implement higher level constructs.

Implementation #

Source
Implementation :: Implementation

Implementation is an AES implementation. Most callers will not need to use this as the package will automatically select the most performant implementation available (See `is_hardware_accelerated()`).

Procedures

13

decrypt_ecb #

Source
decrypt_ecb :: proc(ctx: ^Context_ECB, dst, src: []u8) {…}

decrypt_ecb decrypts the BLOCK_SIZE buffer src, and writes the result to dst.

encrypt_ecb #

Source
encrypt_ecb :: proc(ctx: ^Context_ECB, dst, src: []u8) {…}

encrypt_ecb encrypts the BLOCK_SIZE buffer src, and writes the result to dst.

is_hardware_accelerated #

Source
is_hardware_accelerated :: proc "contextless" () -> bool {…}

is_hardware_accelerated returns true if and only if (⟺) hardware accelerated AES is supported.

keystream_bytes_ctr #

Source
keystream_bytes_ctr :: proc(ctx: ^Context_CTR, dst: []u8) {…}

keystream_bytes_ctr fills dst with the raw AES-CTR keystream output.

open_gcm #

Source
@(require_results)
open_gcm :: proc(
	ctx:                           ^Context_GCM, 
	dst, iv, aad, ciphertext, tag: []u8, 
) -> bool {…}

open_gcm authenticates the aad and ciphertext, and decrypts the ciphertext, with the provided Context_GCM, iv, and tag, and stores the output in dst, returning true if and only if (⟺) the authentication was successful. If authentication fails, the destination buffer will be zeroed. dst and plaintext MUST alias exactly or not at all.

reset_ctr #

Source
reset_ctr :: proc "contextless" (ctx: ^Context_CTR) {…}

reset_ctr sanitizes the Context_CTR. The Context_CTR must be re-initialized to be used again.

reset_ecb #

Source
reset_ecb :: proc "contextless" (ctx: ^Context_ECB) {…}

reset_ecb sanitizes the Context_ECB. The Context_ECB must be re-initialized to be used again.

reset_gcm #

Source
reset_gcm :: proc "contextless" (ctx: ^Context_GCM) {…}

reset_gcm sanitizes the Context_GCM. The Context_GCM must be re-initialized to be used again.

seal_gcm #

Source
seal_gcm :: proc(
	ctx:                          ^Context_GCM, 
	dst, tag, iv, aad, plaintext: []u8, 
) {…}

seal_gcm encrypts the plaintext and authenticates the aad and ciphertext, with the provided Context_GCM and iv, stores the output in dst and tag. dst and plaintext MUST alias exactly or not at all.

xor_bytes_ctr #

Source
xor_bytes_ctr :: proc(ctx: ^Context_CTR, dst, src: []u8) {…}

xor_bytes_ctr XORs each byte in src with bytes taken from the AES-CTR keystream, and writes the resulting output to dst. dst and src MUST alias exactly or not at all.