GeScalarMultBase function Null safety

void GeScalarMultBase(
  1. ExtendedGroupElement h,
  2. Uint8List a
)

GeScalarMultBase computes h = aB, where a = a0+256a1+...+256^31 a31 B is the Ed25519 base point (x,4/5) with x positive.

Preconditions: a31 <= 127

Implementation

void GeScalarMultBase(ExtendedGroupElement h, Uint8List a) {
  var e = List<int>.filled(64, 0);

  for (var i = 0; i < a.length; i++) {
    var v = a[i];
    e[2 * i] = v & 15;
    e[2 * i + 1] = (v >> 4) & 15;
  }

  // each e[i] is between 0 and 15 and e[63] is between 0 and 7.

  var carry = 0;
  for (var i = 0; i < 63; i++) {
    e[i] += carry;
    carry = (e[i] + 8) >> 4;
    e[i] -= carry << 4;
  }
  e[63] += carry;
  // each e[i] is between -8 and 8.

  h.Zero();
  var t = PreComputedGroupElement();
  var r = CompletedGroupElement();
  for (var i = 1; i < 64; i += 2) {
    selectPoint(t, i ~/ 2, e[i]);
    geMixedAdd(r, h, t);
    r.ToExtended(h);
  }

  var s = ProjectiveGroupElement();

  h.Double(r);
  r.ToProjective(s);
  s.Double(r);
  r.ToProjective(s);
  s.Double(r);
  r.ToProjective(s);
  s.Double(r);
  r.ToExtended(h);

  for (var i = 0; i < 64; i += 2) {
    selectPoint(t, i ~/ 2, e[i]);
    geMixedAdd(r, h, t);
    r.ToExtended(h);
  }
}