crypto_scalarmult static method
Implementation
static Uint8List crypto_scalarmult(Uint8List q, Uint8List n, Uint8List p) {
final z = Int8List(32);
final x = Int32List(80);
int r, i;
final a = Int32List(16),
b = Int32List(16),
c = Int32List(16),
d = Int32List(16),
e = Int32List(16),
f = Int32List(16);
for (i = 0; i < 31; i++) {
z[i] = n[i];
}
z[31] = (n[31] & 127) | 64;
z[0] &= 248;
_unpack25519(x, Uint8List.fromList(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 = (z[i >> 3] >> (i & 7)) & 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 q;
}