I am still wrestling with this. I wrote some javacode (gruesome language, but I had to as I am programming a Yubikey emulation for the Android G1). Now, to test it it used the array as you suggested it to be:
Code:
int [] input = {
0x55, 0xaa, 0x00, 0xff, 0x4a, 0x34
};
(Yes, I know, that are int's. I have to use int's, as sick Java does not dig unsigned bytes..
)
Next I wrote a little class that contains the method getcrc - it calculates the CRC over it's input array of 'bytes' (integers..). Parameters are the array and the number of 'bytes' it should use to calculate the checksum. I also wrote a method 'TwoComplement' that does what you think it does, namely: invert the bits and add one.
Then I did:
Code:
java.lang.Integer.toHexString( modhex.TwoComplement(modhex.getcrc( input, 4 ));
.. which gave me 0x344b (not 0x344a) ...
and then I did:
Code:
java.lang.Integer.toHexString( modhex.getcrc(input,6));
.. which gave me 0xf0b8 (the correct checksum).
Now, I am puzzled.
If, instead of using the 2's complement I simply flip bits, it all works as you predicted. Can you help out: do we need to use 2nd complement (and hence your example was flawed) or not? Or..??