@theqrl/mldsa87 0.2.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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@theqrl/mldsa87",
3
+ "version": "0.2.0",
4
+ "description": "ML-DSA-87 cryptography",
5
+ "keywords": [
6
+ "ml-dsa",
7
+ "post-quantum",
8
+ "cryptography"
9
+ ],
10
+ "author": "QRL contributors <info@theqrl.org> (https://theqrl.org)",
11
+ "homepage": "https://github.com/theQRL/qrypto.js#readme",
12
+ "license": "MIT",
13
+ "main": "src/index.js",
14
+ "types": "src/index.d.ts",
15
+ "directories": {
16
+ "lib": "src",
17
+ "test": "test"
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "src/index.d.ts"
22
+ ],
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/theQRL/qrypto.js.git"
29
+ },
30
+ "scripts": {
31
+ "test": "../../node_modules/mocha/bin/mocha.js --timeout 10000",
32
+ "build": "rollup src/index.js --file ./dist/cjs/mldsa87.js --format cjs && rollup src/index.js --file ./dist/mjs/mldsa87.js --format esm && ./fixup",
33
+ "lint-check": "eslint 'src/**/*.js' 'test/**/*.js'",
34
+ "lint": "eslint --fix 'src/**/*.js' 'test/**/*.js'",
35
+ "report-coverage": "c8 --reporter=text-lcov npm run test > coverage.lcov"
36
+ },
37
+ "bugs": {
38
+ "url": "https://github.com/theQRL/qrypto.js/issues"
39
+ },
40
+ "exports": {
41
+ ".": {
42
+ "import": "./dist/mjs/mldsa87.js",
43
+ "require": "./dist/cjs/mldsa87.js"
44
+ }
45
+ },
46
+ "type": "module",
47
+ "devDependencies": {
48
+ "c8": "^9.1.0",
49
+ "chai": "^5.0.0",
50
+ "codecov": "^3.8.3",
51
+ "eslint": "^8.56.0",
52
+ "eslint-config-airbnb": "^19.0.4",
53
+ "eslint-config-prettier": "^9.1.0",
54
+ "eslint-plugin-import": "^2.29.1",
55
+ "eslint-plugin-prettier": "^5.1.3",
56
+ "mocha": "^10.2.0",
57
+ "prettier": "^3.2.4",
58
+ "rollup": "^4.9.5"
59
+ },
60
+ "dependencies": {
61
+ "@noble/hashes": "^1.7.1",
62
+ "randombytes": "^2.1.0"
63
+ }
64
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,204 @@
1
+ /**
2
+ * TypeScript definitions for @theqrl/mldsa87
3
+ * ML-DSA-87 (FIPS 204) post-quantum digital signature scheme
4
+ */
5
+
6
+ // Constants
7
+ export const Shake128Rate: number;
8
+ export const Shake256Rate: number;
9
+ export const Stream128BlockBytes: number;
10
+ export const Stream256BlockBytes: number;
11
+ export const SeedBytes: number;
12
+ export const CRHBytes: number;
13
+ export const TRBytes: number;
14
+ export const RNDBytes: number;
15
+ export const N: number;
16
+ export const Q: number;
17
+ export const QInv: number;
18
+ export const D: number;
19
+ export const K: number;
20
+ export const L: number;
21
+ export const ETA: number;
22
+ export const TAU: number;
23
+ export const BETA: number;
24
+ export const GAMMA1: number;
25
+ export const GAMMA2: number;
26
+ export const OMEGA: number;
27
+ export const CTILDEBytes: number;
28
+ export const PolyT1PackedBytes: number;
29
+ export const PolyT0PackedBytes: number;
30
+ export const PolyETAPackedBytes: number;
31
+ export const PolyZPackedBytes: number;
32
+ export const PolyVecHPackedBytes: number;
33
+ export const PolyW1PackedBytes: number;
34
+ export const CryptoPublicKeyBytes: number;
35
+ export const CryptoSecretKeyBytes: number;
36
+ export const CryptoBytes: number;
37
+ export const PolyUniformNBlocks: number;
38
+ export const PolyUniformETANBlocks: number;
39
+ export const PolyUniformGamma1NBlocks: number;
40
+ export const zetas: readonly number[];
41
+
42
+ // Core signing functions
43
+
44
+ /**
45
+ * Generate an ML-DSA-87 key pair
46
+ * @param seed - Optional 32-byte seed for deterministic key generation (null for random)
47
+ * @param pk - Output buffer for public key (must be CryptoPublicKeyBytes length)
48
+ * @param sk - Output buffer for secret key (must be CryptoSecretKeyBytes length)
49
+ * @returns The seed used for key generation
50
+ * @throws Error if pk/sk buffers are wrong size or null
51
+ */
52
+ export function cryptoSignKeypair(
53
+ seed: Uint8Array | null,
54
+ pk: Uint8Array,
55
+ sk: Uint8Array
56
+ ): Uint8Array;
57
+
58
+ /**
59
+ * Create a signature for a message with optional context
60
+ * @param sig - Output buffer for signature (must be CryptoBytes length minimum)
61
+ * @param m - Message to sign (hex-encoded string)
62
+ * @param sk - Secret key
63
+ * @param randomizedSigning - If true, use random nonce; if false, deterministic
64
+ * @param ctx - Optional context string (max 255 bytes, defaults to "ZOND")
65
+ * @returns 0 on success
66
+ * @throws Error if sk is wrong size or context too long
67
+ */
68
+ export function cryptoSignSignature(
69
+ sig: Uint8Array,
70
+ m: string,
71
+ sk: Uint8Array,
72
+ randomizedSigning: boolean,
73
+ ctx?: Uint8Array
74
+ ): number;
75
+
76
+ /**
77
+ * Sign a message, returning signature concatenated with message
78
+ * @param msg - Message to sign
79
+ * @param sk - Secret key
80
+ * @param randomizedSigning - If true, use random nonce; if false, deterministic
81
+ * @param ctx - Optional context string (max 255 bytes, defaults to "ZOND")
82
+ * @returns Signed message (signature || message)
83
+ * @throws Error if signing fails
84
+ */
85
+ export function cryptoSign(
86
+ msg: Uint8Array,
87
+ sk: Uint8Array,
88
+ randomizedSigning: boolean,
89
+ ctx?: Uint8Array
90
+ ): Uint8Array;
91
+
92
+ /**
93
+ * Verify a signature with optional context
94
+ * @param sig - Signature to verify
95
+ * @param m - Message that was signed (hex-encoded string)
96
+ * @param pk - Public key
97
+ * @param ctx - Optional context string (max 255 bytes, defaults to "ZOND")
98
+ * @returns true if signature is valid, false otherwise
99
+ */
100
+ export function cryptoSignVerify(
101
+ sig: Uint8Array,
102
+ m: string,
103
+ pk: Uint8Array,
104
+ ctx?: Uint8Array
105
+ ): boolean;
106
+
107
+ /**
108
+ * Open a signed message (verify and extract message)
109
+ * @param sm - Signed message (signature || message)
110
+ * @param pk - Public key
111
+ * @param ctx - Optional context string (max 255 bytes, defaults to "ZOND")
112
+ * @returns Message if valid, undefined if verification fails
113
+ */
114
+ export function cryptoSignOpen(
115
+ sm: Uint8Array,
116
+ pk: Uint8Array,
117
+ ctx?: Uint8Array
118
+ ): Uint8Array | undefined;
119
+
120
+ // Utility functions
121
+
122
+ /**
123
+ * Zero out a buffer (best-effort, see SECURITY.md for limitations)
124
+ * @param buffer - Buffer to zero
125
+ * @throws TypeError if buffer is not Uint8Array
126
+ */
127
+ export function zeroize(buffer: Uint8Array): void;
128
+
129
+ /**
130
+ * Check if buffer is all zeros using constant-time comparison
131
+ * @param buffer - Buffer to check
132
+ * @returns true if all bytes are zero
133
+ * @throws TypeError if buffer is not Uint8Array
134
+ */
135
+ export function isZero(buffer: Uint8Array): boolean;
136
+
137
+ // Internal classes (exported but primarily for internal use)
138
+
139
+ export class Poly {
140
+ coeffs: Int32Array;
141
+ constructor();
142
+ copy(poly: Poly): void;
143
+ }
144
+
145
+ export class PolyVecK {
146
+ vec: Poly[];
147
+ constructor();
148
+ }
149
+
150
+ export class PolyVecL {
151
+ vec: Poly[];
152
+ constructor();
153
+ copy(polyVecL: PolyVecL): void;
154
+ }
155
+
156
+ export class KeccakState {
157
+ constructor();
158
+ }
159
+
160
+ // Internal functions (exported but primarily for internal use)
161
+ export function polyNTT(a: Poly): void;
162
+ export function polyInvNTTToMont(a: Poly): void;
163
+ export function polyChallenge(c: Poly, seed: Uint8Array): void;
164
+ export function ntt(a: Int32Array): void;
165
+ export function invNTTToMont(a: Int32Array): void;
166
+ export function montgomeryReduce(a: bigint): bigint;
167
+ export function reduce32(a: number): number;
168
+ export function cAddQ(a: number): number;
169
+ export function decompose(a0: Int32Array, i: number, a: number): number;
170
+ export function power2round(a0: Int32Array, i: number, a: number): number;
171
+ export function makeHint(a0: number, a1: number): number;
172
+ export function useHint(a: number, hint: number): number;
173
+ export function packPk(pk: Uint8Array, rho: Uint8Array, t1: PolyVecK): void;
174
+ export function packSk(
175
+ sk: Uint8Array,
176
+ rho: Uint8Array,
177
+ tr: Uint8Array,
178
+ key: Uint8Array,
179
+ t0: PolyVecK,
180
+ s1: PolyVecL,
181
+ s2: PolyVecK
182
+ ): void;
183
+ export function packSig(
184
+ sig: Uint8Array,
185
+ c: Uint8Array,
186
+ z: PolyVecL,
187
+ h: PolyVecK
188
+ ): void;
189
+ export function unpackPk(rho: Uint8Array, t1: PolyVecK, pk: Uint8Array): void;
190
+ export function unpackSk(
191
+ rho: Uint8Array,
192
+ tr: Uint8Array,
193
+ key: Uint8Array,
194
+ t0: PolyVecK,
195
+ s1: PolyVecL,
196
+ s2: PolyVecK,
197
+ sk: Uint8Array
198
+ ): void;
199
+ export function unpackSig(
200
+ c: Uint8Array,
201
+ z: PolyVecL,
202
+ h: PolyVecK,
203
+ sig: Uint8Array
204
+ ): number;
package/src/index.js ADDED
@@ -0,0 +1,11 @@
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';