blocks method

poly1305 blocks(
  1. Uint8List m,
  2. int mpos,
  3. int bytes
)

Implementation

poly1305 blocks(Uint8List m, int mpos, int bytes) {
  int hibit = this._fin != 0 ? 0 : (1 << 11);
  Int32 t0, t1, t2, t3, t4, t5, t6, t7, c;
  Int32 d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;

  Int32 h0 = this._h[0],
      h1 = this._h[1],
      h2 = this._h[2],
      h3 = this._h[3],
      h4 = this._h[4],
      h5 = this._h[5],
      h6 = this._h[6],
      h7 = this._h[7],
      h8 = this._h[8],
      h9 = this._h[9];

  int r0 = this._r[0].toInt(),
      r1 = this._r[1].toInt(),
      r2 = this._r[2].toInt(),
      r3 = this._r[3].toInt(),
      r4 = this._r[4].toInt(),
      r5 = this._r[5].toInt(),
      r6 = this._r[6].toInt(),
      r7 = this._r[7].toInt(),
      r8 = this._r[8].toInt(),
      r9 = this._r[9].toInt();

  while (bytes >= 16) {
    t0 = Int32(m[mpos + 0] & 0xff | (m[mpos + 1] & 0xff) << 8);
    h0 += (t0).toInt() & 0x1fff;
    t1 = Int32(m[mpos + 2] & 0xff | (m[mpos + 3] & 0xff) << 8);
    h1 += ((t0.shiftRightUnsigned(13)) | (t1 << 3)).toInt() & 0x1fff;
    t2 = Int32(m[mpos + 4] & 0xff | (m[mpos + 5] & 0xff) << 8);
    h2 += ((t1.shiftRightUnsigned(10)) | (t2 << 6)).toInt() & 0x1fff;
    t3 = Int32(m[mpos + 6] & 0xff | (m[mpos + 7] & 0xff) << 8);
    h3 += ((t2.shiftRightUnsigned(7)) | (t3 << 9)).toInt() & 0x1fff;
    t4 = Int32(m[mpos + 8] & 0xff | (m[mpos + 9] & 0xff) << 8);
    h4 += ((t3.shiftRightUnsigned(4)) | (t4 << 12)).toInt() & 0x1fff;
    h5 += ((t4.shiftRightUnsigned(1))).toInt() & 0x1fff;
    t5 = Int32(m[mpos + 10] & 0xff | (m[mpos + 11] & 0xff) << 8);
    h6 += ((t4.shiftRightUnsigned(14)) | (t5 << 2)).toInt() & 0x1fff;
    t6 = Int32(m[mpos + 12] & 0xff | (m[mpos + 13] & 0xff) << 8);
    h7 += ((t5.shiftRightUnsigned(11)) | (t6 << 5)).toInt() & 0x1fff;
    t7 = Int32(m[mpos + 14] & 0xff | (m[mpos + 15] & 0xff) << 8);
    h8 += ((t6.shiftRightUnsigned(8)) | (t7 << 8)).toInt() & 0x1fff;
    h9 += ((t7.shiftRightUnsigned(5))).toInt() | hibit;

    c = Int32(0);

    d0 = c;
    d0 += h0 * r0;
    d0 += h1 * (5 * r9);
    d0 += h2 * (5 * r8);
    d0 += h3 * (5 * r7);
    d0 += h4 * (5 * r6);
    c = (d0.shiftRightUnsigned(13));
    d0 &= 0x1fff;
    d0 += h5 * (5 * r5);
    d0 += h6 * (5 * r4);
    d0 += h7 * (5 * r3);
    d0 += h8 * (5 * r2);
    d0 += h9 * (5 * r1);
    c += (d0.shiftRightUnsigned(13));
    d0 &= 0x1fff;

    d1 = c;
    d1 += h0 * r1;
    d1 += h1 * r0;
    d1 += h2 * (5 * r9);
    d1 += h3 * (5 * r8);
    d1 += h4 * (5 * r7);
    c = (d1.shiftRightUnsigned(13));
    d1 &= 0x1fff;
    d1 += h5 * (5 * r6);
    d1 += h6 * (5 * r5);
    d1 += h7 * (5 * r4);
    d1 += h8 * (5 * r3);
    d1 += h9 * (5 * r2);
    c += (d1.shiftRightUnsigned(13));
    d1 &= 0x1fff;

    d2 = c;
    d2 += h0 * r2;
    d2 += h1 * r1;
    d2 += h2 * r0;
    d2 += h3 * (5 * r9);
    d2 += h4 * (5 * r8);
    c = (d2.shiftRightUnsigned(13));
    d2 &= 0x1fff;
    d2 += h5 * (5 * r7);
    d2 += h6 * (5 * r6);
    d2 += h7 * (5 * r5);
    d2 += h8 * (5 * r4);
    d2 += h9 * (5 * r3);
    c += (d2.shiftRightUnsigned(13));
    d2 &= 0x1fff;

    d3 = c;
    d3 += h0 * r3;
    d3 += h1 * r2;
    d3 += h2 * r1;
    d3 += h3 * r0;
    d3 += h4 * (5 * r9);
    c = (d3.shiftRightUnsigned(13));
    d3 &= 0x1fff;
    d3 += h5 * (5 * r8);
    d3 += h6 * (5 * r7);
    d3 += h7 * (5 * r6);
    d3 += h8 * (5 * r5);
    d3 += h9 * (5 * r4);
    c += (d3.shiftRightUnsigned(13));
    d3 &= 0x1fff;

    d4 = c;
    d4 += h0 * r4;
    d4 += h1 * r3;
    d4 += h2 * r2;
    d4 += h3 * r1;
    d4 += h4 * r0;
    c = (d4.shiftRightUnsigned(13));
    d4 &= 0x1fff;
    d4 += h5 * (5 * r9);
    d4 += h6 * (5 * r8);
    d4 += h7 * (5 * r7);
    d4 += h8 * (5 * r6);
    d4 += h9 * (5 * r5);
    c += (d4.shiftRightUnsigned(13));
    d4 &= 0x1fff;

    d5 = c;
    d5 += h0 * r5;
    d5 += h1 * r4;
    d5 += h2 * r3;
    d5 += h3 * r2;
    d5 += h4 * r1;
    c = (d5.shiftRightUnsigned(13));
    d5 &= 0x1fff;
    d5 += h5 * r0;
    d5 += h6 * (5 * r9);
    d5 += h7 * (5 * r8);
    d5 += h8 * (5 * r7);
    d5 += h9 * (5 * r6);
    c += (d5.shiftRightUnsigned(13));
    d5 &= 0x1fff;

    d6 = c;
    d6 += h0 * r6;
    d6 += h1 * r5;
    d6 += h2 * r4;
    d6 += h3 * r3;
    d6 += h4 * r2;
    c = (d6.shiftRightUnsigned(13));
    d6 &= 0x1fff;
    d6 += h5 * r1;
    d6 += h6 * r0;
    d6 += h7 * (5 * r9);
    d6 += h8 * (5 * r8);
    d6 += h9 * (5 * r7);
    c += (d6.shiftRightUnsigned(13));
    d6 &= 0x1fff;

    d7 = c;
    d7 += h0 * r7;
    d7 += h1 * r6;
    d7 += h2 * r5;
    d7 += h3 * r4;
    d7 += h4 * r3;
    c = (d7.shiftRightUnsigned(13));
    d7 &= 0x1fff;
    d7 += h5 * r2;
    d7 += h6 * r1;
    d7 += h7 * r0;
    d7 += h8 * (5 * r9);
    d7 += h9 * (5 * r8);
    c += (d7.shiftRightUnsigned(13));
    d7 &= 0x1fff;

    d8 = c;
    d8 += h0 * r8;
    d8 += h1 * r7;
    d8 += h2 * r6;
    d8 += h3 * r5;
    d8 += h4 * r4;
    c = (d8.shiftRightUnsigned(13));
    d8 &= 0x1fff;
    d8 += h5 * r3;
    d8 += h6 * r2;
    d8 += h7 * r1;
    d8 += h8 * r0;
    d8 += h9 * (5 * r9);
    c += (d8.shiftRightUnsigned(13));
    d8 &= 0x1fff;

    d9 = c;
    d9 += h0 * r9;
    d9 += h1 * r8;
    d9 += h2 * r7;
    d9 += h3 * r6;
    d9 += h4 * r5;
    c = (d9.shiftRightUnsigned(13));
    d9 &= 0x1fff;
    d9 += h5 * r4;
    d9 += h6 * r3;
    d9 += h7 * r2;
    d9 += h8 * r1;
    d9 += h9 * r0;
    c += (d9.shiftRightUnsigned(13));
    d9 &= 0x1fff;

    c = (((c << 2) + c)) | 0;
    c = (c + d0) | 0;
    d0 = c & 0x1fff;
    c = (c.shiftRightUnsigned(13));
    d1 += c;

    h0 = d0;
    h1 = d1;
    h2 = d2;
    h3 = d3;
    h4 = d4;
    h5 = d5;
    h6 = d6;
    h7 = d7;
    h8 = d8;
    h9 = d9;

    mpos += 16;
    bytes -= 16;
  }
  this._h[0] = h0;
  this._h[1] = h1;
  this._h[2] = h2;
  this._h[3] = h3;
  this._h[4] = h4;
  this._h[5] = h5;
  this._h[6] = h6;
  this._h[7] = h7;
  this._h[8] = h8;
  this._h[9] = h9;

  return this;
}