sm4_setkey(9)
π sm4_setkey(9) β like, the SM4 key setter, bestie
okay so this is a page from the Kernel API Manual and it's all about one little function that sets your SM4 key. it's short, it's sweet, it's giving "small but mighty" energy, and yes we're gonna go through every single detail together because that's just how we do things around here π«Ά
β¨ SYNOPSIS β¨
int sm4_setkey (struct crypto_tfm *tfm , const u8 *in_key , unsigned int
key_len );
like, that's the whole vibe. three args, one int back. slay π
π ARGUMENTS π
tfmβ thecrypto_tfmthat's being used in the context. it's the main character here, honestly πin_keyβ the input key. the actual key. the one you're setting. no cap πkey_lenβ the size of the key. it matters. it really matters (more on that in a sec π)
πΈ DESCRIPTION πΈ
so what does it actually do? it calls sm4_expandkey to expand the key. that's it, that's the job. iconic behaviour honestly β¨
but here's the part where you gotta pay attention, bestie: sm4_ctx _must_ be the private data embedded in tfm, and you get that private data by retrieving it with crypto_tfm_ctx. like, that's not optional. it's a must. capital-M Must. the emphasis is theirs, not mine π
so the flow is: grab the ctx from the tfm via crypto_tfm_ctx, and that ctx has to be a sm4_ctx living as the private data embedded in tfm. then the key expansion does its thing. periodt π
β RETURN β
0on success β we love a happy ending π-EINVALon failure β and ngl this only happens for bad key lengths, so if you're getting this it's akey_lensituation, not a you situation π«Ά
π¦ SEE ALSO π¦
- Kernel file
./crypto/sm4_generic.cβ go read it, it's right there, iykyk π§
lowkey a reminder: bad key lengths are the only failure mode listed here, so double-check that key_len before you come crying to the error code π
and that's the page!! π this little gem is from ./crypto, dated October 2026, and it's sm4_setkey(9) β go forth and set those keys bestie, you're gonna do amazing πππ₯
π¦ 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