---
name: "kcapi_cipher_dec_sm4_ctr"
section: "3"
platform: "linux"
package: "libkcapi-dev"
version: "1.4.0-1+b2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/kcapi_cipher_dec_sm4_ctr"
---

# kcapi\_cipher\_dec\_sm4\_ctr(3)

Convenience function for SM4 CTR decryption

## NAME

kcapi\_cipher\_dec\_sm4\_ctr - Convenience function for SM4 CTR decryption

## 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***);**

## ARGUMENTS

*key*

\[in\] key buffer

*keylen*

\[in\] length of key buffer

*in*

\[in\] ciphertext data buffer

*inlen*

\[in\] length of in buffer

*ctr*

\[in\] start counter value to be used for cipher operation

*out*

\[out\] plaintext data buffer

*outlen*

\[in\] length of out buffer

## DESCRIPTION

The convenience function performs an SM4 counter mode encryption operation using the provided key, the given input buffer and the given IV. The output is stored in the out buffer.

The input buffer can be of arbitrary length.

The output buffer must be at least as large as the input buffer.

The start counter can contain all zeros (not a NULL buffer!) and must be exactly 16 bytes in size.

The SM4 key is fixed 16 bytes long.

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

## AUTHOR

**Stephan Mueller** \<smueller@chronox.de\>

Author.

## COPYRIGHT
