Class AES
- All Implemented Interfaces:
BlockCipher
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 fast version with 8Kbytes of static tables for round precomputation
- Version:
- $Id: AES.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate intprivate intprivate intprivate intprivate booleanprivate static final intprivate static final intprivate static final intprivate static final int[]private intprivate static final byte[]private static final byte[]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 static final int[]private static final int[]private int[][] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate final voiddecryptBlock(int[][] KW) private final voidencryptBlock(int[][] KW) private final intFFmulX(int x) private final 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 valuesfinal Stringfinal intfinal voidinit(boolean forEncryption, byte[] key) initialise an AES cipher.private final intinv_mcol(int x) private final voidpackBlock(byte[] bytes, int off) final intprocessBlock(byte[] in, int inOff, byte[] out, int outOff) final voidreset()private final intshift(int r, int shift) private final intsubWord(int x) voidtransformBlock(byte[] src, int srcoff, byte[] dst, int dstoff) private final voidunpackBlock(byte[] bytes, int off)
-
Field Details
-
S
private static final byte[] S -
Si
private static final byte[] Si -
rcon
private static final int[] rcon -
T0
private static final int[] T0 -
T1
private static final int[] T1 -
T2
private static final int[] T2 -
T3
private static final int[] T3 -
Tinv0
private static final int[] Tinv0 -
Tinv1
private static final int[] Tinv1 -
Tinv2
private static final int[] Tinv2 -
Tinv3
private static final int[] Tinv3 -
m1
private static final int m1- See Also:
-
m2
private static final int m2- See Also:
-
m3
private static final int m3- See Also:
-
ROUNDS
private int ROUNDS -
WorkingKey
private int[][] WorkingKey -
C0
private int C0 -
C1
private int C1 -
C2
private int C2 -
C3
private int C3 -
doEncrypt
private boolean doEncrypt -
BLOCK_SIZE
private static final int BLOCK_SIZE- See Also:
-
-
Constructor Details
-
AES
public AES()default constructor - 128 bit block size.
-
-
Method Details
-
shift
private final int shift(int r, int shift) -
FFmulX
private final int FFmulX(int x) -
inv_mcol
private final int inv_mcol(int x) -
subWord
private final int subWord(int x) -
generateWorkingKey
private final 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 -
init
public final void init(boolean forEncryption, byte[] key) initialise an AES cipher.- Specified by:
initin interfaceBlockCipher- Parameters:
forEncryption- whether or not we are for encryption.key- the key required to set up the cipher.- Throws:
IllegalArgumentException- if the params argument is inappropriate.
-
getAlgorithmName
-
getBlockSize
public final int getBlockSize()- Specified by:
getBlockSizein interfaceBlockCipher
-
processBlock
public final int processBlock(byte[] in, int inOff, byte[] out, int outOff) -
reset
public final void reset() -
unpackBlock
private final void unpackBlock(byte[] bytes, int off) -
packBlock
private final void packBlock(byte[] bytes, int off) -
encryptBlock
private final void encryptBlock(int[][] KW) -
decryptBlock
private final void decryptBlock(int[][] KW) -
transformBlock
public void transformBlock(byte[] src, int srcoff, byte[] dst, int dstoff) - Specified by:
transformBlockin interfaceBlockCipher
-