mul method

JubJubFq mul(
  1. JubJubFq rhs
)

Implementation

JubJubFq mul(JubJubFq rhs) {
  // Schoolbook multiplication
  var tmp = BigintUtils.mac(BigInt.zero, limbs[0], rhs.limbs[0], BigInt.zero);
  BigInt r0 = tmp[0];
  BigInt carry = tmp[1];

  tmp = BigintUtils.mac(BigInt.zero, limbs[0], rhs.limbs[1], carry);
  BigInt r1 = tmp[0];
  carry = tmp[1];

  tmp = BigintUtils.mac(BigInt.zero, limbs[0], rhs.limbs[2], carry);
  BigInt r2 = tmp[0];
  carry = tmp[1];

  tmp = BigintUtils.mac(BigInt.zero, limbs[0], rhs.limbs[3], carry);
  BigInt r3 = tmp[0];
  BigInt r4 = tmp[1];

  tmp = BigintUtils.mac(r1, limbs[1], rhs.limbs[0], BigInt.zero);
  r1 = tmp[0];
  carry = tmp[1];

  tmp = BigintUtils.mac(r2, limbs[1], rhs.limbs[1], carry);
  r2 = tmp[0];
  carry = tmp[1];

  tmp = BigintUtils.mac(r3, limbs[1], rhs.limbs[2], carry);
  r3 = tmp[0];
  carry = tmp[1];

  tmp = BigintUtils.mac(r4, limbs[1], rhs.limbs[3], carry);
  r4 = tmp[0];
  BigInt r5 = tmp[1];

  tmp = BigintUtils.mac(r2, limbs[2], rhs.limbs[0], BigInt.zero);
  r2 = tmp[0];
  carry = tmp[1];

  tmp = BigintUtils.mac(r3, limbs[2], rhs.limbs[1], carry);
  r3 = tmp[0];
  carry = tmp[1];

  tmp = BigintUtils.mac(r4, limbs[2], rhs.limbs[2], carry);
  r4 = tmp[0];
  carry = tmp[1];

  tmp = BigintUtils.mac(r5, limbs[2], rhs.limbs[3], carry);
  r5 = tmp[0];
  BigInt r6 = tmp[1];

  tmp = BigintUtils.mac(r3, limbs[3], rhs.limbs[0], BigInt.zero);
  r3 = tmp[0];
  carry = tmp[1];

  tmp = BigintUtils.mac(r4, limbs[3], rhs.limbs[1], carry);
  r4 = tmp[0];
  carry = tmp[1];

  tmp = BigintUtils.mac(r5, limbs[3], rhs.limbs[2], carry);
  r5 = tmp[0];
  carry = tmp[1];

  tmp = BigintUtils.mac(r6, limbs[3], rhs.limbs[3], carry);
  r6 = tmp[0];
  BigInt r7 = tmp[1];

  return JubJubFq.montgomeryReduce(r0, r1, r2, r3, r4, r5, r6, r7);
}