KCAPI_CIPHER_ENC_SM4(3)
π KCAPI_CIPHER_ENC_SM4 β bestie edition π
okay so this is a page from the libkcapi manual (section 3, the library-functions girlies β¨), and we're talking about kcapi_cipher_enc_sm4_ctr. yes that's a mouthful. no you don't have to say it out loud. let's get into it π«Ά
β¨ NAME β¨
kcapi_cipher_enc_sm4_ctr β the convenience function for SM4 CTR encryption. it's giving "i do one thing and i do it well" π
πΈ SYNOPSIS πΈ
ssize_t kcapi_cipher_enc_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);
that's the whole vibe. one call, seven arguments, zero drama π
π ARGUMENTS π
keyβ[in]the key buffer. this is the secret, guard it with your life π«£keylenβ[in]length of the key buffer.inβ[in]the plaintext data buffer. the raw tea before it gets wrapped up βinlenβ[in]length of theinbuffer.ctrβ[in]the start counter value to be used for the cipher operation. yes bestie, counter mode needs a counter, shocking i know πoutβ[out]the ciphertext data buffer. where the glow-up gets written β¨outlenβ[in]length of theoutbuffer.
π DESCRIPTION π
so what does this little icon actually do? it performs an SM4 counter mode encryption operation using the key you handed over, the input buffer you gave it, and the IV you provided. the result gets stored in the out buffer. periodt. π₯
the input buffer can be of arbitrary length. go off, no length restrictions here π
the output buffer must be at least as large as the input buffer. this is not a suggestion, this is the law, and the law is not playing π
the start counter can contain all zeros β and yes bestie, that means actual zero bytes, not a NULL buffer! β and it must be exactly 16 bytes in size. exactly. sixteen. no more, no less, we're not doing guesswork π
the SM4 key is fixed 16 bytes long. that's it. that's the number. don't come at it with 15 or 17, it will simply not slay. π
and when you call it: it returns the number of bytes generated upon success, or a negative errno-style error code if an error occurred. so if you see a negative number, that's not a flex, that's a problem, go read your errno π¨
π AUTHOR π
Stephan Mueller <smueller@chronox.de>
Author. the main character who wrote all of this, we stan π«Ά
π COPYRIGHT π
this page lives under the libkcapi Manual, version 1.5.0, dated July 2025 β and that's the whole page bestie, you read it, you understood it, you're basically a cryptographer now ππ¦β¨ stay encrypted, stay iconic, mwah π
π¦ 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