Package gnu.crypto.mode

Provides a basic API for using block cipher Modes of Operation.

Interface Summary

IAuthenticatedMode The interface for encryption modes that also produce a message authentication tag.
IMode The basic visible methods of any block cipher mode.

Block ciphers encrypt plaintext in fixed size n-bit blocks.

Class Summary

BaseMode A basic abstract class to facilitate implementing block cipher modes of operations.
CBC The Cipher Block Chaining mode.
CFB The cipher feedback mode.
CTR 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.
EAX A conventional two-pass authenticated-encrypted mode, EAX.
ECB The implementation of the Electronic Codebook mode.

The Electronic Codebook (ECB) mode is a confidentiality mode that is defined as follows:

  • ECB Encryption: Cj = CIPHK(Pj) for j = 1...n
  • ECB Decryption: Pj = CIPH-1K(Cj) for j = 1...n

In ECB encryption, the forward cipher function is applied directly, and independently, to each block of the plaintext.

ICM An implementation of David McGrew Integer Counter Mode (ICM) as an IMode.

ICM is a way to define a pseudorandom keystream generator using a block cipher.

ModeFactory A Factory to instantiate block cipher modes of operations.
OFB The Output Feedback (OFB) mode is a confidentiality mode that requires a unique IV for every message that is ever encrypted under the given key.
Provides a basic API for using block cipher Modes of Operation.

Package overview

Cipher modes operate on the next level up from the underlying block cipher. They transform the blocks going in and out of the cipher in ways to give them desirable properties in certain circumstances.

The following diagram shows the important classes participating in this package:

../../..

gnu.crypto.pad

IMode mode = ModeFactory.getInstance("CFB", "AES", 16);
Map attributes = new HashMap();
// These attributes are defined in gnu.crypto.cipher.IBlockCipher.
attributes.put(IMode.KEY_MATERIAL, key_bytes);
attributes.put(IMode.CIPHER_BLOCK_SIZE, new Integer(16));
// These attributes are defined in IMode.
attributes.put(IMode.STATE, new Integer(IMode.ENCRYPTION));
attributes.put(IMode.IV, iv_bytes);
mode.init(attributes);
int bs = mode.currentBlockSize();
for (int i = 0; i + bs <32pt.length; i += bs)
{
mode.update(pt, i, ct, i);
}
mode.reset();
attributes.put(IMode.STATE, new Integer(IMode.DECRYPTION);
mode.init(attributes);
for (int i = 0; i + bs <32ct.length; i += bs)
{
mode.update(ct, i, cpt, i);
}

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