Class Checksum
- java.lang.Object
-
- javacard.security.Checksum
-
public abstract class Checksum extends Object
TheChecksum
class is the base class for CRC (cyclic redundancy check) checksum algorithms. Implementations of Checksum algorithms must extend this class and implement all the abstract methods.A tear or card reset event resets a
Checksum
object to the initial state (state upon construction).Even if a transaction is in progress, update of intermediate result state in the implementation instance shall not participate in the transaction.
-
-
Field Summary
Fields Modifier and Type Field Description static byte
ALG_ISO3309_CRC16
ISO/IEC 3309 compliant 16 bit CRC algorithm.static byte
ALG_ISO3309_CRC32
ISO/IEC 3309 compliant 32 bit CRC algorithm.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Checksum()
Protected Constructor
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract short
doFinal(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset)
Generates a CRC checksum of all/last input data.abstract byte
getAlgorithm()
Gets the Checksum algorithm.static Checksum
getInstance(byte algorithm, boolean externalAccess)
Creates aChecksum
object instance of the selected algorithm.abstract void
init(byte[] bArray, short bOff, short bLen)
Resets and initializes theChecksum
object with the algorithm specific parameters.abstract void
update(byte[] inBuff, short inOffset, short inLength)
Accumulates a partial checksum of the input data.
-
-
-
Field Detail
-
ALG_ISO3309_CRC16
public static final byte ALG_ISO3309_CRC16
ISO/IEC 3309 compliant 16 bit CRC algorithm. This algorithm uses the generator polynomial :x^16+x^12+x^5+1
. The default initial checksum value used by this algorithm is 0. This algorithm is also compliant with the frame checking sequence as specified in section 4.2.5.2 of the ISO/IEC 13239 specification.To obtain the commonly used CCITT behavior:
- Initialize with
0xFFFF
via theinit()
method - One's complement the result.
- The input data is not reversed (reflected)
- The ISO 3309 algorithm is used with the polynomial value
0x1021
- The resulting 16 bit FCS is not reversed (reflected)
- The 16 bit FCS is xor'd with
OxFFFF
. This is the CRC16 result.
- See Also:
- Constant Field Values
- Initialize with
-
ALG_ISO3309_CRC32
public static final byte ALG_ISO3309_CRC32
ISO/IEC 3309 compliant 32 bit CRC algorithm. This algorithm uses the generator polynomial :X^32 +X^26 +X^23 +X^22 +X^16 +X^12 +X^11 +X^10 +X^8 +X^7 +X^5 +X^4 +X^2 +X +1
. The default initial checksum value used by this algorithm is 0. This algorithm is also compliant with the frame checking sequence as specified in section 4.2.5.3 of the ISO/IEC 13239 specification.To obtain the PKZIP (also JDKTM java.util.zip.CRC32 class) behavior:
- Initialize with
0xFFFFFFFF
via theinit()
method
- The input data is reversed (reflected)
- The ISO 3309 algorithm is used with the polynomial value
0x04C11DB7
- The resulting 32 bit FCS is reversed (reflected)
- The reversed 32 bit FCS is xor'd with OxFFFFFFFF. This is the CRC32 result.
- See Also:
- Constant Field Values
- Initialize with
-
-
Method Detail
-
getInstance
public static final Checksum getInstance(byte algorithm, boolean externalAccess) throws CryptoException
Creates aChecksum
object instance of the selected algorithm.- Parameters:
algorithm
- the desired checksum algorithm. Valid codes listed inALG_*
constants above, for example,ALG_ISO3309_CRC16
.externalAccess
-true
indicates that the instance will be shared among multiple applet instances and that theChecksum
instance will also be accessed (via aShareable
. interface) when the owner of theChecksum
instance is not the currently selected applet. Iftrue
the implementation must not allocate CLEAR_ON_DESELECT transient space for internal data.- Returns:
- the
Checksum
object instance of the requested algorithm. - Throws:
CryptoException
- with the following reason codes:CryptoException.NO_SUCH_ALGORITHM
if the requested algorithm or shared access mode is not supported.
-
init
public abstract void init(byte[] bArray, short bOff, short bLen) throws CryptoException
Resets and initializes theChecksum
object with the algorithm specific parameters.Note:
- The ALG_ISO3309_CRC16 algorithm expects 2 bytes of parameter information in
bArray
representing the initial checksum value. - The ALG_ISO3309_CRC32 algorithm expects 4 bytes of parameter information in
bArray
representing the initial checksum value.
- Parameters:
bArray
- byte array containing algorithm specific initialization informationbOff
- offset withinbArray
where the algorithm specific data beginsbLen
- byte length of algorithm specific parameter data- Throws:
CryptoException
- with the following reason codes:CryptoException.ILLEGAL_VALUE
if a byte array parameter option is not supported by the algorithm or if thebLen
is an incorrect byte length for the algorithm specific data.
- The ALG_ISO3309_CRC16 algorithm expects 2 bytes of parameter information in
-
getAlgorithm
public abstract byte getAlgorithm()
Gets the Checksum algorithm. Valid codes listed inALG_*
constants above, for example,ALG_ISO3309_CRC16
.- Returns:
- the algorithm code defined above
-
doFinal
public abstract short doFinal(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset)
Generates a CRC checksum of all/last input data. The CRC engine processes input data starting with the byte at offsetinOffset
and continuing on until the byte at(inOffset+inLength-1)
of theinBuff
array. Within each byte the processing proceeds from the least significant bit to the most.Completes and returns the checksum computation. The
Checksum
object is reset to the initial state(state upon construction) when this method completes.Note:
- The
ALG_ISO3309_CRC16
andALG_ISO3309_CRC32
algorithms reset the initial checksum value to 0. The initial checksum value can be re-initialized using theinit(byte[], short, short)
method.
The input and output buffer data may overlap.
In addition to returning a
short
result, this method sets the result in an internal state which can be rechecked using assertion methods of theSensitiveResult
class, if supported by the platform.- Parameters:
inBuff
- the input buffer of data to be checksummedinOffset
- the offset into the input buffer at which to begin checksum generationinLength
- the byte length to checksumoutBuff
- the output buffer, may be the same as the input bufferoutOffset
- the offset into the output buffer where the resulting checksum value begins- Returns:
- number of bytes of checksum output in
outBuff
- The
-
update
public abstract void update(byte[] inBuff, short inOffset, short inLength)
Accumulates a partial checksum of the input data. The CRC engine processes input data starting with the byte at offsetinOffset
and continuing on until the byte at(inOffset+inLength-1)
of theinBuff
array. Within each byte the processing proceeds from the least significant bit to the most.This method requires temporary storage of intermediate results. This may result in additional resource consumption and/or slow performance. This method should only be used if all the input data required for the checksum is not available in one byte array. The
doFinal(byte[], short, short, byte[], short)
method is recommended whenever possible.Note:
- If
inLength
is 0 this method does nothing.
- Parameters:
inBuff
- the input buffer of data to be checksummedinOffset
- the offset into the input buffer at which to begin checksum generationinLength
- the byte length to checksum- See Also:
doFinal
- If
-
-