KCAPI_CIPHER_DEC_SM4(3)
π kcapi_cipher_dec_sm4(3) π
okay bestie, so this is a page from the libkcapi Manual, and it's literally about the convenience function kcapi_cipher_dec_sm4_ctr β the SM4 CTR decryption one. yes it's as iconic as it sounds, let's get into it π
β¨ NAME β¨
kcapi_cipher_dec_sm4_ctr β the convenience function for SM4 CTR decryption. it does exactly what it says on the tin, no cap π
πΈ SYNOPSIS πΈ
ssize_t kcapi_cipher_dec_sm4_ctr(const uint8_t * key, uint32_t keylen,
const uint8_t * in, size_t inlen,
const uint8_t * ctr, uint8_t * out,
size_t outlen);
like, seven arguments. she's a lot, but she's worth it π«Ά
π¦ ARGUMENTS π¦
keyβ [in] the key buffer, bestie. the actual key.keylenβ [in] how long that key buffer is.inβ [in] the ciphertext data buffer. this is what you're decrypting, mwah.inlenβ [in] length of theinbuffer.ctrβ [in] the start counter value that gets used for the cipher operation.outβ [out] the plaintext data buffer. this is where the magic lands β¨outlenβ [in] length of theoutbuffer.
π DESCRIPTION π
so this convenience function performs an SM4 counter mode encryption operation β using the key you handed it, the input buffer you gave it, and the IV you gave it. the output gets stored in the out buffer. that's the whole vibe.
- The input buffer can be of arbitrary length. no constraints, she's flexible π
- The output buffer must be at least as large as the input buffer. periodt. don't try to be cute and make it smaller.
- The start counter can contain all zeros β and listen, that is not a NULL buffer, it's a buffer full of zeros, two very different things bestie β and it must be exactly 16 bytes in size.
- The SM4 key is fixed 16 bytes long. 16. not 15, not 17. sixteen π
then, the return: it gives you back the number of bytes generated upon success; and if something went wrong, you get a negative errno-style error code. so if the number is negative, that's not a byte count, that's a problem, okay? π
ngl the zero-vs-NULL counter thing is the classic gotcha here. all zeros = fine, NULL = absolutely not. π
π AUTHOR π
- Stephan Mueller
<smueller@chronox.de>β Author.
π COPYRIGHT π
and that's the whole page, bestie! this was libkcapi Manual 1.5.0, dated July 2025, and you were reading KCAPI_CIPHER_DEC_SM4(3) the entire time πβ¨ go decrypt something cute, ily π«Άπ
π¦ where this page comes from
- fedora 43: libkcapi-devel 1.5.0-6.fc43 Β· BSD-3-Clause OR GPL-2.0-only
- fedora 43: libkcapi-devel 1.5.0-6.fc43 Β· BSD-3-Clause OR GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms