Skip to content

miniproto.crypto.native.aes_256_ctr_crypt

aes_256_ctr_crypt(data: BytesLike, key: bytes, iv: bytes) -> bytes

Apply AES-256-CTR to bytes for encryption or decryption.

Parameters:

  • data (BytesLike) – Input bytes of any length.
  • key (bytes) – Exactly 32 bytes of AES-256 key material.
  • iv (bytes) – Exactly 16 bytes of counter/initialization value.

Returns:

  • bytes – Transformed bytes of the same length.

Raises:

  • ValueError – If the key or IV length is invalid.

CTR is symmetric and does not authenticate input. Never reuse the same key and IV for different plaintexts; this wrapper does not enforce uniqueness. With cryptography installed, the benchmarked C-backed fallback is chosen.