CTR class
Counter (CTR) mode for block ciphers.
The CTR
class provides a counter mode of operation for block ciphers, which turns a block cipher into a
stream cipher. It uses a counter and an initialization vector (IV) to generate a stream of key material that is
XORed with the plaintext to produce the ciphertext. The class supports dynamic block sizes based on the
provided block cipher.
Properties:
_counter
: A byte array used as the counter value._buffer
: A buffer for storing the encrypted block._bufpos
: An internal variable tracking the buffer position._cipher
: The block cipher used for encryption.
Constructor:
CTR
: Initializes the CTR mode with the given block cipher and IV. It allocates space for the counter and the encrypted block buffer and sets up the initial state.
Note: CTR mode effectively converts a block cipher into a stream cipher by generating a keystream. It is used for encrypting data with a block cipher in a parallelizable manner. Ensure that the IV is unique for each message.
Constructors
-
CTR(BlockCipher cipher, List<
int> iv) - Creates a CTR instance with the given block cipher and initialization vector (IV).
Properties
Methods
-
clean(
) → CTR - Clears internal state and data in the Counter (CTR) mode instance for security and memory management.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setCipher(
BlockCipher cipher, List< int> ? iv) → CTR - Sets the block cipher and initialization vector (IV) for the Counter (CTR) mode.
-
stream(
List< int> dst) → void - Generates and writes keystream to the destination.
-
streamXOR(
List< int> src, List<int> dst) → void - XORs source data with the keystream and writes the result to the destination.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited