import { ge_accept_small_order, ge_cache_odd_multiples, ge_double_scalarmult_vartime_to_p3, ge_frombytes, ge_frombytes_negate, ge_is_canonical, ge_reject_small_order } from './ed25519/ge'
import { p3, p3_0, p3_sub_p3, p3_tobytes, p_cached } from './ed25519/p'
import { sc_is_canonical, sc_reduce } from './ed25519/sc'
-import { clear_t, t_fe_0, t_fe_1, t_fe_2 } from './ed25519/t'
+import { clear_t, t_fe_0 } from './ed25519/t'
import { equalbytes } from './ed25519/utils'
// crypto_hash function
* @returns null if public key fails to decode, else return pointer to Ai
*/
export function crypto_verify_decodepubkey (pub: StaticArray<u8>): StaticArray<p_cached> | null {
- const b = ge_frombytes_negate(A, pub, t_fe_0, t_fe_1, t_fe_2, t_u8x32)
+ const b = ge_frombytes_negate(A, pub, t_fe_0, t_u8x32)
clear_t()
if (b != 0) {
p3_0(A)
}
// 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) {
+ if (ge_frombytes_negate(A, pub, t_fe_0, t_u8x32) != 0) {
p3_0(A)
clear_t()
return false
}
// fail if nonce `R` does not decode to a valid curve point
- if (ge_frombytes(expected_r, sig, t_fe_0, t_fe_1, t_fe_2, t_u8x32) != 0) {
+ if (ge_frombytes(expected_r, sig, t_fe_0, t_u8x32) != 0) {
clear_t()
return false
}
v128.store_lane<i64>(h_ptr, v128.neg<i32>(f2), 0, 2 << 4)
}
-/**
- * returns z^((p-5)/8) = z^(2²⁵²-3)
- * used to compute square roots since we have p=5 (mod 8); see Cohen and Frey.
- */
-export function fe_pow22523 (out: FieldElement, z: FieldElement, t_fe_0: FieldElement, t_fe_1: FieldElement, t_fe_2: FieldElement): void {
- fe_sq(t_fe_0, z)
- fe_sq_n(t_fe_1, t_fe_0, 2)
- fe_mul(t_fe_1, t_fe_1, z)
- fe_mul(t_fe_0, t_fe_1, t_fe_0)
-
- fe_sq(t_fe_0, t_fe_0)
- fe_mul(t_fe_0, t_fe_1, t_fe_0)
-
- fe_sq_n(t_fe_1, t_fe_0, 5)
- fe_mul(t_fe_0, t_fe_1, t_fe_0)
-
- fe_sq_n(t_fe_1, t_fe_0, 10)
- fe_mul(t_fe_1, t_fe_1, t_fe_0)
-
- fe_sq_n(t_fe_2, t_fe_1, 20)
- fe_mul(t_fe_1, t_fe_2, t_fe_1)
-
- fe_sq_n(t_fe_1, t_fe_1, 10)
- fe_mul(t_fe_0, t_fe_1, t_fe_0)
-
- fe_sq_n(t_fe_1, t_fe_0, 50)
- fe_mul(t_fe_1, t_fe_1, t_fe_0)
-
- fe_sq_n(t_fe_2, t_fe_1, 100)
- fe_mul(t_fe_1, t_fe_2, t_fe_1)
-
- fe_sq_n(t_fe_1, t_fe_1, 50)
- fe_mul(t_fe_0, t_fe_1, t_fe_0)
-
- fe_sq_n(t_fe_0, t_fe_0, 2)
- fe_mul(out, t_fe_0, z)
-}
-
/**
* Preconditions:
* |h| bounded by 1.1x2²⁶,1.1x2²⁵,1.1x2²⁶,1.1x2²⁵,etc.
*/
import { base } from './base'
import { base2 } from './base2'
-import { FieldElement, fe, fe_1, fe_add, fe_addsub, fe_cmov, fe_frombytes, fe_isnegative, fe_iszero, fe_mul, fe_mul_d, fe_mul_pair_sqrtm1, fe_mul_sqrtm1, fe_neg, fe_pow22523, fe_sq, fe_sub } from './fe'
+import { FieldElement, fe, fe_1, fe_add, fe_addsub, fe_cmov, fe_frombytes, fe_isnegative, fe_iszero, fe_mul, fe_mul_d, fe_mul_pair_sqrtm1, fe_mul_sqrtm1, fe_neg, fe_sq, fe_sub } from './fe'
import { p1p1, p1p1_0, p1p1_to_p2, p1p1_to_p3, p2, p2_0, p2_dbl, p3, p3_0, p3_add_cached, p3_add_cached_output_cached, p3_add_precomp, p3_dbl, p3_dbl_to_p3, p3_sub_cached, p3_sub_precomp, p3_to_cached, p3_tobytes, p_cached, p_precomp, precomp_0 } from './p'
+import { fe_pow22523 } from './pow22523'
function ge_cmov8_base (t: p_precomp, bp: usize, b: i8): void {
const isbneg: i8 = (b >> 7) & 1 /* 0: positive; 1: negative */
*
* @returns {i32} 0 if `s` decodes to a valid point, else -1
*/
-export function ge_frombytes (h: p3, s: StaticArray<u8>,
- t_fe_0: FieldElement, t_fe_1: FieldElement, t_fe_2: FieldElement, t_u8x32: StaticArray<u8>
-): i32 {
+export function ge_frombytes (h: p3, s: StaticArray<u8>, t_fe_0: FieldElement, t_u8x32: StaticArray<u8>): i32 {
const u = ge_frombytes_u
const v = ge_frombytes_v
const vx2 = ge_frombytes_vx2
// x = uv
fe_mul(h.X, u, v)
// x = (uv)⁽𐞥⁻⁵⁾⸍⁸
- fe_pow22523(h.X, h.X, t_fe_0, t_fe_1, t_fe_2)
+ fe_pow22523(h.X, h.X)
// x = u(uv)⁽𐞥⁻⁵⁾⸍⁸
fe_mul(h.X, u, h.X)
*
* @returns {i32} 0 if `s` decodes to a valid point, else -1
*/
-export function ge_frombytes_negate (h: p3, s: StaticArray<u8>,
- t_fe_0: FieldElement, t_fe_1: FieldElement, t_fe_2: FieldElement, t_u8x32: StaticArray<u8>
-): i32 {
- const check = ge_frombytes(h, s, t_fe_0, t_fe_1, t_fe_2, t_u8x32)
+export function ge_frombytes_negate (h: p3, s: StaticArray<u8>, t_fe_0: FieldElement, t_u8x32: StaticArray<u8>): i32 {
+ const check = ge_frombytes(h, s, t_fe_0, t_u8x32)
fe_neg(h.X, h.X)
fe_neg(h.T, h.T)
return check
--- /dev/null
+//! SPDX-FileCopyrightText: 2026 Chris Duncan <chris@codecow.com>
+//! SPDX-License-Identifier: GPL-3.0-or-later
+
+import { FieldElement, fe, fe_mul, fe_sq, fe_sq_n } from './fe'
+
+const a = fe()
+const b = fe()
+const c = fe()
+
+/**
+ * `z⁽ᵖ⁻⁵⁾⸍⁸ = z^(2²⁵²-3)`
+ *
+ * Used to compute square roots since we have p=5 (mod 8); see Cohen and Frey.
+ */
+export function fe_pow22523 (out: FieldElement, z: FieldElement): void {
+ fe_sq(a, z)
+ fe_sq_n(b, a, 2)
+ fe_mul(b, b, z)
+ fe_mul(a, b, a)
+
+ fe_sq(a, a)
+ fe_mul(a, b, a)
+
+ fe_sq_n(b, a, 5)
+ fe_mul(a, b, a)
+
+ fe_sq_n(b, a, 10)
+ fe_mul(b, b, a)
+
+ fe_sq_n(c, b, 20)
+ fe_mul(b, c, b)
+
+ fe_sq_n(b, b, 10)
+ fe_mul(a, b, a)
+
+ fe_sq_n(b, a, 50)
+ fe_mul(b, b, a)
+
+ fe_sq_n(c, b, 100)
+ fe_mul(b, c, b)
+
+ fe_sq_n(b, b, 50)
+ fe_mul(a, b, a)
+
+ fe_sq_n(a, a, 2)
+ fe_mul(out, a, z)
+}