secp256k1ScalarMulShiftVar static method

void secp256k1ScalarMulShiftVar(
  1. Secp256k1Scalar r,
  2. Secp256k1Scalar a,
  3. Secp256k1Scalar b,
  4. int shift,
)

Implementation

static void secp256k1ScalarMulShiftVar(
    Secp256k1Scalar r, Secp256k1Scalar a, Secp256k1Scalar b, int shift) {
  List<BigInt> l = List.filled(8, BigInt.zero);
  int shiftlimbs;
  int shiftlow;
  int shifthigh;
  secp256k1ScalarVerify(a);
  secp256k1ScalarVerify(b);
  _cond(shift >= 256, "secp256k1ScalarMulShiftVar");

  secp256k1ScalarMul512(l, a, b);
  shiftlimbs = shift >> 6;
  shiftlow = shift & 0x3F;
  shifthigh = 64 - shiftlow;

  r[0] = shift < 512
      ? (l[0 + shiftlimbs] >> shiftlow |
          (shift < 448 && shiftlow.toBool
              ? (l[1 + shiftlimbs] << shifthigh)
              : BigInt.zero))
      : BigInt.zero;
  r[1] = shift < 448
      ? (l[1 + shiftlimbs] >> shiftlow |
          (shift < 384 && shiftlow.toBool
              ? (l[2 + shiftlimbs] << shifthigh)
              : BigInt.zero))
      : BigInt.zero;
  r[2] = shift < 384
      ? (l[2 + shiftlimbs] >> shiftlow |
          (shift < 320 && shiftlow.toBool
              ? (l[3 + shiftlimbs] << shifthigh)
              : BigInt.zero))
      : BigInt.zero;
  r[3] = shift < 320 ? (l[3 + shiftlimbs] >> shiftlow) : BigInt.zero;
  secp256k1ScalarCaddBit(
      r,
      0,
      ((l[(shift - 1) >> 6] >> ((shift - 1) & 0x3f)) & BigInt.one)
          .toSignedInt32);

  secp256k1ScalarVerify(r);
}