]> git.codecow.com Git - nano25519.git/commitdiff
Convert between FieldElement singles and pairs.
authorChris Duncan <chris@codecow.com>
Fri, 23 Oct 2026 18:43:58 +0000 (11:43 -0700)
committerChris Duncan <chris@codecow.com>
Fri, 23 Oct 2026 18:43:58 +0000 (11:43 -0700)
src/assembly/ed25519/fep.ts

index c559c9f55f8306a17f95020830f6d6d3e7824e96..02dc1f155c74061d0eaa04ad1675a86cdc7624d6 100644 (file)
@@ -15,6 +15,7 @@
  *
  * `n = 2⁰a[0] + 2²⁶a[1] + 2⁷⁷a[2] ... + 2²³⁰a[9]`
  */
+import { FieldElement } from './fe'
 // import { load_3, load_4 } from './utils'
 
 /**
  * to `v128.load()`.
  */
 export type FieldElementPair = StaticArray<i32>
+
 export function fep (): FieldElementPair {
        return new StaticArray<i32>(20)
 }
 
+export function fep_pack (f: FieldElementPair, f_a: FieldElement, f_b: FieldElement): void {
+       for (let i = 0, j = 0; i < 10; i++, j += 2) {
+               f[j] = f_a[i]
+               f[j + 1] = f_b[i]
+       }
+}
+
+export function fep_unpack (f_a: FieldElementPair, f_b: FieldElement, f: FieldElementPair): void {
+       for (let i = 0, j = 0; i < 10; i++, j += 2) {
+               f_a[i] = f[j]
+               f_b[i] = f[j + 1]
+       }
+}
+
 /**
  * Set all values of a FieldElementPair to zero.
  *