hashToField static method
Implementation
static (List<int>, List<int>) hashToField({
required String curveId,
required String domainPrefix,
required List<int> message,
}) {
final List<int> domainBytes = StringUtils.encode(domainPrefix);
final List<int> curveIdBytes = StringUtils.encode(curveId);
const int chunkLen = 64;
final totalLength = 22 + curveId.length + domainPrefix.length;
List<int> hash(List<List<int>> values) {
return QuickCrypto.blake2bHash(
null,
chunkLen,
batch: values,
personalization: List<int>.filled(16, 0),
);
}
final b0 = hash([
List<int>.filled(128, 0),
message,
[0, chunkLen * 2, 0],
domainBytes,
StringUtils.encode("-"),
curveIdBytes,
StringUtils.encode("_XMD:BLAKE2b_SSWU_RO_"),
[totalLength],
]);
final b1 = hash([
b0,
[1],
domainBytes,
StringUtils.encode("-"),
curveIdBytes,
StringUtils.encode("_XMD:BLAKE2b_SSWU_RO_"),
[totalLength],
]);
final b2 = hash([
...List.generate(b0.length, (index) => [b0[index] ^ b1[index]]),
[2],
domainBytes,
StringUtils.encode("-"),
curveIdBytes,
StringUtils.encode("_XMD:BLAKE2b_SSWU_RO_"),
[totalLength],
]);
return (b1.reversed.toList(), b2.reversed.toList());
}