verify method
Verifies a signature against the provided data using this public key.
This method verifies an EdDSA signature against the given data using this public key. It checks the validity of the signature by comparing it to the data, the encoded public key, and the associated hash function.
Parameters:
- data: The data to be verified.
- signature: The EdDSA signature bytes to be verified.
- hashMethod: A serializable hash function for data hashing.
Returns:
- bool: True if the signature is valid; otherwise, false.
Throws:
- ArgumentException: If the signature length is invalid or if the signature is found to be invalid during the verification process.
Details:
- This method verifies the provided EdDSA signature by checking its length and comparing it to the encoded public key, data, and a hash of the combined values.
- It calculates a verification key 'R' and uses the hash function to compute the scalar 'k' to confirm the signature's validity.
Note: The 'verify' method is essential for verifying EdDSA signatures and ensuring the authenticity and integrity of data.
Implementation
bool verify(
List<int> data,
List<int> signature,
HashFunc hashMethod,
) {
if (signature.length != 2 * baselen) {
throw ArgumentException(
'Invalid signature length, expected: ${2 * baselen} bytes');
}
final R = EDPoint.fromBytes(
curve: generator.curve, data: signature.sublist(0, baselen));
final S = BigintUtils.fromBytes(signature.sublist(baselen),
byteOrder: Endian.little);
if (S >= generator.order!) {
throw const ArgumentException('Invalid signature');
}
List<int> dom = List.empty();
if (generator.curve == Curves.curveEd448) {
dom = List<int>.from([...'SigEd448'.codeUnits, 0x00, 0x00]);
}
final h = hashMethod();
h.update(List<int>.from([...dom, ...R.toBytes(), ..._encoded, ...data]));
final k = BigintUtils.fromBytes(h.digest(), byteOrder: Endian.little);
if (generator * S != _point * k + R) {
return false;
}
return true;
}