* Verify public key `pub` can be decoded.
* @returns null if public key fails to decode, else return pointer to A
*/
-export function crypto_verify_decodepubkey (pub: StaticArray<u8>): ge_p3 | null {
+export function crypto_verify_decodepubkey (pub: StaticArray<u8>): StaticArray<ge_cached> | null {
const b = ge_frombytes_negate_vartime(A, pub, t_u8x32, t_fe_0, t_fe_1, t_fe_2)
clear_t()
- return (b != 0) ? null : A
+ if (b != 0) return null
+ ge_p3_cache_odd_multiples(Ai, A, t_ge_p1p1)
+ return Ai
}
/**
* to `A` for the scalar multiplication step before checking `sB = R + hA`.
* @returns 0 if signature fails to verify, else return 1 if signature is good
*/
-export function crypto_verify_donna (sig: StaticArray<u8>, M: StaticArray<u8>, A: ge_p3, pub: StaticArray<u8>): i32 {
+export function crypto_verify_donna (sig: StaticArray<u8>, M: StaticArray<u8>, Ai: StaticArray<ge_cached>, pub: StaticArray<u8>): i32 {
// fail if private scalar `S` is out of range (`2²⁵³ ≤ S`)
if ((sig[63] & 224) != 0) return 0
blake2b.init().update(sig, 32).update(pub, KEY_BYTELENGTH).update(M, BLOCKHASH_BYTELENGTH).digest(h)
sc_reduce(h)
- ge_p3_cache_odd_multiples(Ai, A, t_ge_p1p1)
ge_double_scalarmult_vartime_to_p3(sb_ah, h, Ai, S)
ge_p3_tobytes(check_r, sb_ah, t_fe_0, t_fe_1, t_fe_2, t_fe_3, t_fe_4, t_fe_5, t_fe_6)
clear_t()
memory.copy(changetype<usize>(pub), changetype<usize>(INPUT_PUB), KEY_BYTELENGTH)
INPUT_PUB.fill(0)
- // Verify public key before proceeding with signature verification
- const A = crypto_verify_decodepubkey(pub)
- if (A != null) {
+ // Verify and cache public key before proceeding with signature verification
+ const Ai = crypto_verify_decodepubkey(pub)
+ if (Ai != null) {
// Iterate over block signature/hash pairs
for (let i = 0, ptr = changetype<usize>(INPUT_MSG); i < count; i++, ptr += SIGNEDBLOCK_BYTELENGTH) {
// Copy block signature/hash from message buffer to locals
memory.copy(changetype<usize>(h), ptr + SIGNATURE_BYTELENGTH, BLOCKHASH_BYTELENGTH)
// Verify hash and signature, then write result to output buffer
- OUTPUT_VERIFY[i] = u8(crypto_verify_donna(sig, h, A, pub))
+ OUTPUT_VERIFY[i] = u8(crypto_verify_donna(sig, h, Ai, pub))
}
}