Top Description Fields Constructors Methods
org.bouncycastle.crypto.fips

pack-priv Class AESEngine

extends Object
implements BlockCipher
Class Inheritance
All Implemented Interfaces
org.bouncycastle.crypto.internal.BlockCipher
Imports
org.bouncycastle.crypto.internal.BlockCipher, .CipherParameters, .DataLengthException, .OutputLengthException, org.bouncycastle.crypto.internal.params.KeyParameter, .KeyParameterImpl, org.bouncycastle.util.Arrays, .Pack

an implementation of the AES (Rijndael), from FIPS-197.

For further details see: http://csrc.nist.gov/encryption/aes/. This implementation is based on optimizations from Dr. Brian Gladman's paper and C code at http://fp.gladman.plus.com/cryptography_technology/rijndael/ There are three levels of tradeoff of speed vs memory Because java has no preprocessor, they are written as three separate classes from which to choose The fastest uses 8Kbytes of static tables to precompute round calculations, 4 256 word tables for encryption and 4 for decryption. The middle performance version uses only one 256 word table for each, for a total of 2Kbytes, adding 12 rotate operations per round to compute the values contained in the other tables from the contents of the first. The slowest version uses no static tables at all and computes the values in each round.

This file contains the middle performance version with 2Kbytes of static tables for round precomputation.

Field Summary

Modifier and TypeField and Description
private static final int
private boolean
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int[]
private int
private static final byte[]
S

private byte[]
s

private static final byte[]
private static final int[]
private static final int[]
private int[][]
private static final KeyParameter

Constructor Summary

AccessConstructor and Description
public
AESEngine()

default constructor - 128 bit block size.

Method Summary

Modifier and TypeMethod and Description
private void
decryptBlock(byte[] input, int inOff, int[][] KW, byte[] out, int outOff)

private void
encryptBlock(byte[] input, int inOff, int[][] KW, byte[] out, int outOff)

private static int
FFmulX(int x)

private static int
FFmulX2(int x)

protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
private int[][]
generateWorkingKey(byte[] key, boolean forEncryption)

Calculate the necessary round keys The number of calculations depends on key size and block size AES specified a fixed block size of 128 bits and key sizes 128/192/256 bits This code is written assuming those are the only possible values

public String
getAlgorithmName()

Implements org.bouncycastle.crypto.internal.BlockCipher.getAlgorithmName.

Return the name of the algorithm the cipher implements.
public int
getBlockSize()

Implements org.bouncycastle.crypto.internal.BlockCipher.getBlockSize.

Return the block size for this cipher (in bytes).
public void
init(boolean
whether or not we are for encryption.
forEncryption
,
CipherParameters
the parameters required to set up the cipher.
params
)

Implements org.bouncycastle.crypto.internal.BlockCipher.init.

initialise an AES cipher.
private static int
inv_mcol(int x)

private void
packBlock(int C0, int C1, int C2, int C3, byte[] bytes, int off)

public int
processBlock(byte[]
the array containing the input data.
in
,
int
offset into the in array the data starts at.
inOff
,
byte[]
the array the output data will be copied into.
out
,
int
the offset into the out array the output will start at.
outOff
)

Implements org.bouncycastle.crypto.internal.BlockCipher.processBlock.

Process one block of input from the array in and write it to the out array.
public void
private static int
shift(int r, int shift)

private static int
subWord(int x)

Inherited from java.lang.Object:
cloneequalsgetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BLOCK_SIZEback to summary
private static final int BLOCK_SIZE
forEncryptionback to summary
private boolean forEncryption
m1back to summary
private static final int m1
m2back to summary
private static final int m2
m3back to summary
private static final int m3
m4back to summary
private static final int m4
m5back to summary
private static final int m5
rconback to summary
private static final int[] rcon
ROUNDSback to summary
private int ROUNDS
Sback to summary
private static final byte[] S
sback to summary
private byte[] s
Siback to summary
private static final byte[] Si
T0back to summary
private static final int[] T0
Tinv0back to summary
private static final int[] Tinv0
WorkingKeyback to summary
private int[][] WorkingKey
ZERO_KEYback to summary
private static final KeyParameter ZERO_KEY

Constructor Detail

AESEngineback to summary
public AESEngine()

default constructor - 128 bit block size.

Method Detail

decryptBlockback to summary
private void decryptBlock(byte[] input, int inOff, int[][] KW, byte[] out, int outOff)
encryptBlockback to summary
private void encryptBlock(byte[] input, int inOff, int[][] KW, byte[] out, int outOff)
FFmulXback to summary
private static int FFmulX(int x)
FFmulX2back to summary
private static int FFmulX2(int x)
finalizeback to summary
protected void finalize() throws Throwable

Overrides java.lang.Object.finalize.

Doc from java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

When running in a Java virtual machine in which finalization has been disabled or removed, the garbage collector will never call finalize(). In a Java virtual machine in which finalization is enabled, the garbage collector might call finalize only after an indefinite delay.

The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Annotations
@Override
Exceptions
Throwable:
the Exception raised by this method
generateWorkingKeyback to summary
private int[][] generateWorkingKey(byte[] key, boolean forEncryption)

Calculate the necessary round keys The number of calculations depends on key size and block size AES specified a fixed block size of 128 bits and key sizes 128/192/256 bits This code is written assuming those are the only possible values

getAlgorithmNameback to summary
public String getAlgorithmName()

Implements org.bouncycastle.crypto.internal.BlockCipher.getAlgorithmName.

Doc from org.bouncycastle.crypto.internal.BlockCipher.getAlgorithmName.

Return the name of the algorithm the cipher implements.

Returns:String

the name of the algorithm the cipher implements.

getBlockSizeback to summary
public int getBlockSize()

Implements org.bouncycastle.crypto.internal.BlockCipher.getBlockSize.

Doc from org.bouncycastle.crypto.internal.BlockCipher.getBlockSize.

Return the block size for this cipher (in bytes).

Returns:int

the block size for this cipher in bytes.

initback to summary
public void init(boolean forEncryption, CipherParameters params)

Implements org.bouncycastle.crypto.internal.BlockCipher.init.

initialise an AES cipher.

Parameters
forEncryption:boolean

whether or not we are for encryption.

params:CipherParameters

the parameters required to set up the cipher.

Exceptions
IllegalArgumentException:
if the params argument is inappropriate.
inv_mcolback to summary
private static int inv_mcol(int x)
packBlockback to summary
private void packBlock(int C0, int C1, int C2, int C3, byte[] bytes, int off)
processBlockback to summary
public int processBlock(byte[] in, int inOff, byte[] out, int outOff)

Implements org.bouncycastle.crypto.internal.BlockCipher.processBlock.

Doc from org.bouncycastle.crypto.internal.BlockCipher.processBlock.

Process one block of input from the array in and write it to the out array.

Parameters
in:byte[]

the array containing the input data.

inOff:int

offset into the in array the data starts at.

out:byte[]

the array the output data will be copied into.

outOff:int

the offset into the out array the output will start at.

Returns:int

the number of bytes processed and produced.

resetback to summary
public void reset()

Implements org.bouncycastle.crypto.internal.BlockCipher.reset.

Doc from org.bouncycastle.crypto.internal.BlockCipher.reset.

Reset the cipher. After resetting the cipher is in the same state as it was after the last init (if there was one).

shiftback to summary
private static int shift(int r, int shift)
subWordback to summary
private static int subWord(int x)