]> git.codecow.com Git - nano25519.git/commitdiff
Move other constants into relevant directory.
authorChris Duncan <chris@codecow.com>
Thu, 5 Nov 2026 06:10:17 +0000 (22:10 -0800)
committerChris Duncan <chris@codecow.com>
Thu, 5 Nov 2026 06:10:17 +0000 (22:10 -0800)
src/assembly/ed25519/constants/d.ts [new file with mode: 0644]
src/assembly/ed25519/constants/d2.ts [new file with mode: 0644]
src/assembly/ed25519/constants/sqrtm1.ts [new file with mode: 0644]
src/assembly/ed25519/fe.ts

diff --git a/src/assembly/ed25519/constants/d.ts b/src/assembly/ed25519/constants/d.ts
new file mode 100644 (file)
index 0000000..0ade701
--- /dev/null
@@ -0,0 +1,27 @@
+//! SPDX-FileCopyrightText: 2026 Chris Duncan <chris@codecow.com>
+//! SPDX-License-Identifier: GPL-3.0-or-later
+
+/**
+ * Ed25519 curve constant d
+ *   = −121665 / 121666
+ *   = 37095705934669439343138083508754565189542113879843219016388785533085940283555
+ *   = [-10913610, 13857413, -15372611, 6949391, 114729, -8787816, -6275908, -3247719, -18696448, -12055116, 0, 0]
+ *
+ * Shuffled for multiplication as the following, where `x` is a `FieldElement` placeholder for 0:
+ *
+ * `0123, 4567, 89xx, 9012, 3456, 78xx`
+ *
+ * Shuffles are also multiplied by 19 for limb wrapping, except limb 0 which does not wrap.
+ */
+export const d_0123 = i32x4(-10913610, 13857413, -15372611, 6949391)
+export const d_4567 = i32x4(114729, -8787816, -6275908, -3247719)
+export const d_89xx = i32x4(-18696448, -12055116, 0, 0)
+export const d_9012 = i32x4(-12055116, -10913610, 13857413, -15372611)
+export const d_3456 = i32x4(6949391, 114729, -8787816, -6275908)
+export const d_78xx = i32x4(-3247719, -18696448, 0, 0)
+export const d_0123_19 = i32x4(-207358590, 263290847, -292079609, 132038429)
+export const d_4567_19 = i32x4(2179851, -166968504, -119242252, -61706661)
+export const d_89xx_19 = i32x4(-355232512, -229047204, 0, 0)
+export const d_9012_19 = i32x4(-229047204, -10913610, 263290847, -292079609)
+export const d_3456_19 = i32x4(132038429, 2179851, -166968504, -119242252)
+export const d_78xx_19 = i32x4(-61706661, -355232512, 0, 0)
diff --git a/src/assembly/ed25519/constants/d2.ts b/src/assembly/ed25519/constants/d2.ts
new file mode 100644 (file)
index 0000000..5a7a6e2
--- /dev/null
@@ -0,0 +1,27 @@
+//! SPDX-FileCopyrightText: 2026 Chris Duncan <chris@codecow.com>
+//! SPDX-License-Identifier: GPL-3.0-or-later
+
+/**
+ * Ed25519 curve constant 2d
+ *   = −121665 / 60833
+ *   = 16295367250680780974490674513165176452449235426866156013048779062215315747161
+ *   = [-21827239, -5839606, -30745221, 13898782, 229458, 15978800, -12551817, -6495438, 29715968, 9444199]
+ *
+ * Shuffled for multiplication as the following, where `x` is a `FieldElement` placeholder for 0:
+ *
+ * `0123, 4567, 89xx, 9012, 3456, 78xx`
+ *
+ * Shuffles are also multiplied by 19 for limb wrapping, except limb 0 which does not wrap.
+ */
+export const d2_0123 = i32x4(-21827239, -5839606, -30745221, 13898782)
+export const d2_4567 = i32x4(229458, 15978800, -12551817, -6495438)
+export const d2_89xx = i32x4(29715968, 9444199, 0, 0)
+export const d2_9012 = i32x4(9444199, -21827239, -5839606, -30745221)
+export const d2_3456 = i32x4(13898782, 229458, 15978800, -12551817)
+export const d2_78xx = i32x4(-6495438, 29715968, 0, 0)
+export const d2_0123_19 = i32x4(-414717541, -110952514, -584159199, 264076858)
+export const d2_4567_19 = i32x4(4359702, 303597200, -238484523, -123413322)
+export const d2_89xx_19 = i32x4(564603392, 179439781, 0, 0)
+export const d2_9012_19 = i32x4(179439781, -21827239, -110952514, -584159199)
+export const d2_3456_19 = i32x4(264076858, 4359702, 303597200, -238484523)
+export const d2_78xx_19 = i32x4(-123413322, 564603392, 0, 0)
diff --git a/src/assembly/ed25519/constants/sqrtm1.ts b/src/assembly/ed25519/constants/sqrtm1.ts
new file mode 100644 (file)
index 0000000..eeccc14
--- /dev/null
@@ -0,0 +1,27 @@
+//! SPDX-FileCopyrightText: 2026 Chris Duncan <chris@codecow.com>
+//! SPDX-License-Identifier: GPL-3.0-or-later
+
+/**
+ * Ed25519 curve constant √-1
+ *   = 2⁽ᵖ⁻¹⁾⸍⁴ mod `p`
+ *   = 19681161376707505956807079304988542015446066515923890162744021073123829784752
+ *   = [-32595792, -7943725, 9377950, 3500415, 12389472, -272473, -25146209, -2005654, 326686, 11406482]
+ *
+ * Shuffled for multiplication as the following, where `x` is a `FieldElement` placeholder for 0:
+ *
+ * `0123, 4567, 89xx, 9012, 3456, 78xx`
+ *
+ * Shuffles are also multiplied by 19 for limb wrapping, except limb 0 which does not wrap.
+ */
+export const sqrtm1_0123 = i32x4(-32595792, -7943725, 9377950, 3500415)
+export const sqrtm1_4567 = i32x4(12389472, -272473, -25146209, -2005654)
+export const sqrtm1_89xx = i32x4(326686, 11406482, 0, 0)
+export const sqrtm1_9012 = i32x4(11406482, -32595792, -7943725, 9377950)
+export const sqrtm1_3456 = i32x4(3500415, 12389472, -272473, -25146209)
+export const sqrtm1_78xx = i32x4(-2005654, 326686, 0, 0)
+export const sqrtm1_0123_19 = i32x4(-619320048, -150930775, 178181050, 66507885)
+export const sqrtm1_4567_19 = i32x4(235399968, -5176987, -477777971, -38107426)
+export const sqrtm1_89xx_19 = i32x4(6207034, 216723158, 0, 0)
+export const sqrtm1_9012_19 = i32x4(216723158, -32595792, -150930775, 178181050)
+export const sqrtm1_3456_19 = i32x4(66507885, 235399968, -5176987, -477777971)
+export const sqrtm1_78xx_19 = i32x4(-38107426, 6207034, 0, 0)
index 4ffa4c2baca2bcaa5baad5486d4392212d96cf3e..b92ed40870299bfd701c7e20d87ff9d7f260b5c6 100644 (file)
  *
  * `n = 2⁰a[0] + 2²⁶a[1] + 2⁵¹a[2] ... + 2²³⁰a[9]`
  */
+import { d_0123, d_0123_19, d_3456, d_3456_19, d_4567, d_4567_19, d_78xx, d_78xx_19, d_89xx, d_89xx_19, d_9012, d_9012_19 } from './constants/d'
+import { d2_0123, d2_0123_19, d2_3456, d2_3456_19, d2_4567, d2_4567_19, d2_78xx, d2_78xx_19, d2_89xx, d2_89xx_19, d2_9012, d2_9012_19 } from './constants/d2'
+import { sqrtm1_0123, sqrtm1_0123_19, sqrtm1_3456, sqrtm1_3456_19, sqrtm1_4567, sqrtm1_4567_19, sqrtm1_78xx, sqrtm1_78xx_19, sqrtm1_89xx, sqrtm1_89xx_19, sqrtm1_9012, sqrtm1_9012_19 } from './constants/sqrtm1'
 import { load_3, load_4 } from './utils'
 
 const t_fe = fe()
 const t_u8x32 = new StaticArray<u8>(32)
 
-/**
- * Ed25519 curve constant √-1
- *   = 2⁽ᵖ⁻¹⁾⸍⁴ mod `p`
- *   = 19681161376707505956807079304988542015446066515923890162744021073123829784752
- *   = [-32595792, -7943725, 9377950, 3500415, 12389472, -272473, -25146209, -2005654, 326686, 11406482]
- *
- * Shuffled for multiplication as the following, where `x` is a `FieldElement` placeholder for 0:
- *
- * `0123, 4567, 89xx, 9012, 3456, 78xx`
- *
- * Shuffles are also multiplied by 19 for limb wrapping, except limb 0 which does not wrap.
- */
-const sqrtm1_0123 = i32x4(-32595792, -7943725, 9377950, 3500415)
-const sqrtm1_4567 = i32x4(12389472, -272473, -25146209, -2005654)
-const sqrtm1_89xx = i32x4(326686, 11406482, 0, 0)
-const sqrtm1_9012 = i32x4(11406482, -32595792, -7943725, 9377950)
-const sqrtm1_3456 = i32x4(3500415, 12389472, -272473, -25146209)
-const sqrtm1_78xx = i32x4(-2005654, 326686, 0, 0)
-const sqrtm1_0123_19 = i32x4(-619320048, -150930775, 178181050, 66507885)
-const sqrtm1_4567_19 = i32x4(235399968, -5176987, -477777971, -38107426)
-const sqrtm1_89xx_19 = i32x4(6207034, 216723158, 0, 0)
-const sqrtm1_9012_19 = i32x4(216723158, -32595792, -150930775, 178181050)
-const sqrtm1_3456_19 = i32x4(66507885, 235399968, -5176987, -477777971)
-const sqrtm1_78xx_19 = i32x4(-38107426, 6207034, 0, 0)
-
-/**
- * Ed25519 curve constant d
- *   = −121665 / 121666
- *   = 37095705934669439343138083508754565189542113879843219016388785533085940283555
- *   = [-10913610, 13857413, -15372611, 6949391, 114729, -8787816, -6275908, -3247719, -18696448, -12055116, 0, 0]
- *
- * Shuffled for multiplication as the following, where `x` is a `FieldElement` placeholder for 0:
- *
- * `0123, 4567, 89xx, 9012, 3456, 78xx`
- *
- * Shuffles are also multiplied by 19 for limb wrapping, except limb 0 which does not wrap.
- */
-const d_0123 = i32x4(-10913610, 13857413, -15372611, 6949391)
-const d_4567 = i32x4(114729, -8787816, -6275908, -3247719)
-const d_89xx = i32x4(-18696448, -12055116, 0, 0)
-const d_9012 = i32x4(-12055116, -10913610, 13857413, -15372611)
-const d_3456 = i32x4(6949391, 114729, -8787816, -6275908)
-const d_78xx = i32x4(-3247719, -18696448, 0, 0)
-const d_0123_19 = i32x4(-207358590, 263290847, -292079609, 132038429)
-const d_4567_19 = i32x4(2179851, -166968504, -119242252, -61706661)
-const d_89xx_19 = i32x4(-355232512, -229047204, 0, 0)
-const d_9012_19 = i32x4(-229047204, -10913610, 263290847, -292079609)
-const d_3456_19 = i32x4(132038429, 2179851, -166968504, -119242252)
-const d_78xx_19 = i32x4(-61706661, -355232512, 0, 0)
-
-/**
- * Ed25519 curve constant 2d
- *   = −121665 / 60833
- *   = 16295367250680780974490674513165176452449235426866156013048779062215315747161
- *   = [-21827239, -5839606, -30745221, 13898782, 229458, 15978800, -12551817, -6495438, 29715968, 9444199]
- *
- * Shuffled for multiplication as the following, where `x` is a `FieldElement` placeholder for 0:
- *
- * `0123, 4567, 89xx, 9012, 3456, 78xx`
- *
- * Shuffles are also multiplied by 19 for limb wrapping, except limb 0 which does not wrap.
- */
-const d2_0123 = i32x4(-21827239, -5839606, -30745221, 13898782)
-const d2_4567 = i32x4(229458, 15978800, -12551817, -6495438)
-const d2_89xx = i32x4(29715968, 9444199, 0, 0)
-const d2_9012 = i32x4(9444199, -21827239, -5839606, -30745221)
-const d2_3456 = i32x4(13898782, 229458, 15978800, -12551817)
-const d2_78xx = i32x4(-6495438, 29715968, 0, 0)
-const d2_0123_19 = i32x4(-414717541, -110952514, -584159199, 264076858)
-const d2_4567_19 = i32x4(4359702, 303597200, -238484523, -123413322)
-const d2_89xx_19 = i32x4(564603392, 179439781, 0, 0)
-const d2_9012_19 = i32x4(179439781, -21827239, -110952514, -584159199)
-const d2_3456_19 = i32x4(264076858, 4359702, 303597200, -238484523)
-const d2_78xx_19 = i32x4(-123413322, 564603392, 0, 0)
-
 /**
  * 10x 25- and 26-bit array of values representing a large integer `n mod p`. In
  * this implementation, 12 elements are allocated instead of 10, and this is for