de.flexiprovider.core.mac
Class CBCMac

java.lang.Object
  |
  +--javax.crypto.MacSpi
        |
        +--de.flexiprovider.api.Mac
              |
              +--de.flexiprovider.core.mac.CBCMac
Direct Known Subclasses:
CBCMac.AES128, CBCMac.AES192, CBCMac.AES256, CBCMac.Camellia, CBCMac.DESede, CBCMac.IDEA, CBCMac.MARS, CBCMac.Misty1, CBCMac.RC2, CBCMac.RC5, CBCMac.RC6, CBCMac.SAFERPlus, CBCMac.SAFERPlusPlus, CBCMac.Serpent, CBCMac.Shacal, CBCMac.Shacal2, CBCMac.Twofish

public abstract class CBCMac
extends Mac

This is an implementation of the CBC MAC (ANSI X9.9) using the "flexicore" jce implementation. Padding is only to put 0x00 until block boundary . We emulate (single) DES by initializing all three parts of the key identically. For reference look at V. Oorschot et. al. Handbook of Applied Cryptography chapter 9.5.1 As here is no support for this algorithm directly it is constructed using the following steps: 1. generating (single)des encryption over cipher1Input value using following algorithm: Cipher.getInstance("DESede/CBC/NoPadding","FlexiCore"); 1. creating an triple-DES key equivalent to DES by choosing keyA=keyB=keyC = key1 2. decrypting result with algorithm Cipher.getInstance("DESede","FlexiCore"); using key keyA=keyB=keyC = key2 3. encrypting result with algorithm Cipher.getInstance("DESede","FlexiCore"); using key keyA=keyB=keyC = key1

Author:
Paul Nguentcheu

Inner Class Summary
static class CBCMac.AES128
          CBC-MAC with AES128 algorithm
static class CBCMac.AES192
          CBC-MAC with AES192 algorithm
static class CBCMac.AES256
          CBC-MAC with AES256 algorithm
static class CBCMac.Camellia
          CBC-MAC with Camellia algorithm
static class CBCMac.DESede
          CBC-MAC with DESede algorithm
static class CBCMac.IDEA
          CBC-MAC with IDEA algorithm
static class CBCMac.MARS
          CBC-MAC with MARS algorithm
static class CBCMac.Misty1
          CBC-MAC with Misty1 algorithm
static class CBCMac.RC2
          CBC-MAC with RC2 algorithm
static class CBCMac.RC5
          CBC-MAC with RC5 algorithm
static class CBCMac.RC6
          CBC-MAC with RC6 algorithm
static class CBCMac.SAFERPlus
          CBC-MAC with SAFERPlus algorithm
static class CBCMac.SAFERPlusPlus
          CBC-MAC with SAFERPlusPlus algorithm
static class CBCMac.Serpent
          CBC-MAC with Serpent algorithm
static class CBCMac.Shacal
          CBC-MAC with Shacal algorithm
static class CBCMac.Shacal2
          CBC-MAC with Shacal2 algorithm
static class CBCMac.Twofish
          CBC-MAC with Twofish algorithm
 
Constructor Summary
protected CBCMac(BlockCipher blockCipher)
          This constructor is called by every subclass for specifying the particular algorithm to be used for CBC-MAC computation.
 
Method Summary
 byte[] doFinal()
          Return the computed MAC value.
 int getMacLength()
          Return the MAC length.
 void init(SecretKey key, AlgorithmParameterSpec params)
          Initialize this MAC with the given secret key and parameters.
 void reset()
          Reset this MAC object so that it may be used for further MAC computations.
 void update(byte input)
          Process the given byte
 void update(byte[] input, int inOff, int inLen)
          Process the given number of bytes, supplied in a byte array starting at the given position.
 
Methods inherited from class de.flexiprovider.api.Mac
doFinal, doFinal, engineDoFinal, engineGetMacLength, engineInit, engineReset, engineUpdate, engineUpdate, init, update
 
Methods inherited from class javax.crypto.MacSpi
clone
 
Methods inherited from class java.lang.Object
, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CBCMac

protected CBCMac(BlockCipher blockCipher)
This constructor is called by every subclass for specifying the particular algorithm to be used for CBC-MAC computation.
Parameters:
blockCipher - the cipher algorithm to use
Method Detail

getMacLength

public int getMacLength()
Description copied from class: Mac
Return the MAC length. This method is guaranteed to return a sane value only after the MAC has been initialized.
Overrides:
getMacLength in class Mac
Returns:
the length of the MAC value in bytes

init

public void init(SecretKey key,
                 AlgorithmParameterSpec params)
          throws InvalidKeyException,
                 InvalidAlgorithmParameterException
Initialize this MAC with the given secret key and parameters.
Overrides:
init in class Mac
Parameters:
key - the secret key
params - the parameters
Throws:
InvalidKeyException - if the key is invalid.
InvalidAlgorithmParameterException - if the parameters are invalid.

update

public void update(byte input)
Process the given byte
Overrides:
update in class Mac
Parameters:
input - the byte to be processed

update

public void update(byte[] input,
                   int inOff,
                   int inLen)
Process the given number of bytes, supplied in a byte array starting at the given position.
Overrides:
update in class Mac
Parameters:
input - byte array containing the message to be processed
inOff - offset into the array to start from
inLen - number of bytes to be processed

doFinal

public byte[] doFinal()
Return the computed MAC value. After the MAC has been calculated, the MAC object is reset for further computations.
Overrides:
doFinal in class Mac
Returns:
the computed MAC value

reset

public void reset()
Reset this MAC object so that it may be used for further MAC computations.
Overrides:
reset in class Mac