store<i32>(changetype<usize>(h), 1, 0)
}
+/**
+ * Add two FieldElements and store the sum.
+ *
+ * @param h FieldElement sum destination
+ * @param f FieldElement summand source
+ * @param g FieldElement summand source
+ */
+//@ts-expect-error
+@inline
+export function fe_add (h: FieldElement, f: FieldElement, g: FieldElement): void {
+ const h_ptr = changetype<usize>(h)
+ const f_ptr = changetype<usize>(f)
+ const g_ptr = changetype<usize>(g)
+
+ let h0: v128, h1: v128, h2: v128
+
+ let f0 = v128.load(f_ptr, 0)
+ let f1 = v128.load(f_ptr, 16)
+ let f2 = v128.load(f_ptr, 32)
+
+ let g0 = v128.load(g_ptr, 0)
+ let g1 = v128.load(g_ptr, 16)
+ let g2 = v128.load(g_ptr, 32)
+
+ ${fe_add('h', 'f', 'g')}
+
+ // store h
+ v128.store(h_ptr, h0, 0)
+ v128.store(h_ptr, h1, 16)
+ v128.store_lane<u64>(h_ptr, h2, 0, 32)
+}
+
/**
* Conditionally copy values from one FieldElement to another.
*
//! SPDX-FileCopyrightText: 2026 Chris Duncan <chris@codecow.com>
//! SPDX-License-Identifier: GPL-3.0-or-later
-
/**
* Arithmetic on field elements. These are integers in the range
*
*
* `n = 2⁰a[0] + 2²⁶a[1] + 2⁷⁷a[2] ... + 2²³⁰a[9]`
*/
+
import { load_3, load_4, sodium_is_zero } from './utils'
/**
const h_ptr = changetype<usize>(h)
const f_ptr = changetype<usize>(f)
const g_ptr = changetype<usize>(g)
- v128.store(h_ptr, v128.add<i32>(v128.load(f_ptr, 0), v128.load(g_ptr, 0)), 0)
- v128.store(h_ptr, v128.add<i32>(v128.load(f_ptr, 16), v128.load(g_ptr, 16)), 16)
- v128.store_lane<i64>(h_ptr, v128.add<i32>(v128.load(f_ptr, 32), v128.load(g_ptr, 32)), 0, 32)
+
+ let h0: v128, h1: v128, h2: v128
+
+ let f0 = v128.load(f_ptr, 0)
+ let f1 = v128.load(f_ptr, 16)
+ let f2 = v128.load(f_ptr, 32)
+
+ let g0 = v128.load(g_ptr, 0)
+ let g1 = v128.load(g_ptr, 16)
+ let g2 = v128.load(g_ptr, 32)
+
+ h0 = v128.add<i32>(f0, g0)
+ h1 = v128.add<i32>(f1, g1)
+ h2 = v128.add<i32>(f2, g2)
+
+ // store h
+ v128.store(h_ptr, h0, 0)
+ v128.store(h_ptr, h1, 16)
+ v128.store_lane<u64>(h_ptr, h2, 0, 32)
}
/**