crypto_hash_off static method

int crypto_hash_off(
  1. Uint8List out,
  2. Uint8List m,
  3. int moff,
  4. int n,
)

int crypto_hash(Uint8List out, Uint8List m, long n)

Implementation

static int crypto_hash_off(
    Uint8List out, Uint8List m, final int moff, int n) {
  List<Int32> hh = List<Int32>(8), hl = List<Int32>(8);
  Uint8List x = Uint8List(256);
  int i, b = n;
  Int64 u;

  hh[0] = Int32(0x6a09e667);
  hh[1] = Int32(0xbb67ae85);
  hh[2] = Int32(0x3c6ef372);
  hh[3] = Int32(0xa54ff53a);
  hh[4] = Int32(0x510e527f);
  hh[5] = Int32(0x9b05688c);
  hh[6] = Int32(0x1f83d9ab);
  hh[7] = Int32(0x5be0cd19);

  hl[0] = Int32(0xf3bcc908);
  hl[1] = Int32(0x84caa73b);
  hl[2] = Int32(0xfe94f82b);
  hl[3] = Int32(0x5f1d36f1);
  hl[4] = Int32(0xade682d1);
  hl[5] = Int32(0x2b3e6c1f);
  hl[6] = Int32(0xfb41bd6b);
  hl[7] = Int32(0x137e2179);

  if (n >= 128) {
    crypto_hashblocks_hl(hh, hl, m, moff, n);
    n %= 128;
  }

  for (i = 0; i < n; i++) x[i] = m[b - n + i + moff];
  x[n] = 128;

  n = 256 - 128 * (n < 112 ? 1 : 0);
  x[n - 9] = 0;

  _ts64(x, n - 8, Int64(b << 3) /*(b / 0x20000000) | 0, b << 3*/);

  crypto_hashblocks_hl(hh, hl, x, 0, n);

  for (i = 0; i < 8; i++) {
    u = Int64(hh[i].toInt());
    u <<= 32;
    u |= Int64(hl[i].toInt()) & 0xffffffff;
    _ts64(out, 8 * i, u);
  }

  return 0;
}