crypto_skcipher_setkey(9)
π crypto_skcipher_setkey(9) β the Kernel API Manual, bestie edition π
okay so real talk: this is a page from the Kernel API Manual (yes, that one, section 9, the kernel-flavored section, iykyk) and it's all about handing a cipher its key. it's short, it's sweet, it's giving "tiny function, huge consequences" energy. let's go β¨
πΈ NAME πΈ
crypto_skcipher_setkey β set key for cipher
likeβ¦ that's literally the whole job. it sets the key. for the cipher. slay π
β¨ SYNOPSIS β¨
int crypto_skcipher_setkey (struct crypto_skcipher *tfm , const u8 *key
, unsigned int keylen );
that's the whole signature, no cap. returns an int, takes three things, we'll get to those π«Ά
π¦ ARGUMENTS π¦
tfmβ the cipher handle. your main character struct. the thing you're setting a key on πkeyβ a buffer holding the key. the actual bytes. the secret sauce πkeylenβ length of the key in bytes. not bits, not vibes, bytes. β
π DESCRIPTION π
so the caller hands over a key, and that key gets set for the skcipher referenced by the cipher handle. simple as that, bestie. the handle knows which cipher it is, you bring the key, done π
but here's the iconic part π β the key length determines the cipher type. like, the size of the key you pass is literally what decides which flavor you get. many block ciphers implement different cipher modes depending on the key size, such as AES-128 vs AES-192 vs AES-256. so when you provide a 16 byte key for an AES cipher handle, AES-128 is performed. sixteen bytes in, AES-128 out. that's the vibe check, and it passed π
β¨
π¨ lowkey important: don't assume the handle picks the mode for you β the length of the key is the choice.16bytes βAES-128. periodt.
π₯ RETURN π₯
0β the setting of the key was successful. we love to see it π₯³< 0β an error occurred. something went wrong, go check it π
π§ SEE ALSO π§
so many friends in the cast list, fr fr. all of these live in the kernel file ./include/crypto/skcipher.h:
struct skcipher_request(9)struct skcipher_alg(9)struct lskcipher_alg(9)Symmetric Key Cipher API(9)crypto_alloc_skcipher(9)crypto_alloc_lskcipher(9)crypto_free_skcipher(9)crypto_free_lskcipher(9)crypto_has_skcipher(9)crypto_skcipher_ivsize(9)crypto_lskcipher_ivsize(9)crypto_skcipher_blocksize(9)crypto_lskcipher_blocksize(9)crypto_skcipher_chunksize(9)crypto_lskcipher_chunksize(9)crypto_skcipher_statesize(9)crypto_lskcipher_statesize(9)crypto_lskcipher_setkey(9)crypto_skcipher_reqtfm(9)crypto_skcipher_encrypt(9)crypto_skcipher_decrypt(9)crypto_skcipher_export(9)crypto_skcipher_import(9)crypto_lskcipher_encrypt(9)crypto_lskcipher_decrypt(9)Symmetric Key Cipher Request Handle(9)crypto_skcipher_reqsize(9)skcipher_request_set_tfm(9)skcipher_request_alloc(9)skcipher_request_free(9)skcipher_request_set_callback(9)skcipher_request_set_crypt(9)
and that's the page, bestie π this lil icon lives in ./include/crypto, and the version we're reading is dated October 2026 β so go set some keys, pick your key length on purpose, and remember: keylen is the whole personality here ππ§π
π¦ 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