Top Description Fields Constructors Methods
org.bouncycastle.crypto.general

pack-priv Class ISO9797Alg3Mac

extends Object
implements Mac
Class Inheritance
All Implemented Interfaces
org.bouncycastle.crypto.internal.Mac
Imports
org.bouncycastle.crypto.internal.BlockCipher, .CipherParameters, .Mac, org.bouncycastle.crypto.internal.modes.CBCBlockCipher, org.bouncycastle.crypto.internal.paddings.BlockCipherPadding, org.bouncycastle.crypto.internal.params.KeyParameter, .KeyParameterImpl, .ParametersWithIV

DES based CBC Block Cipher MAC according to ISO9797, algorithm 3 (ANSI X9.19 Retail MAC) This could as well be derived from CBCBlockCipherMac, but then the property mac in the base class must be changed to protected

Field Summary

Modifier and TypeField and Description
private byte[]
private int
private BlockCipher
private KeyParameter
private KeyParameter
private byte[]
private int
private BlockCipherPadding

Constructor Summary

AccessConstructor and Description
public
ISO9797Alg3Mac(BlockCipher
the cipher to be used as the basis of the MAC generation. This must be DESEngine.
cipher
)

create a Retail-MAC based on a CBC block cipher.

public
ISO9797Alg3Mac(BlockCipher
the cipher to be used as the basis of the MAC generation.
cipher
,
BlockCipherPadding
the padding to be used to complete the last block.
padding
)

create a Retail-MAC based on a CBC block cipher.

public
ISO9797Alg3Mac(BlockCipher
the cipher to be used as the basis of the MAC generation.
cipher
,
int
the size of the MAC in bits, must be a multiple of 8.
macSizeInBits
)

create a Retail-MAC based on a block cipher with the size of the MAC been given in bits.

public
ISO9797Alg3Mac(BlockCipher
the cipher to be used as the basis of the MAC generation.
cipher
,
int
the size of the MAC in bits, must be a multiple of 8.
macSizeInBits
,
BlockCipherPadding
the padding to be used to complete the last block.
padding
)

create a standard MAC based on a block cipher with the size of the MAC been given in bits.

Method Summary

Modifier and TypeMethod and Description
public int
doFinal(byte[]
the array the MAC is to be output to.
out
,
int
the offset into the out buffer the output is to start at.
outOff
)

Implements org.bouncycastle.crypto.internal.Mac.doFinal.

Compute the final stage of the MAC writing the output to the out parameter.
public String
getAlgorithmName()

Implements org.bouncycastle.crypto.internal.Mac.getAlgorithmName.

Return the name of the algorithm the MAC implements.
public int
getMacSize()

Implements org.bouncycastle.crypto.internal.Mac.getMacSize.

Return the block size for this MAC (in bytes).
public void
init(CipherParameters
the key and other data required by the MAC.
params
)

Implements org.bouncycastle.crypto.internal.Mac.init.

Initialise the MAC.
public void
reset()

Implements org.bouncycastle.crypto.internal.Mac.reset.

Reset the mac generator.
public void
update(byte
the byte to be processed.
in
)

Implements org.bouncycastle.crypto.internal.Mac.update.

add a single byte to the mac for processing.
public void
update(byte[]
the array containing the input.
in
,
int
the index in the array the data begins at.
inOff
,
int
the length of the input starting at inOff.
len
)

Implements org.bouncycastle.crypto.internal.Mac.update.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufback to summary
private byte[] buf
bufOffback to summary
private int bufOff
cipherback to summary
private BlockCipher cipher
lastKey2back to summary
private KeyParameter lastKey2
lastKey3back to summary
private KeyParameter lastKey3
macback to summary
private byte[] mac
macSizeback to summary
private int macSize
paddingback to summary
private BlockCipherPadding padding

Constructor Detail

ISO9797Alg3Macback to summary
public ISO9797Alg3Mac(BlockCipher cipher)

create a Retail-MAC based on a CBC block cipher. This will produce an authentication code of the length of the block size of the cipher.

Parameters
cipher:BlockCipher

the cipher to be used as the basis of the MAC generation. This must be DESEngine.

ISO9797Alg3Macback to summary
public ISO9797Alg3Mac(BlockCipher cipher, BlockCipherPadding padding)

create a Retail-MAC based on a CBC block cipher. This will produce an authentication code of the length of the block size of the cipher.

Parameters
cipher:BlockCipher

the cipher to be used as the basis of the MAC generation.

padding:BlockCipherPadding

the padding to be used to complete the last block.

ISO9797Alg3Macback to summary
public ISO9797Alg3Mac(BlockCipher cipher, int macSizeInBits)

create a Retail-MAC based on a block cipher with the size of the MAC been given in bits. This class uses single DES CBC mode as the basis for the MAC generation.

Note

the size of the MAC must be at least 24 bits (FIPS Publication 81), or 16 bits if being used as a data authenticator (FIPS Publication 113), and in general should be less than the size of the block cipher as it reduces the chance of an exhaustive attack (see Handbook of Applied Cryptography).

Parameters
cipher:BlockCipher

the cipher to be used as the basis of the MAC generation.

macSizeInBits:int

the size of the MAC in bits, must be a multiple of 8.

ISO9797Alg3Macback to summary
public ISO9797Alg3Mac(BlockCipher cipher, int macSizeInBits, BlockCipherPadding padding)

create a standard MAC based on a block cipher with the size of the MAC been given in bits. This class uses single DES CBC mode as the basis for the MAC generation. The final block is decrypted and then encrypted using the middle and right part of the key.

Note

the size of the MAC must be at least 24 bits (FIPS Publication 81), or 16 bits if being used as a data authenticator (FIPS Publication 113), and in general should be less than the size of the block cipher as it reduces the chance of an exhaustive attack (see Handbook of Applied Cryptography).

Parameters
cipher:BlockCipher

the cipher to be used as the basis of the MAC generation.

macSizeInBits:int

the size of the MAC in bits, must be a multiple of 8.

padding:BlockCipherPadding

the padding to be used to complete the last block.

Method Detail

doFinalback to summary
public int doFinal(byte[] out, int outOff)

Implements org.bouncycastle.crypto.internal.Mac.doFinal.

Doc from org.bouncycastle.crypto.internal.Mac.doFinal.

Compute the final stage of the MAC writing the output to the out parameter.

doFinal leaves the MAC in the same state it was after the last init.

Parameters
out:byte[]

the array the MAC is to be output to.

outOff:int

the offset into the out buffer the output is to start at.

getAlgorithmNameback to summary
public String getAlgorithmName()

Implements org.bouncycastle.crypto.internal.Mac.getAlgorithmName.

Doc from org.bouncycastle.crypto.internal.Mac.getAlgorithmName.

Return the name of the algorithm the MAC implements.

Returns:String

the name of the algorithm the MAC implements.

getMacSizeback to summary
public int getMacSize()

Implements org.bouncycastle.crypto.internal.Mac.getMacSize.

Doc from org.bouncycastle.crypto.internal.Mac.getMacSize.

Return the block size for this MAC (in bytes).

Returns:int

the block size for this MAC in bytes.

initback to summary
public void init(CipherParameters params)

Implements org.bouncycastle.crypto.internal.Mac.init.

Doc from org.bouncycastle.crypto.internal.Mac.init.

Initialise the MAC.

Parameters
params:CipherParameters

the key and other data required by the MAC.

resetback to summary
public void reset()

Implements org.bouncycastle.crypto.internal.Mac.reset.

Reset the mac generator.

updateback to summary
public void update(byte in)

Implements org.bouncycastle.crypto.internal.Mac.update.

Doc from org.bouncycastle.crypto.internal.Mac.update.

add a single byte to the mac for processing.

Parameters
in:byte

the byte to be processed.

updateback to summary
public void update(byte[] in, int inOff, int len)

Implements org.bouncycastle.crypto.internal.Mac.update.

Parameters
in:byte[]

Doc from org.bouncycastle.crypto.internal.Mac.update.

the array containing the input.

inOff:int

Doc from org.bouncycastle.crypto.internal.Mac.update.

the index in the array the data begins at.

len:int

Doc from org.bouncycastle.crypto.internal.Mac.update.

the length of the input starting at inOff.