@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,88 @@
|
|
|
1
|
+
import type { FnDsaCreateOptions, FnDsaSignerInterface, FnDsaVerifierInterface } from "./interfaces.js";
|
|
2
|
+
/**
|
|
3
|
+
* Generates a key pair of FN-DSA-1024 (NIST security category 5).
|
|
4
|
+
*
|
|
5
|
+
* The public key is 1793 octets in length, and the private key 2305 octets.
|
|
6
|
+
*
|
|
7
|
+
* @returns A promise that resolves to a key pair [publicKey, privateKey].
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import {
|
|
13
|
+
* createFnDsa1024Signer,
|
|
14
|
+
* createFnDsa1024Verifier,
|
|
15
|
+
* generateFnDsa1024KeyPair,
|
|
16
|
+
* } from "@webpqc/fndsa";
|
|
17
|
+
*
|
|
18
|
+
* const [pk, sk] = await generateFnDsa1024KeyPair();
|
|
19
|
+
*
|
|
20
|
+
* const signer = await createFnDsa1024Signer(sk);
|
|
21
|
+
* const msg = new TextEncoder().encode("hello world");
|
|
22
|
+
* const sig = await signer.sign(msg);
|
|
23
|
+
* signer.destroy();
|
|
24
|
+
*
|
|
25
|
+
* const verifier = await createFnDsa1024Verifier(pk);
|
|
26
|
+
* const ok = await verifier.verify(sig, msg);
|
|
27
|
+
* // ok === true
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function generateFnDsa1024KeyPair(): Promise<[Uint8Array, Uint8Array]>;
|
|
31
|
+
/**
|
|
32
|
+
* Derives a key pair of FN-DSA-1024 deterministically from a 48-octet seed.
|
|
33
|
+
*
|
|
34
|
+
* Unlike the other packages of webpqc, the private key is not the seed: it
|
|
35
|
+
* is the encoded private key (2305 octets), as key generation takes much
|
|
36
|
+
* longer than decoding a key.
|
|
37
|
+
*
|
|
38
|
+
* @param seed A 48-octet seed.
|
|
39
|
+
* @returns A promise that resolves to a key pair [publicKey, privateKey].
|
|
40
|
+
*/
|
|
41
|
+
export declare function deriveFnDsa1024KeyPair(seed: Uint8Array): Promise<[Uint8Array, Uint8Array]>;
|
|
42
|
+
/**
|
|
43
|
+
* Creates an FN-DSA-1024 (NIST security category 5) signer which holds a
|
|
44
|
+
* private key.
|
|
45
|
+
*
|
|
46
|
+
* The signature is 1280 octets in length. Call `destroy()` of the signer to
|
|
47
|
+
* erase the private key which it holds, when it is no longer needed.
|
|
48
|
+
*
|
|
49
|
+
* @param sk A private key (2305 octets).
|
|
50
|
+
* @param opts Options: see {@link FnDsaCreateOptions}.
|
|
51
|
+
* @returns A promise that resolves to an {@link FnDsaSignerInterface} instance.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
*
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { createFnDsa1024Signer, generateFnDsa1024KeyPair } from "@webpqc/fndsa";
|
|
57
|
+
*
|
|
58
|
+
* const [_pk, sk] = await generateFnDsa1024KeyPair();
|
|
59
|
+
* const signer = await createFnDsa1024Signer(sk);
|
|
60
|
+
* const sig = await signer.sign(new TextEncoder().encode("hello world"));
|
|
61
|
+
* signer.destroy();
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function createFnDsa1024Signer(sk: Uint8Array, opts?: FnDsaCreateOptions): Promise<FnDsaSignerInterface>;
|
|
65
|
+
/**
|
|
66
|
+
* Creates an FN-DSA-1024 (NIST security category 5) verifier which holds a
|
|
67
|
+
* public key.
|
|
68
|
+
*
|
|
69
|
+
* An application which uses only this does not bundle the code for key
|
|
70
|
+
* generation and signing.
|
|
71
|
+
*
|
|
72
|
+
* @param pk A public key (1793 octets).
|
|
73
|
+
* @param opts Options: see {@link FnDsaCreateOptions}.
|
|
74
|
+
* @returns A promise that resolves to an {@link FnDsaVerifierInterface} instance.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
*
|
|
78
|
+
* ```ts
|
|
79
|
+
* import { createFnDsa1024Verifier } from "@webpqc/fndsa";
|
|
80
|
+
*
|
|
81
|
+
* async function verify(pk: Uint8Array, sig: Uint8Array, msg: Uint8Array) {
|
|
82
|
+
* const verifier = await createFnDsa1024Verifier(pk);
|
|
83
|
+
* return await verifier.verify(sig, msg);
|
|
84
|
+
* }
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare function createFnDsa1024Verifier(pk: Uint8Array, opts?: FnDsaCreateOptions): Promise<FnDsaVerifierInterface>;
|
|
88
|
+
//# sourceMappingURL=fnDsa1024.d.ts.map
|
|
@@ -0,0 +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;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"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { createSignerHandle } from "./fnDsaSigner.js";
|
|
2
|
+
import { FnDsaVerifier } from "./fnDsaVerifier.js";
|
|
3
|
+
import { deriveKeyPair, generateKeyPair } from "./fnDsaKeyGen.js";
|
|
4
|
+
import { FN_DSA_1024 } from "./params.js";
|
|
5
|
+
/**
|
|
6
|
+
* Generates a key pair of FN-DSA-1024 (NIST security category 5).
|
|
7
|
+
*
|
|
8
|
+
* The public key is 1793 octets in length, and the private key 2305 octets.
|
|
9
|
+
*
|
|
10
|
+
* @returns A promise that resolves to a key pair [publicKey, privateKey].
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import {
|
|
16
|
+
* createFnDsa1024Signer,
|
|
17
|
+
* createFnDsa1024Verifier,
|
|
18
|
+
* generateFnDsa1024KeyPair,
|
|
19
|
+
* } from "@webpqc/fndsa";
|
|
20
|
+
*
|
|
21
|
+
* const [pk, sk] = await generateFnDsa1024KeyPair();
|
|
22
|
+
*
|
|
23
|
+
* const signer = await createFnDsa1024Signer(sk);
|
|
24
|
+
* const msg = new TextEncoder().encode("hello world");
|
|
25
|
+
* const sig = await signer.sign(msg);
|
|
26
|
+
* signer.destroy();
|
|
27
|
+
*
|
|
28
|
+
* const verifier = await createFnDsa1024Verifier(pk);
|
|
29
|
+
* const ok = await verifier.verify(sig, msg);
|
|
30
|
+
* // ok === true
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function generateFnDsa1024KeyPair() {
|
|
34
|
+
return generateKeyPair(FN_DSA_1024);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Derives a key pair of FN-DSA-1024 deterministically from a 48-octet seed.
|
|
38
|
+
*
|
|
39
|
+
* Unlike the other packages of webpqc, the private key is not the seed: it
|
|
40
|
+
* is the encoded private key (2305 octets), as key generation takes much
|
|
41
|
+
* longer than decoding a key.
|
|
42
|
+
*
|
|
43
|
+
* @param seed A 48-octet seed.
|
|
44
|
+
* @returns A promise that resolves to a key pair [publicKey, privateKey].
|
|
45
|
+
*/
|
|
46
|
+
export function deriveFnDsa1024KeyPair(seed) {
|
|
47
|
+
return deriveKeyPair(FN_DSA_1024, seed);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates an FN-DSA-1024 (NIST security category 5) signer which holds a
|
|
51
|
+
* private key.
|
|
52
|
+
*
|
|
53
|
+
* The signature is 1280 octets in length. Call `destroy()` of the signer to
|
|
54
|
+
* erase the private key which it holds, when it is no longer needed.
|
|
55
|
+
*
|
|
56
|
+
* @param sk A private key (2305 octets).
|
|
57
|
+
* @param opts Options: see {@link FnDsaCreateOptions}.
|
|
58
|
+
* @returns A promise that resolves to an {@link FnDsaSignerInterface} instance.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { createFnDsa1024Signer, generateFnDsa1024KeyPair } from "@webpqc/fndsa";
|
|
64
|
+
*
|
|
65
|
+
* const [_pk, sk] = await generateFnDsa1024KeyPair();
|
|
66
|
+
* const signer = await createFnDsa1024Signer(sk);
|
|
67
|
+
* const sig = await signer.sign(new TextEncoder().encode("hello world"));
|
|
68
|
+
* signer.destroy();
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export function createFnDsa1024Signer(sk, opts) {
|
|
72
|
+
return createSignerHandle(FN_DSA_1024, sk, opts);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Creates an FN-DSA-1024 (NIST security category 5) verifier which holds a
|
|
76
|
+
* public key.
|
|
77
|
+
*
|
|
78
|
+
* An application which uses only this does not bundle the code for key
|
|
79
|
+
* generation and signing.
|
|
80
|
+
*
|
|
81
|
+
* @param pk A public key (1793 octets).
|
|
82
|
+
* @param opts Options: see {@link FnDsaCreateOptions}.
|
|
83
|
+
* @returns A promise that resolves to an {@link FnDsaVerifierInterface} instance.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
*
|
|
87
|
+
* ```ts
|
|
88
|
+
* import { createFnDsa1024Verifier } from "@webpqc/fndsa";
|
|
89
|
+
*
|
|
90
|
+
* async function verify(pk: Uint8Array, sig: Uint8Array, msg: Uint8Array) {
|
|
91
|
+
* const verifier = await createFnDsa1024Verifier(pk);
|
|
92
|
+
* return await verifier.verify(sig, msg);
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export function createFnDsa1024Verifier(pk, opts) {
|
|
97
|
+
return FnDsaVerifier._create(FN_DSA_1024, pk, opts);
|
|
98
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { FnDsaCreateOptions, FnDsaSignerInterface, FnDsaVerifierInterface } from "./interfaces.js";
|
|
2
|
+
/**
|
|
3
|
+
* Generates a key pair of FN-DSA-512 (NIST security category 1).
|
|
4
|
+
*
|
|
5
|
+
* The public key is 897 octets in length, and the private key 1281 octets.
|
|
6
|
+
*
|
|
7
|
+
* @returns A promise that resolves to a key pair [publicKey, privateKey].
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import {
|
|
13
|
+
* createFnDsa512Signer,
|
|
14
|
+
* createFnDsa512Verifier,
|
|
15
|
+
* generateFnDsa512KeyPair,
|
|
16
|
+
* } from "@webpqc/fndsa";
|
|
17
|
+
*
|
|
18
|
+
* const [pk, sk] = await generateFnDsa512KeyPair();
|
|
19
|
+
*
|
|
20
|
+
* const signer = await createFnDsa512Signer(sk);
|
|
21
|
+
* const msg = new TextEncoder().encode("hello world");
|
|
22
|
+
* const sig = await signer.sign(msg);
|
|
23
|
+
* signer.destroy();
|
|
24
|
+
*
|
|
25
|
+
* const verifier = await createFnDsa512Verifier(pk);
|
|
26
|
+
* const ok = await verifier.verify(sig, msg);
|
|
27
|
+
* // ok === true
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function generateFnDsa512KeyPair(): Promise<[Uint8Array, Uint8Array]>;
|
|
31
|
+
/**
|
|
32
|
+
* Derives a key pair of FN-DSA-512 deterministically from a 48-octet seed.
|
|
33
|
+
*
|
|
34
|
+
* Unlike the other packages of webpqc, the private key is not the seed: it
|
|
35
|
+
* is the encoded private key (1281 octets), as key generation takes much
|
|
36
|
+
* longer than decoding a key.
|
|
37
|
+
*
|
|
38
|
+
* @param seed A 48-octet seed.
|
|
39
|
+
* @returns A promise that resolves to a key pair [publicKey, privateKey].
|
|
40
|
+
*/
|
|
41
|
+
export declare function deriveFnDsa512KeyPair(seed: Uint8Array): Promise<[Uint8Array, Uint8Array]>;
|
|
42
|
+
/**
|
|
43
|
+
* Creates an FN-DSA-512 (NIST security category 1) signer which holds a
|
|
44
|
+
* private key.
|
|
45
|
+
*
|
|
46
|
+
* The signature is 666 octets in length. Call `destroy()` of the signer to
|
|
47
|
+
* erase the private key which it holds, when it is no longer needed.
|
|
48
|
+
*
|
|
49
|
+
* @param sk A private key (1281 octets).
|
|
50
|
+
* @param opts Options: see {@link FnDsaCreateOptions}.
|
|
51
|
+
* @returns A promise that resolves to an {@link FnDsaSignerInterface} instance.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
*
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { createFnDsa512Signer, generateFnDsa512KeyPair } from "@webpqc/fndsa";
|
|
57
|
+
*
|
|
58
|
+
* const [_pk, sk] = await generateFnDsa512KeyPair();
|
|
59
|
+
* const signer = await createFnDsa512Signer(sk);
|
|
60
|
+
* const sig = await signer.sign(new TextEncoder().encode("hello world"));
|
|
61
|
+
* signer.destroy();
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function createFnDsa512Signer(sk: Uint8Array, opts?: FnDsaCreateOptions): Promise<FnDsaSignerInterface>;
|
|
65
|
+
/**
|
|
66
|
+
* Creates an FN-DSA-512 (NIST security category 1) verifier which holds a
|
|
67
|
+
* public key.
|
|
68
|
+
*
|
|
69
|
+
* An application which uses only this does not bundle the code for key
|
|
70
|
+
* generation and signing.
|
|
71
|
+
*
|
|
72
|
+
* @param pk A public key (897 octets).
|
|
73
|
+
* @param opts Options: see {@link FnDsaCreateOptions}.
|
|
74
|
+
* @returns A promise that resolves to an {@link FnDsaVerifierInterface} instance.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
*
|
|
78
|
+
* ```ts
|
|
79
|
+
* import { createFnDsa512Verifier } from "@webpqc/fndsa";
|
|
80
|
+
*
|
|
81
|
+
* async function verify(pk: Uint8Array, sig: Uint8Array, msg: Uint8Array) {
|
|
82
|
+
* const verifier = await createFnDsa512Verifier(pk);
|
|
83
|
+
* return await verifier.verify(sig, msg);
|
|
84
|
+
* }
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare function createFnDsa512Verifier(pk: Uint8Array, opts?: FnDsaCreateOptions): Promise<FnDsaVerifierInterface>;
|
|
88
|
+
//# sourceMappingURL=fnDsa512.d.ts.map
|
|
@@ -0,0 +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;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"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { createSignerHandle } from "./fnDsaSigner.js";
|
|
2
|
+
import { FnDsaVerifier } from "./fnDsaVerifier.js";
|
|
3
|
+
import { deriveKeyPair, generateKeyPair } from "./fnDsaKeyGen.js";
|
|
4
|
+
import { FN_DSA_512 } from "./params.js";
|
|
5
|
+
/**
|
|
6
|
+
* Generates a key pair of FN-DSA-512 (NIST security category 1).
|
|
7
|
+
*
|
|
8
|
+
* The public key is 897 octets in length, and the private key 1281 octets.
|
|
9
|
+
*
|
|
10
|
+
* @returns A promise that resolves to a key pair [publicKey, privateKey].
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import {
|
|
16
|
+
* createFnDsa512Signer,
|
|
17
|
+
* createFnDsa512Verifier,
|
|
18
|
+
* generateFnDsa512KeyPair,
|
|
19
|
+
* } from "@webpqc/fndsa";
|
|
20
|
+
*
|
|
21
|
+
* const [pk, sk] = await generateFnDsa512KeyPair();
|
|
22
|
+
*
|
|
23
|
+
* const signer = await createFnDsa512Signer(sk);
|
|
24
|
+
* const msg = new TextEncoder().encode("hello world");
|
|
25
|
+
* const sig = await signer.sign(msg);
|
|
26
|
+
* signer.destroy();
|
|
27
|
+
*
|
|
28
|
+
* const verifier = await createFnDsa512Verifier(pk);
|
|
29
|
+
* const ok = await verifier.verify(sig, msg);
|
|
30
|
+
* // ok === true
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function generateFnDsa512KeyPair() {
|
|
34
|
+
return generateKeyPair(FN_DSA_512);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Derives a key pair of FN-DSA-512 deterministically from a 48-octet seed.
|
|
38
|
+
*
|
|
39
|
+
* Unlike the other packages of webpqc, the private key is not the seed: it
|
|
40
|
+
* is the encoded private key (1281 octets), as key generation takes much
|
|
41
|
+
* longer than decoding a key.
|
|
42
|
+
*
|
|
43
|
+
* @param seed A 48-octet seed.
|
|
44
|
+
* @returns A promise that resolves to a key pair [publicKey, privateKey].
|
|
45
|
+
*/
|
|
46
|
+
export function deriveFnDsa512KeyPair(seed) {
|
|
47
|
+
return deriveKeyPair(FN_DSA_512, seed);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates an FN-DSA-512 (NIST security category 1) signer which holds a
|
|
51
|
+
* private key.
|
|
52
|
+
*
|
|
53
|
+
* The signature is 666 octets in length. Call `destroy()` of the signer to
|
|
54
|
+
* erase the private key which it holds, when it is no longer needed.
|
|
55
|
+
*
|
|
56
|
+
* @param sk A private key (1281 octets).
|
|
57
|
+
* @param opts Options: see {@link FnDsaCreateOptions}.
|
|
58
|
+
* @returns A promise that resolves to an {@link FnDsaSignerInterface} instance.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { createFnDsa512Signer, generateFnDsa512KeyPair } from "@webpqc/fndsa";
|
|
64
|
+
*
|
|
65
|
+
* const [_pk, sk] = await generateFnDsa512KeyPair();
|
|
66
|
+
* const signer = await createFnDsa512Signer(sk);
|
|
67
|
+
* const sig = await signer.sign(new TextEncoder().encode("hello world"));
|
|
68
|
+
* signer.destroy();
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export function createFnDsa512Signer(sk, opts) {
|
|
72
|
+
return createSignerHandle(FN_DSA_512, sk, opts);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Creates an FN-DSA-512 (NIST security category 1) verifier which holds a
|
|
76
|
+
* public key.
|
|
77
|
+
*
|
|
78
|
+
* An application which uses only this does not bundle the code for key
|
|
79
|
+
* generation and signing.
|
|
80
|
+
*
|
|
81
|
+
* @param pk A public key (897 octets).
|
|
82
|
+
* @param opts Options: see {@link FnDsaCreateOptions}.
|
|
83
|
+
* @returns A promise that resolves to an {@link FnDsaVerifierInterface} instance.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
*
|
|
87
|
+
* ```ts
|
|
88
|
+
* import { createFnDsa512Verifier } from "@webpqc/fndsa";
|
|
89
|
+
*
|
|
90
|
+
* async function verify(pk: Uint8Array, sig: Uint8Array, msg: Uint8Array) {
|
|
91
|
+
* const verifier = await createFnDsa512Verifier(pk);
|
|
92
|
+
* return await verifier.verify(sig, msg);
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export function createFnDsa512Verifier(pk, opts) {
|
|
97
|
+
return FnDsaVerifier._create(FN_DSA_512, pk, opts);
|
|
98
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { FnDsaCreateOptions, FnDsaSignerInterface } from "./interfaces.js";
|
|
2
|
+
import type { FnDsaParams } from "./params.js";
|
|
3
|
+
/**
|
|
4
|
+
* Signing of FN-DSA.
|
|
5
|
+
*
|
|
6
|
+
* An instance holds a private key, which signs any number of messages until
|
|
7
|
+
* destroy() erases it. Use one of the factory functions to create an
|
|
8
|
+
* instance: `createFnDsa512Signer` or `createFnDsa1024Signer`.
|
|
9
|
+
*/
|
|
10
|
+
export declare class FnDsaSigner implements FnDsaSignerInterface {
|
|
11
|
+
#private;
|
|
12
|
+
protected _api: Crypto;
|
|
13
|
+
protected _logn: number;
|
|
14
|
+
protected _sigSize: number;
|
|
15
|
+
constructor(params: FnDsaParams, api: Crypto);
|
|
16
|
+
/** Signs a message: returns signature. */
|
|
17
|
+
sign(msg: Uint8Array): Promise<Uint8Array>;
|
|
18
|
+
/** Erases the private key which the instance holds. */
|
|
19
|
+
destroy(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a signer which holds a private key.
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
static _create(params: FnDsaParams, sk: Uint8Array, opts?: FnDsaCreateOptions): Promise<FnDsaSigner>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates a signer which holds a private key, for a factory function.
|
|
28
|
+
*/
|
|
29
|
+
export declare function createSignerHandle(params: FnDsaParams, sk: Uint8Array, opts?: FnDsaCreateOptions): Promise<FnDsaSignerInterface>;
|
|
30
|
+
//# sourceMappingURL=fnDsaSigner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|