de.flexiprovider.core.mac
Class CMac

java.lang.Object
  |
  +--javax.crypto.MacSpi
        |
        +--de.flexiprovider.api.Mac
              |
              +--de.flexiprovider.core.mac.CMac
Direct Known Subclasses:
CMac.AES128, CMac.AES192, CMac.AES256, CMac.DESede

public class CMac
extends Mac

This is an implementaion of the CMAC ( NIST Special Publication 800-38B).

Author:
Paul Nguentcheu

Inner Class Summary
static class CMac.AES128
          CMAC with AES128 algorithm
static class CMac.AES192
          CMAC with AES192 algorithm
static class CMac.AES256
          CMAC with AES256 algorithm
static class CMac.DESede
          CMAC with DESede algorithm
 
Constructor Summary
protected CMac(BlockCipher blockCipher)
          This constructor is called by every subclass for specifying the particular algorithm to be used for CMAC computation.
 
Method Summary
 byte[] doFinal()
          Returns the calculated MAC value.
 int getMacLength()
          Returns the length of the calculated MAC value in bytes.
 void init(SecretKey key, AlgorithmParameterSpec params)
          Initializes this Mac Object with the given secret key and algorithm parameterSpec specification.
 void keySchedule(byte[] key)
          This method implements the CMac Key expansion.
 void reset()
          Reset this MAC object so that it may be used for further MAC computations.
 void update(byte b)
          Processes the given byte
 void update(byte[] bytes, int offset, int len)
          Processes 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

CMac

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

doFinal

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

getMacLength

public int getMacLength()
Returns the length of the calculated MAC value in bytes.
Overrides:
getMacLength in class Mac
Returns:
the length of the MAC value

init

public void init(SecretKey key,
                 AlgorithmParameterSpec params)
          throws InvalidKeyException,
                 InvalidAlgorithmParameterException
Initializes this Mac Object with the given secret key and algorithm parameterSpec specification. The parameters are ignored.
Overrides:
init in class Mac
Parameters:
key - the secret key with which this MAC object is initialized.
params - the parameters
Throws:
InvalidKeyException - if the key is invalid.
InvalidAlgorithmParameterException - if the parameters are inappropriate for initializing the underlying block cipher.

keySchedule

public void keySchedule(byte[] key)
This method implements the CMac Key expansion. The subkeys K1 and K2 are stored in the variables K1, K2.
Parameters:
key - - the byte array containing the key.

reset

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

update

public void update(byte b)
Processes the given byte
Overrides:
update in class Mac
Parameters:
b - the byte to be processed.

update

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