fromBytes static method

EdwardsLimbPoint fromBytes(
  1. List<int> b
)

Implementation

static EdwardsLimbPoint fromBytes(List<int> b) {
  if (b.length != 32) {
    throw CoreErrors.invalidOperationArguments(
      "fromBytes",
      reason: "Invalid length.",
    );
  }
  final bit = (b[31] >> 7) & 1;
  final yb = List<int>.of(b)..[31] &= 0x7F;
  final y = Ed25519Fp.fromBytes(yb);
  // x^2 = (y^2-1)/(d*y^2+1)  (a=-1)
  final y2 = y.square();
  final num = y2 - Ed25519Fp.one;
  final den = EdwardsLimbParams.d * y2 + Ed25519Fp.one;
  final x2 = num * den.invert()!;
  final r = x2.sqrt();
  if (!r.isSquare) {
    // Matches the legacy decoder contract (non-residue surfaced as
    // CryptoException through the old sqrt helper).
    throw CoreErrors.cryptoFailed(
      "EdwardsLimbPoint.fromBytes",
      reason: "Not on curve.",
    );
  }
  var x = r.result;
  if (((x.toBytes()[0] & 1) != bit)) x = -x;
  final z = Ed25519Fp.one;
  final t = x * y;
  return EdwardsLimbPoint(x: x, y: y, z: z, t: t);
}