KCAPI_CIPHER_ENC_SM4(3)
β¨ kcapi_cipher_enc_sm4_cbc β the SM4 CBC glow-up β¨
okay so bestie, this is a page from the libkcapi manual (section 3, the library functions section, iykyk) and it's about one very specific little function called kcapi_cipher_enc_sm4_cbc. it's a convenience function for SM4 CBC encryption and honestly? she's simple, she's focused, she does exactly one thing. π
πΈ NAME πΈ
kcapi_cipher_enc_sm4_cbc β the convenience function that does SM4 CBC encryption for you π
β¨ SYNOPSIS β¨
ssize_t kcapi_cipher_enc_sm4_cbc(const uint8_t * key, uint32_t keylen,
const uint8_t * in, size_t inlen,
const uint8_t * iv, uint8_t * out,
size_t outlen);
like, look at her. seven arguments. she's not complicated, she just knows what she wants π
π¦ ARGUMENTS π¦
keyβ [in] the key buffer. this is the secret. guard it with your life fr fr πkeylenβ [in] length of that key buffer.inβ [in] the plaintext data buffer. this is the tea before it gets scrambled βinlenβ [in] length of theinbuffer.ivβ [in] the IV to be used for the cipher operation. yes you need one, no you can't skip it π«outβ [out] the ciphertext data buffer. this is where the scrambled result lands π«Άoutlenβ [in] length of theoutbuffer.
π DESCRIPTION π
so what does she actually do? the convenience function performs an SM4 CBC encryption operation using the provided key, the given input buffer and the given IV. the output gets stored in the out buffer. that's it. that's the whole vibe. β¨
β οΈ important bestie β οΈ note that SM4 CBC requires an input data that is a multiple of 16 bytes. if you have data that is not guaranteed to be multiples of 16 bytes, either add zero bytes at the end of the buffer to pad it up to a multiple of 16 bytes. otherwise, the CTR mode encryption operation may be usable. (so like, know your byte math before you come for her π)
the output buffer must be at least as large as the input buffer. no tiny buffers allowed, she needs room to work π
the IV must be exactly 16 bytes in size. exactly. not 15, not 17. sixteen. periodt. π―
the SM4 key is fixed 16 bytes long. that's just how SM4 is, she's built different. π
and the return value? number of bytes generated upon success; a negative errno-style error code if an error occurred. so like, if it's negative, something went wrong, go read the errno and figure out your life π
π AUTHOR π
Stephan Mueller <smueller@chronox.de>
- Author.
π COPYRIGHT π
that's the whole page, bestie! it's from the libkcapi Manual version 1.5.0, dated July 2025, and yes, it lives at KCAPI_CIPHER_ENC_SM4(3) β section 3, cipher encryption, SM4, iykyk. go forth and encrypt responsibly π§π
π¦ 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