@noble/post-quantum 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +158 -180
- package/_crystals.d.ts +0 -1
- package/_crystals.d.ts.map +1 -1
- package/_crystals.js +1 -31
- package/_crystals.js.map +1 -1
- package/esm/_crystals.d.ts +33 -0
- package/esm/_crystals.d.ts.map +1 -0
- package/esm/_crystals.js +0 -30
- package/esm/_crystals.js.map +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/ml-dsa.d.ts +44 -0
- package/esm/ml-dsa.d.ts.map +1 -0
- package/esm/ml-dsa.js +67 -88
- package/esm/ml-dsa.js.map +1 -1
- package/esm/ml-kem.d.ts +55 -0
- package/esm/ml-kem.d.ts.map +1 -0
- package/esm/ml-kem.js +26 -83
- package/esm/ml-kem.js.map +1 -1
- package/esm/slh-dsa.d.ts +46 -0
- package/esm/slh-dsa.d.ts.map +1 -0
- package/esm/slh-dsa.js +27 -111
- package/esm/slh-dsa.js.map +1 -1
- package/esm/utils.d.ts +38 -0
- package/esm/utils.d.ts.map +1 -0
- package/esm/utils.js +2 -1
- package/esm/utils.js.map +1 -1
- package/ml-dsa.d.ts +27 -20
- package/ml-dsa.d.ts.map +1 -1
- package/ml-dsa.js +66 -87
- package/ml-dsa.js.map +1 -1
- package/ml-kem.d.ts +1 -80
- package/ml-kem.d.ts.map +1 -1
- package/ml-kem.js +26 -83
- package/ml-kem.js.map +1 -1
- package/package.json +14 -22
- package/slh-dsa.d.ts +0 -24
- package/slh-dsa.d.ts.map +1 -1
- package/slh-dsa.js +27 -111
- package/slh-dsa.js.map +1 -1
- package/src/_crystals.ts +0 -33
- package/src/ml-dsa.ts +75 -92
- package/src/ml-kem.ts +28 -87
- package/src/slh-dsa.ts +27 -121
- package/src/utils.ts +2 -1
- package/utils.d.ts +2 -2
- package/utils.d.ts.map +1 -1
- package/utils.js +7 -6
- package/utils.js.map +1 -1
package/src/slh-dsa.ts
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
import { HMAC } from '@noble/hashes/hmac';
|
3
3
|
import { sha256, sha512 } from '@noble/hashes/sha2';
|
4
4
|
import { shake256 } from '@noble/hashes/sha3';
|
5
|
-
import { bytesToHex, hexToBytes, createView, concatBytes
|
5
|
+
import { bytesToHex, hexToBytes, createView, concatBytes } from '@noble/hashes/utils';
|
6
6
|
import {
|
7
7
|
Signer,
|
8
8
|
cleanBytes,
|
@@ -19,11 +19,6 @@ Hash-based digital signature algorithm. See [official site](https://sphincs.org)
|
|
19
19
|
We implement spec v3.1 with latest FIPS-205 changes.
|
20
20
|
It's compatible with the latest version in the [official repo](https://github.com/sphincs/sphincsplus).
|
21
21
|
|
22
|
-
Three versions are provided:
|
23
|
-
|
24
|
-
1. SHAKE256-based
|
25
|
-
2. SHA2-based
|
26
|
-
3. SLH-DSA aka [FIPS-205](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.205.ipd.pdf)
|
27
22
|
*/
|
28
23
|
|
29
24
|
/*
|
@@ -102,8 +97,7 @@ export type GetContext = (
|
|
102
97
|
|
103
98
|
function hexToNumber(hex: string): bigint {
|
104
99
|
if (typeof hex !== 'string') throw new Error('hex string expected, got ' + typeof hex);
|
105
|
-
// Big Endian
|
106
|
-
return BigInt(hex === '' ? '0' : `0x${hex}`);
|
100
|
+
return BigInt(hex === '' ? '0' : '0x' + hex); // Big Endian
|
107
101
|
}
|
108
102
|
|
109
103
|
// BE: Big Endian, LE: Little Endian
|
@@ -115,32 +109,20 @@ function numberToBytesBE(n: number | bigint, len: number): Uint8Array {
|
|
115
109
|
return hexToBytes(n.toString(16).padStart(len * 2, '0'));
|
116
110
|
}
|
117
111
|
|
118
|
-
// Same as bitsCoder.decode, but bits are BE instead of LE (so we cannot re-use it).
|
119
|
-
// NOTE: difference happens only if d < 8.
|
120
|
-
const base_2bBE = (N: number, d: number) => {
|
121
|
-
const mask = getMask(d);
|
122
|
-
return (bytes: Uint8Array) => {
|
123
|
-
const r = new Uint32Array(N);
|
124
|
-
for (let i = 0, buf = 0, bufLen = 0, pos = 0; i < bytes.length; i++) {
|
125
|
-
buf |= bytes[i] << bufLen;
|
126
|
-
bufLen += 8;
|
127
|
-
for (; bufLen >= d; bufLen -= d) r[pos++] = (buf >>> (bufLen - d)) & mask;
|
128
|
-
buf &= getMask(bufLen);
|
129
|
-
}
|
130
|
-
return r;
|
131
|
-
};
|
132
|
-
};
|
133
112
|
// Same as bitsCoder.decode, but maybe spec will change and unify with base2bBE.
|
134
|
-
const
|
135
|
-
const mask = getMask(
|
113
|
+
const base2b = (outLen: number, b: number) => {
|
114
|
+
const mask = getMask(b);
|
136
115
|
return (bytes: Uint8Array) => {
|
137
|
-
const
|
138
|
-
for (let
|
139
|
-
|
140
|
-
|
141
|
-
|
116
|
+
const baseB = new Uint32Array(outLen);
|
117
|
+
for (let out = 0, pos = 0, bits = 0, total = 0; out < outLen; out++) {
|
118
|
+
while (bits < b) {
|
119
|
+
total = (total << 8) | bytes[pos++];
|
120
|
+
bits += 8;
|
121
|
+
}
|
122
|
+
bits -= b;
|
123
|
+
baseB[out] = (total >>> bits) & mask;
|
142
124
|
}
|
143
|
-
return
|
125
|
+
return baseB;
|
144
126
|
};
|
145
127
|
};
|
146
128
|
|
@@ -220,9 +202,9 @@ function gen(opts: SphincsOpts, hashOpts: SphincsHashOpts): SphincsSigner {
|
|
220
202
|
return addr;
|
221
203
|
};
|
222
204
|
|
223
|
-
const chainCoder =
|
205
|
+
const chainCoder = base2b(WOTS_LEN2, WOTS_LOGW);
|
224
206
|
const chainLengths = (msg: Uint8Array) => {
|
225
|
-
const W1 =
|
207
|
+
const W1 = base2b(WOTS_LEN1, WOTS_LOGW)(msg);
|
226
208
|
let csum = 0;
|
227
209
|
for (let i = 0; i < W1.length; i++) csum += W - 1 - W1[i]; // ▷ Compute checksum
|
228
210
|
csum <<= (8 - ((WOTS_LEN2 * WOTS_LOGW) % 8)) % 8; // csum ← csum ≪ ((8 − ((len2 · lg(w)) mod 8)) mod 8
|
@@ -234,9 +216,7 @@ function gen(opts: SphincsOpts, hashOpts: SphincsHashOpts): SphincsSigner {
|
|
234
216
|
lengths.set(W2, W1.length);
|
235
217
|
return lengths;
|
236
218
|
};
|
237
|
-
|
238
|
-
const msgCoder = base_2bLE(K, A);
|
239
|
-
const messageToIndices = (msg: Uint8Array) => msgCoder(msg);
|
219
|
+
const messageToIndices = base2b(K, A);
|
240
220
|
|
241
221
|
const TREE_BITS = TREE_HEIGHT * (D - 1);
|
242
222
|
const LEAF_BITS = TREE_HEIGHT;
|
@@ -542,15 +522,12 @@ function gen(opts: SphincsOpts, hashOpts: SphincsHashOpts): SphincsSigner {
|
|
542
522
|
}
|
543
523
|
|
544
524
|
const genShake =
|
545
|
-
(
|
546
|
-
(opts: SphincsOpts) =>
|
547
|
-
(pubSeed: Uint8Array, skSeed?: Uint8Array) => {
|
548
|
-
const ADDR_BYTES = 32;
|
525
|
+
(): GetContext => (opts: SphincsOpts) => (pubSeed: Uint8Array, skSeed?: Uint8Array) => {
|
549
526
|
const { N } = opts;
|
550
527
|
const stats = { prf: 0, thash: 0, hmsg: 0, gen_message_random: 0 };
|
551
528
|
const h0 = shake256.create({}).update(pubSeed);
|
552
529
|
const h0tmp = h0.clone();
|
553
|
-
const
|
530
|
+
const thash = (blocks: number, input: Uint8Array, addr: ADRS) => {
|
554
531
|
stats.thash++;
|
555
532
|
return h0
|
556
533
|
._cloneInto(h0tmp)
|
@@ -558,24 +535,12 @@ const genShake =
|
|
558
535
|
.update(input.subarray(0, blocks * N))
|
559
536
|
.xof(N);
|
560
537
|
};
|
561
|
-
const thash_robust = (blocks: number, input: Uint8Array, addr: ADRS) => {
|
562
|
-
stats.thash++;
|
563
|
-
const buf = new Uint8Array(ADDR_BYTES + (blocks + 1) * N);
|
564
|
-
buf.subarray(0, N).set(pubSeed);
|
565
|
-
buf.subarray(N, N + ADDR_BYTES).set(addr);
|
566
|
-
shake256
|
567
|
-
.create({})
|
568
|
-
.update(buf.subarray(0, N + ADDR_BYTES))
|
569
|
-
.xofInto(buf.subarray(N + ADDR_BYTES));
|
570
|
-
for (let i = 0; i < blocks * N; i++) buf[N + ADDR_BYTES + i] ^= input[i];
|
571
|
-
return shake256.create({}).update(buf).xof(N);
|
572
|
-
};
|
573
|
-
const thash = robust ? thash_robust : thash_simple;
|
574
538
|
return {
|
575
539
|
PRFaddr: (addr: ADRS) => {
|
576
540
|
if (!skSeed) throw new Error('no sk seed');
|
577
541
|
stats.prf++;
|
578
|
-
|
542
|
+
const res = h0._cloneInto(h0tmp).update(addr).update(skSeed).xof(N);
|
543
|
+
return res;
|
579
544
|
},
|
580
545
|
PRFmsg: (skPRF: Uint8Array, random: Uint8Array, msg: Uint8Array) => {
|
581
546
|
stats.gen_message_random++;
|
@@ -595,21 +560,7 @@ const genShake =
|
|
595
560
|
};
|
596
561
|
};
|
597
562
|
|
598
|
-
const SHAKE_SIMPLE = { getContext: genShake(
|
599
|
-
const SHAKE_ROBUST = { getContext: genShake(true) };
|
600
|
-
|
601
|
-
export const sphincs_shake_128f_simple = /* @__PURE__ */ gen(PARAMS['128f'], SHAKE_SIMPLE);
|
602
|
-
export const sphincs_shake_128f_robust = /* @__PURE__ */ gen(PARAMS['128f'], SHAKE_ROBUST);
|
603
|
-
export const sphincs_shake_128s_simple = /* @__PURE__ */ gen(PARAMS['128s'], SHAKE_SIMPLE);
|
604
|
-
export const sphincs_shake_128s_robust = /* @__PURE__ */ gen(PARAMS['128s'], SHAKE_ROBUST);
|
605
|
-
export const sphincs_shake_192f_simple = /* @__PURE__ */ gen(PARAMS['192f'], SHAKE_SIMPLE);
|
606
|
-
export const sphincs_shake_192f_robust = /* @__PURE__ */ gen(PARAMS['192f'], SHAKE_ROBUST);
|
607
|
-
export const sphincs_shake_192s_simple = /* @__PURE__ */ gen(PARAMS['192s'], SHAKE_SIMPLE);
|
608
|
-
export const sphincs_shake_192s_robust = /* @__PURE__ */ gen(PARAMS['192s'], SHAKE_ROBUST);
|
609
|
-
export const sphincs_shake_256f_simple = /* @__PURE__ */ gen(PARAMS['256f'], SHAKE_SIMPLE);
|
610
|
-
export const sphincs_shake_256f_robust = /* @__PURE__ */ gen(PARAMS['256f'], SHAKE_ROBUST);
|
611
|
-
export const sphincs_shake_256s_simple = /* @__PURE__ */ gen(PARAMS['256s'], SHAKE_SIMPLE);
|
612
|
-
export const sphincs_shake_256s_robust = /* @__PURE__ */ gen(PARAMS['256s'], SHAKE_ROBUST);
|
563
|
+
const SHAKE_SIMPLE = { getContext: genShake() };
|
613
564
|
|
614
565
|
// Only simple mode in SLH-DSA
|
615
566
|
export const slh_dsa_shake_128f = /* @__PURE__ */ gen(PARAMS['128f'], SHAKE_SIMPLE);
|
@@ -621,7 +572,7 @@ export const slh_dsa_shake_256s = /* @__PURE__ */ gen(PARAMS['256s'], SHAKE_SIMP
|
|
621
572
|
|
622
573
|
type ShaType = typeof sha256 | typeof sha512;
|
623
574
|
const genSha =
|
624
|
-
(h0: ShaType, h1: ShaType
|
575
|
+
(h0: ShaType, h1: ShaType): GetContext =>
|
625
576
|
(opts) =>
|
626
577
|
(pub_seed, sk_seed?) => {
|
627
578
|
const { N } = opts;
|
@@ -660,7 +611,7 @@ const genSha =
|
|
660
611
|
return out.subarray(0, length);
|
661
612
|
}
|
662
613
|
|
663
|
-
const
|
614
|
+
const thash =
|
664
615
|
(_: ShaType, h: typeof h0ps, hTmp: typeof h0ps) =>
|
665
616
|
(blocks: number, input: Uint8Array, addr: ADRS) => {
|
666
617
|
stats.thash++;
|
@@ -671,40 +622,17 @@ const genSha =
|
|
671
622
|
.digest();
|
672
623
|
return d.subarray(0, N);
|
673
624
|
};
|
674
|
-
|
675
|
-
const thash_robust =
|
676
|
-
(sha: ShaType, h: typeof h0ps, _: typeof h0ps) =>
|
677
|
-
(blocks: number, input: Uint8Array, addr: ADRS) => {
|
678
|
-
stats.thash++;
|
679
|
-
stats.mgf1++;
|
680
|
-
// inlined mgf1
|
681
|
-
const addr8 = addr;
|
682
|
-
const hh = sha.create().update(pub_seed).update(addr8);
|
683
|
-
let bitmask = new Uint8Array(Math.ceil((blocks * N) / sha.outputLen) * sha.outputLen);
|
684
|
-
for (let counter = 0, o = bitmask; o.length; counter++) {
|
685
|
-
counterV.setUint32(0, counter, false);
|
686
|
-
hh.clone().update(counterB).digestInto(o);
|
687
|
-
o = o.subarray(sha.outputLen);
|
688
|
-
}
|
689
|
-
bitmask = bitmask.subarray(0, blocks * N);
|
690
|
-
const ou32 = u32(input);
|
691
|
-
const bm32 = u32(bitmask);
|
692
|
-
for (let i = 0; i < bm32.length; i++) bm32[i] ^= ou32[i];
|
693
|
-
const d = h.clone().update(addr8).update(bitmask).digest();
|
694
|
-
return d.subarray(0, N);
|
695
|
-
};
|
696
|
-
|
697
|
-
const thash = robust ? thash_robust : thash_simple;
|
698
625
|
return {
|
699
626
|
PRFaddr: (addr: ADRS) => {
|
700
627
|
if (!sk_seed) throw new Error('No sk seed');
|
701
628
|
stats.prf++;
|
702
|
-
|
629
|
+
const res = h0ps
|
703
630
|
._cloneInto(h0tmp as any)
|
704
631
|
.update(addr)
|
705
632
|
.update(sk_seed)
|
706
633
|
.digest()
|
707
634
|
.subarray(0, N);
|
635
|
+
return res;
|
708
636
|
},
|
709
637
|
PRFmsg: (skPRF: Uint8Array, random: Uint8Array, msg: Uint8Array) => {
|
710
638
|
stats.gen_message_random++;
|
@@ -733,34 +661,12 @@ const genSha =
|
|
733
661
|
|
734
662
|
const SHA256_SIMPLE = {
|
735
663
|
isCompressed: true,
|
736
|
-
getContext: genSha(sha256, sha256
|
737
|
-
};
|
738
|
-
const SHA256_ROBUST = {
|
739
|
-
isCompressed: true,
|
740
|
-
getContext: genSha(sha256, sha256, true),
|
664
|
+
getContext: genSha(sha256, sha256),
|
741
665
|
};
|
742
666
|
const SHA512_SIMPLE = {
|
743
667
|
isCompressed: true,
|
744
|
-
getContext: genSha(sha256, sha512
|
668
|
+
getContext: genSha(sha256, sha512),
|
745
669
|
};
|
746
|
-
const SHA512_ROBUST = {
|
747
|
-
isCompressed: true,
|
748
|
-
getContext: genSha(sha256, sha512, true),
|
749
|
-
};
|
750
|
-
|
751
|
-
export const sphincs_sha2_128f_simple = /* @__PURE__ */ gen(PARAMS['128f'], SHA256_SIMPLE);
|
752
|
-
export const sphincs_sha2_128f_robust = /* @__PURE__ */ gen(PARAMS['128f'], SHA256_ROBUST);
|
753
|
-
export const sphincs_sha2_128s_simple = /* @__PURE__ */ gen(PARAMS['128s'], SHA256_SIMPLE);
|
754
|
-
export const sphincs_sha2_128s_robust = /* @__PURE__ */ gen(PARAMS['128s'], SHA256_ROBUST);
|
755
|
-
|
756
|
-
export const sphincs_sha2_192f_simple = /* @__PURE__ */ gen(PARAMS['192f'], SHA512_SIMPLE);
|
757
|
-
export const sphincs_sha2_192f_robust = /* @__PURE__ */ gen(PARAMS['192f'], SHA512_ROBUST);
|
758
|
-
export const sphincs_sha2_192s_simple = /* @__PURE__ */ gen(PARAMS['192s'], SHA512_SIMPLE);
|
759
|
-
export const sphincs_sha2_192s_robust = /* @__PURE__ */ gen(PARAMS['192s'], SHA512_ROBUST);
|
760
|
-
export const sphincs_sha2_256f_simple = /* @__PURE__ */ gen(PARAMS['256f'], SHA512_SIMPLE);
|
761
|
-
export const sphincs_sha2_256f_robust = /* @__PURE__ */ gen(PARAMS['256f'], SHA512_ROBUST);
|
762
|
-
export const sphincs_sha2_256s_simple = /* @__PURE__ */ gen(PARAMS['256s'], SHA512_SIMPLE);
|
763
|
-
export const sphincs_sha2_256s_robust = /* @__PURE__ */ gen(PARAMS['256s'], SHA512_ROBUST);
|
764
670
|
|
765
671
|
// Only simple mode in SLH-DSA
|
766
672
|
export const slh_dsa_sha2_128f = /* @__PURE__ */ gen(PARAMS['128f'], SHA256_SIMPLE);
|
package/src/utils.ts
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */
|
2
2
|
import { bytes as abytes } from '@noble/hashes/_assert';
|
3
|
-
import { TypedArray, randomBytes as randb } from '@noble/hashes/utils';
|
3
|
+
import { TypedArray, randomBytes as randb, concatBytes } from '@noble/hashes/utils';
|
4
4
|
|
5
5
|
export const ensureBytes = abytes;
|
6
6
|
export const randomBytes = randb;
|
7
|
+
export { concatBytes };
|
7
8
|
|
8
9
|
// Compares 2 u8a-s in kinda constant time
|
9
10
|
export function equalBytes(a: Uint8Array, b: Uint8Array) {
|
package/utils.d.ts
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */
|
2
2
|
import { bytes as abytes } from '@noble/hashes/_assert';
|
3
|
-
import { TypedArray, randomBytes as randb } from '@noble/hashes/utils';
|
3
|
+
import { TypedArray, randomBytes as randb, concatBytes } from '@noble/hashes/utils';
|
4
4
|
export declare const ensureBytes: typeof abytes;
|
5
5
|
export declare const randomBytes: typeof randb;
|
6
|
+
export { concatBytes };
|
6
7
|
export declare function equalBytes(a: Uint8Array, b: Uint8Array): boolean;
|
7
8
|
export type Signer = {
|
8
9
|
signRandBytes: number;
|
@@ -34,5 +35,4 @@ export declare function splitCoder<T extends (number | BytesCoderLen<any>)[]>(..
|
|
34
35
|
export declare function vecCoder<T>(c: BytesCoderLen<T>, vecLen: number): BytesCoderLen<T[]>;
|
35
36
|
export declare function cleanBytes(...list: (TypedArray | TypedArray[])[]): void;
|
36
37
|
export declare function getMask(bits: number): number;
|
37
|
-
export {};
|
38
38
|
//# sourceMappingURL=utils.d.ts.map
|
package/utils.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["src/utils.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,OAAO,EAAE,KAAK,IAAI,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,WAAW,IAAI,KAAK,EAAE,MAAM,qBAAqB,CAAC;
|
1
|
+
{"version":3,"file":"ut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AU,CAAC,CAAC,CAAC,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAGpE,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAC5D,KAAK,QAAQ,CAAC,CAAC,SAAS,CAAC,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI;KACxD,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACjE,CAAC;AACF,wBAAgB,UAAU,CAAC,CAAC,SAAS,CAAC,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,EAClE,GAAG,OAAO,EAAE,CAAC,GACZ,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CA8BhD;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC,CAAC,EAAE,CAAC,CAwBnF;AAGD,wBAAgB,UAAU,CAAC,GAAG,IAAI,EAAE,CAAC,UAAU,GAAG,UAAU,EAAE,CAAC,EAAE,QAKhE;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,UAEnC"}
|
package/utils.js
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.concatBytes = exports.randomBytes = exports.ensureBytes = void 0;
|
4
|
+
exports.equalBytes = equalBytes;
|
5
|
+
exports.splitCoder = splitCoder;
|
6
|
+
exports.vecCoder = vecCoder;
|
7
|
+
exports.cleanBytes = cleanBytes;
|
8
|
+
exports.getMask = getMask;
|
4
9
|
/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */
|
5
10
|
const _assert_1 = require("@noble/hashes/_assert");
|
6
11
|
const utils_1 = require("@noble/hashes/utils");
|
12
|
+
Object.defineProperty(exports, "concatBytes", { enumerable: true, get: function () { return utils_1.concatBytes; } });
|
7
13
|
exports.ensureBytes = _assert_1.bytes;
|
8
14
|
exports.randomBytes = utils_1.randomBytes;
|
9
15
|
// Compares 2 u8a-s in kinda constant time
|
@@ -15,7 +21,6 @@ function equalBytes(a, b) {
|
|
15
21
|
diff |= a[i] ^ b[i];
|
16
22
|
return diff === 0;
|
17
23
|
}
|
18
|
-
exports.equalBytes = equalBytes;
|
19
24
|
function splitCoder(...lengths) {
|
20
25
|
const getLength = (c) => (typeof c === 'number' ? c : c.bytesLen);
|
21
26
|
const bytesLen = lengths.reduce((sum, a) => sum + getLength(a), 0);
|
@@ -48,7 +53,6 @@ function splitCoder(...lengths) {
|
|
48
53
|
},
|
49
54
|
};
|
50
55
|
}
|
51
|
-
exports.splitCoder = splitCoder;
|
52
56
|
// nano-packed.array (fixed size)
|
53
57
|
function vecCoder(c, vecLen) {
|
54
58
|
const bytesLen = vecLen * c.bytesLen;
|
@@ -75,7 +79,6 @@ function vecCoder(c, vecLen) {
|
|
75
79
|
},
|
76
80
|
};
|
77
81
|
}
|
78
|
-
exports.vecCoder = vecCoder;
|
79
82
|
// cleanBytes(new Uint8Array(), [new Uint16Array(), new Uint32Array()])
|
80
83
|
function cleanBytes(...list) {
|
81
84
|
for (const t of list) {
|
@@ -86,9 +89,7 @@ function cleanBytes(...list) {
|
|
86
89
|
t.fill(0);
|
87
90
|
}
|
88
91
|
}
|
89
|
-
exports.cleanBytes = cleanBytes;
|
90
92
|
function getMask(bits) {
|
91
93
|
return (1 << bits) - 1; // 4 -> 0b1111
|
92
94
|
}
|
93
|
-
exports.getMask = getMask;
|
94
95
|
//# sourceMappingURL=utils.js.map
|
package/utils.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["src/utils.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["src/utils.ts"],"names":[],"mappings":";;;AASA,gCAKC;AA6BD,gCAgCC;AAED,4BAwBC;AAGD,gCAKC;AAED,0BAEC;AAjHD,4EAA4E;AAC5E,mDAAwD;AACxD,+CAAoF;AAI3E,4FAJkC,mBAAW,OAIlC;AAFP,QAAA,WAAW,GAAG,eAAM,CAAC;AACrB,QAAA,WAAW,GAAG,mBAAK,CAAC;AAGjC,0CAA0C;AAC1C,SAAgB,UAAU,CAAC,CAAa,EAAE,CAAa;IACrD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACxC,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACvD,OAAO,IAAI,KAAK,CAAC,CAAC;AACpB,CAAC;AA6BD,SAAgB,UAAU,CACxB,GAAG,OAAU;IAEb,MAAM,SAAS,GAAG,CAAC,CAA8B,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC/F,MAAM,QAAQ,GAAW,OAAO,CAAC,MAAM,CAAC,CAAC,GAAW,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACnF,OAAO;QACL,QAAQ;QACR,MAAM,EAAE,CAAC,IAAO,EAAE,EAAE;YAClB,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,QAAQ,CAAC,CAA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