public class RijndaelEngine extends java.lang.Object implements BlockCipher
Note: this implementation is based on information prior to final NIST publication.
Modifier and Type | Field and Description |
---|---|
private long |
A0 |
private long |
A1 |
private long |
A2 |
private long |
A3 |
private static byte[] |
aLogtable |
private int |
BC |
private long |
BC_MASK |
private int |
blockBits |
private boolean |
forEncryption |
private static byte[] |
logtable |
private static int |
MAXKC |
private static int |
MAXROUNDS |
private static int[] |
rcon |
private int |
ROUNDS |
private static byte[] |
S |
(package private) static byte[][] |
shifts0 |
private byte[] |
shifts0SC |
(package private) static byte[][] |
shifts1 |
private byte[] |
shifts1SC |
private static byte[] |
Si |
private long[][] |
workingKey |
Constructor and Description |
---|
RijndaelEngine()
default constructor - 128 bit block size.
|
RijndaelEngine(int blockBits)
basic constructor - set the cipher up for a given blocksize
|
Modifier and Type | Method and Description |
---|---|
private long |
applyS(long r,
byte[] box) |
private void |
decryptBlock(long[][] rk) |
private void |
encryptBlock(long[][] rk) |
private long[][] |
generateWorkingKey(byte[] key)
Calculate the necessary round keys
The number of calculations depends on keyBits and blockBits
|
java.lang.String |
getAlgorithmName()
Return the name of the algorithm the cipher implements.
|
int |
getBlockSize()
Return the block size for this cipher (in bytes).
|
void |
init(boolean forEncryption,
CipherParameters params)
initialise a Rijndael cipher.
|
private void |
InvMixColumn()
Mix the bytes of every column in a linear way
This is the opposite operation of Mixcolumn
|
private void |
KeyAddition(long[] rk)
xor corresponding text input and round key input bytes
|
private void |
MixColumn()
Mix the bytes of every column in a linear way
|
private byte |
mul0x2(int b)
multiply two elements of GF(2^m)
needed for MixColumn and InvMixColumn
|
private byte |
mul0x3(int b) |
private byte |
mul0x9(int b) |
private byte |
mul0xb(int b) |
private byte |
mul0xd(int b) |
private byte |
mul0xe(int b) |
private void |
packBlock(byte[] bytes,
int off) |
int |
processBlock(byte[] in,
int inOff,
byte[] out,
int outOff)
Process one block of input from the array in and write it to
the out array.
|
void |
reset()
Reset the cipher.
|
private long |
shift(long r,
int shift) |
private void |
ShiftRow(byte[] shiftsSC)
Row 0 remains unchanged
The other three rows are shifted a variable amount
|
private void |
Substitution(byte[] box)
Replace every byte of the input by the byte at that place
in the nonlinear S-box
|
private void |
unpackBlock(byte[] bytes,
int off) |
private static final int MAXROUNDS
private static final int MAXKC
private static final byte[] logtable
private static final byte[] aLogtable
private static final byte[] S
private static final byte[] Si
private static final int[] rcon
static byte[][] shifts0
static byte[][] shifts1
private int BC
private long BC_MASK
private int ROUNDS
private int blockBits
private long[][] workingKey
private long A0
private long A1
private long A2
private long A3
private boolean forEncryption
private byte[] shifts0SC
private byte[] shifts1SC
public RijndaelEngine()
public RijndaelEngine(int blockBits)
blockBits
- the blocksize in bits, must be 128, 192, or 256.private byte mul0x2(int b)
private byte mul0x3(int b)
private byte mul0x9(int b)
private byte mul0xb(int b)
private byte mul0xd(int b)
private byte mul0xe(int b)
private void KeyAddition(long[] rk)
private long shift(long r, int shift)
private void ShiftRow(byte[] shiftsSC)
private long applyS(long r, byte[] box)
private void Substitution(byte[] box)
private void MixColumn()
private void InvMixColumn()
private long[][] generateWorkingKey(byte[] key)
public void init(boolean forEncryption, CipherParameters params)
init
in interface BlockCipher
forEncryption
- whether or not we are for encryption.params
- the parameters required to set up the cipher.java.lang.IllegalArgumentException
- if the params argument is
inappropriate.public java.lang.String getAlgorithmName()
BlockCipher
getAlgorithmName
in interface BlockCipher
public int getBlockSize()
BlockCipher
getBlockSize
in interface BlockCipher
public int processBlock(byte[] in, int inOff, byte[] out, int outOff)
BlockCipher
processBlock
in interface BlockCipher
in
- the array containing the input data.inOff
- offset into the in array the data starts at.out
- the array the output data will be copied into.outOff
- the offset into the out array the output will start at.public void reset()
BlockCipher
reset
in interface BlockCipher
private void unpackBlock(byte[] bytes, int off)
private void packBlock(byte[] bytes, int off)
private void encryptBlock(long[][] rk)
private void decryptBlock(long[][] rk)