aes_xts_preparekey(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ aes_xts_preparekey ✨ (section 9, from the Kernel API Manual, bestie πŸ’…)

okay so listen β€” this is aes_xts_preparekey, and it's literally the glow-up your raw key needs before it can do AES-XTS encryption and decryption. πŸŽ€


🌸 NAME 🌸

aes_xts_preparekey β€” prepare a key for AES-XTS encryption and decryption. that's it, that's the job, and it ate. πŸ’–


✨ SYNOPSIS ✨

int aes_xts_preparekey (struct aes_xts_key *key , const u8 *in_key ,
size_t key_len , int flags );

πŸ¦‹ ARGUMENTS πŸ¦‹

  • key β€” (output) the key structure to initialize. this is your main character struct, the one getting all dressed up. πŸ‘‘
  • in_key β€” the raw AES-XTS key. the before picture. πŸ™ˆ
  • key_len β€” length of the raw key, in bytes. sizes matter, ikyk. πŸ“
  • flags β€” optional flag XTS_FORBID_WEAK_KEYS, which does exactly what it says on the tin: it forbids keys whose two halves are the same. no identical-twin keys on its watch, no cap. 🚫

πŸ’œ DESCRIPTION πŸ’œ

okay so here's the self-care routine: users should use memzero_explicit to zeroize the key struct at the end of its lifetime. wipe it down, cleanse it, keep it out of memory's camera roll. πŸ§–β€β™€οΈ

but β€” and this is the plot twist β€” if this function fails, zeroization is unnecessary. nothing to scrub if nothing ever got set up, periodt. πŸ’€


🌈 CONTEXT 🌈

Any context. any. it's giving low-maintenance icon, fr fr. ✨


πŸ”₯ RETURN πŸ”₯

  • 0 on success. slay, we love a clean win. πŸŽ‰
  • -EINVAL if the key is rejected, and there are two whole reasons that can happen:
    • because its length isn't 32, 64, or (when FIPS mode isn't enabled) 48; or
    • because its two halves are the same and either XTS_FORBID_WEAK_KEYS is given or FIPS mode is enabled. πŸ”΄
ngl, get the length or the halves wrong and it's an instant -EINVAL, no second chances. read the requirements before you slide into the function call. 😭

πŸ‘€ SEE ALSO πŸ‘€

Kernel file ./include/crypto/aes-xts.h, struct aes_xts_key(9), aes_xts_encrypt(9), aes_xts_decrypt(9) β€” go read the whole friend group, they're all iconic. 🫢


and that's the page, bestie! πŸ’– signed off by ./include/crypto, dated October 2026 β€” mwah, catch you in section 9. πŸ’…β­πŸŒΈ

πŸ“¦ where this page comes from