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_vartime, ge_is_canonical, ge_reject_small_order } from './ed25519/ge'
-import { ge_cached, ge_p1p1, ge_p3, ge_p3_tobytes, ge_p3_sub_p3 } from './ed25519/p'
+import { ge_accept_small_order, ge_double_scalarmult_vartime_to_p3, ge_frombytes, ge_frombytes_negate_vartime, ge_is_canonical, ge_p3_cache_odd_multiples, ge_reject_small_order } from './ed25519/ge'
+import { ge_cached, ge_p1p1, ge_p3, ge_p3_sub_p3, ge_p3_tobytes } 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'
// algorithm variables
const A = new ge_p3()
+/** A, 3A, 5A, 7A, 9A, 11A, 13A, 15A */
+const Ai: StaticArray<ge_cached> = StaticArray.fromArray<ge_cached>([
+ new ge_cached(),
+ new ge_cached(),
+ new ge_cached(),
+ new ge_cached(),
+ new ge_cached(),
+ new ge_cached(),
+ new ge_cached(),
+ new ge_cached()
+])
const S = new StaticArray<u8>(32)
const expected_r = new ge_p3()
const h = new StaticArray<u8>(64)
blake2b.init().update(sig, 32).update(pub, KEY_BYTELENGTH).update(M, BLOCKHASH_BYTELENGTH).digest(h)
sc_reduce(h)
- ge_double_scalarmult_vartime_to_p3(sb_ah, h, A, S)
+ 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()
blake2b.init().update(sig, 32).update(pub, 32).update(M, mlen).digest(h)
sc_reduce(h)
- ge_double_scalarmult_vartime_to_p3(sb_ah, h, A, S)
+ ge_p3_cache_odd_multiples(Ai, A, t_ge_p1p1)
+ ge_double_scalarmult_vartime_to_p3(sb_ah, h, Ai, S)
ge_p3_sub_p3(check, expected_r, sb_ah, t_ge_cached, t_ge_p1p1)
// after cofactoring, `check` should be small order and not malformed in order
blake2b.init().update(sig, 32).update(pub, 32).update(M, mlen).digest(h)
sc_reduce(h)
- ge_double_scalarmult_vartime_to_p3(sb_ah, h, A, S)
+ 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()
return equalbytes(sig, check_r, KEY_BYTELENGTH)
}
}
-/** A,3A,5A,7A,9A,11A,13A,15A */
-const ge_double_scalarmult_vartime_Ai: StaticArray<ge_cached> = StaticArray.fromArray<ge_cached>([
- new ge_cached(),
- new ge_cached(),
- new ge_cached(),
- new ge_cached(),
- new ge_cached(),
- new ge_cached(),
- new ge_cached(),
- new ge_cached()
-])
const ge_double_scalarmult_vartime_aslide: StaticArray<i8> = new StaticArray<i8>(256)
const ge_double_scalarmult_vartime_bslide: StaticArray<i8> = new StaticArray<i8>(256)
const ge_double_scalarmult_vartime_p: ge_p2 = new ge_p2()
*
* Variable-time; only used for signature verification.
*/
-export function ge_double_scalarmult_vartime_to_p3 (r: ge_p3, a: StaticArray<u8>, A: ge_p3, b: StaticArray<u8>): void {
- const Ai = ge_double_scalarmult_vartime_Ai
+export function ge_double_scalarmult_vartime_to_p3 (r: ge_p3, a: StaticArray<u8>, Ai: StaticArray<ge_cached>, b: StaticArray<u8>): void {
const Bi = base2
const aslide = ge_double_scalarmult_vartime_aslide
const bslide = ge_double_scalarmult_vartime_bslide
slide_vartime(aslide, a)
slide_vartime(bslide, b)
- ge_p3_cache_odd_multiples(Ai, A, t)
-
ge_p2_0(p)
let i: i32 = 255