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

public Class IDEAEngine

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

A class that provides a basic International Data Encryption Algorithm (IDEA) engine.

This implementation is based on the "HOWTO: INTERNATIONAL DATA ENCRYPTION ALGORITHM" implementation summary by Fauzan Mirza ([email protected]). (barring 1 typo at the end of the mulinv function!).

It can be found at ftp://ftp.funet.fi/pub/crypt/cryptography/symmetric/idea/

Note

This algorithm was patented in the USA, Japan and Europe. These patents expired in 2011/2012.

Field Summary

Modifier and TypeField and Description
private static final int
protected static final int
private boolean
private static final int
private int[]

Constructor Summary

AccessConstructor and Description
public
IDEAEngine()

standard constructor.

Method Summary

Modifier and TypeMethod and Description
pack-priv int
addInv(int x)

Return the additive inverse of x.

private int
bytesToWord(byte[] in, int inOff)

private int[]
expandKey(byte[] uKey)

The following function is used to expand the user key to the encryption subkey.

private int[]
generateWorkingKey(boolean forEncryption, byte[] userKey)

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).

private void
ideaFunc(int[] workingKey, byte[] in, int inOff, byte[] out, int outOff)

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 an IDEA cipher.

private int[]
invertKey(int[] inKey)

The function to invert the encryption subkey to the decryption subkey.

private int

Returns:

x = x * y
mul
(int
the x value
x
,
int
the y value
y
)

return x = x * y where the multiplication is done modulo 65537 (0x10001) (as defined in the IDEA specification) and a zero input is taken to be 65536 (0x10000).

private int
mulInv(int x)

This function computes multiplicative inverse using Euclid's Greatest Common Divisor algorithm.

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 void
wordToBytes(int word, byte[] out, int outOff)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BASEback to summary
private static final int BASE
BLOCK_SIZEback to summary
protected static final int BLOCK_SIZE
forEncryptionback to summary
private boolean forEncryption
MASKback to summary
private static final int MASK
workingKeyback to summary
private int[] workingKey

Constructor Detail

IDEAEngineback to summary
public IDEAEngine()

standard constructor.

Method Detail

addInvback to summary
pack-priv int addInv(int x)

Return the additive inverse of x.

i.e. x + addInv(x) == 0

bytesToWordback to summary
private int bytesToWord(byte[] in, int inOff)
expandKeyback to summary
private int[] expandKey(byte[] uKey)

The following function is used to expand the user key to the encryption subkey. The first 16 bytes are the user key, and the rest of the subkey is calculated by rotating the previous 16 bytes by 25 bits to the left, and so on until the subkey is completed.

generateWorkingKeyback to summary
private int[] generateWorkingKey(boolean forEncryption, byte[] userKey)
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.

ideaFuncback to summary
private void ideaFunc(int[] workingKey, byte[] in, int inOff, byte[] out, int outOff)
initback to summary
public void init(boolean forEncryption, CipherParameters params)

Implements org.bouncycastle.crypto.BlockCipher.init.

initialise an IDEA 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.
invertKeyback to summary
private int[] invertKey(int[] inKey)

The function to invert the encryption subkey to the decryption subkey. It also involves the multiplicative inverse and the additive inverse functions.

mulback to summary
private int mul(int x, int y)

return x = x * y where the multiplication is done modulo 65537 (0x10001) (as defined in the IDEA specification) and a zero input is taken to be 65536 (0x10000).

Parameters
x:int

the x value

y:int

the y value

Returns:int

x = x * y

mulInvback to summary
private int mulInv(int x)

This function computes multiplicative inverse using Euclid's Greatest Common Divisor algorithm. Zero and one are self inverse.

i.e. x * mulInv(x) == 1 (modulo BASE)

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).

wordToBytesback to summary
private void wordToBytes(int word, byte[] out, int outOff)