KCAPI_CIPHER_ENCRYPT(3)

πŸ’– kcapi_cipher_encrypt(3) β€” bestie edition πŸ’–

okay so, welcome to kcapi_cipher_encrypt(3) from the libkcapi programming interface ✨ this one's your girl for encrypting data, synchronous one-shot style. no drama, no streaming, just one call and we're done. periodt πŸ’…


✨ NAME ✨

kcapi_cipher_encrypt β€” encrypt data (synchronous one shot) πŸ”


🌸 SYNOPSIS 🌸

ssize_t kcapi_cipher_encrypt(struct kcapi_handle * handle,
                             const uint8_t * in, size_t inlen,
                             const uint8_t * iv, uint8_t * out,
                             size_t outlen, int access);

like, one function, seven args, and she delivers. πŸ‘‘


πŸŽ€ ARGUMENTS πŸŽ€

  • handle β€” [in] the cipher handle 🫢 your lil connection to the cipher, bestie.
  • in β€” [in] the plaintext data buffer. this is the tea before we encrypt it πŸ“
  • inlen β€” [in] length of in buffer. yes queen, we need to know how big it is.
  • iv β€” [in] IV to be used for cipher operation. the initialization vector, iconic behavior only πŸ’œ
  • out β€” [out] ciphertext data buffer. the glow-up version goes here 🌈
  • outlen β€” [in] length of out buffer. don't skip this one, fr fr.
  • access β€” [in] kernel access type, and she's got options 😌
    • KCAPI_ACCESS_HEURISTIC β€” use internal heuristic for fastest kernel access (the "let her pick" vibe, main character energy tbh)
    • KCAPI_ACCESS_VMSPLICE β€” use vmsplice access
    • KCAPI_ACCESS_SENDMSG β€” sendmsg access

πŸ’« DESCRIPTION πŸ’«

okay so first things first: it is perfectly legal to use the same buffer as the plaintext and ciphertext pointers πŸ‘€ that means after the encryption operation, the plaintext is overwritten with the ciphertext. in-place glow-up, we love to see it. no cap.

now, the memory should be aligned at the page boundary using posix_memalign(sysconf(_SC_PAGESIZE)). and bestie, if it is not aligned at the page boundary, the vmsplice call may not send all data to the kernel 😭 like it'll just leave some of your data behind at the function. not the vibe. please align it.

the IV buffer must be exactly kcapi_cipher_ivsize bytes in size. exactly. not "about that", not "close enough". exactly. 🎯

and what does she give you back? return number of bytes encrypted upon success ✨ a negative errno-style error code if an error occurred πŸ’€ so like, positive number = slay, negative = we have a problem.

real talk though: that same-buffer trick is legal, but it does overwrite your plaintext. once she's gone, she's gone πŸ™ˆ plan accordingly.

πŸ¦‹ AUTHOR πŸ¦‹

Stephan Mueller <smueller@chronox.de> β€” Author. the icon who wrote this πŸ’–


part of the libkcapi Manual 1.5.0, dated July 2025 πŸ—“οΈ


and that's the whole page bestie, go encrypt something and be iconic about it πŸ’…βœ¨πŸ¦‹πŸŒΈπŸŽ€πŸ’œ

πŸ“¦ where this page comes from