EDPoint.fromBytes constructor
Factory constructor to create an EDPoint from a byte representation.
Parameters:
curve: The Edwards curve associated with the point.data: The byte array representing the point's coordinates.order: The order of the point (optional).
Implementation
factory EDPoint.fromBytes({
required CurveED curve,
required List<int> data,
BigInt? order,
}) {
data = data.clone();
final p = curve.p;
final expLen = (p.bitLength + 1 + 7) ~/ 8;
if (data.length != expLen) {
throw ArgumentException.invalidOperationArguments(
"EDPoint",
name: "data",
reason: "Incorrect bytes length.",
expecteLen: expLen,
);
}
final x0 = (data[expLen - 1] & 0x80) >> 7;
data[expLen - 1] &= 0x80 - 1;
final y = BigintUtils.fromBytes(data, byteOrder: Endian.little);
final x2 =
(y * y - BigInt.from(1)) *
BigintUtils.inverseMod(curve.d * y * y - curve.a, p) %
p;
BigInt x = ECDSAUtils.modularSquareRootPrime(x2, p);
if (x.isOdd != (x0 == 1)) {
x = (-x) % p;
}
final t = x * y;
return EDPoint(
curve: curve,
x: x,
y: y,
z: BigInt.one,
t: t,
generator: false,
order: order,
);
}