gnu.crypto.mode

Class CTR

Implemented Interfaces:
Cloneable, IBlockCipher, IMode

public class CTR
extends BaseMode
implements Cloneable

The implementation of the Counter Mode.

The algorithm steps are formally described as follows:

    CTR Encryption: O[j] = E(K)(T[j]); for j = 1, 2...n;
                    C[j] = P[j] ^ O[j]; for j = 1, 2...n.
    CTR Decryption: O[j] = E(K)(T[j]); for j = 1, 2...n;
                    P[j] = C[j] ^ O[j]; for j = 1, 2...n.
 

where P is the plaintext, C is the ciphertext, E(K) is the underlying block cipher encryption function parametrised with the session key K, and T is the Counter.

This implementation, uses a standard incrementing function with a step of 1, and an initial value similar to that described in the NIST document.

References:

  1. Recommendation for Block Cipher Modes of Operation Methods and Techniques, Morris Dworkin.
Version:
$Revision: 1.7 $

Field Summary

Fields inherited from class gnu.crypto.mode.BaseMode

cipher, cipherBlockSize, iv, lock, modeBlockSize, name, state

Fields inherited from interface gnu.crypto.cipher.IBlockCipher

CIPHER_BLOCK_SIZE, KEY_MATERIAL

Fields inherited from interface gnu.crypto.mode.IMode

DECRYPTION, ENCRYPTION, IV, MODE_BLOCK_SIZE, STATE

Constructor Summary

CTR(IBlockCipher underlyingCipher, int cipherBlockSize)
Trivial package-private constructor for use by the Factory class.

Method Summary

Iterator
blockSizes()
Object
clone()
void
decryptBlock(byte[] in, int i, byte[] out, int o)
void
encryptBlock(byte[] in, int i, byte[] out, int o)
void
setup()
void
teardown()

Methods inherited from class gnu.crypto.mode.BaseMode

blockSizes, clone, currentBlockSize, decryptBlock, defaultBlockSize, defaultKeySize, encryptBlock, init, keySizes, name, reset, selfTest, setup, teardown, update

Constructor Details

CTR

(package private)  CTR(IBlockCipher underlyingCipher,
                       int cipherBlockSize)
Trivial package-private constructor for use by the Factory class.
Parameters:
underlyingCipher - the underlying cipher implementation.
cipherBlockSize - the underlying cipher block size to use.

Method Details

blockSizes

public Iterator blockSizes()
Specified by:
blockSizes in interface IBlockCipher
Overrides:
blockSizes in interface BaseMode

clone

public Object clone()
Specified by:
clone in interface IBlockCipher
Overrides:
clone in interface BaseMode

decryptBlock

public void decryptBlock(byte[] in,
                         int i,
                         byte[] out,
                         int o)
Specified by:
decryptBlock in interface IBlockCipher
Overrides:
decryptBlock in interface BaseMode

encryptBlock

public void encryptBlock(byte[] in,
                         int i,
                         byte[] out,
                         int o)
Specified by:
encryptBlock in interface IBlockCipher
Overrides:
encryptBlock in interface BaseMode

setup

public void setup()
Overrides:
setup in interface BaseMode

teardown

public void teardown()
Overrides:
teardown in interface BaseMode

Copyright © 2001, 2002, 2003 Free Software Foundation, Inc. All Rights Reserved.