return r\r
}\r
\r
- const gf0 = gf()\r
- const gf1 = gf([1])\r
- const D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203])\r
- const D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406])\r
- const X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169])\r
- const Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666])\r
- const I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83])\r
-\r
- function vn (x, xi, y, yi, n): number {\r
- var i, d = 0\r
- for (i = 0; i < n; i++) d |= x[xi + i] ^ y[yi + i]\r
+ const gf0: Float64Array = gf()\r
+ const gf1: Float64Array = gf([1])\r
+ const D: Float64Array = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203])\r
+ const D2: Float64Array = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406])\r
+ const X: Float64Array = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169])\r
+ const Y: Float64Array = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666])\r
+ const I: Float64Array = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83])\r
+\r
+ function vn (x: Uint8Array, xi: number, y: Uint8Array, yi: number, n: number): number {\r
+ let d = 0\r
+ for (let i = 0; i < n; i++) d |= x[xi + i] ^ y[yi + i]\r
return (1 & ((d - 1) >>> 8)) - 1\r
}\r
\r
- function crypto_verify_32 (x, xi, y, yi): number {\r
+ function crypto_verify_32 (x: Uint8Array, xi: number, y: Uint8Array, yi: number): number {\r
return vn(x, xi, y, yi, 32)\r
}\r
\r
- function set25519 (r, a): void {\r
- var i\r
- for (i = 0; i < 16; i++) r[i] = a[i] | 0\r
+ function set25519 (r: Float64Array, a: Float64Array): void {\r
+ for (let i = 0; i < 16; i++) r[i] = a[i] | 0\r
}\r
\r
- function car25519 (o) {\r
- var i, v, c = 1\r
- for (i = 0; i < 16; i++) {\r
+ function car25519 (o): void {\r
+ let v, c = 1\r
+ for (let i = 0; i < 16; i++) {\r
v = o[i] + c + 65535\r
c = Math.floor(v / 65536)\r
o[i] = v - c * 65536\r
for (let i = 0; i < 16; i++) o[i] = a[i] + b[i]\r
}\r
\r
- function Z (o, a, b): void {\r
+ function Z (o, a: Float64Array, b): void {\r
for (let i = 0; i < 16; i++) o[i] = a[i] - b[i]\r
}\r
\r
- function M (o, a, b): void {\r
+ function M (o, 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
\r
function pow2523 (o, i): void {\r
var c = gf()\r
- var a\r
- for (a = 0; a < 16; a++) c[a] = i[a]\r
- for (a = 250; a >= 0; a--) {\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
if (a !== 1) 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
// Note: difference from TweetNaCl - BLAKE2b used to hash instead of SHA-512.\r
r[31] ^= par25519(tx) << 7\r
}\r
\r
- function scalarmult (p, q, s): void {\r
+ function scalarmult (p: Float64Array[], q: Float64Array[], s: Uint8Array): void {\r
set25519(p[0], gf0)\r
set25519(p[1], gf1)\r
set25519(p[2], gf1)\r
}\r
}\r
\r
- function scalarbase (p, s): void {\r
- const q = [gf(), gf(), gf(), gf()]\r
+ function scalarbase (p: Float64Array[], s: Uint8Array): void {\r
+ const q: Float64Array[] = [gf(), gf(), gf(), gf()]\r
set25519(q[0], X)\r
set25519(q[1], Y)\r
set25519(q[2], gf1)\r
\r
const L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10])\r
\r
- function modL (r, x): void {\r
+ function modL (r: Uint8Array, x: Float64Array): void {\r
let carry, i, j, k\r
for (i = 63; i >= 32; --i) {\r
carry = 0\r
}\r
}\r
\r
- function reduce (r): void {\r
- let x = new Float64Array(64), i\r
- for (i = 0; i < 64; i++) x[i] = r[i]\r
- for (i = 0; i < 64; i++) r[i] = 0\r
+ function reduce (r: Uint8Array): void {\r
+ let x = new Float64Array(64)\r
+ for (let i = 0; i < 64; i++) x[i] = r[i]\r
+ for (let i = 0; i < 64; i++) r[i] = 0\r
modL(r, x)\r
}\r
\r
// Note: difference from C - smlen returned, not passed as argument.\r
function crypto_sign (sm: Uint8Array, m: Uint8Array, n: number, sk: Uint8Array): number {\r
- const d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64)\r
+ const d = new Uint8Array(64)\r
+ const h = new Uint8Array(64)\r
+ const r = new Uint8Array(64)\r
const x = new Float64Array(64)\r
- const p = [gf(), gf(), gf(), gf()]\r
+ const p: Float64Array[] = [gf(), gf(), gf(), gf()]\r
\r
crypto_hash(d, sk, 32)\r
d[0] &= 248\r
return smlen\r
}\r
\r
- function unpackneg (r, p): -1 | 0 {\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
}\r
\r
function crypto_sign_open (m: Uint8Array, sm: Uint8Array, n: number, pk: Uint8Array): number {\r
- var t = new Uint8Array(32), h = new Uint8Array(64)\r
- var p = [gf(), gf(), gf(), gf()],\r
- q = [gf(), gf(), gf(), gf()]\r
+ const t = new Uint8Array(32)\r
+ const h = new Uint8Array(64)\r
+ const p: Float64Array[] = [gf(), gf(), gf(), gf()]\r
+ const q: Float64Array[] = [gf(), gf(), gf(), gf()]\r
\r
if (n < 64) return -1\r
\r
function parseHex (hex: string): Uint8Array {\r
if (hex.length % 2 === 1) hex = `0${hex}`\r
const arr = hex.match(/.{1,2}/g)?.map(byte => parseInt(byte, 16))\r
- return Uint8Array.from(arr)\r
+ return Uint8Array.from(arr ?? [])\r
}\r
\r
function hexify (buf: Uint8Array): string {\r
throw new Error('bad seed size')\r
\r
const pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES)\r
- const p = [gf(), gf(), gf(), gf()]\r
+ const p: Float64Array[] = [gf(), gf(), gf(), gf()]\r
\r
const hash = new Blake2b(64).update(seed).digest()\r
hash[0] &= 248\r