aes_gcm_init(9)
π aes_gcm_init(9)
okay so this is a page straight out of the Kernel API Manual, and honestly? it's kind of a big deal. bestie, we're talking about aes_gcm_init β the little function that kicks off AES-GCM. buckle up π
β¨ NAME β¨
aes_gcm_init β initializes the context for incremental AES-GCM encryption or decryption, or for AES-GMAC computation. that's it, that's the vibe π
π¦ SYNOPSIS π¦
void aes_gcm_init (struct aes_gcm_ctx *ctx , const u8 nonce[static 12] ,
const struct aes_gcm_key *key );
like, look at her. tiny signature, huge responsibility. π₯
πΈ ARGUMENTS πΈ
ctxβ the context you're initializing. this is her moment, this is her main character energy πnonceβ the 12-byte nonce. and listen, this part is not a joke: every single(key, nonce)pair you use for encryption or MAC generation MUST be distinct. no repeating, no recycling, no "eh it's probably fine". it is not fine. πkeyβ the key, which you've already prepped withaes_gcm_preparekey. β οΈ heads up though: a pointer to the key gets saved inside the context, so that key must live at least as long as the context does. no yeeting it out of scope early, bestie, that's how you get undefined behavior and a bad time π
π DESCRIPTION π
so, first things first: the context should be zeroized when it's done living its life. usually that zeroization just happens on its own inside aes_gcm_encrypt_final or aes_gcm_decrypt_final β slay, automatic. π«Ά but if you're the kind of caller who abandons a context without ever finalizing it? yeah, you gotta zeroize it explicitly. no skipping. π§Ή
IMPORTANT π₯ if you're decrypting data, or computing a GMAC value for verification, you MUST NOT assume that any decrypted data or associated data is authentic until the authentication tag has actually been verified. like, at all. zero trust until the tag checks out, periodt. π
and why does this incremental API even exist? because some callers can't efficiently use the one-shot functions β their data layout is nonlinear. that's the only reason. it's giving "specialized tool for a specialized problem." π
π incremental AES-GCM encryption
here's the recipe, in order:
aes_gcm_initaes_gcm_auth_update(any number of times)aes_gcm_encrypt_update(any number of times)aes_gcm_encrypt_final
π incremental AES-GCM decryption
same energy, different middle steps:
aes_gcm_initaes_gcm_auth_update(any number of times)aes_gcm_decrypt_update(any number of times)aes_gcm_decrypt_final
π incremental AES-GMAC computation
fun fact: AES-GMAC is just AES-GCM with zero bytes en/decrypted. literally the same thing with nothing going in or out, iconic. β¨ so for incremental AES-GMAC:
aes_gcm_initaes_gcm_auth_update(any number of times)aes_gcm_encrypt_finalto return the computed tag to the caller, oraes_gcm_decrypt_finalto directly verify the computed tag
see? two paths, both valid, pick your fighter. π₯
β CONTEXT β
Any context. (yes really, she's flexible like that π¦)
π SEE ALSO π
Kernel file ./include/crypto/aes-gcm.h, plus the whole friend group:
struct aes_gcm_key(9)struct aes_gcm_ctx(9)aes_gcm_preparekey(9)aes_gcm_encrypt(9)aes_gcm_decrypt(9)aes_gcm_auth_update(9)aes_gcm_encrypt_update(9)aes_gcm_decrypt_update(9)aes_gcm_encrypt_final(9)aes_gcm_decrypt_final(9)
go read them, iykyk ππ
and that's the whole page, bestie! π this lil masterpiece lives in ./include/crypto and it's dated October 2026 β go off, future manpage. mwah. πβ¨
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms