crypto_stream_salsa20_xor static method

int crypto_stream_salsa20_xor(
  1. Uint8List c,
  2. int cpos,
  3. Uint8List m,
  4. int mpos,
  5. int b,
  6. Uint8List n,
  7. Uint8List k, [
  8. int ic = 0,
])

Implementation

static int crypto_stream_salsa20_xor(Uint8List c, int cpos, Uint8List m,
    int mpos, int b, Uint8List n, Uint8List k,
    [int ic = 0]) {
  final z = Uint8List(16), x = Uint8List(64);
  int i;
  int u;

  for (i = 0; i < 16; i++) {
    z[i] = 0;
  }

  for (i = 0; i < 8; i++) {
    z[i] = n[i];
  }

  for (i = 8; i < 16; i++) {
    z[i] = ic & 0xff;
    ic >>= 8;
  }

  while (b >= 64) {
    crypto_core_salsa20(x, z, k, _sigma);
    for (i = 0; i < 64; i++) {
      c[cpos + i] = m[mpos + i] ^ x[i];
    }
    u = 1;
    for (i = 8; i < 16; i++) {
      u = u + z[i];
      z[i] = u;
      u = _shr32(u, 8);
    }
    b -= 64;
    cpos += 64;
    mpos += 64;
  }
  if (b > 0) {
    crypto_core_salsa20(x, z, k, _sigma);
    for (i = 0; i < b; i++) {
      c[cpos + i] = m[mpos + i] ^ x[i];
    }
  }

  return 0;
}