hi folks
i'm trying to accomplish a similar Yubikey simulator, only implemented in Java.
unfortunately, i'm still stuck in the crc calculation. in Alex's php project it's written just the same, but for some reason it's not working for me - when i take the generated block (16 bytes including the crc), in order to validate the generated block i call:
Code:
new com.yubico.base.Token(block);
that runs it through its own crc check, but then i get
Quote:
java.lang.IllegalArgumentException: CRC failure
i can't figure out why is that, especially that it worked for Alex?
my CRC generation code:
Code:
private static int calculateCrc(byte[] b) {
int crc = 0x5af0;
for (int i = 0; i < 14; i++) {
crc ^= b[i] & 0xFF;
for (int j = 0; j < 8; j++){
int n = crc & 1;
crc >>= 1;
if (n != 0) {
crc ^= 0x8408;
}
}
}
return crc;
}
i'm aware of the difference between java and other languages in the implementation of unsigned bytes (there are no unsigned types in Java). but given that all the operations are bitwise, i don't think it should matter, should it? because negative numbers are just specific representations of the same bits..
i will publish the whole project once it's ready, but in the meantime i can appreciate your kind help
many thanks,
Yuval