aes_gcm_decrypt(9)
π aes_gcm_decrypt β bestie edition
okay so this is aes_gcm_decrypt(9) from the Kernel API Manual, and it is literally the function that decrypts a message with AES-GCM. she's an icon, she's a legend, and she's about to hand you back your plaintext π
β¨ SYNOPSIS β¨
int aes_gcm_decrypt (u8 *dst , const u8 *src , size_t data_len ,
const u8 *authtag , const u8 *ad , size_t ad_len ,
const u8 nonce[static 12] ,
const struct aes_gcm_key *key );
πΈ ARGUMENTS πΈ
dstβ where the decrypted plaintext goes, queen. it can be in-place or out-of-place, we love flexibility π but for any other overlap, the behavior is unspecified β so don't get cute with it, bestie, that's an unhinged vibe check you will fail.srcβ the source ciphertext data. the scrambled-up little mystery we're solving π΅οΈββοΈdata_lenβ length of the plaintext in bytes (and also the length of the ciphertext excluding the tag). max is at most 2^36 - 32. memorise it. it's giving strict but fair.authtagβ the stored authentication tag π·οΈ its length is theauthtag_lenthat was passed toaes_gcm_preparekey. usually, protocols using AES-GCM put the tag at the end of the ciphertext β in which case this should be set tosrc + data_len, andsrcmust have room for the tag. iykyk β¨adβ the associated data (yes, the data that travels alongside, no, it doesn't get encrypted, don't ask).ad_lenβ length of associated data in bytes: at most 2^61 - 1. huge. iconic. periodt.nonceβ the 12-byte nonce. twelve. exactly twelve. not eleven, not thirteen. πkeyβ the key, already prepared usingaes_gcm_preparekey. like, already prepared. do not show up here with a raw key, that's embarrassing for everyone.
π¦ DESCRIPTION π¦
For AES-GMAC (i.e., AES-GCM without any data en/decrypted β a vibe-only run, no payload), use dst=NULL, src=NULL, and data_len=0 to verify the AES-GMAC value. yes bestie, that's the whole trick. no data, just trust β¨
π CONTEXT π
Any context. she does not gatekeep, she does not discriminate, any context is welcome in this house π«Ά
π RETURN π
0on success π this is the only case where any decrypted or associated data can be used. like, the only one. if you're not seeing a0, hands off the data, fr fr.-EBADMSGif the message is inauthentic π that's a fake friend, do not trust that message, do not read that message, do not let it into the group chat.
π¨ real talk: anything that isn't 0 means the output is not usable. the whole point of GCM is that the tag check is the gate, and this gate does not accept vibes as authentication.
π§ SEE ALSO π§
Kernel file ./include/crypto/aes-gcm.h, plus her whole friend group:
struct aes_gcm_key(9)struct aes_gcm_ctx(9)aes_gcm_preparekey(9)aes_gcm_encrypt(9)aes_gcm_init(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)
and that's the page, bestie π this queen lives over in ./include/crypto, she's dated October 2026, and she ships as part of the Kernel API Manual β go decrypt something responsibly, 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