de.flexiprovider.core.serpent
Class Serpent

java.lang.Object
  |
  +--javax.crypto.CipherSpi
        |
        +--de.flexiprovider.api.Cipher
              |
              +--de.flexiprovider.api.BlockCipher
                    |
                    +--de.flexiprovider.core.serpent.Serpent
Direct Known Subclasses:
Serpent.Serpent128_CBC, Serpent.Serpent128_CFB, Serpent.Serpent128_ECB, Serpent.Serpent128_OFB, Serpent.Serpent192_CBC, Serpent.Serpent192_CFB, Serpent.Serpent192_ECB, Serpent.Serpent192_OFB, Serpent.Serpent256_CBC, Serpent.Serpent256_CFB, Serpent.Serpent256_ECB, Serpent.Serpent256_OFB

public class Serpent
extends BlockCipher

This class implementes the Serpent block cipher. For more information, see http://www.cl.cam.ac.uk/~ rja14/serpent.html. Serpent uses a block size of 128 bits. The key size can be 128, 192, or 256 bits. Encryption/decryption takes 32 rounds.

Author:
Katja Rauch, Martin Döring

Inner Class Summary
static class Serpent.Serpent128_CBC
          Serpent128_CBC
static class Serpent.Serpent128_CFB
          Serpent128_CFB
static class Serpent.Serpent128_ECB
          Serpent128_ECB
static class Serpent.Serpent128_OFB
          Serpent128_OFB
static class Serpent.Serpent192_CBC
          Serpent192_CBC
static class Serpent.Serpent192_CFB
          Serpent192_CFB
static class Serpent.Serpent192_ECB
          Serpent192_ECB
static class Serpent.Serpent192_OFB
          Serpent192_OFB
static class Serpent.Serpent256_CBC
          Serpent256_CBC
static class Serpent.Serpent256_CFB
          Serpent256_CFB
static class Serpent.Serpent256_ECB
          Serpent256_ECB
static class Serpent.Serpent256_OFB
          Serpent256_OFB
 
Field Summary
static java.lang.String ALG_NAME
          The algorithm name.
static java.lang.String OID
          The OID of Serpent (defined by the GNU project, see http://www.gnupg.org/oids.html).
 
Fields inherited from class de.flexiprovider.api.BlockCipher
random
 
Fields inherited from class de.flexiprovider.api.Cipher
DECRYPT_MODE, ENCRYPT_MODE, opMode
 
Constructor Summary
  Serpent()
          Constructor.
protected Serpent(java.lang.String modeName, int keySize)
          Constructor.
 
Method Summary
 int getCipherBlockSize()
          This method returns the blocksize the algorithm uses.
 int getKeySize(Key key)
          Return the key size of the given key object.
 java.lang.String getName()
           
protected  void initCipherDecrypt(SecretKey key, AlgorithmParameterSpec params)
          Initialize the block cipher with a secret key for data decryption.
protected  void initCipherEncrypt(SecretKey key, AlgorithmParameterSpec params)
          Initialize the block cipher with a secret key for data encryption.
protected  void singleBlockDecrypt(byte[] in, int inoffset, byte[] out, int outoffset)
          This method decrypts a single block of data.
protected  void singleBlockEncrypt(byte[] in, int inoffset, byte[] out, int outoffset)
          This method encrypts a single block of data.
 
Methods inherited from class de.flexiprovider.api.BlockCipher
doFinal, doFinal, engineInit, getBlockSize, getIV, getOutputSize, getParameters, initDecrypt, initDecrypt, initDecrypt, initEncrypt, initEncrypt, initEncrypt, initEncrypt, setMode, setPadding, update, update
 
Methods inherited from class de.flexiprovider.api.Cipher
doFinal, doFinal, engineDoFinal, engineDoFinal, engineGetBlockSize, engineGetIV, engineGetKeySize, engineGetOutputSize, engineGetParameters, engineInit, engineInit, engineSetMode, engineSetPadding, engineUpdate, engineUpdate, update
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALG_NAME

public static final java.lang.String ALG_NAME
The algorithm name.

OID

public static final java.lang.String OID
The OID of Serpent (defined by the GNU project, see http://www.gnupg.org/oids.html).
Constructor Detail

Serpent

protected Serpent(java.lang.String modeName,
                  int keySize)
Constructor.
Parameters:
modeName - the mode to use
keySize - the key size in words

Serpent

public Serpent()
Constructor.
Method Detail

getName

public java.lang.String getName()
Overrides:
getName in class Cipher
Returns:
the name of this cipher

getKeySize

public int getKeySize(Key key)
               throws InvalidKeyException
Return the key size of the given key object. Checks whether the key object is an instance of SerpentKey or SecretKeySpec and whether the key size is within the specified range for Serpent. For the AES submission, the key size was fixed to be either 128, 192, or 256 bits, however shorter keys are allowed and appropriately padded as long as the key size is a multiple of 32 bits.
Overrides:
getKeySize in class Cipher
Parameters:
key - the key object
Returns:
the key size of the given key object.
Throws:
InvalidKeyException - if key is invalid.

getCipherBlockSize

public int getCipherBlockSize()
This method returns the blocksize the algorithm uses. It will be called by the padding scheme.
Overrides:
getCipherBlockSize in class BlockCipher
Returns:
the used blocksize in bytes

initCipherEncrypt

protected void initCipherEncrypt(SecretKey key,
                                 AlgorithmParameterSpec params)
                          throws InvalidKeyException
Initialize the block cipher with a secret key for data encryption. The algorithm parameters are not used.
Overrides:
initCipherEncrypt in class BlockCipher
Parameters:
key - - the SecretKey which has to be used to decrypt data.
params - - algorithmParameterSpec, not used for here
Throws:
InvalidKeyException - if the given key is inappropriate for initialising this cipher.

initCipherDecrypt

protected void initCipherDecrypt(SecretKey key,
                                 AlgorithmParameterSpec params)
                          throws InvalidKeyException
Initialize the block cipher with a secret key for data decryption. The algorithm parameters are not used.
Overrides:
initCipherDecrypt in class BlockCipher
Parameters:
key - - the SecretKey which has to be used to decrypt data.
params - - algorithmParameterSpec, not used for here
Throws:
InvalidKeyException - if the given key is inappropriate for initialising this cipher.

singleBlockEncrypt

protected void singleBlockEncrypt(byte[] in,
                                  int inoffset,
                                  byte[] out,
                                  int outoffset)
This method encrypts a single block of data. The array in must contain a whole block starting at inOffset and out must be large enough to hold an encrypted block starting at outOffset .
Overrides:
singleBlockEncrypt in class BlockCipher
Parameters:
in - array of bytes containing the plaintext to be encrypted
inoffset - index in array in, where the plaintext block starts
out - array of bytes which will contain the ciphertext starting at outOffset
outoffset - index in array out, where the ciphertext block will start

singleBlockDecrypt

protected void singleBlockDecrypt(byte[] in,
                                  int inoffset,
                                  byte[] out,
                                  int outoffset)
This method decrypts a single block of data. The array in must contain a whole block starting at inOffset and out must be large enough to hold an encrypted block starting at outOffset .
Overrides:
singleBlockDecrypt in class BlockCipher
Parameters:
in - array of bytes containig the ciphertext to be decrypted
inoffset - index in array in, where the ciphertext block starts
out - array of bytes which will contain the plaintext starting at outOffset
outoffset - index in array out, where the plaintext block will start