// SPDX-FileCopyrightText: 2024 Chris Duncan <chris@zoso.dev>\r
// SPDX-License-Identifier: GPL-3.0-or-later\r
-//@ts-nocheck\r
+\r
'use strict'\r
\r
import { Blake2b } from './blake2b.js'\r
o[0] += c - 1 + 37 * (c - 1)\r
}\r
\r
- function sel25519 (p, q, b): void {\r
+ function sel25519 (p: Float64Array, q: Float64Array, b: number): void {\r
let t\r
const c = ~(b - 1)\r
for (let i = 0; i < 16; i++) {\r
}\r
}\r
\r
- function pack25519 (o, n): void {\r
+ function pack25519 (o: Uint8Array, n: Float64Array): void {\r
let b: number\r
const m: Float64Array = gf()\r
const t: Float64Array = gf()\r
}\r
}\r
\r
- function neq25519 (a, b): number {\r
- var c = new Uint8Array(32), d = new Uint8Array(32)\r
+ function neq25519 (a: Float64Array, b: Float64Array): number {\r
+ const c = new Uint8Array(32)\r
+ const d = new Uint8Array(32)\r
pack25519(c, a)\r
pack25519(d, b)\r
return crypto_verify_32(c, 0, d, 0)\r
}\r
\r
- function par25519 (a): number {\r
+ function par25519 (a: Float64Array): number {\r
var d = new Uint8Array(32)\r
pack25519(d, a)\r
return d[0] & 1\r
}\r
\r
- function unpack25519 (o, n): void {\r
- var i\r
- for (i = 0; i < 16; i++) o[i] = n[2 * i] + (n[2 * i + 1] << 8)\r
+ function unpack25519 (o: Float64Array, n: Uint8Array): void {\r
+ for (let i = 0; i < 16; i++) o[i] = n[2 * i] + (n[2 * i + 1] << 8)\r
o[15] &= 0x7fff\r
}\r
\r
- function A (o, a, b): void {\r
+ function A (o: Float64Array, a: Float64Array, b: Float64Array): void {\r
for (let i = 0; i < 16; i++) o[i] = a[i] + b[i]\r
}\r
\r
- function Z (o, a: Float64Array, b): void {\r
+ function Z (o: Float64Array, a: Float64Array, b: Float64Array): void {\r
for (let i = 0; i < 16; i++) o[i] = a[i] - b[i]\r
}\r
\r
- function M (o, a: Float64Array, b: Float64Array): void {\r
+ function M (o: Float64Array, a: Float64Array, b: Float64Array): void {\r
let v, c,\r
t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0,\r
t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0,\r
o[15] = t15\r
}\r
\r
- function S (o, a): void {\r
+ function S (o: Float64Array, a: Float64Array): void {\r
M(o, a, a)\r
}\r
\r
- function inv25519 (o, i): void {\r
- var c = gf()\r
- var a\r
- for (a = 0; a < 16; a++) c[a] = i[a]\r
- for (a = 253; a >= 0; a--) {\r
+ function inv25519 (o: Float64Array, i: Float64Array): void {\r
+ const c: Float64Array = gf()\r
+ for (let a = 0; a < 16; a++) c[a] = i[a]\r
+ for (let a = 253; a >= 0; a--) {\r
S(c, c)\r
if (a !== 2 && a !== 4) M(c, c, i)\r
}\r
- for (a = 0; a < 16; a++) o[a] = c[a]\r
+ for (let a = 0; a < 16; a++) o[a] = c[a]\r
}\r
\r
- function pow2523 (o, i): void {\r
- var c = gf()\r
+ function pow2523 (o: Float64Array, i: Float64Array): void {\r
+ const c: Float64Array = gf()\r
for (let a = 0; a < 16; a++) c[a] = i[a]\r
for (let a = 250; a >= 0; a--) {\r
S(c, c)\r
return 0\r
}\r
\r
- function add (p, q): void {\r
- const a = gf(), b = gf(), c = gf(),\r
- d = gf(), e = gf(), f = gf(),\r
- g = gf(), h = gf(), t = gf()\r
+ function add (p: Float64Array[], q: Float64Array[]): void {\r
+ const a: Float64Array = gf()\r
+ const b: Float64Array = gf()\r
+ const c: Float64Array = gf()\r
+ const d: Float64Array = gf()\r
+ const e: Float64Array = gf()\r
+ const f: Float64Array = gf()\r
+ const g: Float64Array = gf()\r
+ const h: Float64Array = gf()\r
+ const t: Float64Array = gf()\r
\r
Z(a, p[1], p[0])\r
Z(t, q[1], q[0])\r
M(p[3], e, h)\r
}\r
\r
- function cswap (p, q, b): void {\r
+ function cswap (p: Float64Array[], q: Float64Array[], b: number): void {\r
for (let i = 0; i < 4; i++) {\r
sel25519(p[i], q[i], b)\r
}\r
}\r
\r
- function pack (r, p): void {\r
- const tx = gf(), ty = gf(), zi = gf()\r
+ function pack (r: Uint8Array, p: Float64Array[]): void {\r
+ const tx: Float64Array = gf()\r
+ const ty: Float64Array = gf()\r
+ const zi: Float64Array = gf()\r
inv25519(zi, p[2])\r
M(tx, p[0], zi)\r
M(ty, p[1], zi)\r
}\r
\r
function unpackneg (r: Float64Array[], p: Uint8Array): -1 | 0 {\r
- const t = gf(), chk = gf(), num = gf(),\r
- den = gf(), den2 = gf(), den4 = gf(),\r
- den6 = gf()\r
+ const t: Float64Array = gf()\r
+ const chk: Float64Array = gf()\r
+ const num: Float64Array = gf()\r
+ const den: Float64Array = gf()\r
+ const den2: Float64Array = gf()\r
+ const den4: Float64Array = gf()\r
+ const den6: Float64Array = gf()\r
\r
set25519(r[2], gf1)\r
unpack25519(r[1], p)\r