crypto_stream_salsa20 static method

int crypto_stream_salsa20(
  1. Uint8List c,
  2. int cpos,
  3. int b,
  4. Uint8List n,
  5. Uint8List k,
)

Implementation

static int crypto_stream_salsa20(
    Uint8List c, int cpos, int b, Uint8List n, Uint8List k) {
  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];
  }

  while (b >= 64) {
    crypto_core_salsa20(x, z, k, _sigma);
    for (i = 0; i < 64; i++) {
      c[cpos + 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;
  }

  if (b > 0) {
    crypto_core_salsa20(x, z, k, _sigma);
    for (i = 0; i < b; i++) {
      c[cpos + i] = x[i];
    }
  }

  return 0;
}