crypto_scalarmult static method

int crypto_scalarmult(
  1. Uint8List q,
  2. Uint8List n,
  3. Uint8List p
)

Implementation

static int crypto_scalarmult(Uint8List q, Uint8List n, Uint8List p) {
  Uint8List z = Uint8List(32);
  Int64List x = Int64List(80);
  int r, i;
  Int64List a = Int64List(16),
      b = Int64List(16),
      c = Int64List(16),
      d = Int64List(16),
      e = Int64List(16),
      f = Int64List(16);
  for (i = 0; i < 31; i++) z[i] = n[i];
  z[31] = (((n[31] & 127) | 64) & 0xff).toInt();
  z[0] &= 248;
  unpack25519(x, p);
  for (i = 0; i < 16; i++) {
    b[i] = x[i];
    d[i] = a[i] = c[i] = 0;
  }
  a[0] = d[0] = 1;
  for (i = 254; i >= 0; --i) {
    r = (Int32(z[Int32(i).shiftRightUnsigned(3).toInt()])
                .shiftRightUnsigned(i & 7))
            .toInt() &
        1;
    _sel25519(a, b, r);
    _sel25519(c, d, r);
    _A(e, a, c);
    _Z(a, a, c);
    _A(c, b, d);
    _Z(b, b, d);
    _S(d, e);
    _S(f, a);
    _M(a, c, a);
    _M(c, b, e);
    _A(e, a, c);
    _Z(a, a, c);
    _S(b, a);
    _Z(c, d, f);
    _M(a, c, _121665);
    _A(a, a, d);
    _M(c, c, a);
    _M(a, d, f);
    _M(d, b, x);
    _S(b, e);
    _sel25519(a, b, r);
    _sel25519(c, d, r);
  }
  for (i = 0; i < 16; i++) {
    x[i + 16] = a[i];
    x[i + 32] = c[i];
    x[i + 48] = b[i];
    x[i + 64] = d[i];
  }
  _inv25519(x, 32, x, 32);
  _M_off(x, 16, x, 16, x, 32);
  _pack25519(q, x, 16);

  return 0;
}