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

public Class RijndaelEngine

extends Object
implements BlockCipher
Class Inheritance
All Implemented Interfaces
org.bouncycastle.crypto.BlockCipher
Imports
org.bouncycastle.crypto.BlockCipher, .CipherParameters, .CryptoServicesRegistrar, .DataLengthException, .OutputLengthException, org.bouncycastle.crypto.constraints.DefaultServiceProperties, org.bouncycastle.crypto.params.KeyParameter

an implementation of Rijndael, based on the documentation and reference implementation by Paulo Barreto, Vincent Rijmen, for v2.0 August '99.

Note

this implementation is based on information prior to final NIST publication.

Field Summary

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

pack-priv static byte[][]
private byte[]
pack-priv static byte[][]
private byte[]
private static final byte[]
private long[][]

Constructor Summary

AccessConstructor and Description
public
RijndaelEngine()

default constructor - 128 bit block size.

public
RijndaelEngine(int
the blocksize in bits, must be 128, 192, or 256.
blockBits
)

basic constructor - set the cipher up for a given blocksize

Method Summary

Modifier and TypeMethod 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

public String
getAlgorithmName()

Implements org.bouncycastle.crypto.BlockCipher.getAlgorithmName.

Return the name of the algorithm the cipher implements.

public int
getBlockSize()

Implements org.bouncycastle.crypto.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.BlockCipher.init.

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)

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.BlockCipher.processBlock.

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

public void
reset()

Implements org.bouncycastle.crypto.BlockCipher.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)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

A0back to summary
private long A0
A1back to summary
private long A1
A2back to summary
private long A2
A3back to summary
private long A3
aLogtableback to summary
private static final byte[] aLogtable
BCback to summary
private int BC
BC_MASKback to summary
private long BC_MASK
blockBitsback to summary
private int blockBits
forEncryptionback to summary
private boolean forEncryption
logtableback to summary
private static final byte[] logtable
MAXKCback to summary
private static final int MAXKC
MAXROUNDSback to summary
private static final int MAXROUNDS
rconback to summary
private static final int[] rcon
ROUNDSback to summary
private int ROUNDS
Sback to summary
private static final byte[] S
shifts0back to summary
pack-priv static byte[][] shifts0
shifts0SCback to summary
private byte[] shifts0SC
shifts1back to summary
pack-priv static byte[][] shifts1
shifts1SCback to summary
private byte[] shifts1SC
Siback to summary
private static final byte[] Si
workingKeyback to summary
private long[][] workingKey

Constructor Detail

RijndaelEngineback to summary
public RijndaelEngine()

default constructor - 128 bit block size.

RijndaelEngineback to summary
public RijndaelEngine(int blockBits)

basic constructor - set the cipher up for a given blocksize

Parameters
blockBits:int

the blocksize in bits, must be 128, 192, or 256.

Method Detail

applySback to summary
private long applyS(long r, byte[] box)
decryptBlockback to summary
private void decryptBlock(long[][] rk)
encryptBlockback to summary
private void encryptBlock(long[][] rk)
generateWorkingKeyback to summary
private long[][] generateWorkingKey(byte[] key)

Calculate the necessary round keys The number of calculations depends on keyBits and blockBits

getAlgorithmNameback to summary
public String getAlgorithmName()

Implements org.bouncycastle.crypto.BlockCipher.getAlgorithmName.

Doc from org.bouncycastle.crypto.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.BlockCipher.getBlockSize.

Doc from org.bouncycastle.crypto.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.BlockCipher.init.

initialise a Rijndael 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.
InvMixColumnback to summary
private void InvMixColumn()

Mix the bytes of every column in a linear way This is the opposite operation of Mixcolumn

KeyAdditionback to summary
private void KeyAddition(long[] rk)

xor corresponding text input and round key input bytes

MixColumnback to summary
private void MixColumn()

Mix the bytes of every column in a linear way

mul0x2back to summary
private byte mul0x2(int b)

multiply two elements of GF(2^m) needed for MixColumn and InvMixColumn

mul0x3back to summary
private byte mul0x3(int b)
mul0x9back to summary
private byte mul0x9(int b)
mul0xbback to summary
private byte mul0xb(int b)
mul0xdback to summary
private byte mul0xd(int b)
mul0xeback to summary
private byte mul0xe(int b)
packBlockback to summary
private void packBlock(byte[] bytes, int off)
processBlockback to summary
public int processBlock(byte[] in, int inOff, byte[] out, int outOff)

Implements org.bouncycastle.crypto.BlockCipher.processBlock.

Doc from org.bouncycastle.crypto.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.BlockCipher.reset.

Doc from org.bouncycastle.crypto.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 long shift(long r, int shift)
ShiftRowback to summary
private void ShiftRow(byte[] shiftsSC)

Row 0 remains unchanged The other three rows are shifted a variable amount

Substitutionback to summary
private void Substitution(byte[] box)

Replace every byte of the input by the byte at that place in the nonlinear S-box

unpackBlockback to summary
private void unpackBlock(byte[] bytes, int off)