AES-CTR Mode
AES-CTR Mode
CTR mode turns a block cipher into a stream cipher by encrypting a nonce and counter to produce a keystream, then XORing with plaintext.
Function signature
func CryptCTR(key [16]byte, nonce [8]byte, counter uint64, data []byte) []byte
Behavior
- Construct the counter block as
nonce || counter(8 bytes each, big-endian). - For each 16-byte block, encrypt the counter block with AES.
- XOR the keystream with data; increment the counter for the next block.
- Encryption and decryption are identical.
Notes
- AES block encryption is provided.
- Reusing the same (nonce, counter) pair with the same key is catastrophic.
Run tests to see results
No issues detected