std1.0.0-beta-7 SafeC docs

std :: crypto::aes

Struct std::AesCtx

#include <std/crypto/aes.h> source

struct AesCtx {
    unsigned int ks[AES_KS_WORDS];
    int rounds;
    unsigned char iv[AES_BLOCK_SIZE];
}

Fields

§unsigned int ks[AES_KS_WORDS]source

expanded key schedule

§int roundssource

10 (AES-128) or 14 (AES-256)

§unsigned char iv[AES_BLOCK_SIZE]source

CBC initialisation vector

Methods

§static struct AesCtx new_128([]const unsigned char key)source · definition

An AES-128 context from a 16-byte key (IV zeroed).

§static struct AesCtx new_256([]const unsigned char key)source · definition

An AES-256 context from a 32-byte key (IV zeroed).

§void encrypt_block([]unsigned char block)source · definition

Encrypt one 16-byte block in-place (ECB).

§void decrypt_block([]unsigned char block)source · definition

Decrypt one 16-byte block in-place (ECB).

§void cbc_encrypt([]unsigned char data)source · definition

Encrypt len bytes (must be multiple of 16) in CBC mode. Uses and updates self.iv.

§void cbc_decrypt([]unsigned char data)source · definition

Decrypt len bytes in CBC mode. Uses and updates self.iv.

§void set_iv([]const unsigned char iv)source · definition

Set the CBC initialisation vector.

§void gcm_encrypt( []const unsigned char iv, []const unsigned char aad, []unsigned char data, []unsigned char tag, )source · definition

AES-GCM (NIST SP 800-38D) with a 12-byte IV and a 16-byte tag: encrypts data[0..len) in place and writes the tag over the additional data aad[0..aad_len) (aad may be null when aad_len is 0) and the ciphertext. Never reuse an IV with the same key.

§int gcm_decrypt( []const unsigned char iv, []const unsigned char aad, []unsigned char data, []const unsigned char tag, )source · definition

Checks the tag (in constant time) and, only if it matches, decrypts data[0..len) in place. Returns 1 if authentic, 0 if not (data is then left as the unauthenticated ciphertext).

§void drop()source · definition

Securely wipe the expanded key schedule and IV (via mem_zero_secure — a volatile write-through that survives dead-store elimination, unlike a plain assignment the optimizer could see is never read again and drop). Call this once a context is done being used, before it goes out of scope, so the key material doesn't linger readable in memory (e.g. in a stack frame reused by a later, unrelated function, or in a crash dump).

§void destroy() consumesource · definition

= drop()