private void calculateSubkey(byte[] key, byte[] K1, byte[] K2) { byte[] zero = new byte[0x10]; byte[] L = new byte[0x10]; ToolsImpl.aesecbEncrypt(key, zero, 0, L, 0, zero.Length); BigInteger aux = new BigInteger(ConversionUtils.reverseByteWithSizeFIX(L)); if ((L[0] & 0x80) != 0) { //Case MSB is set aux = (aux << 1) ^ (new BigInteger(0x87)); } else { aux = aux << 1; } byte[] aux1 = ConversionUtils.reverseByteWithSizeFIX(aux.ToByteArray()); if (aux1.Length >= 0x10) { ConversionUtils.arraycopy(aux1, aux1.Length - 0x10, K1, 0, 0x10); } else { ConversionUtils.arraycopy(zero, 0, K1, 0, zero.Length); ConversionUtils.arraycopy(aux1, 0, K1, 0x10 - aux1.Length, aux1.Length); } aux = new BigInteger(ConversionUtils.reverseByteWithSizeFIX(K1)); if ((K1[0] & 0x80) != 0) { aux = (aux << 1) ^ (new BigInteger(0x87)); } else { aux = aux << 1; } aux1 = ConversionUtils.reverseByteWithSizeFIX(aux.ToByteArray()); if (aux1.Length >= 0x10) { ConversionUtils.arraycopy(aux1, aux1.Length - 0x10, K2, 0, 0x10); } else { ConversionUtils.arraycopy(zero, 0, K2, 0, zero.Length); ConversionUtils.arraycopy(aux1, 0, K2, 0x10 - aux1.Length, aux1.Length); } }