de.flexiprovider.core.saferplus
Class SAFERPlus

java.lang.Object
  |
  +--javax.crypto.CipherSpi
        |
        +--de.flexiprovider.api.Cipher
              |
              +--de.flexiprovider.api.BlockCipher
                    |
                    +--de.flexiprovider.core.saferplus.SAFERPlus

public class SAFERPlus
extends BlockCipher

This class provides the symmetric blockcipher SAFER+. It is used whithin the JCE/JCA. The SAFER+ is a substitution/linear transformation cipher, wich takes 16 bytes as input, processes it with a 128, 192 or 256 bit key and calculates 16 bytes of output. The calculation is done during 8, 12 or 16 rounds with addition/subtraction in two additive groupes, namely addition bytewise mod 256 and bitwise mod 2 (xor). A nonliner layer is provided by exponentiation/logarithmation to the base 45 mod 257. Fast diffusion is achieved by a linear transformation. This transformation is done by multiplying the cipherblock with 16x16 invertible matrix.

Author:
Martin Strese, Marcus Lippert, Oliver Seiler

Field Summary
static java.lang.String ALG_NAME
          The algorithm name.
 
Fields inherited from class de.flexiprovider.api.BlockCipher
random
 
Fields inherited from class de.flexiprovider.api.Cipher
DECRYPT_MODE, ENCRYPT_MODE, opMode
 
Constructor Summary
SAFERPlus()
          This is the default constructor.
 
Method Summary
 int getCipherBlockSize()
          This method returns the blocksize, the algorithm uses.
 int getKeySize(Key key)
          Returns the key size of the given key object.
 java.lang.String getName()
           
protected  void initCipherDecrypt(SecretKey key, AlgorithmParameterSpec params)
          This method guarantees the AlgorithmParameterSpec compatibility.
protected  void initCipherEncrypt(SecretKey key, AlgorithmParameterSpec params)
          This method guarantees the AlgorithmParameterSpec compatibility.
protected  void singleBlockDecrypt(byte[] in, int inOffset, byte[] out, int outOffset)
          This method decrypts a single block of data, and may only be called, when the block cipher is in decrytion mode.
protected  void singleBlockEncrypt(byte[] in, int inOffset, byte[] out, int outOffset)
          This method encrypts a single block of data, and may only be called, when the block cipher is in encrytion mode, what the surrounding framework has to asure.
 
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.
Constructor Detail

SAFERPlus

public SAFERPlus()
This is the default constructor. It initializes the tables needed during en- and decryption, i.e. exponentiation, logarithmation and bias values.
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
Returns the key size of the given key object. Checks whether the key object is an instance of SAFERPlusKey or SecretKeySpec and whether the key size is within the specified range for SAFER+. 128, 192 and 256 bit keys are allowed.
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. This method will normaly be called by the padding scheme. It must be assured, that this method is exclusivly called, when the algorithm is either in encryption or in decryption mode. The blocksize in SAFERPlus is always 16 bytes.
Overrides:
getCipherBlockSize in class BlockCipher
Returns:
the used blocksize

initCipherEncrypt

protected void initCipherEncrypt(SecretKey key,
                                 AlgorithmParameterSpec params)
                          throws InvalidKeyException
This method guarantees the AlgorithmParameterSpec compatibility. As these are not used here it just calls the origin InitDecrypt method.
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
This method guarantees the AlgorithmParameterSpec compatibility. As these are not used here it just calls the origin InitDecrypt method.
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, and may only be called, when the block cipher is in encrytion mode, what the surrounding framework has to asure. It has to be assured, too, that the array in contains a whole block starting at inOffset and that out is large enough to hold an encrypted block starting at outOffset
Overrides:
singleBlockEncrypt in class BlockCipher
Parameters:
in - array of bytes which contains the plaintext to be encrypted
inOffset - index in array in, where the plaintext block starts
out - array of bytes which will contain the ciphertext
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, and may only be called, when the block cipher is in decrytion mode. It has to be asured, too, that the array in contains a whole block starting at inOffset and that out is large enogh to hold an decrypted block starting at outOffset
Overrides:
singleBlockDecrypt in class BlockCipher
Parameters:
in - array of bytes which contains 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