@webpqc/fndsa 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +49 -0
- package/README.md +221 -2
- package/esm/mod.d.ts +6 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +3 -0
- package/esm/package.json +3 -0
- package/esm/src/basis.d.ts +11 -0
- package/esm/src/basis.d.ts.map +1 -0
- package/esm/src/basis.js +78 -0
- package/esm/src/codec.d.ts +28 -0
- package/esm/src/codec.d.ts.map +1 -0
- package/esm/src/codec.js +212 -0
- package/esm/src/common.d.ts +49 -0
- package/esm/src/common.d.ts.map +1 -0
- package/esm/src/common.js +112 -0
- package/esm/src/consts.d.ts +11 -0
- package/esm/src/consts.d.ts.map +1 -0
- package/esm/src/consts.js +10 -0
- package/esm/src/deps.d.ts +2 -0
- package/esm/src/deps.d.ts.map +1 -0
- package/esm/src/deps.js +1 -0
- package/esm/src/errors.d.ts +7 -0
- package/esm/src/errors.d.ts.map +1 -0
- package/esm/src/errors.js +19 -0
- package/esm/src/fft.d.ts +58 -0
- package/esm/src/fft.d.ts.map +1 -0
- package/esm/src/fft.js +364 -0
- package/esm/src/fnDsa1024.d.ts +88 -0
- package/esm/src/fnDsa1024.d.ts.map +1 -0
- package/esm/src/fnDsa1024.js +98 -0
- package/esm/src/fnDsa512.d.ts +88 -0
- package/esm/src/fnDsa512.d.ts.map +1 -0
- package/esm/src/fnDsa512.js +98 -0
- package/esm/src/fnDsaKeyGen.d.ts +6 -0
- package/esm/src/fnDsaKeyGen.d.ts.map +1 -0
- package/esm/src/fnDsaKeyGen.js +92 -0
- package/esm/src/fnDsaSigner.d.ts +30 -0
- package/esm/src/fnDsaSigner.d.ts.map +1 -0
- package/esm/src/fnDsaSigner.js +211 -0
- package/esm/src/fnDsaVerifier.d.ts +24 -0
- package/esm/src/fnDsaVerifier.d.ts.map +1 -0
- package/esm/src/fnDsaVerifier.js +134 -0
- package/esm/src/interfaces.d.ts +49 -0
- package/esm/src/interfaces.d.ts.map +1 -0
- package/esm/src/interfaces.js +1 -0
- package/esm/src/keygen.d.ts +29 -0
- package/esm/src/keygen.d.ts.map +1 -0
- package/esm/src/keygen.js +1956 -0
- package/esm/src/native.d.ts +15 -0
- package/esm/src/native.d.ts.map +1 -0
- package/esm/src/native.js +16 -0
- package/esm/src/params.d.ts +20 -0
- package/esm/src/params.d.ts.map +1 -0
- package/esm/src/params.js +18 -0
- package/esm/src/rng.d.ts +22 -0
- package/esm/src/rng.d.ts.map +1 -0
- package/esm/src/rng.js +151 -0
- package/esm/src/sha3/keccak.d.ts +58 -0
- package/esm/src/sha3/keccak.d.ts.map +1 -0
- package/esm/src/sha3/keccak.js +500 -0
- package/esm/src/sign.d.ts +31 -0
- package/esm/src/sign.d.ts.map +1 -0
- package/esm/src/sign.js +718 -0
- package/esm/src/utils.d.ts +24 -0
- package/esm/src/utils.d.ts.map +1 -0
- package/esm/src/utils.js +51 -0
- package/esm/src/vrfy.d.ts +27 -0
- package/esm/src/vrfy.d.ts.map +1 -0
- package/esm/src/vrfy.js +242 -0
- package/package.json +49 -4
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @webpqc/fndsa is a port of the reference implementation of Falcon
|
|
3
|
+
* (round 3), which is under the MIT license:
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2017-2019 Falcon Project
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
8
|
+
* a copy of this software and associated documentation files (the
|
|
9
|
+
* "Software"), to deal in the Software without restriction, including
|
|
10
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
|
11
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
12
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
|
13
|
+
* the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be
|
|
16
|
+
* included in all copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
19
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
20
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
21
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
22
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
23
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
24
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
25
|
+
*/
|
|
26
|
+
import { Keccak } from "./deps.js";
|
|
27
|
+
/** A new SHAKE256 instance. */
|
|
28
|
+
export declare function newShake256(): Keccak;
|
|
29
|
+
/**
|
|
30
|
+
* Squeezes a SHAKE256 instance, which has absorbed the nonce and the
|
|
31
|
+
* message, to n values modulo q (HashToPoint), by rejection sampling of
|
|
32
|
+
* 16-bit values.
|
|
33
|
+
*
|
|
34
|
+
* Its timing depends on the hash, that is, on the nonce and the message,
|
|
35
|
+
* and not on a key: the nonce is in the signature, so this reveals nothing
|
|
36
|
+
* to who has the signed message.
|
|
37
|
+
*/
|
|
38
|
+
export declare function hashToPoint(sc: Keccak, x: Uint16Array, logn: number): void;
|
|
39
|
+
/**
|
|
40
|
+
* Whether the squared norm of (s1, s2) is at most the bound. The sum
|
|
41
|
+
* saturates if it reaches 2^31, so it does not wrap around.
|
|
42
|
+
*/
|
|
43
|
+
export declare function isShort(s1: Int16Array, s2: Int16Array, logn: number): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Like {@link isShort}, with the squared norm of s1 already computed (and
|
|
46
|
+
* saturated) in `sqn`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function isShortHalf(sqn: number, s2: Int16Array, logn: number): boolean;
|
|
49
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/src/common.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAYH,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,+BAA+B;AAC/B,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAkB1E;AAiBD;;;GAGG;AACH,wBAAgB,OAAO,CACrB,EAAE,EAAE,UAAU,EACd,EAAE,EAAE,UAAU,EACd,IAAI,EAAE,MAAM,GACX,OAAO,CAYT;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,GAAG,EAAE,MAAM,EACX,EAAE,EAAE,UAAU,EACd,IAAI,EAAE,MAAM,GACX,OAAO,CAST"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @webpqc/fndsa is a port of the reference implementation of Falcon
|
|
3
|
+
* (round 3), which is under the MIT license:
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2017-2019 Falcon Project
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
8
|
+
* a copy of this software and associated documentation files (the
|
|
9
|
+
* "Software"), to deal in the Software without restriction, including
|
|
10
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
|
11
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
12
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
|
13
|
+
* the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be
|
|
16
|
+
* included in all copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
19
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
20
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
21
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
22
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
23
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
24
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
25
|
+
*/
|
|
26
|
+
/*
|
|
27
|
+
* Hashing to a point, and the bound on the norm of a signature: a port of
|
|
28
|
+
* common.c. Author: Thomas Pornin <thomas.pornin@nccgroup.com>
|
|
29
|
+
*
|
|
30
|
+
* The notice above is a legal comment (it starts with "!"), which bundlers
|
|
31
|
+
* and minifiers keep: this module is in every bundle of the package, as
|
|
32
|
+
* both signing and verification import it.
|
|
33
|
+
*/
|
|
34
|
+
import { Q } from "./consts.js";
|
|
35
|
+
import { Keccak } from "./deps.js";
|
|
36
|
+
/** A new SHAKE256 instance. */
|
|
37
|
+
export function newShake256() {
|
|
38
|
+
return new Keccak(136, 0x1f, 32, true);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Squeezes a SHAKE256 instance, which has absorbed the nonce and the
|
|
42
|
+
* message, to n values modulo q (HashToPoint), by rejection sampling of
|
|
43
|
+
* 16-bit values.
|
|
44
|
+
*
|
|
45
|
+
* Its timing depends on the hash, that is, on the nonce and the message,
|
|
46
|
+
* and not on a key: the nonce is in the signature, so this reveals nothing
|
|
47
|
+
* to who has the signed message.
|
|
48
|
+
*/
|
|
49
|
+
export function hashToPoint(sc, x, logn) {
|
|
50
|
+
const n = 1 << logn;
|
|
51
|
+
// A multiple of 2, to keep whole values.
|
|
52
|
+
const buf = new Uint8Array(272);
|
|
53
|
+
let u = 0;
|
|
54
|
+
while (u < n) {
|
|
55
|
+
sc.writeIntoUnsafe(buf);
|
|
56
|
+
for (let i = 0; i < buf.length && u < n; i += 2) {
|
|
57
|
+
let w = (buf[i] << 8) | buf[i + 1];
|
|
58
|
+
// 61445 = 5 * q
|
|
59
|
+
if (w < 61445) {
|
|
60
|
+
while (w >= Q) {
|
|
61
|
+
w -= Q;
|
|
62
|
+
}
|
|
63
|
+
x[u++] = w;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** The bound on the squared norm of a signature (s1, s2), by logn. */
|
|
69
|
+
const L2BOUND = [
|
|
70
|
+
0,
|
|
71
|
+
101498,
|
|
72
|
+
208714,
|
|
73
|
+
428865,
|
|
74
|
+
892039,
|
|
75
|
+
1852696,
|
|
76
|
+
3842630,
|
|
77
|
+
7959734,
|
|
78
|
+
16468416,
|
|
79
|
+
34034726,
|
|
80
|
+
70265242,
|
|
81
|
+
];
|
|
82
|
+
/**
|
|
83
|
+
* Whether the squared norm of (s1, s2) is at most the bound. The sum
|
|
84
|
+
* saturates if it reaches 2^31, so it does not wrap around.
|
|
85
|
+
*/
|
|
86
|
+
export function isShort(s1, s2, logn) {
|
|
87
|
+
const n = 1 << logn;
|
|
88
|
+
let s = 0;
|
|
89
|
+
let ng = 0;
|
|
90
|
+
for (let u = 0; u < n; u++) {
|
|
91
|
+
s = (s + s1[u] * s1[u]) | 0;
|
|
92
|
+
ng |= s;
|
|
93
|
+
s = (s + s2[u] * s2[u]) | 0;
|
|
94
|
+
ng |= s;
|
|
95
|
+
}
|
|
96
|
+
s |= -(ng >>> 31);
|
|
97
|
+
return (s >>> 0) <= L2BOUND[logn];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Like {@link isShort}, with the squared norm of s1 already computed (and
|
|
101
|
+
* saturated) in `sqn`.
|
|
102
|
+
*/
|
|
103
|
+
export function isShortHalf(sqn, s2, logn) {
|
|
104
|
+
const n = 1 << logn;
|
|
105
|
+
let ng = -(sqn >>> 31);
|
|
106
|
+
for (let u = 0; u < n; u++) {
|
|
107
|
+
sqn = (sqn + s2[u] * s2[u]) | 0;
|
|
108
|
+
ng |= sqn;
|
|
109
|
+
}
|
|
110
|
+
sqn |= -(ng >>> 31);
|
|
111
|
+
return (sqn >>> 0) <= L2BOUND[logn];
|
|
112
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The modulus q. */
|
|
2
|
+
export declare const Q = 12289;
|
|
3
|
+
/** The length of the nonce (the salt r) of a signature in octets. */
|
|
4
|
+
export declare const NONCE_LEN = 40;
|
|
5
|
+
/** The size of the seed of key generation, and of signing, in octets. */
|
|
6
|
+
export declare const SEED_SIZE = 48;
|
|
7
|
+
/** The header of a public key: 0x00 + logn. */
|
|
8
|
+
export declare const PK_HEADER = 0;
|
|
9
|
+
/** The header of a private key: 0x50 + logn. */
|
|
10
|
+
export declare const SK_HEADER = 80;
|
|
11
|
+
//# sourceMappingURL=consts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../src/src/consts.ts"],"names":[],"mappings":"AAAA,qBAAqB;AACrB,eAAO,MAAM,CAAC,QAAQ,CAAC;AAEvB,qEAAqE;AACrE,eAAO,MAAM,SAAS,KAAK,CAAC;AAE5B,yEAAyE;AACzE,eAAO,MAAM,SAAS,KAAK,CAAC;AAE5B,+CAA+C;AAC/C,eAAO,MAAM,SAAS,IAAO,CAAC;AAE9B,gDAAgD;AAChD,eAAO,MAAM,SAAS,KAAO,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The modulus q. */
|
|
2
|
+
export const Q = 12289;
|
|
3
|
+
/** The length of the nonce (the salt r) of a signature in octets. */
|
|
4
|
+
export const NONCE_LEN = 40;
|
|
5
|
+
/** The size of the seed of key generation, and of signing, in octets. */
|
|
6
|
+
export const SEED_SIZE = 48;
|
|
7
|
+
/** The header of a public key: 0x00 + logn. */
|
|
8
|
+
export const PK_HEADER = 0x00;
|
|
9
|
+
/** The header of a private key: 0x50 + logn. */
|
|
10
|
+
export const SK_HEADER = 0x50;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deps.d.ts","sourceRoot":"","sources":["../../src/src/deps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,MAAM,EAAE,MAAM,kBAAkB,CAAC"}
|
package/esm/src/deps.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { KeccakCore as Keccak } from "./sha3/keccak.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;gBAChB,CAAC,EAAE,OAAO;CAc9B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The base error class of fndsa.
|
|
3
|
+
*/
|
|
4
|
+
export class FnDsaError extends Error {
|
|
5
|
+
constructor(e) {
|
|
6
|
+
let message;
|
|
7
|
+
if (e instanceof Error) {
|
|
8
|
+
message = e.message;
|
|
9
|
+
}
|
|
10
|
+
else if (typeof e === "string") {
|
|
11
|
+
message = e;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
message = "";
|
|
15
|
+
}
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = this.constructor.name;
|
|
18
|
+
}
|
|
19
|
+
}
|
package/esm/src/fft.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GM[2k] + i * GM[2k + 1] = exp(i * pi * brv(k) / 1024), where brv reverses
|
|
3
|
+
* 10 bits (fpr_gm_tab of the reference implementation).
|
|
4
|
+
*/
|
|
5
|
+
export declare const GM: Float64Array;
|
|
6
|
+
/** Converts a polynomial to the FFT representation, in place. */
|
|
7
|
+
export declare function FFT(f: Float64Array, logn: number): void;
|
|
8
|
+
/** Converts a polynomial back from the FFT representation, in place. */
|
|
9
|
+
export declare function iFFT(f: Float64Array, logn: number): void;
|
|
10
|
+
/** a += b */
|
|
11
|
+
export declare function polyAdd(a: Float64Array, b: Float64Array, logn: number): void;
|
|
12
|
+
/** a -= b */
|
|
13
|
+
export declare function polySub(a: Float64Array, b: Float64Array, logn: number): void;
|
|
14
|
+
/** a = -a */
|
|
15
|
+
export declare function polyNeg(a: Float64Array, logn: number): void;
|
|
16
|
+
/** a = adj(a), in the FFT representation. */
|
|
17
|
+
export declare function polyAdjFft(a: Float64Array, logn: number): void;
|
|
18
|
+
/** a *= b, in the FFT representation. */
|
|
19
|
+
export declare function polyMulFft(a: Float64Array, b: Float64Array, logn: number): void;
|
|
20
|
+
/** a *= adj(b), in the FFT representation. */
|
|
21
|
+
export declare function polyMuladjFft(a: Float64Array, b: Float64Array, logn: number): void;
|
|
22
|
+
/** a *= adj(a), in the FFT representation. */
|
|
23
|
+
export declare function polyMulselfadjFft(a: Float64Array, logn: number): void;
|
|
24
|
+
/** a *= x, for a real constant x. */
|
|
25
|
+
export declare function polyMulconst(a: Float64Array, x: number, logn: number): void;
|
|
26
|
+
/** a /= b, in the FFT representation. */
|
|
27
|
+
export declare function polyDivFft(a: Float64Array, b: Float64Array, logn: number): void;
|
|
28
|
+
/**
|
|
29
|
+
* d = 1 / (a * adj(a) + b * adj(b)), in the FFT representation. The result
|
|
30
|
+
* is real: only the first half of d is set.
|
|
31
|
+
*/
|
|
32
|
+
export declare function polyInvnorm2Fft(d: Float64Array, a: Float64Array, b: Float64Array, logn: number): void;
|
|
33
|
+
/** d = F * adj(f) + G * adj(g), in the FFT representation. */
|
|
34
|
+
export declare function polyAddMuladjFft(d: Float64Array, F: Float64Array, G: Float64Array, f: Float64Array, g: Float64Array, logn: number): void;
|
|
35
|
+
/**
|
|
36
|
+
* a *= b, where b is self-adjoint (real in the FFT representation): only
|
|
37
|
+
* the first half of b is read.
|
|
38
|
+
*/
|
|
39
|
+
export declare function polyMulAutoadjFft(a: Float64Array, b: Float64Array, logn: number): void;
|
|
40
|
+
/**
|
|
41
|
+
* a /= b, where b is self-adjoint (real in the FFT representation): only
|
|
42
|
+
* the first half of b is read.
|
|
43
|
+
*/
|
|
44
|
+
export declare function polyDivAutoadjFft(a: Float64Array, b: Float64Array, logn: number): void;
|
|
45
|
+
/**
|
|
46
|
+
* The LDL decomposition of the self-adjoint matrix [[g00, g01], [adj(g01),
|
|
47
|
+
* g11]]: d11 and l10 are set so that it is L * diag(g00, d11) * adj(L) with
|
|
48
|
+
* L = [[1, 0], [l10, 1]]. The inputs are not modified.
|
|
49
|
+
*/
|
|
50
|
+
export declare function polyLDLmvFft(d11: Float64Array, l10: Float64Array, g00: Float64Array, g01: Float64Array, g11: Float64Array, logn: number): void;
|
|
51
|
+
/**
|
|
52
|
+
* Splits f, in the FFT representation, to f0 and f1 of half its degree,
|
|
53
|
+
* such that f = f0(x^2) + x * f1(x^2).
|
|
54
|
+
*/
|
|
55
|
+
export declare function polySplitFft(f0: Float64Array, f1: Float64Array, f: Float64Array, logn: number): void;
|
|
56
|
+
/** The inverse of {@link polySplitFft}. */
|
|
57
|
+
export declare function polyMergeFft(f: Float64Array, f0: Float64Array, f1: Float64Array, logn: number): void;
|
|
58
|
+
//# sourceMappingURL=fft.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fft.d.ts","sourceRoot":"","sources":["../../src/src/fft.ts"],"names":[],"mappings":"AAmEA;;;GAGG;AACH,eAAO,MAAM,EAAE,EAAE,YAYb,CAAC;AAEL,iEAAiE;AACjE,wBAAgB,GAAG,CAAC,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CA0BvD;AAED,wEAAwE;AACxE,wBAAgB,IAAI,CAAC,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAmCxD;AAED,aAAa;AACb,wBAAgB,OAAO,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAK5E;AAED,aAAa;AACb,wBAAgB,OAAO,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAK5E;AAED,aAAa;AACb,wBAAgB,OAAO,CAAC,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAK3D;AAED,6CAA6C;AAC7C,wBAAgB,UAAU,CAAC,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAK9D;AAED,yCAAyC;AACzC,wBAAgB,UAAU,CACxB,CAAC,EAAE,YAAY,EACf,CAAC,EAAE,YAAY,EACf,IAAI,EAAE,MAAM,GACX,IAAI,CAUN;AAED,8CAA8C;AAC9C,wBAAgB,aAAa,CAC3B,CAAC,EAAE,YAAY,EACf,CAAC,EAAE,YAAY,EACf,IAAI,EAAE,MAAM,GACX,IAAI,CAUN;AAED,8CAA8C;AAC9C,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAQrE;AAED,qCAAqC;AACrC,wBAAgB,YAAY,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAK3E;AAED,yCAAyC;AACzC,wBAAgB,UAAU,CACxB,CAAC,EAAE,YAAY,EACf,CAAC,EAAE,YAAY,EACf,IAAI,EAAE,MAAM,GACX,IAAI,CAaN;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,CAAC,EAAE,YAAY,EACf,CAAC,EAAE,YAAY,EACf,CAAC,EAAE,YAAY,EACf,IAAI,EAAE,MAAM,GACX,IAAI,CASN;AAED,8DAA8D;AAC9D,wBAAgB,gBAAgB,CAC9B,CAAC,EAAE,YAAY,EACf,CAAC,EAAE,YAAY,EACf,CAAC,EAAE,YAAY,EACf,CAAC,EAAE,YAAY,EACf,CAAC,EAAE,YAAY,EACf,IAAI,EAAE,MAAM,GACX,IAAI,CAkBN;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,CAAC,EAAE,YAAY,EACf,CAAC,EAAE,YAAY,EACf,IAAI,EAAE,MAAM,GACX,IAAI,CAMN;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,CAAC,EAAE,YAAY,EACf,CAAC,EAAE,YAAY,EACf,IAAI,EAAE,MAAM,GACX,IAAI,CAON;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,YAAY,EACjB,GAAG,EAAE,YAAY,EACjB,GAAG,EAAE,YAAY,EACjB,GAAG,EAAE,YAAY,EACjB,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,MAAM,GACX,IAAI,CAwBN;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,EAAE,EAAE,YAAY,EAChB,EAAE,EAAE,YAAY,EAChB,CAAC,EAAE,YAAY,EACf,IAAI,EAAE,MAAM,GACX,IAAI,CAoBN;AAED,2CAA2C;AAC3C,wBAAgB,YAAY,CAC1B,CAAC,EAAE,YAAY,EACf,EAAE,EAAE,YAAY,EAChB,EAAE,EAAE,YAAY,EAChB,IAAI,EAAE,MAAM,GACX,IAAI,CAmBN"}
|
package/esm/src/fft.js
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* FFT over the ring of FN-DSA, on IEEE 754 binary64 values.
|
|
3
|
+
*
|
|
4
|
+
* This is a port of fft.c of the reference implementation of Falcon
|
|
5
|
+
* (round 3), which is under the MIT license:
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2017-2019 Falcon Project
|
|
8
|
+
* Author: Thomas Pornin <thomas.pornin@nccgroup.com>
|
|
9
|
+
*
|
|
10
|
+
* A polynomial of degree less than n = 2^logn is n values: in the FFT
|
|
11
|
+
* representation, the real parts of n/2 complex values and then their
|
|
12
|
+
* imaginary parts (the other n/2 values are their conjugates).
|
|
13
|
+
*
|
|
14
|
+
* Only +, -, * and / are used, which are correctly rounded in every runtime
|
|
15
|
+
* and are not fused, so the results are those of the reference
|
|
16
|
+
* implementation, bit for bit.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* cos(j * pi / 1024) for j = 0..512, correctly rounded. Math.cos is not
|
|
20
|
+
* used: its result may differ between runtimes, and so would the signatures.
|
|
21
|
+
*
|
|
22
|
+
* The values are computed with integers, which gives the same result in
|
|
23
|
+
* every runtime: in fixed point with 128 fractional bits, from cos(0) = 1
|
|
24
|
+
* and cos(pi/2) = 0, by the half-angle formulas
|
|
25
|
+
*
|
|
26
|
+
* cos(x/2) = sqrt((1 + cos(x)) / 2)
|
|
27
|
+
* cos(pi/2 - x/2) = sin(x/2) = sqrt((1 - cos(x)) / 2)
|
|
28
|
+
*
|
|
29
|
+
* with the integer square root. The error is far below the 53 bits of a
|
|
30
|
+
* binary64 value, which the conversion of a BigInt rounds to correctly. The
|
|
31
|
+
* values are public constants, and the same as the ones of the table of the
|
|
32
|
+
* reference implementation (fpr_gm_tab), which the tests check; having them
|
|
33
|
+
* in the code would take most of its size, as they do not compress.
|
|
34
|
+
*/
|
|
35
|
+
function mkcos() {
|
|
36
|
+
const one = 1n << 128n;
|
|
37
|
+
const c = [];
|
|
38
|
+
c[0] = one;
|
|
39
|
+
c[512] = 0n;
|
|
40
|
+
// floor(sqrt(x)) for 0 < x <= 2^256, by Newton's method from above.
|
|
41
|
+
const sqrt = (x) => {
|
|
42
|
+
let r = one;
|
|
43
|
+
for (;;) {
|
|
44
|
+
const t = (r + x / r) >> 1n;
|
|
45
|
+
if (t >= r) {
|
|
46
|
+
return r;
|
|
47
|
+
}
|
|
48
|
+
r = t;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
for (let s = 256; s >= 1; s >>= 1) {
|
|
52
|
+
for (let j = s; j <= 256; j += 2 * s) {
|
|
53
|
+
const d = c[2 * j];
|
|
54
|
+
c[j] = sqrt((one + d) << 127n);
|
|
55
|
+
c[512 - j] = sqrt((one - d) << 127n);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const cos = new Float64Array(513);
|
|
59
|
+
for (let j = 0; j <= 512; j++) {
|
|
60
|
+
cos[j] = Number(c[j]) / 2 ** 128;
|
|
61
|
+
}
|
|
62
|
+
// The table of the reference implementation has -0 for cos(pi/2).
|
|
63
|
+
cos[512] = -0;
|
|
64
|
+
return cos;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* GM[2k] + i * GM[2k + 1] = exp(i * pi * brv(k) / 1024), where brv reverses
|
|
68
|
+
* 10 bits (fpr_gm_tab of the reference implementation).
|
|
69
|
+
*/
|
|
70
|
+
export const GM = /* @__PURE__ */ (() => {
|
|
71
|
+
const cos = mkcos();
|
|
72
|
+
const gm = new Float64Array(2048);
|
|
73
|
+
for (let k = 1; k < 1024; k++) {
|
|
74
|
+
let j = 0;
|
|
75
|
+
for (let b = 0; b < 10; b++) {
|
|
76
|
+
j |= ((k >> b) & 1) << (9 - b);
|
|
77
|
+
}
|
|
78
|
+
gm[2 * k] = j <= 512 ? cos[j] : -cos[1024 - j];
|
|
79
|
+
gm[2 * k + 1] = cos[j <= 512 ? 512 - j : j - 512];
|
|
80
|
+
}
|
|
81
|
+
return gm;
|
|
82
|
+
})();
|
|
83
|
+
/** Converts a polynomial to the FFT representation, in place. */
|
|
84
|
+
export function FFT(f, logn) {
|
|
85
|
+
const n = 1 << logn;
|
|
86
|
+
const hn = n >> 1;
|
|
87
|
+
let t = hn;
|
|
88
|
+
for (let u = 1, m = 2; u < logn; u++, m <<= 1) {
|
|
89
|
+
const ht = t >> 1;
|
|
90
|
+
const hm = m >> 1;
|
|
91
|
+
for (let i1 = 0, j1 = 0; i1 < hm; i1++, j1 += t) {
|
|
92
|
+
const j2 = j1 + ht;
|
|
93
|
+
const sRe = GM[(m + i1) << 1];
|
|
94
|
+
const sIm = GM[((m + i1) << 1) + 1];
|
|
95
|
+
for (let j = j1; j < j2; j++) {
|
|
96
|
+
const xRe = f[j];
|
|
97
|
+
const xIm = f[j + hn];
|
|
98
|
+
const aRe = f[j + ht];
|
|
99
|
+
const aIm = f[j + ht + hn];
|
|
100
|
+
const yRe = aRe * sRe - aIm * sIm;
|
|
101
|
+
const yIm = aRe * sIm + aIm * sRe;
|
|
102
|
+
f[j] = xRe + yRe;
|
|
103
|
+
f[j + hn] = xIm + yIm;
|
|
104
|
+
f[j + ht] = xRe - yRe;
|
|
105
|
+
f[j + ht + hn] = xIm - yIm;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
t = ht;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** Converts a polynomial back from the FFT representation, in place. */
|
|
112
|
+
export function iFFT(f, logn) {
|
|
113
|
+
const n = 1 << logn;
|
|
114
|
+
const hn = n >> 1;
|
|
115
|
+
let t = 1;
|
|
116
|
+
let m = n;
|
|
117
|
+
for (let u = logn; u > 1; u--) {
|
|
118
|
+
const hm = m >> 1;
|
|
119
|
+
const dt = t << 1;
|
|
120
|
+
for (let i1 = 0, j1 = 0; j1 < hn; i1++, j1 += dt) {
|
|
121
|
+
const j2 = j1 + t;
|
|
122
|
+
const sRe = GM[(hm + i1) << 1];
|
|
123
|
+
const sIm = -GM[((hm + i1) << 1) + 1];
|
|
124
|
+
for (let j = j1; j < j2; j++) {
|
|
125
|
+
const xRe = f[j];
|
|
126
|
+
const xIm = f[j + hn];
|
|
127
|
+
const yRe = f[j + t];
|
|
128
|
+
const yIm = f[j + t + hn];
|
|
129
|
+
f[j] = xRe + yRe;
|
|
130
|
+
f[j + hn] = xIm + yIm;
|
|
131
|
+
const dRe = xRe - yRe;
|
|
132
|
+
const dIm = xIm - yIm;
|
|
133
|
+
f[j + t] = dRe * sRe - dIm * sIm;
|
|
134
|
+
f[j + t + hn] = dRe * sIm + dIm * sRe;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
t = dt;
|
|
138
|
+
m = hm;
|
|
139
|
+
}
|
|
140
|
+
if (logn > 0) {
|
|
141
|
+
// 2 / n, a power of two.
|
|
142
|
+
const ni = 2 / n;
|
|
143
|
+
for (let u = 0; u < n; u++) {
|
|
144
|
+
f[u] *= ni;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/** a += b */
|
|
149
|
+
export function polyAdd(a, b, logn) {
|
|
150
|
+
const n = 1 << logn;
|
|
151
|
+
for (let u = 0; u < n; u++) {
|
|
152
|
+
a[u] += b[u];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/** a -= b */
|
|
156
|
+
export function polySub(a, b, logn) {
|
|
157
|
+
const n = 1 << logn;
|
|
158
|
+
for (let u = 0; u < n; u++) {
|
|
159
|
+
a[u] -= b[u];
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/** a = -a */
|
|
163
|
+
export function polyNeg(a, logn) {
|
|
164
|
+
const n = 1 << logn;
|
|
165
|
+
for (let u = 0; u < n; u++) {
|
|
166
|
+
a[u] = -a[u];
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/** a = adj(a), in the FFT representation. */
|
|
170
|
+
export function polyAdjFft(a, logn) {
|
|
171
|
+
const n = 1 << logn;
|
|
172
|
+
for (let u = n >> 1; u < n; u++) {
|
|
173
|
+
a[u] = -a[u];
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/** a *= b, in the FFT representation. */
|
|
177
|
+
export function polyMulFft(a, b, logn) {
|
|
178
|
+
const hn = (1 << logn) >> 1;
|
|
179
|
+
for (let u = 0; u < hn; u++) {
|
|
180
|
+
const aRe = a[u];
|
|
181
|
+
const aIm = a[u + hn];
|
|
182
|
+
const bRe = b[u];
|
|
183
|
+
const bIm = b[u + hn];
|
|
184
|
+
a[u] = aRe * bRe - aIm * bIm;
|
|
185
|
+
a[u + hn] = aRe * bIm + aIm * bRe;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/** a *= adj(b), in the FFT representation. */
|
|
189
|
+
export function polyMuladjFft(a, b, logn) {
|
|
190
|
+
const hn = (1 << logn) >> 1;
|
|
191
|
+
for (let u = 0; u < hn; u++) {
|
|
192
|
+
const aRe = a[u];
|
|
193
|
+
const aIm = a[u + hn];
|
|
194
|
+
const bRe = b[u];
|
|
195
|
+
const bIm = -b[u + hn];
|
|
196
|
+
a[u] = aRe * bRe - aIm * bIm;
|
|
197
|
+
a[u + hn] = aRe * bIm + aIm * bRe;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/** a *= adj(a), in the FFT representation. */
|
|
201
|
+
export function polyMulselfadjFft(a, logn) {
|
|
202
|
+
const hn = (1 << logn) >> 1;
|
|
203
|
+
for (let u = 0; u < hn; u++) {
|
|
204
|
+
const aRe = a[u];
|
|
205
|
+
const aIm = a[u + hn];
|
|
206
|
+
a[u] = aRe * aRe + aIm * aIm;
|
|
207
|
+
a[u + hn] = 0;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/** a *= x, for a real constant x. */
|
|
211
|
+
export function polyMulconst(a, x, logn) {
|
|
212
|
+
const n = 1 << logn;
|
|
213
|
+
for (let u = 0; u < n; u++) {
|
|
214
|
+
a[u] *= x;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/** a /= b, in the FFT representation. */
|
|
218
|
+
export function polyDivFft(a, b, logn) {
|
|
219
|
+
const hn = (1 << logn) >> 1;
|
|
220
|
+
for (let u = 0; u < hn; u++) {
|
|
221
|
+
const aRe = a[u];
|
|
222
|
+
const aIm = a[u + hn];
|
|
223
|
+
let bRe = b[u];
|
|
224
|
+
let bIm = b[u + hn];
|
|
225
|
+
const m = 1 / (bRe * bRe + bIm * bIm);
|
|
226
|
+
bRe = bRe * m;
|
|
227
|
+
bIm = -bIm * m;
|
|
228
|
+
a[u] = aRe * bRe - aIm * bIm;
|
|
229
|
+
a[u + hn] = aRe * bIm + aIm * bRe;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* d = 1 / (a * adj(a) + b * adj(b)), in the FFT representation. The result
|
|
234
|
+
* is real: only the first half of d is set.
|
|
235
|
+
*/
|
|
236
|
+
export function polyInvnorm2Fft(d, a, b, logn) {
|
|
237
|
+
const hn = (1 << logn) >> 1;
|
|
238
|
+
for (let u = 0; u < hn; u++) {
|
|
239
|
+
const aRe = a[u];
|
|
240
|
+
const aIm = a[u + hn];
|
|
241
|
+
const bRe = b[u];
|
|
242
|
+
const bIm = b[u + hn];
|
|
243
|
+
d[u] = 1 / ((aRe * aRe + aIm * aIm) + (bRe * bRe + bIm * bIm));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/** d = F * adj(f) + G * adj(g), in the FFT representation. */
|
|
247
|
+
export function polyAddMuladjFft(d, F, G, f, g, logn) {
|
|
248
|
+
const hn = (1 << logn) >> 1;
|
|
249
|
+
for (let u = 0; u < hn; u++) {
|
|
250
|
+
const FRe = F[u];
|
|
251
|
+
const FIm = F[u + hn];
|
|
252
|
+
const GRe = G[u];
|
|
253
|
+
const GIm = G[u + hn];
|
|
254
|
+
const fRe = f[u];
|
|
255
|
+
const fIm = -f[u + hn];
|
|
256
|
+
const gRe = g[u];
|
|
257
|
+
const gIm = -g[u + hn];
|
|
258
|
+
const aRe = FRe * fRe - FIm * fIm;
|
|
259
|
+
const aIm = FRe * fIm + FIm * fRe;
|
|
260
|
+
const bRe = GRe * gRe - GIm * gIm;
|
|
261
|
+
const bIm = GRe * gIm + GIm * gRe;
|
|
262
|
+
d[u] = aRe + bRe;
|
|
263
|
+
d[u + hn] = aIm + bIm;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* a *= b, where b is self-adjoint (real in the FFT representation): only
|
|
268
|
+
* the first half of b is read.
|
|
269
|
+
*/
|
|
270
|
+
export function polyMulAutoadjFft(a, b, logn) {
|
|
271
|
+
const hn = (1 << logn) >> 1;
|
|
272
|
+
for (let u = 0; u < hn; u++) {
|
|
273
|
+
a[u] *= b[u];
|
|
274
|
+
a[u + hn] *= b[u];
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* a /= b, where b is self-adjoint (real in the FFT representation): only
|
|
279
|
+
* the first half of b is read.
|
|
280
|
+
*/
|
|
281
|
+
export function polyDivAutoadjFft(a, b, logn) {
|
|
282
|
+
const hn = (1 << logn) >> 1;
|
|
283
|
+
for (let u = 0; u < hn; u++) {
|
|
284
|
+
const ib = 1 / b[u];
|
|
285
|
+
a[u] *= ib;
|
|
286
|
+
a[u + hn] *= ib;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* The LDL decomposition of the self-adjoint matrix [[g00, g01], [adj(g01),
|
|
291
|
+
* g11]]: d11 and l10 are set so that it is L * diag(g00, d11) * adj(L) with
|
|
292
|
+
* L = [[1, 0], [l10, 1]]. The inputs are not modified.
|
|
293
|
+
*/
|
|
294
|
+
export function polyLDLmvFft(d11, l10, g00, g01, g11, logn) {
|
|
295
|
+
const hn = (1 << logn) >> 1;
|
|
296
|
+
for (let u = 0; u < hn; u++) {
|
|
297
|
+
const g00Re = g00[u];
|
|
298
|
+
const g00Im = g00[u + hn];
|
|
299
|
+
const g01Re = g01[u];
|
|
300
|
+
const g01Im = g01[u + hn];
|
|
301
|
+
const g11Re = g11[u];
|
|
302
|
+
const g11Im = g11[u + hn];
|
|
303
|
+
// mu = g01 / g00
|
|
304
|
+
const m = 1 / (g00Re * g00Re + g00Im * g00Im);
|
|
305
|
+
const iRe = g00Re * m;
|
|
306
|
+
const iIm = -g00Im * m;
|
|
307
|
+
const muRe = g01Re * iRe - g01Im * iIm;
|
|
308
|
+
const muIm = g01Re * iIm + g01Im * iRe;
|
|
309
|
+
// mu * adj(g01)
|
|
310
|
+
const cIm = -g01Im;
|
|
311
|
+
const tRe = muRe * g01Re - muIm * cIm;
|
|
312
|
+
const tIm = muRe * cIm + muIm * g01Re;
|
|
313
|
+
d11[u] = g11Re - tRe;
|
|
314
|
+
d11[u + hn] = g11Im - tIm;
|
|
315
|
+
l10[u] = muRe;
|
|
316
|
+
l10[u + hn] = -muIm;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Splits f, in the FFT representation, to f0 and f1 of half its degree,
|
|
321
|
+
* such that f = f0(x^2) + x * f1(x^2).
|
|
322
|
+
*/
|
|
323
|
+
export function polySplitFft(f0, f1, f, logn) {
|
|
324
|
+
const hn = (1 << logn) >> 1;
|
|
325
|
+
const qn = hn >> 1;
|
|
326
|
+
// For n = 2, which the loop below does not cover.
|
|
327
|
+
f0[0] = f[0];
|
|
328
|
+
f1[0] = f[hn];
|
|
329
|
+
for (let u = 0; u < qn; u++) {
|
|
330
|
+
const aRe = f[u << 1];
|
|
331
|
+
const aIm = f[(u << 1) + hn];
|
|
332
|
+
const bRe = f[(u << 1) + 1];
|
|
333
|
+
const bIm = f[(u << 1) + 1 + hn];
|
|
334
|
+
f0[u] = (aRe + bRe) * 0.5;
|
|
335
|
+
f0[u + qn] = (aIm + bIm) * 0.5;
|
|
336
|
+
const tRe = aRe - bRe;
|
|
337
|
+
const tIm = aIm - bIm;
|
|
338
|
+
const sRe = GM[(u + hn) << 1];
|
|
339
|
+
const sIm = -GM[((u + hn) << 1) + 1];
|
|
340
|
+
f1[u] = (tRe * sRe - tIm * sIm) * 0.5;
|
|
341
|
+
f1[u + qn] = (tRe * sIm + tIm * sRe) * 0.5;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
/** The inverse of {@link polySplitFft}. */
|
|
345
|
+
export function polyMergeFft(f, f0, f1, logn) {
|
|
346
|
+
const hn = (1 << logn) >> 1;
|
|
347
|
+
const qn = hn >> 1;
|
|
348
|
+
f[0] = f0[0];
|
|
349
|
+
f[hn] = f1[0];
|
|
350
|
+
for (let u = 0; u < qn; u++) {
|
|
351
|
+
const aRe = f0[u];
|
|
352
|
+
const aIm = f0[u + qn];
|
|
353
|
+
const cRe = f1[u];
|
|
354
|
+
const cIm = f1[u + qn];
|
|
355
|
+
const sRe = GM[(u + hn) << 1];
|
|
356
|
+
const sIm = GM[((u + hn) << 1) + 1];
|
|
357
|
+
const bRe = cRe * sRe - cIm * sIm;
|
|
358
|
+
const bIm = cRe * sIm + cIm * sRe;
|
|
359
|
+
f[u << 1] = aRe + bRe;
|
|
360
|
+
f[(u << 1) + hn] = aIm + bIm;
|
|
361
|
+
f[(u << 1) + 1] = aRe - bRe;
|
|
362
|
+
f[(u << 1) + 1 + hn] = aIm - bIm;
|
|
363
|
+
}
|
|
364
|
+
}
|