DOKK / manpages / debian 11 / libkcapi-dev / kcapi_cipher_encrypt.3.en
KCAPI_CIPHER_ENCRYPT(3) Programming Interface KCAPI_CIPHER_ENCRYPT(3)

kcapi_cipher_encrypt - encrypt data (synchronous one shot)

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

handle

[in] cipher handle

in

[in] plaintext data buffer

inlen

[in] length of in buffer

iv

[in] IV to be used for cipher operation

out

[out] ciphertext data buffer

outlen

[in] length of out buffer

access

[in] kernel access type (KCAPI_ACCESS_HEURISTIC - use internal heuristic for fastest kernel access; KCAPI_ACCESS_VMSPLICE - use vmsplice access; KCAPI_ACCESS_SENDMSG - sendmsg access)

It is perfectly legal to use the same buffer as the plaintext and ciphertext pointers. That would mean that after the encryption operation, the plaintext is overwritten with the ciphertext.

The memory should be aligned at the page boundary using posix_memalign(sysconf(_SC_PAGESIZE)), If it is not aligned at the page boundary, the vmsplice call may not send all data to the kernel.

The IV buffer must be exactly kcapi_cipher_ivsize bytes in size.

return number of bytes encrypted upon success; a negative errno-style error code if an error occurred

Stephan Mueller <smueller@chronox.de>

Author.

November 2020 libkcapi Manual 1.2.1