From 4e80b02796d6d99bc53448fd3236ca0d51894a29 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 30 Oct 2026 14:47:33 -0700 Subject: [PATCH] Clear A if public key fails verification. --- src/assembly/crypto_verify.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/assembly/crypto_verify.ts b/src/assembly/crypto_verify.ts index 717e2f1..d57fe8b 100644 --- a/src/assembly/crypto_verify.ts +++ b/src/assembly/crypto_verify.ts @@ -4,7 +4,7 @@ import { BLOCKHASH_BYTELENGTH, KEY_BYTELENGTH } from './constants' import { Blake2b } from './ed25519/blake2b' import { ge_accept_small_order, ge_double_scalarmult_vartime_to_p3, ge_frombytes, ge_frombytes_negate, ge_is_canonical, ge_cache_odd_multiples, ge_reject_small_order } from './ed25519/ge' -import { p_cached, p3, p3_sub_p3, p3_tobytes } from './ed25519/p' +import { p_cached, p3, p3_sub_p3, p3_tobytes, p3_0 } from './ed25519/p' import { sc_is_canonical, sc_reduce } from './ed25519/sc' import { clear_t, t_fe_0, t_fe_1, t_fe_2, t_fe_3, t_fe_4, t_fe_5, t_fe_6 } from './ed25519/t' import { equalbytes } from './ed25519/utils' @@ -41,7 +41,10 @@ const t_u8x32 = new StaticArray(32) export function crypto_verify_decodepubkey (pub: StaticArray): StaticArray | null { const b = ge_frombytes_negate(A, pub, t_fe_0, t_fe_1, t_fe_2, t_u8x32) clear_t() - if (b != 0) return null + if (b != 0) { + p3_0(A) + return null + } ge_cache_odd_multiples(Ai, A, t_p3, t_fe_0) return Ai } @@ -159,12 +162,14 @@ export function verify_pubkey (pub: StaticArray): boolean { // fail if public key cannot be decoded if (ge_frombytes_negate(A, pub, t_fe_0, t_fe_1, t_fe_2, t_u8x32) != 0) { + p3_0(A) clear_t() return false } // fail if public key `k` is small order if (ge_reject_small_order(A, t_fe_0, t_u8x32) != 0) { + p3_0(A) clear_t() return false } -- 2.52.0