0

在与卡进行相互身份验证时,我遇到了速度严重不足的问题。这大约需要 13 到 20 秒,这似乎至少是 10 倍。

最慢的部分是“Get-Challenge”,我认为这可能是因为我构建了一个不泄漏的地图和单独的“向左旋转”

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;
}

除了做一些 XOR、AND、旋转以及所有它们的密钥生成和实际加密(使用 AES-128 完成)之外,由于这种开销,我可以忍受它需要更长的时间。我应该使用瞬态数组吗(这会有很大的不同)?

所有这些都使用 JCOP!

4

0 回答 0