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