std :: crypto::aes
Struct std::AesCtx
struct AesCtx {
unsigned int ks[AES_KS_WORDS];
int rounds;
unsigned char iv[AES_BLOCK_SIZE];
}Fields
expanded key schedule
10 (AES-128) or 14 (AES-256)
CBC initialisation vector
Methods
An AES-128 context from a 16-byte key (IV zeroed).
An AES-256 context from a 32-byte key (IV zeroed).
Encrypt one 16-byte block in-place (ECB).
Decrypt one 16-byte block in-place (ECB).
Encrypt len bytes (must be multiple of 16) in CBC mode.
Uses and updates self.iv.
Decrypt len bytes in CBC mode. Uses and updates self.iv.
Set the CBC initialisation vector.
void gcm_encrypt(
[]const unsigned char iv,
[]const unsigned char aad,
[]unsigned char data,
[]unsigned char tag,
)source · definitionAES-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 · definitionChecks 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).
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).
= drop()