mul method

JubJubFr mul(
  1. JubJubFr rhs
)

Implementation

JubJubFr mul(JubJubFr rhs) {
  final x0 = limbs[0];
  final x1 = limbs[1];
  final x2 = limbs[2];
  final x3 = limbs[3];

  final y0 = rhs.limbs[0];
  final y1 = rhs.limbs[1];
  final y2 = rhs.limbs[2];
  final y3 = rhs.limbs[3];

  // ---------------- SCHOOLBOOK MULTIPLICATION ----------------

  // row 0
  List<BigInt> t = BigintUtils.mac(BigInt.zero, x0, y0, BigInt.zero);
  BigInt r0 = t[0];
  BigInt carry = t[1];

  t = BigintUtils.mac(BigInt.zero, x0, y1, carry);
  BigInt r1 = t[0];
  carry = t[1];

  t = BigintUtils.mac(BigInt.zero, x0, y2, carry);
  BigInt r2 = t[0];
  carry = t[1];

  t = BigintUtils.mac(BigInt.zero, x0, y3, carry);
  BigInt r3 = t[0];
  BigInt r4 = t[1];

  // row 1
  t = BigintUtils.mac(r1, x1, y0, BigInt.zero);
  r1 = t[0];
  carry = t[1];

  t = BigintUtils.mac(r2, x1, y1, carry);
  r2 = t[0];
  carry = t[1];

  t = BigintUtils.mac(r3, x1, y2, carry);
  r3 = t[0];
  carry = t[1];

  t = BigintUtils.mac(r4, x1, y3, carry);
  r4 = t[0];
  BigInt r5 = t[1];

  // row 2
  t = BigintUtils.mac(r2, x2, y0, BigInt.zero);
  r2 = t[0];
  carry = t[1];

  t = BigintUtils.mac(r3, x2, y1, carry);
  r3 = t[0];
  carry = t[1];

  t = BigintUtils.mac(r4, x2, y2, carry);
  r4 = t[0];
  carry = t[1];

  t = BigintUtils.mac(r5, x2, y3, carry);
  r5 = t[0];
  BigInt r6 = t[1];

  // row 3
  t = BigintUtils.mac(r3, x3, y0, BigInt.zero);
  r3 = t[0];
  carry = t[1];

  t = BigintUtils.mac(r4, x3, y1, carry);
  r4 = t[0];
  carry = t[1];

  t = BigintUtils.mac(r5, x3, y2, carry);
  r5 = t[0];
  carry = t[1];

  t = BigintUtils.mac(r6, x3, y3, carry);
  r6 = t[0];
  BigInt r7 = t[1];
  return JubJubFr.montgomeryReduce(r0, r1, r2, r3, r4, r5, r6, r7);
}