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.
| Modifier and Type | Field and Description |
|---|---|
| private static final int | |
| protected static final int | |
| private boolean | |
| private static final int | |
| private int[] |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv int | |
| private int | |
| private int[] | expandKey(byte[] uKey)
The following function is used to expand the user key to the encryption subkey. |
| private int[] | |
| public String | getAlgorithmName()
Implements org. Return the name of the algorithm the cipher implements. |
| public int | getBlockSize()
Implements org. Return the block size for this cipher (in bytes). |
| private void | |
| public void | init(boolean
whether or not we are for encryption. forEncryption, CipherParameters the parameters required to set up the cipher. params)Implements org. initialise an IDEA cipher. |
| private int[] | |
| private int | Returns: x = x * ythe 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. Process one block of input from the array in and write it to the out array. |
| public void | |
| private void |
| BASE | back to summary |
|---|---|
| private static final int BASE | |
| BLOCK_SIZE | back to summary |
|---|---|
| protected static final int BLOCK_SIZE | |
| forEncryption | back to summary |
|---|---|
| private boolean forEncryption | |
| MASK | back to summary |
|---|---|
| private static final int MASK | |
| workingKey | back to summary |
|---|---|
| private int[] workingKey | |
| IDEAEngine | back to summary |
|---|---|
| public IDEAEngine() standard constructor. | |
| addInv | back to summary |
|---|---|
| pack-priv int addInv(int x) Return the additive inverse of x. i.e. x + addInv(x) == 0 | |
| bytesToWord | back to summary |
|---|---|
| private int bytesToWord(byte[] in, int inOff) | |
| expandKey | back 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. | |
| generateWorkingKey | back to summary |
|---|---|
| private int[] generateWorkingKey(boolean forEncryption, byte[] userKey) | |
| getAlgorithmName | back to summary |
|---|---|
| public String getAlgorithmName() Implements org. Doc from org. Return the name of the algorithm the cipher implements.
| |
| getBlockSize | back to summary |
|---|---|
| public int getBlockSize() Implements org. Doc from org. Return the block size for this cipher (in bytes).
| |
| ideaFunc | back to summary |
|---|---|
| private void ideaFunc(int[] workingKey, byte[] in, int inOff, byte[] out, int outOff) | |
| init | back to summary |
|---|---|
| public void init(boolean forEncryption, CipherParameters params) Implements org. initialise an IDEA cipher.
| |
| invertKey | back 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. | |
| mul | back 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).
| |
| mulInv | back 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) | |
| processBlock | back to summary |
|---|---|
| public int processBlock(byte[] in, int inOff, byte[] out, int outOff) Implements org. Doc from org. Process one block of input from the array in and write it to the out array.
| |
| reset | back to summary |
|---|---|
| public void reset() Implements org. Doc from org. Reset the cipher. After resetting the cipher is in the same state as it was after the last init (if there was one). | |
| wordToBytes | back to summary |
|---|---|
| private void wordToBytes(int word, byte[] out, int outOff) | |