@theqrl/mldsa87 0.2.0 → 1.0.3
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 +21 -0
- package/README.md +167 -6
- package/package.json +14 -12
- package/src/index.js +0 -11
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-2026 The Quantum Resistant Ledger
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,11 +1,172 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @theqrl/mldsa87
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Post-quantum digital signatures using ML-DSA-87 (FIPS 204).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This package implements the ML-DSA-87 signature scheme at NIST security level 5 (AES-256 equivalent). It follows the [FIPS 204](https://csrc.nist.gov/pubs/fips/204/final) standard and is recommended for new implementations.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
import { cryptoSign, cryptoSignKeypair, cryptoSignOpen, cryptoSignVerify, cryptoSignSignature } from '@theqrl/mldsa87';
|
|
7
|
+
## Installation
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
```bash
|
|
10
|
+
npm install @theqrl/mldsa87
|
|
11
11
|
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
import {
|
|
17
|
+
cryptoSignKeypair,
|
|
18
|
+
cryptoSign,
|
|
19
|
+
cryptoSignOpen,
|
|
20
|
+
CryptoPublicKeyBytes,
|
|
21
|
+
CryptoSecretKeyBytes,
|
|
22
|
+
} from '@theqrl/mldsa87';
|
|
23
|
+
|
|
24
|
+
// Generate keypair
|
|
25
|
+
const pk = new Uint8Array(CryptoPublicKeyBytes); // 2592 bytes
|
|
26
|
+
const sk = new Uint8Array(CryptoSecretKeyBytes); // 4896 bytes
|
|
27
|
+
cryptoSignKeypair(null, pk, sk); // null = random seed
|
|
28
|
+
|
|
29
|
+
// Sign a message (uses default "ZOND" context)
|
|
30
|
+
const message = new TextEncoder().encode('Hello, quantum world!');
|
|
31
|
+
const signedMessage = cryptoSign(message, sk, false); // false = deterministic
|
|
32
|
+
|
|
33
|
+
// Verify and extract
|
|
34
|
+
const extracted = cryptoSignOpen(signedMessage, pk);
|
|
35
|
+
if (extracted === undefined) {
|
|
36
|
+
throw new Error('Invalid signature');
|
|
37
|
+
}
|
|
38
|
+
console.log(new TextDecoder().decode(extracted)); // "Hello, quantum world!"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Context Parameter
|
|
42
|
+
|
|
43
|
+
ML-DSA-87 supports a context parameter for domain separation (FIPS 204 feature). This allows the same keypair to be used safely across different applications.
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
// With custom context
|
|
47
|
+
const ctx = new TextEncoder().encode('my-app-v1');
|
|
48
|
+
const signed = cryptoSign(message, sk, false, ctx);
|
|
49
|
+
const extracted = cryptoSignOpen(signed, pk, ctx);
|
|
50
|
+
|
|
51
|
+
// Context must match for verification
|
|
52
|
+
cryptoSignOpen(signed, pk); // undefined - wrong context (default "ZOND")
|
|
53
|
+
cryptoSignOpen(signed, pk, ctx); // message - correct context
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The default context is `"ZOND"` (for QRL Zond network compatibility). Context can be 0-255 bytes.
|
|
57
|
+
|
|
58
|
+
## API
|
|
59
|
+
|
|
60
|
+
### Constants
|
|
61
|
+
|
|
62
|
+
| Constant | Value | Description |
|
|
63
|
+
|----------|-------|-------------|
|
|
64
|
+
| `CryptoPublicKeyBytes` | 2592 | Public key size in bytes |
|
|
65
|
+
| `CryptoSecretKeyBytes` | 4896 | Secret key size in bytes |
|
|
66
|
+
| `CryptoBytes` | 4627 | Signature size in bytes |
|
|
67
|
+
| `SeedBytes` | 32 | Seed size for key generation |
|
|
68
|
+
|
|
69
|
+
### Functions
|
|
70
|
+
|
|
71
|
+
#### `cryptoSignKeypair(seed, pk, sk)`
|
|
72
|
+
|
|
73
|
+
Generate a keypair from a seed.
|
|
74
|
+
|
|
75
|
+
- `seed`: `Uint8Array(32)` or `null` for random
|
|
76
|
+
- `pk`: `Uint8Array(2592)` - output buffer for public key
|
|
77
|
+
- `sk`: `Uint8Array(4896)` - output buffer for secret key
|
|
78
|
+
- Returns: The seed used (useful when `seed` is `null`)
|
|
79
|
+
|
|
80
|
+
#### `cryptoSign(message, sk, randomized, context?)`
|
|
81
|
+
|
|
82
|
+
Sign a message (combined mode: returns signature || message).
|
|
83
|
+
|
|
84
|
+
- `message`: `Uint8Array` - message to sign
|
|
85
|
+
- `sk`: `Uint8Array(4896)` - secret key
|
|
86
|
+
- `randomized`: `boolean` - `true` for hedged signing, `false` for deterministic
|
|
87
|
+
- `context`: `Uint8Array` (optional) - context string, 0-255 bytes. Default: `"ZOND"`
|
|
88
|
+
- Returns: `Uint8Array` containing signature + message
|
|
89
|
+
|
|
90
|
+
#### `cryptoSignOpen(signedMessage, pk, context?)`
|
|
91
|
+
|
|
92
|
+
Verify and extract message from signed message.
|
|
93
|
+
|
|
94
|
+
- `signedMessage`: `Uint8Array` - output from `cryptoSign()`
|
|
95
|
+
- `pk`: `Uint8Array(2592)` - public key
|
|
96
|
+
- `context`: `Uint8Array` (optional) - must match signing context
|
|
97
|
+
- Returns: Original message if valid, `undefined` if verification fails
|
|
98
|
+
|
|
99
|
+
#### `cryptoSignSignature(sig, message, sk, randomized, context?)`
|
|
100
|
+
|
|
101
|
+
Create a detached signature.
|
|
102
|
+
|
|
103
|
+
- `sig`: `Uint8Array(4627)` - output buffer for signature
|
|
104
|
+
- `message`: `Uint8Array` - message to sign
|
|
105
|
+
- `sk`: `Uint8Array(4896)` - secret key
|
|
106
|
+
- `randomized`: `boolean` - `true` for hedged, `false` for deterministic
|
|
107
|
+
- `context`: `Uint8Array` (optional) - context string, 0-255 bytes
|
|
108
|
+
- Returns: `0` on success
|
|
109
|
+
|
|
110
|
+
#### `cryptoSignVerify(sig, message, pk, context?)`
|
|
111
|
+
|
|
112
|
+
Verify a detached signature.
|
|
113
|
+
|
|
114
|
+
- `sig`: `Uint8Array(4627)` - signature to verify
|
|
115
|
+
- `message`: `Uint8Array` - original message
|
|
116
|
+
- `pk`: `Uint8Array(2592)` - public key
|
|
117
|
+
- `context`: `Uint8Array` (optional) - must match signing context
|
|
118
|
+
- Returns: `true` if valid, `false` otherwise
|
|
119
|
+
|
|
120
|
+
#### `zeroize(buffer)`
|
|
121
|
+
|
|
122
|
+
Zero out sensitive data (best-effort, see security notes).
|
|
123
|
+
|
|
124
|
+
#### `isZero(buffer)`
|
|
125
|
+
|
|
126
|
+
Check if buffer is all zeros (constant-time).
|
|
127
|
+
|
|
128
|
+
## Interoperability
|
|
129
|
+
|
|
130
|
+
Both this library and go-qrllib process ML-DSA-87 seeds identically. Raw seeds produce matching keys:
|
|
131
|
+
|
|
132
|
+
```javascript
|
|
133
|
+
// Same seed produces same keys in both implementations
|
|
134
|
+
cryptoSignKeypair(seed, pk, sk);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Verified against the [pq-crystals reference implementation](https://github.com/pq-crystals/dilithium).
|
|
138
|
+
|
|
139
|
+
## ML-DSA-87 vs Dilithium5
|
|
140
|
+
|
|
141
|
+
| Feature | ML-DSA-87 | Dilithium5 |
|
|
142
|
+
|---------|-----------|------------|
|
|
143
|
+
| Standard | FIPS 204 | CRYSTALS Round 3 |
|
|
144
|
+
| Signature size | 4627 bytes | 4595 bytes |
|
|
145
|
+
| Context parameter | Supported | Not supported |
|
|
146
|
+
| Use case | New implementations | go-qrllib compatibility |
|
|
147
|
+
|
|
148
|
+
Use [@theqrl/dilithium5](https://www.npmjs.com/package/@theqrl/dilithium5) only if you need compatibility with existing QRL infrastructure.
|
|
149
|
+
|
|
150
|
+
## Security
|
|
151
|
+
|
|
152
|
+
See [SECURITY.md](../../SECURITY.md) for important information about:
|
|
153
|
+
|
|
154
|
+
- JavaScript memory security limitations
|
|
155
|
+
- Constant-time verification
|
|
156
|
+
- Secure key handling recommendations
|
|
157
|
+
|
|
158
|
+
## Requirements
|
|
159
|
+
|
|
160
|
+
- Node.js 18+ or modern browsers with ES2020 support
|
|
161
|
+
- Full TypeScript definitions included
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
MIT
|
|
166
|
+
|
|
167
|
+
## Links
|
|
168
|
+
|
|
169
|
+
- [Main documentation](../../README.md)
|
|
170
|
+
- [FIPS 204](https://csrc.nist.gov/pubs/fips/204/final) - ML-DSA specification
|
|
171
|
+
- [go-qrllib](https://github.com/theQRL/go-qrllib) - Go implementation
|
|
172
|
+
- [QRL Website](https://theqrl.org)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theqrl/mldsa87",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "ML-DSA-87 cryptography",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ml-dsa",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"author": "QRL contributors <info@theqrl.org> (https://theqrl.org)",
|
|
11
11
|
"homepage": "https://github.com/theQRL/qrypto.js#readme",
|
|
12
12
|
"license": "MIT",
|
|
13
|
-
"main": "
|
|
13
|
+
"main": "dist/cjs/mldsa87.js",
|
|
14
|
+
"module": "dist/mjs/mldsa87.js",
|
|
14
15
|
"types": "src/index.d.ts",
|
|
15
16
|
"directories": {
|
|
16
17
|
"lib": "src",
|
|
@@ -18,7 +19,9 @@
|
|
|
18
19
|
},
|
|
19
20
|
"files": [
|
|
20
21
|
"dist",
|
|
21
|
-
"src/index.d.ts"
|
|
22
|
+
"src/index.d.ts",
|
|
23
|
+
"LICENSE",
|
|
24
|
+
"README.md"
|
|
22
25
|
],
|
|
23
26
|
"publishConfig": {
|
|
24
27
|
"access": "public"
|
|
@@ -45,17 +48,16 @@
|
|
|
45
48
|
},
|
|
46
49
|
"type": "module",
|
|
47
50
|
"devDependencies": {
|
|
48
|
-
"c8": "^
|
|
49
|
-
"chai": "^5.
|
|
50
|
-
"
|
|
51
|
-
"eslint": "^8.56.0",
|
|
51
|
+
"c8": "^10.1.3",
|
|
52
|
+
"chai": "^5.2.1",
|
|
53
|
+
"eslint": "^8.57.1",
|
|
52
54
|
"eslint-config-airbnb": "^19.0.4",
|
|
53
55
|
"eslint-config-prettier": "^9.1.0",
|
|
54
|
-
"eslint-plugin-import": "^2.
|
|
55
|
-
"eslint-plugin-prettier": "^5.
|
|
56
|
-
"mocha": "^10.2
|
|
57
|
-
"prettier": "^3.
|
|
58
|
-
"rollup": "^4.
|
|
56
|
+
"eslint-plugin-import": "^2.32.0",
|
|
57
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
58
|
+
"mocha": "^10.8.2",
|
|
59
|
+
"prettier": "^3.7.4",
|
|
60
|
+
"rollup": "^4.55.1"
|
|
59
61
|
},
|
|
60
62
|
"dependencies": {
|
|
61
63
|
"@noble/hashes": "^1.7.1",
|
package/src/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from './const.js';
|
|
2
|
-
export * from './poly.js';
|
|
3
|
-
export * from './polyvec.js';
|
|
4
|
-
export * from './packing.js';
|
|
5
|
-
export * from './reduce.js';
|
|
6
|
-
export * from './rounding.js';
|
|
7
|
-
export * from './symmetric-shake.js';
|
|
8
|
-
export * from './ntt.js';
|
|
9
|
-
export * from './fips202.js';
|
|
10
|
-
export * from './sign.js';
|
|
11
|
-
export * from './utils.js';
|