CRC16



com.licel.jcardsim.crypto
Class CRC16

java.lang.Object
  extended by javacard.security.Checksum
      extended by com.licel.jcardsim.crypto.CRC16

public class CRC16
extends Checksum


Field Summary
 
Fields inherited from class javacard.security.Checksum
ALG_ISO3309_CRC16, ALG_ISO3309_CRC32
 
Constructor Summary
CRC16()
           
 
Method Summary
 short doFinal(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset)
          Generates a CRC checksum of all/last input data.
 byte getAlgorithm()
          Gets the Checksum algorithm.
 void init(byte[] bArray, short bOff, short bLen)
          Resets and initializes the Checksum object with the algorithm specific Note: The ALG_ISO3309_CRC16 algorithm expects 2 bytes of parameter information in bArray representing the initial checksum value.
 void update(byte[] inBuff, short inOffset, short inLength)
          Accumulates a partial checksum of the input data.
 
Methods inherited from class javacard.security.Checksum
getInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CRC16

public CRC16()
Method Detail

getAlgorithm

public byte getAlgorithm()
Description copied from class: Checksum
Gets the Checksum algorithm. Valid codes listed in ALG_ .. constants above, for example, Checksum.ALG_ISO3309_CRC16

Specified by:
getAlgorithm in class Checksum
Returns:
the algorithm code defined above

init

public void init(byte[] bArray,
                 short bOff,
                 short bLen)
          throws CryptoException
Description copied from class: Checksum
Resets and initializes the Checksum object with the algorithm specific

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.

Specified by:
init in class Checksum
Parameters:
bArray - byte array containing algorithm specific initialization information
bOff - offset within bArray where the algorithm specific data begins
bLen - 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 the bLen is an incorrect byte length for the algorithm specific data.

doFinal

public short doFinal(byte[] inBuff,
                     short inOffset,
                     short inLength,
                     byte[] outBuff,
                     short outOffset)
Description copied from class: Checksum
Generates a CRC checksum of all/last input data. The CRC engine processes input data starting with the byte at offset inOffset and continuing on until the byte at (inOffset+inLength-1) of the inBuff 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 and ALG_ISO3309_CRC32 algorithms reset the initial checksum value to 0. The initial checksum value can be re-initialized using the Checksum.init(byte[], short, short) method.

The input and output buffer data may overlap.

Specified by:
doFinal in class Checksum
Parameters:
inBuff - the input buffer of data to be checksummed
inOffset - the offset into the input buffer at which to begin checksum generation
inLength - the byte length to checksum
outBuff - the output buffer, may be the same as the input buffer
outOffset - the offset into the output buffer where the resulting checksum value begins
Returns:
number of bytes of checksum output in outBuff

update

public void update(byte[] inBuff,
                   short inOffset,
                   short inLength)
Description copied from class: Checksum
Accumulates a partial checksum of the input data. The CRC engine processes input data starting with the byte at offset inOffset and continuing on until the byte at (inOffset+inLength-1) of the inBuff 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 Checksum.html#doFinal(byte[], short, short, byte[], short) doFinal(byte[], short, short, byte[], short) method is recommended whenever possible.

Note:

  • If inLength is 0 this method does nothing.

Specified by:
update in class Checksum
Parameters:
inBuff - the input buffer of data to be checksummed
inOffset - the offset into the input buffer at which to begin checksum generation
inLength - the byte length to checksum
See Also:
Checksum.doFinal(byte[], short, short, byte[], short)