sign method
Implementation
Uint8List sign(Uint8List message) {
Curve curve = this.curve;
Point generator = curve.generator;
BigInt order = curve.order;
Uint8List h = this._hashPrivateKey();
Uint8List leftHalf = h.sublist(0, this.curve.keySize);
Uint8List s = _getPrivateScalar(leftHalf);
Point A = _getPublicKeyPoint(s);
Uint8List prefix = _getSignaturePrefix(h);
Shake256 hash = curve.hash;
Uint8List curveSigner;
if (curve.curveName == 'Ed448') {
String m = 'SigEd448' + String.fromCharCodes([0x00, 0x00]);
curveSigner = Uint8List.fromList(m.codeUnits);
} else if (curve.curveName == 'Ed521') {
String m = 'SigEd521' + String.fromCharCodes([0x00, 0x00]);
curveSigner = Uint8List.fromList(m.codeUnits);
} else {
throw Exception("Curve not supported");
}
hash.update(curveSigner);
hash.update(prefix);
hash.update(message);
Uint8List r = hash.digest(curve.signatureSize);
r = toLittleEndian(r);
BigInt rBigInt = decodeBigInt(r);
rBigInt = rBigInt % order;
r = encodeBigInt(rBigInt, curve.signatureSize);
Point pointR = generator.mul(r);
Uint8List R = curve.encodePoint(pointR);
// Compute S
Uint8List eA = curve.encodePoint(A);
hash.update(curveSigner);
hash.update(R);
hash.update(eA);
hash.update(message);
Uint8List k = hash.digest(curve.signatureSize);
k = toLittleEndian(k);
BigInt reducedK = decodeBigInt(k) % order;
Uint8List S = encodeBigInt(
(decodeBigInt(r) + (reducedK * decodeBigInt(s))) % order,
curve.keySize);
S = toLittleEndian(S);
return Uint8List.fromList(R + S);
}