|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.rim.device.api.crypto.AbstractMAC
net.rim.device.api.crypto.CBCMAC
public final class CBCMAC
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.
Constructor Summary | ||
---|---|---|
|
CBCMAC(BlockEncryptorEngine encryptorEngine)
Creates an instance of the CBCMAC object with a given block cipher. |
|
|
CBCMAC(BlockEncryptorEngine encryptorEngine,
BlockDecryptorEngine decryptorEngine)
Creates an instance of the CBCMAC object with given encryptor and decryptor engines. |
|
|
CBCMAC(SymmetricKey encryptorKey)
Creates an instance of the CBCMAC object with a given key. |
|
|
CBCMAC(SymmetricKey encryptorKey,
SymmetricKey decryptorKey)
Creates an instance of the CBCMAC object with given keys. |
Method Summary | ||
---|---|---|
|
String |
getAlgorithm()
Returns the name of the MAC algorithm, ie "CBCMAC/" + BlockEncryptorEngine.getAlgorithm() . |
|
int |
getLength()
Returns the length, in bytes, of the MAC. |
|
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. |
|
void |
reset()
Reinitializes the MAC. |
|
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 |
---|
public CBCMAC(BlockEncryptorEngine encryptorEngine) throws CryptoTokenException
encryptorEngine
- The block cipher to use with this instance, eg AESEncryptorEngine.
CryptoTokenException
- Thrown if an error occurs with the crypto
token or the crypto token is invalid.public CBCMAC(BlockEncryptorEngine encryptorEngine, BlockDecryptorEngine decryptorEngine) throws CryptoTokenException
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.
CryptoTokenException
- Thrown if an error occurs with the crypto
token or the crypto token is invalid.public CBCMAC(SymmetricKey encryptorKey) throws CryptoTokenException, NoSuchAlgorithmException, CryptoUnsupportedOperationException, CryptoException
encryptorKey
- The key to be used in the CBCMAC base cipher.
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
public CBCMAC(SymmetricKey encryptorKey, SymmetricKey decryptorKey) throws CryptoTokenException, NoSuchAlgorithmException, CryptoUnsupportedOperationException, CryptoException
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.
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
Method Detail |
---|
public String getAlgorithm()
"CBCMAC/" + BlockEncryptorEngine.getAlgorithm()
.
getAlgorithm
in interface MAC
getAlgorithm
in class AbstractMAC
public void reset() throws CryptoTokenException
AbstractMAC
reset
in interface MAC
reset
in class AbstractMAC
CryptoTokenException
- Thrown if an error occurs with the crypto
token or the crypto token is invalid.public int getLength()
AbstractMAC
getLength
in interface MAC
getLength
in class AbstractMAC
public void update(byte[] data, int offset, int length) throws CryptoTokenException
AbstractMAC
update
in interface MAC
update
in class AbstractMAC
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.
CryptoTokenException
- Thrown when a problem occurs with a crypto token or the crypto token is invalid.public int getMAC(byte[] buffer, int offset, boolean reset) throws CryptoTokenException
AbstractMAC
getMAC
in interface MAC
getMAC
in class AbstractMAC
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.
CryptoTokenException
- Thrown when a problem occurs with a crypto token or the crypto token is invalid.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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