Page 1 of 1
Checksum result is different between host and card
Posted: Mon Dec 26, 2016 11:42 pm
by afrascoi
I tried to send a message with a CRC32 code from the java host to the java card. The host creates a checksum and send it with the message to the card and I also created a checksum on the card side. But I got the different results from two sides.
Why?
Re: Checksum result is different between host and card
Posted: Tue Dec 27, 2016 3:03 am
by mabel
pls make your question more detailed and show your code firstly.
Re: Checksum result is different between host and card
Posted: Tue Dec 27, 2016 4:42 am
by afrascoi
My host code to creates a checksum
Code: Select all
Checksum checksum = new CRC32();
checksum.update(rawData, 0, rawData.length);
long checksum_value = checksum.getValue();
Create checksum on card
Code: Select all
Checksum checksum = Checksum.getInstance(Checksum.ALG_ISO3309_CRC32, false);
checksum.doFinal(data, (short)0, (short)data.length, checksum_value, (short)0);
But the result differs from what the host creates.
Re: Checksum result is different between host and card
Posted: Tue Dec 27, 2016 5:27 am
by afrascoi
I just found that Java CRC32 starts with an initial value 0xFFFFFFFF.
So I set the card to 0xFFFFFFFF, it works. Now both the card and host checksum result is same.
Code: Select all
byte[] ini = new byte[]{(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF};
checksum.init(ini, (short)0, (short)ini.length);
The problem was caused by the initial value.
Re: Checksum result is different between host and card
Posted: Tue Dec 27, 2016 6:07 am
by mabel
The below is the introduction about Checksum.ALG_ISO3309_CRC32 from javacard API document.
To obtain the PKZIP (also JDKTM java.util.zip.CRC32 class) behavior:
- Initialize with 0xFFFFFFFF via the init() method