Exemple #1
0
  // ------------------------------------------------
  public final short pbocpadding(byte[] data, short len) {
    short f;

    data[len] = (byte) 0x80;
    len++;

    f = (short) (len % 8);
    f = (short) (8 - f);

    if (f != (short) 8) Util.arrayFillNonAtomic(data, len, f, (byte) 0);
    else f = (short) 0;

    return (short) (len + f);
  }
Exemple #2
0
  // ------------------------------------------------
  public final void gmac4(byte alg, byte[] key, byte[] data, short dl, byte[] mac) {
    dl = pbocpadding(data, dl);

    Util.arrayFillNonAtomic(tbuf1, (short) 0, (short) 8, (byte) 0);

    for (short i = (short) 0; i < dl; i += (short) 8) {
      xorblock8(tbuf1, data, i);
      cdes(key, (short) 0, tbuf1, (short) 0, (short) 8, tbuf2, (short) 0, Cipher.MODE_ENCRYPT);
      Util.arrayCopyNonAtomic(tbuf2, (short) 0, tbuf1, (short) 0, (short) 8);
    }

    if (alg == ALG_3DES) {
      cdes(key, (short) 8, tbuf1, (short) 0, (short) 8, tbuf2, (short) 0, Cipher.MODE_DECRYPT);
      cdes(key, (short) 0, tbuf2, (short) 0, (short) 8, tbuf1, (short) 0, Cipher.MODE_ENCRYPT);
    }

    Util.arrayCopyNonAtomic(tbuf1, (short) 0, mac, (short) 0, (short) 4);
  }