@theqrl/dilithium5 1.0.3 → 1.0.4
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/dist/cjs/dilithium5.js +11 -11
- package/dist/mjs/dilithium5.js +1 -1
- package/package.json +9 -8
package/dist/cjs/dilithium5.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var sha3_js = require('@noble/hashes/sha3.js');
|
|
4
4
|
var pkg = require('randombytes');
|
|
5
5
|
|
|
6
6
|
const Shake128Rate = 168;
|
|
@@ -85,7 +85,7 @@ class KeccakState {
|
|
|
85
85
|
// SHAKE-128 functions
|
|
86
86
|
|
|
87
87
|
function shake128Init(state) {
|
|
88
|
-
state.hasher =
|
|
88
|
+
state.hasher = sha3_js.shake128.create({});
|
|
89
89
|
state.finalized = false;
|
|
90
90
|
}
|
|
91
91
|
|
|
@@ -107,7 +107,7 @@ function shake128SqueezeBlocks(out, outputOffset, nBlocks, state) {
|
|
|
107
107
|
// SHAKE-256 functions
|
|
108
108
|
|
|
109
109
|
function shake256Init(state) {
|
|
110
|
-
state.hasher =
|
|
110
|
+
state.hasher = sha3_js.shake256.create({});
|
|
111
111
|
state.finalized = false;
|
|
112
112
|
}
|
|
113
113
|
|
|
@@ -1081,7 +1081,7 @@ function cryptoSignKeypair(passedSeed, pk, sk) {
|
|
|
1081
1081
|
const seed = passedSeed || randomBytes(SeedBytes);
|
|
1082
1082
|
|
|
1083
1083
|
const outputLength = 2 * SeedBytes + CRHBytes;
|
|
1084
|
-
const seedBuf =
|
|
1084
|
+
const seedBuf = sha3_js.shake256.create({}).update(seed).xof(outputLength);
|
|
1085
1085
|
const rho = seedBuf.slice(0, SeedBytes);
|
|
1086
1086
|
const rhoPrime = seedBuf.slice(SeedBytes, SeedBytes + CRHBytes);
|
|
1087
1087
|
const key = seedBuf.slice(SeedBytes + CRHBytes);
|
|
@@ -1110,7 +1110,7 @@ function cryptoSignKeypair(passedSeed, pk, sk) {
|
|
|
1110
1110
|
packPk(pk, rho, t1);
|
|
1111
1111
|
|
|
1112
1112
|
// Compute H(rho, t1) and write secret key
|
|
1113
|
-
const tr =
|
|
1113
|
+
const tr = sha3_js.shake256.create({}).update(pk).xof(TRBytes);
|
|
1114
1114
|
packSk(sk, rho, tr, key, t0, s1, s2);
|
|
1115
1115
|
|
|
1116
1116
|
return seed;
|
|
@@ -1160,12 +1160,12 @@ function cryptoSignSignature(sig, m, sk, randomizedSigning) {
|
|
|
1160
1160
|
|
|
1161
1161
|
// Convert hex message to bytes
|
|
1162
1162
|
const mBytes = typeof m === 'string' ? hexToBytes(m) : m;
|
|
1163
|
-
const mu =
|
|
1163
|
+
const mu = sha3_js.shake256.create({}).update(tr).update(mBytes).xof(CRHBytes);
|
|
1164
1164
|
|
|
1165
1165
|
if (randomizedSigning) {
|
|
1166
1166
|
rhoPrime = new Uint8Array(randomBytes(CRHBytes));
|
|
1167
1167
|
} else {
|
|
1168
|
-
rhoPrime =
|
|
1168
|
+
rhoPrime = sha3_js.shake256.create({}).update(key).update(mu).xof(CRHBytes);
|
|
1169
1169
|
}
|
|
1170
1170
|
|
|
1171
1171
|
polyVecMatrixExpand(mat, rho);
|
|
@@ -1187,7 +1187,7 @@ function cryptoSignSignature(sig, m, sk, randomizedSigning) {
|
|
|
1187
1187
|
polyVecKDecompose(w1, w0, w1);
|
|
1188
1188
|
polyVecKPackW1(sig, w1);
|
|
1189
1189
|
|
|
1190
|
-
const cHash =
|
|
1190
|
+
const cHash = sha3_js.shake256
|
|
1191
1191
|
.create({})
|
|
1192
1192
|
.update(mu)
|
|
1193
1193
|
.update(sig.slice(0, K * PolyW1PackedBytes))
|
|
@@ -1308,12 +1308,12 @@ function cryptoSignVerify(sig, m, pk) {
|
|
|
1308
1308
|
}
|
|
1309
1309
|
|
|
1310
1310
|
/* Compute CRH(H(rho, t1), msg) */
|
|
1311
|
-
const tr =
|
|
1311
|
+
const tr = sha3_js.shake256.create({}).update(pk).xof(TRBytes);
|
|
1312
1312
|
mu.set(tr);
|
|
1313
1313
|
|
|
1314
1314
|
// Convert hex message to bytes
|
|
1315
1315
|
const mBytes = typeof m === 'string' ? hexToBytes(m) : m;
|
|
1316
|
-
const muFull =
|
|
1316
|
+
const muFull = sha3_js.shake256.create({}).update(mu.slice(0, TRBytes)).update(mBytes).xof(CRHBytes);
|
|
1317
1317
|
mu.set(muFull);
|
|
1318
1318
|
|
|
1319
1319
|
/* Matrix-vector multiplication; compute Az - c2^dt1 */
|
|
@@ -1338,7 +1338,7 @@ function cryptoSignVerify(sig, m, pk) {
|
|
|
1338
1338
|
polyVecKPackW1(buf, w1);
|
|
1339
1339
|
|
|
1340
1340
|
/* Call random oracle and verify challenge */
|
|
1341
|
-
const c2Hash =
|
|
1341
|
+
const c2Hash = sha3_js.shake256.create({}).update(mu).update(buf).xof(SeedBytes);
|
|
1342
1342
|
c2.set(c2Hash);
|
|
1343
1343
|
|
|
1344
1344
|
// Constant-time comparison to prevent timing attacks
|
package/dist/mjs/dilithium5.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theqrl/dilithium5",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Dilithium-5 cryptography",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dilithium",
|
|
@@ -48,19 +48,20 @@
|
|
|
48
48
|
},
|
|
49
49
|
"type": "module",
|
|
50
50
|
"devDependencies": {
|
|
51
|
+
"@eslint/js": "^9.39.0",
|
|
51
52
|
"c8": "^10.1.3",
|
|
52
|
-
"chai": "^
|
|
53
|
-
"eslint": "^
|
|
54
|
-
"eslint-config-
|
|
55
|
-
"eslint-
|
|
56
|
-
"eslint-plugin-import": "^2.32.0",
|
|
53
|
+
"chai": "^6.2.2",
|
|
54
|
+
"eslint": "^9.39.2",
|
|
55
|
+
"eslint-config-prettier": "^10.1.8",
|
|
56
|
+
"eslint-plugin-import-x": "^4.15.0",
|
|
57
57
|
"eslint-plugin-prettier": "^5.5.4",
|
|
58
|
-
"
|
|
58
|
+
"globals": "^16.2.0",
|
|
59
|
+
"mocha": "^11.7.5",
|
|
59
60
|
"prettier": "^3.7.4",
|
|
60
61
|
"rollup": "^4.55.1"
|
|
61
62
|
},
|
|
62
63
|
"dependencies": {
|
|
63
|
-
"@noble/hashes": "^
|
|
64
|
+
"@noble/hashes": "^2.0.1",
|
|
64
65
|
"randombytes": "^2.1.0"
|
|
65
66
|
}
|
|
66
67
|
}
|