@webpqc/fndsa 0.0.1 → 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/README.md +3 -2
- 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/consts.d.ts +6 -0
- package/esm/src/consts.d.ts.map +1 -1
- package/esm/src/consts.js +6 -0
- package/esm/src/fft.d.ts +5 -0
- package/esm/src/fft.d.ts.map +1 -1
- package/esm/src/fft.js +48 -13
- package/esm/src/fnDsa1024.d.ts.map +1 -1
- package/esm/src/fnDsa1024.js +4 -3
- package/esm/src/fnDsa512.d.ts.map +1 -1
- package/esm/src/fnDsa512.js +4 -3
- 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 +1 -15
- package/esm/src/fnDsaSigner.d.ts.map +1 -1
- package/esm/src/fnDsaSigner.js +5 -104
- package/esm/src/fnDsaVerifier.d.ts.map +1 -1
- package/esm/src/fnDsaVerifier.js +1 -3
- package/esm/src/keygen.d.ts +3 -8
- package/esm/src/keygen.d.ts.map +1 -1
- package/esm/src/keygen.js +95 -589
- package/esm/src/utils.d.ts +2 -0
- package/esm/src/utils.d.ts.map +1 -1
- package/esm/src/utils.js +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,8 +49,9 @@ An experimental FN-DSA (Falcon) implementation written in TypeScript.<br>
|
|
|
49
49
|
floating-point operations which IEEE 754 defines exactly are used, in the same
|
|
50
50
|
order.
|
|
51
51
|
- ✅ No dependencies on other libraries.
|
|
52
|
-
- ✅ Tree-shaking friendly: key generation and
|
|
53
|
-
|
|
52
|
+
- ✅ Tree-shaking friendly: key generation, the signer and the verifier are
|
|
53
|
+
separated, so an application bundles only the code of the roles which it uses.
|
|
54
|
+
Verification uses only integers.
|
|
54
55
|
- ✅ The same API as [`@webpqc/mldsa`](../mldsa/) and
|
|
55
56
|
[`@webpqc/slhdsa`](../slhdsa/): a signer holds a private key and a verifier a
|
|
56
57
|
public key, and all the operations are asynchronous.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether (g, -f) and its orthogonalized vector are short enough: the
|
|
3
|
+
* bounds which the sampler of signing relies on, as the standard deviations
|
|
4
|
+
* which it is given are in the range it supports only for such a basis.
|
|
5
|
+
*
|
|
6
|
+
* Key generation keeps only the f and g which pass this, and a private key
|
|
7
|
+
* which is imported has to pass it as well. rt1 and rt2 are work areas of n
|
|
8
|
+
* values, and rt3 of n/2: they are left with values which depend on f and g.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isShortBasis(f: Int8Array, g: Int8Array, logn: number, rt1: Float64Array, rt2: Float64Array, rt3: Float64Array): boolean;
|
|
11
|
+
//# sourceMappingURL=basis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basis.d.ts","sourceRoot":"","sources":["../../src/src/basis.ts"],"names":[],"mappings":"AA8CA;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,CAAC,EAAE,SAAS,EACZ,CAAC,EAAE,SAAS,EACZ,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,YAAY,EACjB,GAAG,EAAE,YAAY,EACjB,GAAG,EAAE,YAAY,GAChB,OAAO,CAkCT"}
|
package/esm/src/basis.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The bounds of a private key, which key generation ensures and which the
|
|
3
|
+
* sampler of signing relies on.
|
|
4
|
+
*
|
|
5
|
+
* This is a part of keygen.c of the reference implementation of Falcon
|
|
6
|
+
* (round 3), which is under the MIT license:
|
|
7
|
+
*
|
|
8
|
+
* Copyright (c) 2017-2019 Falcon Project
|
|
9
|
+
* Author: Thomas Pornin <thomas.pornin@nccgroup.com>
|
|
10
|
+
*
|
|
11
|
+
* It is a module of its own so that an application which only signs does not
|
|
12
|
+
* bundle key generation.
|
|
13
|
+
*/
|
|
14
|
+
import { FFT, iFFT, polyAdjFft, polyInvnorm2Fft, polyMulAutoadjFft, polyMulconst, } from "./fft.js";
|
|
15
|
+
/**
|
|
16
|
+
* The squared norm of a short vector: 2^32-1 if it is not lower than 2^31.
|
|
17
|
+
*/
|
|
18
|
+
function polySmallSqnorm(f, logn) {
|
|
19
|
+
const n = 1 << logn;
|
|
20
|
+
let s = 0;
|
|
21
|
+
let ng = 0;
|
|
22
|
+
for (let u = 0; u < n; u++) {
|
|
23
|
+
const z = f[u];
|
|
24
|
+
s = (s + z * z) | 0;
|
|
25
|
+
ng |= s;
|
|
26
|
+
}
|
|
27
|
+
return (s | -(ng >>> 31)) >>> 0;
|
|
28
|
+
}
|
|
29
|
+
/** Converts a small vector to floating point. */
|
|
30
|
+
function polySmallToFp(x, f, logn) {
|
|
31
|
+
const n = 1 << logn;
|
|
32
|
+
for (let u = 0; u < n; u++) {
|
|
33
|
+
x[u] = f[u];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Whether (g, -f) and its orthogonalized vector are short enough: the
|
|
38
|
+
* bounds which the sampler of signing relies on, as the standard deviations
|
|
39
|
+
* which it is given are in the range it supports only for such a basis.
|
|
40
|
+
*
|
|
41
|
+
* Key generation keeps only the f and g which pass this, and a private key
|
|
42
|
+
* which is imported has to pass it as well. rt1 and rt2 are work areas of n
|
|
43
|
+
* values, and rt3 of n/2: they are left with values which depend on f and g.
|
|
44
|
+
*/
|
|
45
|
+
export function isShortBasis(f, g, logn, rt1, rt2, rt3) {
|
|
46
|
+
const n = 1 << logn;
|
|
47
|
+
// The bound is 1.17*sqrt(q): the squared bound is
|
|
48
|
+
// (1.17^2) * 12289 = 16822.4121, and the squared norm of (g, -f) is an
|
|
49
|
+
// integer.
|
|
50
|
+
const normf = polySmallSqnorm(f, logn);
|
|
51
|
+
const normg = polySmallSqnorm(g, logn);
|
|
52
|
+
const norm = ((normf + normg) | -((normf | normg) >>> 31)) >>> 0;
|
|
53
|
+
if (norm >= 16823) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
// The norm of the orthogonalized vector, which is
|
|
57
|
+
// (q*adj(f)/(f*adj(f)+g*adj(g)), q*adj(g)/(f*adj(f)+g*adj(g))).
|
|
58
|
+
polySmallToFp(rt1, f, logn);
|
|
59
|
+
polySmallToFp(rt2, g, logn);
|
|
60
|
+
FFT(rt1, logn);
|
|
61
|
+
FFT(rt2, logn);
|
|
62
|
+
polyInvnorm2Fft(rt3, rt1, rt2, logn);
|
|
63
|
+
polyAdjFft(rt1, logn);
|
|
64
|
+
polyAdjFft(rt2, logn);
|
|
65
|
+
polyMulconst(rt1, 12289, logn);
|
|
66
|
+
polyMulconst(rt2, 12289, logn);
|
|
67
|
+
polyMulAutoadjFft(rt1, rt3, logn);
|
|
68
|
+
polyMulAutoadjFft(rt2, rt3, logn);
|
|
69
|
+
iFFT(rt1, logn);
|
|
70
|
+
iFFT(rt2, logn);
|
|
71
|
+
let bnorm = 0;
|
|
72
|
+
for (let u = 0; u < n; u++) {
|
|
73
|
+
bnorm += rt1[u] * rt1[u];
|
|
74
|
+
bnorm += rt2[u] * rt2[u];
|
|
75
|
+
}
|
|
76
|
+
// Not NaN either, which a division by zero gives.
|
|
77
|
+
return bnorm < 16822.4121;
|
|
78
|
+
}
|
package/esm/src/consts.d.ts
CHANGED
|
@@ -2,4 +2,10 @@
|
|
|
2
2
|
export declare const Q = 12289;
|
|
3
3
|
/** The length of the nonce (the salt r) of a signature in octets. */
|
|
4
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;
|
|
5
11
|
//# sourceMappingURL=consts.d.ts.map
|
package/esm/src/consts.d.ts.map
CHANGED
|
@@ -1 +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"}
|
|
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"}
|
package/esm/src/consts.js
CHANGED
|
@@ -2,3 +2,9 @@
|
|
|
2
2
|
export const Q = 12289;
|
|
3
3
|
/** The length of the nonce (the salt r) of a signature in octets. */
|
|
4
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;
|
package/esm/src/fft.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
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;
|
|
1
6
|
/** Converts a polynomial to the FFT representation, in place. */
|
|
2
7
|
export declare function FFT(f: Float64Array, logn: number): void;
|
|
3
8
|
/** Converts a polynomial back from the FFT representation, in place. */
|
package/esm/src/fft.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fft.d.ts","sourceRoot":"","sources":["../../src/src/fft.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fft.d.ts","sourceRoot":"","sources":["../../src/src/fft.ts"],"names":[],"mappings":"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"}
|
package/esm/src/fft.js
CHANGED
|
@@ -16,24 +16,59 @@
|
|
|
16
16
|
* implementation, bit for bit.
|
|
17
17
|
*/
|
|
18
18
|
/**
|
|
19
|
-
* cos(j * pi / 1024) for j = 0..512, correctly rounded
|
|
20
|
-
*
|
|
21
|
-
*
|
|
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.
|
|
22
34
|
*/
|
|
23
|
-
|
|
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
|
+
}
|
|
24
66
|
/**
|
|
25
67
|
* GM[2k] + i * GM[2k + 1] = exp(i * pi * brv(k) / 1024), where brv reverses
|
|
26
68
|
* 10 bits (fpr_gm_tab of the reference implementation).
|
|
27
69
|
*/
|
|
28
|
-
const GM = /* @__PURE__ */ (() => {
|
|
29
|
-
const
|
|
30
|
-
const cos = new Float64Array(513);
|
|
31
|
-
for (let j = 0; j <= 512; j++) {
|
|
32
|
-
for (let b = 0; b < 8; b++) {
|
|
33
|
-
view.setUint8(b, parseInt(COS_HEX.substring(16 * j + 2 * b, 16 * j + 2 * b + 2), 16));
|
|
34
|
-
}
|
|
35
|
-
cos[j] = view.getFloat64(0);
|
|
36
|
-
}
|
|
70
|
+
export const GM = /* @__PURE__ */ (() => {
|
|
71
|
+
const cos = mkcos();
|
|
37
72
|
const gm = new Float64Array(2048);
|
|
38
73
|
for (let k = 1; k < 1024; k++) {
|
|
39
74
|
let j = 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fnDsa1024.d.ts","sourceRoot":"","sources":["../../src/src/fnDsa1024.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"fnDsa1024.d.ts","sourceRoot":"","sources":["../../src/src/fnDsa1024.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,iBAAiB,CAAC;AAIzB;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,wBAAwB,IAAI,OAAO,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAE5E;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,UAAU,GACf,OAAO,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAEnC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,UAAU,EACd,IAAI,CAAC,EAAE,kBAAkB,GACxB,OAAO,CAAC,oBAAoB,CAAC,CAE/B;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,uBAAuB,CACrC,EAAE,EAAE,UAAU,EACd,IAAI,CAAC,EAAE,kBAAkB,GACxB,OAAO,CAAC,sBAAsB,CAAC,CAEjC"}
|
package/esm/src/fnDsa1024.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { createSignerHandle
|
|
1
|
+
import { createSignerHandle } from "./fnDsaSigner.js";
|
|
2
2
|
import { FnDsaVerifier } from "./fnDsaVerifier.js";
|
|
3
|
+
import { deriveKeyPair, generateKeyPair } from "./fnDsaKeyGen.js";
|
|
3
4
|
import { FN_DSA_1024 } from "./params.js";
|
|
4
5
|
/**
|
|
5
6
|
* Generates a key pair of FN-DSA-1024 (NIST security category 5).
|
|
@@ -30,7 +31,7 @@ import { FN_DSA_1024 } from "./params.js";
|
|
|
30
31
|
* ```
|
|
31
32
|
*/
|
|
32
33
|
export function generateFnDsa1024KeyPair() {
|
|
33
|
-
return
|
|
34
|
+
return generateKeyPair(FN_DSA_1024);
|
|
34
35
|
}
|
|
35
36
|
/**
|
|
36
37
|
* Derives a key pair of FN-DSA-1024 deterministically from a 48-octet seed.
|
|
@@ -43,7 +44,7 @@ export function generateFnDsa1024KeyPair() {
|
|
|
43
44
|
* @returns A promise that resolves to a key pair [publicKey, privateKey].
|
|
44
45
|
*/
|
|
45
46
|
export function deriveFnDsa1024KeyPair(seed) {
|
|
46
|
-
return
|
|
47
|
+
return deriveKeyPair(FN_DSA_1024, seed);
|
|
47
48
|
}
|
|
48
49
|
/**
|
|
49
50
|
* Creates an FN-DSA-1024 (NIST security category 5) signer which holds a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fnDsa512.d.ts","sourceRoot":"","sources":["../../src/src/fnDsa512.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"fnDsa512.d.ts","sourceRoot":"","sources":["../../src/src/fnDsa512.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,iBAAiB,CAAC;AAIzB;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,uBAAuB,IAAI,OAAO,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAE3E;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,UAAU,GACf,OAAO,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAEnC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,oBAAoB,CAClC,EAAE,EAAE,UAAU,EACd,IAAI,CAAC,EAAE,kBAAkB,GACxB,OAAO,CAAC,oBAAoB,CAAC,CAE/B;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,UAAU,EACd,IAAI,CAAC,EAAE,kBAAkB,GACxB,OAAO,CAAC,sBAAsB,CAAC,CAEjC"}
|
package/esm/src/fnDsa512.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { createSignerHandle
|
|
1
|
+
import { createSignerHandle } from "./fnDsaSigner.js";
|
|
2
2
|
import { FnDsaVerifier } from "./fnDsaVerifier.js";
|
|
3
|
+
import { deriveKeyPair, generateKeyPair } from "./fnDsaKeyGen.js";
|
|
3
4
|
import { FN_DSA_512 } from "./params.js";
|
|
4
5
|
/**
|
|
5
6
|
* Generates a key pair of FN-DSA-512 (NIST security category 1).
|
|
@@ -30,7 +31,7 @@ import { FN_DSA_512 } from "./params.js";
|
|
|
30
31
|
* ```
|
|
31
32
|
*/
|
|
32
33
|
export function generateFnDsa512KeyPair() {
|
|
33
|
-
return
|
|
34
|
+
return generateKeyPair(FN_DSA_512);
|
|
34
35
|
}
|
|
35
36
|
/**
|
|
36
37
|
* Derives a key pair of FN-DSA-512 deterministically from a 48-octet seed.
|
|
@@ -43,7 +44,7 @@ export function generateFnDsa512KeyPair() {
|
|
|
43
44
|
* @returns A promise that resolves to a key pair [publicKey, privateKey].
|
|
44
45
|
*/
|
|
45
46
|
export function deriveFnDsa512KeyPair(seed) {
|
|
46
|
-
return
|
|
47
|
+
return deriveKeyPair(FN_DSA_512, seed);
|
|
47
48
|
}
|
|
48
49
|
/**
|
|
49
50
|
* Creates an FN-DSA-512 (NIST security category 1) signer which holds a
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FnDsaParams } from "./params.js";
|
|
2
|
+
/** Generates a keypair [publicKey, privateKey]. */
|
|
3
|
+
export declare function generateKeyPair(params: FnDsaParams): Promise<[Uint8Array, Uint8Array]>;
|
|
4
|
+
/** Derives a keypair [publicKey, privateKey] from a 48-octet seed. */
|
|
5
|
+
export declare function deriveKeyPair(params: FnDsaParams, seed: Uint8Array): Promise<[Uint8Array, Uint8Array]>;
|
|
6
|
+
//# sourceMappingURL=fnDsaKeyGen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fnDsaKeyGen.d.ts","sourceRoot":"","sources":["../../src/src/fnDsaKeyGen.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,mDAAmD;AAEnD,wBAAsB,eAAe,CACnC,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAUnC;AAED,sEAAsE;AAEtE,wBAAsB,aAAa,CACjC,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,UAAU,GACf,OAAO,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAenC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Key pair generation, for the factory functions.
|
|
3
|
+
*
|
|
4
|
+
* It is a module of its own, and not a part of the signer, so that an
|
|
5
|
+
* application which only signs does not bundle key generation, and one which
|
|
6
|
+
* only generates key pairs does not bundle signing.
|
|
7
|
+
*/
|
|
8
|
+
import { MAX_FG_BITS, MAX_fg_BITS, modqEncode, trimI8Encode } from "./codec.js";
|
|
9
|
+
import { newShake256 } from "./common.js";
|
|
10
|
+
import { PK_HEADER, SEED_SIZE, SK_HEADER } from "./consts.js";
|
|
11
|
+
import { FnDsaError } from "./errors.js";
|
|
12
|
+
import { keygen } from "./keygen.js";
|
|
13
|
+
import { assertBytes, byteLengthOf, copyBytes, getCrypto } from "./utils.js";
|
|
14
|
+
/** Generates a keypair [publicKey, privateKey]. */
|
|
15
|
+
// deno-lint-ignore require-await
|
|
16
|
+
export async function generateKeyPair(params) {
|
|
17
|
+
const seed = new Uint8Array(SEED_SIZE);
|
|
18
|
+
try {
|
|
19
|
+
getCrypto().getRandomValues(seed);
|
|
20
|
+
return keyGen(params, seed);
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
throw new FnDsaError(e);
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
seed.fill(0);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** Derives a keypair [publicKey, privateKey] from a 48-octet seed. */
|
|
30
|
+
// deno-lint-ignore require-await
|
|
31
|
+
export async function deriveKeyPair(params, seed) {
|
|
32
|
+
let copy;
|
|
33
|
+
try {
|
|
34
|
+
assertBytes(seed, "seed");
|
|
35
|
+
if (byteLengthOf(seed) !== SEED_SIZE) {
|
|
36
|
+
throw new Error("seed must be 48 bytes in length");
|
|
37
|
+
}
|
|
38
|
+
// See copyBytes().
|
|
39
|
+
copy = copyBytes(seed);
|
|
40
|
+
return keyGen(params, copy);
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
throw new FnDsaError(e);
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
copy?.fill(0);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Key generation from a seed, which SHAKE256 expands. */
|
|
50
|
+
function keyGen(params, seed) {
|
|
51
|
+
const logn = params.logn;
|
|
52
|
+
const n = 1 << logn;
|
|
53
|
+
const f = new Int8Array(n);
|
|
54
|
+
const g = new Int8Array(n);
|
|
55
|
+
const F = new Int8Array(n);
|
|
56
|
+
const h = new Uint16Array(n);
|
|
57
|
+
const rng = newShake256();
|
|
58
|
+
const sk = new Uint8Array(params.skSize);
|
|
59
|
+
let ok = false;
|
|
60
|
+
try {
|
|
61
|
+
rng.updateUnsafe(seed);
|
|
62
|
+
keygen(rng, f, g, F, null, h, logn);
|
|
63
|
+
sk[0] = SK_HEADER + logn;
|
|
64
|
+
let u = 1;
|
|
65
|
+
for (const [x, bits] of [[f, MAX_fg_BITS], [g, MAX_fg_BITS]]) {
|
|
66
|
+
const v = trimI8Encode(sk.subarray(u), x, logn, bits[logn]);
|
|
67
|
+
if (v === 0) {
|
|
68
|
+
throw new Error("key generation failed");
|
|
69
|
+
}
|
|
70
|
+
u += v;
|
|
71
|
+
}
|
|
72
|
+
const v = trimI8Encode(sk.subarray(u), F, logn, MAX_FG_BITS[logn]);
|
|
73
|
+
if (v === 0 || u + v !== params.skSize) {
|
|
74
|
+
throw new Error("key generation failed");
|
|
75
|
+
}
|
|
76
|
+
const pk = new Uint8Array(params.pkSize);
|
|
77
|
+
pk[0] = PK_HEADER + logn;
|
|
78
|
+
if (modqEncode(pk.subarray(1), h, logn) !== params.pkSize - 1) {
|
|
79
|
+
throw new Error("key generation failed");
|
|
80
|
+
}
|
|
81
|
+
ok = true;
|
|
82
|
+
return [pk, sk];
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
if (!ok)
|
|
86
|
+
sk.fill(0);
|
|
87
|
+
f.fill(0);
|
|
88
|
+
g.fill(0);
|
|
89
|
+
F.fill(0);
|
|
90
|
+
rng.reset();
|
|
91
|
+
}
|
|
92
|
+
}
|
package/esm/src/fnDsaSigner.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FnDsaCreateOptions, FnDsaSignerInterface } from "./interfaces.js";
|
|
2
2
|
import type { FnDsaParams } from "./params.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Signing of FN-DSA.
|
|
5
5
|
*
|
|
6
6
|
* An instance holds a private key, which signs any number of messages until
|
|
7
7
|
* destroy() erases it. Use one of the factory functions to create an
|
|
@@ -22,20 +22,6 @@ export declare class FnDsaSigner implements FnDsaSignerInterface {
|
|
|
22
22
|
* @internal
|
|
23
23
|
*/
|
|
24
24
|
static _create(params: FnDsaParams, sk: Uint8Array, opts?: FnDsaCreateOptions): Promise<FnDsaSigner>;
|
|
25
|
-
/**
|
|
26
|
-
* Generates a keypair [publicKey, privateKey].
|
|
27
|
-
* @internal
|
|
28
|
-
*/
|
|
29
|
-
static _generateKeyPair(params: FnDsaParams): Promise<[Uint8Array, Uint8Array]>;
|
|
30
|
-
/**
|
|
31
|
-
* Derives a keypair [publicKey, privateKey] from a 48-octet seed.
|
|
32
|
-
* @internal
|
|
33
|
-
*/
|
|
34
|
-
static _deriveKeyPair(params: FnDsaParams, seed: Uint8Array): Promise<[Uint8Array, Uint8Array]>;
|
|
35
|
-
/**
|
|
36
|
-
* Key generation from a seed, which SHAKE256 expands.
|
|
37
|
-
*/
|
|
38
|
-
private static _keyGen;
|
|
39
25
|
}
|
|
40
26
|
/**
|
|
41
27
|
* Creates a signer which holds a private key, for a factory function.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fnDsaSigner.d.ts","sourceRoot":"","sources":["../../src/src/fnDsaSigner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fnDsaSigner.d.ts","sourceRoot":"","sources":["../../src/src/fnDsaSigner.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEhF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAa/C;;;;;;GAMG;AACH,qBAAa,WAAY,YAAW,oBAAoB;;IACtD,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAWf,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM;IAO5C,0CAA0C;IAEpC,IAAI,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IA8ChD,uDAAuD;IACvD,OAAO,IAAI,IAAI;IAKf;;;OAGG;WAEU,OAAO,CAClB,MAAM,EAAE,WAAW,EACnB,EAAE,EAAE,UAAU,EACd,IAAI,CAAC,EAAE,kBAAkB,GACxB,OAAO,CAAC,WAAW,CAAC;CAgFxB;AA6BD;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,WAAW,EACnB,EAAE,EAAE,UAAU,EACd,IAAI,CAAC,EAAE,kBAAkB,GACxB,OAAO,CAAC,oBAAoB,CAAC,CAE/B"}
|
package/esm/src/fnDsaSigner.js
CHANGED
|
@@ -10,31 +10,19 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _FnDsaSigner_hasKey, _FnDsaSigner_expandedKey, _FnDsaSignerHandle_signer;
|
|
13
|
-
import {
|
|
13
|
+
import { isShortBasis } from "./basis.js";
|
|
14
|
+
import { compEncode, MAX_FG_BITS, MAX_fg_BITS, trimI8Decode } from "./codec.js";
|
|
14
15
|
import { hashToPoint, newShake256 } from "./common.js";
|
|
15
|
-
import { NONCE_LEN } from "./consts.js";
|
|
16
|
+
import { NONCE_LEN, SEED_SIZE, SK_HEADER } from "./consts.js";
|
|
16
17
|
import { FnDsaError } from "./errors.js";
|
|
17
|
-
import { isShortBasis, keygen } from "./keygen.js";
|
|
18
18
|
import { assertWebCryptoOption } from "./native.js";
|
|
19
19
|
import { expandedKeySize, expandPrivkey, isNtruBasis, signTree, } from "./sign.js";
|
|
20
|
-
import { assertBytes, byteLengthOf, copyBytes } from "./utils.js";
|
|
20
|
+
import { assertBytes, byteLengthOf, copyBytes, getCrypto } from "./utils.js";
|
|
21
21
|
import { completePrivate } from "./vrfy.js";
|
|
22
|
-
/** The size of the seed of key generation, and of signing, in octets. */
|
|
23
|
-
const SEED_SIZE = 48;
|
|
24
|
-
/** The header of a public key: 0x00 + logn. */
|
|
25
|
-
const PK_HEADER = 0x00;
|
|
26
|
-
/** The header of a private key: 0x50 + logn. */
|
|
27
|
-
const SK_HEADER = 0x50;
|
|
28
22
|
/** The header of a signature with the compressed encoding: 0x30 + logn. */
|
|
29
23
|
const SIG_HEADER = 0x30;
|
|
30
|
-
function getCrypto() {
|
|
31
|
-
if (globalThis.crypto === undefined) {
|
|
32
|
-
throw new Error("Web Crypto API is not available");
|
|
33
|
-
}
|
|
34
|
-
return globalThis.crypto;
|
|
35
|
-
}
|
|
36
24
|
/**
|
|
37
|
-
*
|
|
25
|
+
* Signing of FN-DSA.
|
|
38
26
|
*
|
|
39
27
|
* An instance holds a private key, which signs any number of messages until
|
|
40
28
|
* destroy() erases it. Use one of the factory functions to create an
|
|
@@ -189,93 +177,6 @@ export class FnDsaSigner {
|
|
|
189
177
|
rt.fill(0);
|
|
190
178
|
}
|
|
191
179
|
}
|
|
192
|
-
/**
|
|
193
|
-
* Generates a keypair [publicKey, privateKey].
|
|
194
|
-
* @internal
|
|
195
|
-
*/
|
|
196
|
-
// deno-lint-ignore require-await
|
|
197
|
-
static async _generateKeyPair(params) {
|
|
198
|
-
const seed = new Uint8Array(SEED_SIZE);
|
|
199
|
-
try {
|
|
200
|
-
getCrypto().getRandomValues(seed);
|
|
201
|
-
return FnDsaSigner._keyGen(params, seed);
|
|
202
|
-
}
|
|
203
|
-
catch (e) {
|
|
204
|
-
throw new FnDsaError(e);
|
|
205
|
-
}
|
|
206
|
-
finally {
|
|
207
|
-
seed.fill(0);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Derives a keypair [publicKey, privateKey] from a 48-octet seed.
|
|
212
|
-
* @internal
|
|
213
|
-
*/
|
|
214
|
-
// deno-lint-ignore require-await
|
|
215
|
-
static async _deriveKeyPair(params, seed) {
|
|
216
|
-
let copy;
|
|
217
|
-
try {
|
|
218
|
-
assertBytes(seed, "seed");
|
|
219
|
-
if (byteLengthOf(seed) !== SEED_SIZE) {
|
|
220
|
-
throw new Error("seed must be 48 bytes in length");
|
|
221
|
-
}
|
|
222
|
-
// See copyBytes().
|
|
223
|
-
copy = copyBytes(seed);
|
|
224
|
-
return FnDsaSigner._keyGen(params, copy);
|
|
225
|
-
}
|
|
226
|
-
catch (e) {
|
|
227
|
-
throw new FnDsaError(e);
|
|
228
|
-
}
|
|
229
|
-
finally {
|
|
230
|
-
copy?.fill(0);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Key generation from a seed, which SHAKE256 expands.
|
|
235
|
-
*/
|
|
236
|
-
static _keyGen(params, seed) {
|
|
237
|
-
const logn = params.logn;
|
|
238
|
-
const n = 1 << logn;
|
|
239
|
-
const f = new Int8Array(n);
|
|
240
|
-
const g = new Int8Array(n);
|
|
241
|
-
const F = new Int8Array(n);
|
|
242
|
-
const h = new Uint16Array(n);
|
|
243
|
-
const rng = newShake256();
|
|
244
|
-
const sk = new Uint8Array(params.skSize);
|
|
245
|
-
let ok = false;
|
|
246
|
-
try {
|
|
247
|
-
rng.updateUnsafe(seed);
|
|
248
|
-
keygen(rng, f, g, F, null, h, logn);
|
|
249
|
-
sk[0] = SK_HEADER + logn;
|
|
250
|
-
let u = 1;
|
|
251
|
-
for (const [x, bits] of [[f, MAX_fg_BITS], [g, MAX_fg_BITS]]) {
|
|
252
|
-
const v = trimI8Encode(sk.subarray(u), x, logn, bits[logn]);
|
|
253
|
-
if (v === 0) {
|
|
254
|
-
throw new Error("key generation failed");
|
|
255
|
-
}
|
|
256
|
-
u += v;
|
|
257
|
-
}
|
|
258
|
-
const v = trimI8Encode(sk.subarray(u), F, logn, MAX_FG_BITS[logn]);
|
|
259
|
-
if (v === 0 || u + v !== params.skSize) {
|
|
260
|
-
throw new Error("key generation failed");
|
|
261
|
-
}
|
|
262
|
-
const pk = new Uint8Array(params.pkSize);
|
|
263
|
-
pk[0] = PK_HEADER + logn;
|
|
264
|
-
if (modqEncode(pk.subarray(1), h, logn) !== params.pkSize - 1) {
|
|
265
|
-
throw new Error("key generation failed");
|
|
266
|
-
}
|
|
267
|
-
ok = true;
|
|
268
|
-
return [pk, sk];
|
|
269
|
-
}
|
|
270
|
-
finally {
|
|
271
|
-
if (!ok)
|
|
272
|
-
sk.fill(0);
|
|
273
|
-
f.fill(0);
|
|
274
|
-
g.fill(0);
|
|
275
|
-
F.fill(0);
|
|
276
|
-
rng.reset();
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
180
|
}
|
|
280
181
|
_FnDsaSigner_hasKey = new WeakMap(), _FnDsaSigner_expandedKey = new WeakMap();
|
|
281
182
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fnDsaVerifier.d.ts","sourceRoot":"","sources":["../../src/src/fnDsaVerifier.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,kBAAkB,EAClB,sBAAsB,EACvB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"fnDsaVerifier.d.ts","sourceRoot":"","sources":["../../src/src/fnDsaVerifier.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,kBAAkB,EAClB,sBAAsB,EACvB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAO/C;;;;;;GAMG;AACH,qBAAa,aAAc,YAAW,sBAAsB;IAC1D,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC;IAI3B,SAAS,CAAC,WAAW,EAAE,MAAM,CAAC;IAG9B,SAAS,CAAC,EAAE,EAAE,WAAW,CAAC;gBAEd,MAAM,EAAE,WAAW;IAQ/B,wEAAwE;IAElE,MAAM,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IAsDhE;;;OAGG;WAEU,OAAO,CAClB,MAAM,EAAE,WAAW,EACnB,EAAE,EAAE,UAAU,EACd,IAAI,CAAC,EAAE,kBAAkB,GACxB,OAAO,CAAC,aAAa,CAAC;CAwB1B"}
|
package/esm/src/fnDsaVerifier.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { compDecode, modqDecode } from "./codec.js";
|
|
2
2
|
import { hashToPoint, newShake256 } from "./common.js";
|
|
3
|
-
import { NONCE_LEN } from "./consts.js";
|
|
3
|
+
import { NONCE_LEN, PK_HEADER } from "./consts.js";
|
|
4
4
|
import { FnDsaError } from "./errors.js";
|
|
5
5
|
import { assertWebCryptoOption } from "./native.js";
|
|
6
6
|
import { assertBytes, byteLengthOf, copyBytes } from "./utils.js";
|
|
7
7
|
import { toNttMonty, verifyRaw } from "./vrfy.js";
|
|
8
|
-
/** The header of a public key: 0x00 + logn. */
|
|
9
|
-
const PK_HEADER = 0x00;
|
|
10
8
|
/** The header of a signature with the compressed encoding: 0x30 + logn. */
|
|
11
9
|
const SIG_HEADER = 0x30;
|
|
12
10
|
/**
|
package/esm/src/keygen.d.ts
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import type { Keccak } from "./deps.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* which it is given are in the range it supports only for such a basis.
|
|
6
|
-
*
|
|
7
|
-
* Key generation keeps only the f and g which pass this, and a private key
|
|
8
|
-
* which is imported has to pass it as well. rt1 and rt2 are work areas of n
|
|
9
|
-
* values, and rt3 of n/2: they are left with values which depend on f and g.
|
|
3
|
+
* PRIMES, with its first `count` primes at least: all of them by default,
|
|
4
|
+
* for the tests.
|
|
10
5
|
*/
|
|
11
|
-
export declare function
|
|
6
|
+
export declare function primes(count?: number): Uint32Array;
|
|
12
7
|
/**
|
|
13
8
|
* Generates a key pair (Zf(keygen)).
|
|
14
9
|
*
|
package/esm/src/keygen.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keygen.d.ts","sourceRoot":"","sources":["../../src/src/keygen.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"keygen.d.ts","sourceRoot":"","sources":["../../src/src/keygen.ts"],"names":[],"mappings":"AA4CA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AA0HxC;;;GAGG;AACH,wBAAgB,MAAM,CAAC,KAAK,GAAE,MAAY,GAAG,WAAW,CAKvD;AAwpED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,MAAM,CACpB,GAAG,EAAE,MAAM,EACX,CAAC,EAAE,SAAS,EACZ,CAAC,EAAE,SAAS,EACZ,CAAC,EAAE,SAAS,EACZ,CAAC,EAAE,SAAS,GAAG,IAAI,EACnB,CAAC,EAAE,WAAW,GAAG,IAAI,EACrB,IAAI,EAAE,MAAM,GACX,IAAI,CAkDN"}
|