I am suffering of a massive lack of speed when it comes to mutual authenticate with the card. This takes about 13 to 20 seconds which seems at least 10 times to much.
The slowest part is the "Get-Challenge" and I think it might be because of my construction of a non-leaking map and the seperate "rotate-left"
public static byte[] NLM (byte[] x, byte[] y) {
final byte[] f1 = new byte[] {(byte) 0x35, (byte) 0xB0,(byte) 0x88,(byte) 0xCC,(byte) 0xE1,(byte) 0x73}; //48-bit unsigned integer
final byte[] constant = new byte[] {(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01}; //constant
byte[] Y = new byte[6]; //48-bit unsigned integer
byte[] Y1 = new byte[6]; //48-bit unsigned integer
byte[] R = new byte[6]; //48-bit unsigned integer
byte[] R1 = new byte[6]; //48-bit unsigned integer
short size = 6;
JCArrayInt[] Red = new JCArrayInt[2]; // array of 48-bit unsigned integers
JCArrayInt[] Mul = new JCArrayInt[2]; // array of 48-bit unsigned integers
byte k = 48;
Red[0] = new JCArrayInt(size);
Mul[0] = new JCArrayInt(size);
Red[1] = new JCArrayInt(size);
Mul[1] = new JCArrayInt(size);
Red[1].jcint = Utils.XOR(f1, constant);
Mul[1].jcint = x;
Y = y;
for (short i = 0; i < 48; i++) {
R = rotateLeft48(R);
R1 = Utils.AND(R, constant);
R = Utils.XOR(R, Red[R1[5]].jcint);
Y = rotateLeft48(Y);
Y1 = Utils.AND(Y, constant);
R = Utils.XOR(R, Mul[Y1[5]].jcint);
}
return R;
}
public static byte[] rotateLeft48 (byte[] data) {
byte t = (byte)((data[0] >>> 7) & 0x001);
short l = (short) (data.length - 1);
for (short i = 0; i < l; ++i) {
data[i] = (byte)(((data[i] << 1) & 0x0FE) | ((data[i + 1] >>> 7) & 0x001));
}
data[l] = (byte)(((data[l] << 1) & 0x0FE) | t);
return data;
}
I can live with it taking a little longer due to this overhead besides doing some XOR, AND, rotation and all they key generation and actual encrypting (done with AES-128). should I use transient arrays (would that make that big of a difference)?
Using JCOP for all that!