org.bouncycastle.crypto.engines
Class SEEDEngine

java.lang.Object
  extended by org.bouncycastle.crypto.engines.SEEDEngine
All Implemented Interfaces:
BlockCipher

public class SEEDEngine
extends java.lang.Object
implements BlockCipher

Implementation of the SEED algorithm as described in RFC 4009


Field Summary
private  int BLOCK_SIZE
           
private  boolean forEncryption
           
private static int[] KC
           
private static int[] SS0
           
private static int[] SS1
           
private static int[] SS2
           
private static int[] SS3
           
private  int[] wKey
           
 
Constructor Summary
SEEDEngine()
           
 
Method Summary
private  long bytesToLong(byte[] src, int srcOff)
           
private  int[] createWorkingKey(byte[] inKey)
           
private  int extractW0(long lVal)
           
private  int extractW1(long lVal)
           
private  long F(int ki0, int ki1, long r)
           
private  int G(int x)
           
 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 the cipher.
private  void longToBytes(byte[] dest, int destOff, long value)
           
private  int phaseCalc1(int r0, int ki0, int r1, int ki1)
           
private  int phaseCalc2(int r0, int ki0, int r1, int ki1)
           
 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 rotateLeft8(long x)
           
private  long rotateRight8(long x)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BLOCK_SIZE

private final int BLOCK_SIZE
See Also:
Constant Field Values

SS0

private static final int[] SS0

SS1

private static final int[] SS1

SS2

private static final int[] SS2

SS3

private static final int[] SS3

KC

private static final int[] KC

wKey

private int[] wKey

forEncryption

private boolean forEncryption
Constructor Detail

SEEDEngine

public SEEDEngine()
Method Detail

init

public void init(boolean forEncryption,
                 CipherParameters params)
          throws java.lang.IllegalArgumentException
Description copied from interface: BlockCipher
Initialise the cipher.

Specified by:
init in interface BlockCipher
Parameters:
forEncryption - if true the cipher is initialised for encryption, if false for decryption.
params - the key and other data required by the cipher.
Throws:
java.lang.IllegalArgumentException - if the params argument is inappropriate.

getAlgorithmName

public java.lang.String getAlgorithmName()
Description copied from interface: BlockCipher
Return the name of the algorithm the cipher implements.

Specified by:
getAlgorithmName in interface BlockCipher
Returns:
the name of the algorithm the cipher implements.

getBlockSize

public int getBlockSize()
Description copied from interface: BlockCipher
Return the block size for this cipher (in bytes).

Specified by:
getBlockSize in interface BlockCipher
Returns:
the block size for this cipher in bytes.

processBlock

public int processBlock(byte[] in,
                        int inOff,
                        byte[] out,
                        int outOff)
                 throws DataLengthException,
                        java.lang.IllegalStateException
Description copied from interface: BlockCipher
Process one block of input from the array in and write it to the out array.

Specified by:
processBlock in interface BlockCipher
Parameters:
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.
Returns:
the number of bytes processed and produced.
Throws:
DataLengthException - if there isn't enough data in in, or space in out.
java.lang.IllegalStateException - if the cipher isn't initialised.

reset

public void reset()
Description copied from interface: BlockCipher
Reset the cipher. After resetting the cipher is in the same state as it was after the last init (if there was one).

Specified by:
reset in interface BlockCipher

createWorkingKey

private int[] createWorkingKey(byte[] inKey)

extractW1

private int extractW1(long lVal)

extractW0

private int extractW0(long lVal)

rotateLeft8

private long rotateLeft8(long x)

rotateRight8

private long rotateRight8(long x)

bytesToLong

private long bytesToLong(byte[] src,
                         int srcOff)

longToBytes

private void longToBytes(byte[] dest,
                         int destOff,
                         long value)

G

private int G(int x)

F

private long F(int ki0,
               int ki1,
               long r)

phaseCalc1

private int phaseCalc1(int r0,
                       int ki0,
                       int r1,
                       int ki1)

phaseCalc2

private int phaseCalc2(int r0,
                       int ki0,
                       int r1,
                       int ki1)