net.rim.device.api.crypto
Class CBCMAC

java.lang.Object
  extended by net.rim.device.api.crypto.AbstractMAC
      extended by net.rim.device.api.crypto.CBCMAC
All Implemented Interfaces:
MAC

public final class CBCMAC
extends AbstractMAC
implements MAC

CBCMAC is method of producing a Message Authentication Code (MAC) using a block cipher in cipher-block-chaining (CBC) mode. You do not want to use a CBCEncryptorEngine with this class. This class will perform all of the CBC functionality necessary for this MAC.

CBC Mode is defined where the encryption of each block depends on the encryption of the previous block.

Note: The CBCMAC specification has an initialization vector of zeroes so there is no need to pass in a InitializationVector to this class.

CBCMAC has two modes of operation, One-Key and Two-Key.

One-Key CBCMAC works by encrypting the data, that you wish to be mac'ed, in CBC mode. Then, the MAC tag value is simply the last block of the encrypted data. You can create a One-Key CBCMAC using the CBCMAC( BlockEncryptorEngine ) constructor or the CBCMAC( SymmetricKey ) constructor.

In Two-Key CBCMAC, the data to be mac'ed is also encrypted in CBC mode, using the first key. But, rather than just returning the final encrypted block, an extra step of decrypting the final block, with the second key, and then re-encrypting that block with the first key, takes place. This final, modified, block is returned as the MAC tag. You can create a Two-Key CBCMAC using the CBCMAC( BlockEncryptorEngine, BlockDecryptorEngine ) constructor or the CBCMAC( SymmetricKey, SymmetricKey ) constructor.

For information on cryptographic algorithms, see Crypto Algorithms.

More information can be found in the FIPS 81 document in Table F1.

Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

Constructor Summary
Category: Signed CBCMAC(BlockEncryptorEngine encryptorEngine)
          Creates an instance of the CBCMAC object with a given block cipher.
Category: Signed CBCMAC(BlockEncryptorEngine encryptorEngine, BlockDecryptorEngine decryptorEngine)
          Creates an instance of the CBCMAC object with given encryptor and decryptor engines.
Category: Signed CBCMAC(SymmetricKey encryptorKey)
          Creates an instance of the CBCMAC object with a given key.
Category: Signed CBCMAC(SymmetricKey encryptorKey, SymmetricKey decryptorKey)
          Creates an instance of the CBCMAC object with given keys.
 
Method Summary
Category: Signed  String getAlgorithm()
          Returns the name of the MAC algorithm, ie "CBCMAC/" + BlockEncryptorEngine.getAlgorithm().
Category: Signed  int getLength()
          Returns the length, in bytes, of the MAC.
Category: Signed  int getMAC(byte[] buffer, int offset, boolean reset)
          Puts the MAC of all the input data since the last reset into the given buffer starting at the specified offset.
Category: Signed  void reset()
          Reinitializes the MAC.
Category: Signed  void update(byte[] data, int offset, int length)
          Feeds more data into the MAC algorithm.
 
Methods inherited from class net.rim.device.api.crypto.AbstractMAC
checkMAC, checkMAC, checkMAC, checkMAC, getMAC, getMAC, getMAC, update, update
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.rim.device.api.crypto.MAC
checkMAC, checkMAC, checkMAC, checkMAC, getMAC, getMAC, getMAC, update, update
 



Constructor Detail

CBCMAC

public CBCMAC(BlockEncryptorEngine encryptorEngine)
       throws CryptoTokenException
Creates an instance of the CBCMAC object with a given block cipher. This is a One-Key CBCMAC.

Parameters:
encryptorEngine - The block cipher to use with this instance, eg AESEncryptorEngine.
Throws:
CryptoTokenException - Thrown if an error occurs with the crypto token or the crypto token is invalid.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

CBCMAC

public CBCMAC(BlockEncryptorEngine encryptorEngine,
              BlockDecryptorEngine decryptorEngine)
       throws CryptoTokenException
Creates an instance of the CBCMAC object with given encryptor and decryptor engines. This is a Two-Key CBCMAC.

Parameters:
encryptorEngine - An engine to use with this instance, eg AESEncryptorEngine.
decryptorEngine - An extra engine to be used in an optional two-key triple-encryption on the last block.
Throws:
CryptoTokenException - Thrown if an error occurs with the crypto token or the crypto token is invalid.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

CBCMAC

public CBCMAC(SymmetricKey encryptorKey)
       throws CryptoTokenException,
              NoSuchAlgorithmException,
              CryptoUnsupportedOperationException,
              CryptoException
Creates an instance of the CBCMAC object with a given key. This is a One-Key CBCMAC.

Parameters:
encryptorKey - The key to be used in the CBCMAC base cipher.
Throws:
CryptoTokenException - Thrown if an error occurs with a crypto token or the crypto token is invalid.
NoSuchAlgorithmException - Thrown if the specified algorithm is invalid.
CryptoUnsupportedOperationException - Thrown if a call is made to an unsupported operation.
CryptoException
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

CBCMAC

public CBCMAC(SymmetricKey encryptorKey,
              SymmetricKey decryptorKey)
       throws CryptoTokenException,
              NoSuchAlgorithmException,
              CryptoUnsupportedOperationException,
              CryptoException
Creates an instance of the CBCMAC object with given keys. This is a Two-Key CBCMAC.

Parameters:
encryptorKey - The key to be used in the CBCMAC base cipher.
decryptorKey - The key to be used in an optional two-key triple-encryption on the last block.
Throws:
CryptoTokenException - Thrown if an error occurs with a crypto token or the crypto token is invalid.
NoSuchAlgorithmException - Thrown if the specified algorithm is invalid.
CryptoUnsupportedOperationException - Thrown if a call is made to an unsupported operation.
CryptoException
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0


Method Detail

getAlgorithm

public String getAlgorithm()
Returns the name of the MAC algorithm, ie "CBCMAC/" + BlockEncryptorEngine.getAlgorithm().

Specified by:
getAlgorithm in interface MAC
Specified by:
getAlgorithm in class AbstractMAC
Returns:
A String representing the name of the digest or cipher.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

reset

public void reset()
           throws CryptoTokenException
Description copied from class: AbstractMAC
Reinitializes the MAC.

Specified by:
reset in interface MAC
Specified by:
reset in class AbstractMAC
Throws:
CryptoTokenException - Thrown if an error occurs with the crypto token or the crypto token is invalid.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

getLength

public int getLength()
Description copied from class: AbstractMAC
Returns the length, in bytes, of the MAC.

Specified by:
getLength in interface MAC
Specified by:
getLength in class AbstractMAC
Returns:
An integer that represents the length of the MAC.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

update

public void update(byte[] data,
                   int offset,
                   int length)
            throws CryptoTokenException
Description copied from class: AbstractMAC
Feeds more data into the MAC algorithm.

Specified by:
update in interface MAC
Specified by:
update in class AbstractMAC
Parameters:
data - The array containing the input data.
offset - The offset, or initial position, of the data within the array.
length - The length of the input data, in bytes.
Throws:
CryptoTokenException - Thrown when a problem occurs with a crypto token or the crypto token is invalid.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

getMAC

public int getMAC(byte[] buffer,
                  int offset,
                  boolean reset)
           throws CryptoTokenException
Description copied from class: AbstractMAC
Puts the MAC of all the input data since the last reset into the given buffer starting at the specified offset. The MAC is then reset.

Specified by:
getMAC in interface MAC
Specified by:
getMAC in class AbstractMAC
Parameters:
buffer - The array to contain the MAC.
offset - The offset, or initial position, of teh MAC data within the buffer.
reset - If true then the MAC is reset.
Returns:
An integer representing the number of bytes written to the buffer.
Throws:
CryptoTokenException - Thrown when a problem occurs with a crypto token or the crypto token is invalid.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0





Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal