KCAPI_CIPHER_DEC_SM4(3)

πŸ’– NAME πŸ’–

kcapi_cipher_dec_sm4_cbc β€” the convenience function that does SM4 CBC decryption for you, no cap, and it's literally called KCAPI_CIPHER_DEC_SM4 in the manual pages bestie ✨


πŸŽ€ SYNOPSIS πŸŽ€

ssize_t kcapi_cipher_dec_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);

πŸ¦‹ ARGUMENTS πŸ¦‹

Okay so here's the whole cast, and every single one of them matters:

  • key β€” [in] the key buffer, your little secret πŸ’œ
  • keylen β€” [in] how long that key buffer is
  • in β€” [in] the ciphertext data buffer (the locked-up version, the mystery)
  • inlen β€” [in] how long the in buffer is
  • iv β€” [in] the IV that's getting used for this cipher operation
  • out β€” [out] the plaintext data buffer, where the decoded truth lands 🫢
  • outlen β€” [in] how long the out buffer is

✨ DESCRIPTION ✨

So this convenience function performs an SM4 CBC decryption operation using the provided key, the given input buffer, and the given iv. The output gets stored in the out buffer. Iconic behaviour, honestly.

Real talk though, bestie: SM4 CBC requires input data that is a multiple of 16 bytes. If your data is not guaranteed to be a multiple of 16 bytes, either add zero bytes at the end of the buffer to pad it up to a multiple of 16 bytes β€” or, alternatively, the CTR mode encryption operation may be usable. Just saying, you have options. πŸ’…

The out buffer must be at least as large as the in buffer. No shrinking, no skimping, the output needs room to breathe.

The iv must be exactly 16 bytes in size. Exactly. Not 15, not 17. Periodt. 🌸

The SM4 key is fixed 16 bytes long. That's the vibe, that's the law.

And the return value: it hands you the number of bytes generated upon success, or a negative errno-style error code if an error occurred. So if it's negative, something went wrong and you should go read the errno, fr fr 😭


πŸ‘‘ AUTHOR πŸ‘‘

  • Stephan Mueller <smueller@chronox.de>
    • Author. The main character who wrote all this. Respect. 🫢

This whole thing is the libkcapi Manual, version 1.5.0, dated July 2025 β€” and that's a wrap, bestie πŸ’–βœ¨ Go forth and decrypt your SM4 CBC data responsibly, and remember: multiple of 16 bytes, IV of 16 bytes, key of 16 bytes. Slay. πŸŽ€πŸ¦‹πŸ’œ

πŸ“¦ where this page comes from