@ocap/mcrypto 1.30.23 → 1.30.25
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/esm/crypter/aes-legacy.d.mts +11 -0
- package/esm/crypter/aes-legacy.mjs +67 -15
- package/esm/crypter/aes.d.mts +14 -2
- package/esm/crypter/aes.mjs +69 -3
- package/esm/encode.mjs +1 -1
- package/esm/hasher/keccak.mjs +7 -2
- package/esm/hasher/sha2.d.mts +1 -1
- package/esm/hasher/sha2.mjs +26 -11
- package/esm/hasher/sha3.d.mts +1 -1
- package/esm/hasher/sha3.mjs +21 -6
- package/esm/index.d.mts +1 -1
- package/esm/signer/ed25519.d.mts +1 -1
- package/esm/signer/ed25519.mjs +143 -16
- package/esm/signer/ethereum.mjs +7 -3
- package/esm/signer/secp256k1.mjs +3 -2
- package/esm/webauthn.d.mts +68 -2
- package/esm/webauthn.mjs +64 -16
- package/lib/_vendor/@noble/curves/LICENSE +21 -0
- package/lib/_vendor/@noble/curves/abstract/curve.cjs +373 -0
- package/lib/_vendor/@noble/curves/abstract/modular.cjs +616 -0
- package/lib/_vendor/@noble/curves/abstract/weierstrass.cjs +1020 -0
- package/lib/_vendor/@noble/curves/nist.cjs +91 -0
- package/lib/_vendor/@noble/curves/secp256k1.cjs +73 -0
- package/lib/_vendor/@noble/curves/utils.cjs +463 -0
- package/lib/_vendor/@noble/ed25519/LICENSE +21 -0
- package/lib/_vendor/@noble/ed25519/index.cjs +512 -0
- package/lib/_vendor/@noble/hashes/LICENSE +21 -0
- package/lib/_vendor/@noble/hashes/_md.cjs +230 -0
- package/lib/_vendor/@noble/hashes/_u64.cjs +67 -0
- package/lib/_vendor/@noble/hashes/hmac.cjs +86 -0
- package/lib/_vendor/@noble/hashes/sha2.cjs +477 -0
- package/lib/_vendor/@noble/hashes/sha3.cjs +329 -0
- package/lib/_vendor/@noble/hashes/utils.cjs +410 -0
- package/lib/crypter/aes-legacy.cjs +68 -21
- package/lib/crypter/aes-legacy.d.cts +11 -0
- package/lib/crypter/aes.cjs +69 -2
- package/lib/crypter/aes.d.cts +14 -2
- package/lib/encode.cjs +1 -1
- package/lib/hasher/keccak.cjs +13 -8
- package/lib/hasher/sha2.cjs +32 -17
- package/lib/hasher/sha2.d.cts +1 -1
- package/lib/hasher/sha3.cjs +27 -12
- package/lib/hasher/sha3.d.cts +1 -1
- package/lib/index.d.cts +1 -1
- package/lib/signer/ed25519.cjs +146 -20
- package/lib/signer/ed25519.d.cts +1 -1
- package/lib/signer/ethereum.cjs +16 -12
- package/lib/signer/secp256k1.cjs +11 -10
- package/lib/webauthn.cjs +80 -31
- package/lib/webauthn.d.cts +68 -2
- package/package.json +6 -7
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
const require__u64 = require('./_u64.cjs');
|
|
2
|
+
const require_utils = require('./utils.cjs');
|
|
3
|
+
const require__md = require('./_md.cjs');
|
|
4
|
+
|
|
5
|
+
//#region ../../node_modules/@noble/hashes/sha2.js
|
|
6
|
+
/**
|
|
7
|
+
* SHA2 hash function. A.k.a. sha256, sha384, sha512, sha512_224, sha512_256.
|
|
8
|
+
* SHA256 is the fastest hash implementable in JS, even faster than Blake3.
|
|
9
|
+
* Check out {@link https://www.rfc-editor.org/rfc/rfc4634 | RFC 4634} and
|
|
10
|
+
* {@link https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf | FIPS 180-4}.
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* SHA-224 / SHA-256 round constants from RFC 6234 §5.1: the first 32 bits
|
|
15
|
+
* of the cube roots of the first 64 primes (2..311).
|
|
16
|
+
*/
|
|
17
|
+
const SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
18
|
+
1116352408,
|
|
19
|
+
1899447441,
|
|
20
|
+
3049323471,
|
|
21
|
+
3921009573,
|
|
22
|
+
961987163,
|
|
23
|
+
1508970993,
|
|
24
|
+
2453635748,
|
|
25
|
+
2870763221,
|
|
26
|
+
3624381080,
|
|
27
|
+
310598401,
|
|
28
|
+
607225278,
|
|
29
|
+
1426881987,
|
|
30
|
+
1925078388,
|
|
31
|
+
2162078206,
|
|
32
|
+
2614888103,
|
|
33
|
+
3248222580,
|
|
34
|
+
3835390401,
|
|
35
|
+
4022224774,
|
|
36
|
+
264347078,
|
|
37
|
+
604807628,
|
|
38
|
+
770255983,
|
|
39
|
+
1249150122,
|
|
40
|
+
1555081692,
|
|
41
|
+
1996064986,
|
|
42
|
+
2554220882,
|
|
43
|
+
2821834349,
|
|
44
|
+
2952996808,
|
|
45
|
+
3210313671,
|
|
46
|
+
3336571891,
|
|
47
|
+
3584528711,
|
|
48
|
+
113926993,
|
|
49
|
+
338241895,
|
|
50
|
+
666307205,
|
|
51
|
+
773529912,
|
|
52
|
+
1294757372,
|
|
53
|
+
1396182291,
|
|
54
|
+
1695183700,
|
|
55
|
+
1986661051,
|
|
56
|
+
2177026350,
|
|
57
|
+
2456956037,
|
|
58
|
+
2730485921,
|
|
59
|
+
2820302411,
|
|
60
|
+
3259730800,
|
|
61
|
+
3345764771,
|
|
62
|
+
3516065817,
|
|
63
|
+
3600352804,
|
|
64
|
+
4094571909,
|
|
65
|
+
275423344,
|
|
66
|
+
430227734,
|
|
67
|
+
506948616,
|
|
68
|
+
659060556,
|
|
69
|
+
883997877,
|
|
70
|
+
958139571,
|
|
71
|
+
1322822218,
|
|
72
|
+
1537002063,
|
|
73
|
+
1747873779,
|
|
74
|
+
1955562222,
|
|
75
|
+
2024104815,
|
|
76
|
+
2227730452,
|
|
77
|
+
2361852424,
|
|
78
|
+
2428436474,
|
|
79
|
+
2756734187,
|
|
80
|
+
3204031479,
|
|
81
|
+
3329325298
|
|
82
|
+
]);
|
|
83
|
+
/** Reusable SHA-224 / SHA-256 message schedule buffer `W_t` from RFC 6234 §6.2 step 1. */
|
|
84
|
+
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
85
|
+
/** Internal SHA-224 / SHA-256 compression engine from RFC 6234 §6.2. */
|
|
86
|
+
var SHA2_32B = class extends require__md.HashMD {
|
|
87
|
+
constructor(outputLen) {
|
|
88
|
+
super(64, outputLen, 8, false);
|
|
89
|
+
}
|
|
90
|
+
get() {
|
|
91
|
+
const { A, B, C, D, E, F, G, H } = this;
|
|
92
|
+
return [
|
|
93
|
+
A,
|
|
94
|
+
B,
|
|
95
|
+
C,
|
|
96
|
+
D,
|
|
97
|
+
E,
|
|
98
|
+
F,
|
|
99
|
+
G,
|
|
100
|
+
H
|
|
101
|
+
];
|
|
102
|
+
}
|
|
103
|
+
set(A, B, C, D, E, F, G, H) {
|
|
104
|
+
this.A = A | 0;
|
|
105
|
+
this.B = B | 0;
|
|
106
|
+
this.C = C | 0;
|
|
107
|
+
this.D = D | 0;
|
|
108
|
+
this.E = E | 0;
|
|
109
|
+
this.F = F | 0;
|
|
110
|
+
this.G = G | 0;
|
|
111
|
+
this.H = H | 0;
|
|
112
|
+
}
|
|
113
|
+
process(view, offset) {
|
|
114
|
+
for (let i = 0; i < 16; i++, offset += 4) SHA256_W[i] = view.getUint32(offset, false);
|
|
115
|
+
for (let i = 16; i < 64; i++) {
|
|
116
|
+
const W15 = SHA256_W[i - 15];
|
|
117
|
+
const W2 = SHA256_W[i - 2];
|
|
118
|
+
const s0 = require_utils.rotr(W15, 7) ^ require_utils.rotr(W15, 18) ^ W15 >>> 3;
|
|
119
|
+
SHA256_W[i] = (require_utils.rotr(W2, 17) ^ require_utils.rotr(W2, 19) ^ W2 >>> 10) + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
120
|
+
}
|
|
121
|
+
let { A, B, C, D, E, F, G, H } = this;
|
|
122
|
+
for (let i = 0; i < 64; i++) {
|
|
123
|
+
const sigma1 = require_utils.rotr(E, 6) ^ require_utils.rotr(E, 11) ^ require_utils.rotr(E, 25);
|
|
124
|
+
const T1 = H + sigma1 + require__md.Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
125
|
+
const T2 = (require_utils.rotr(A, 2) ^ require_utils.rotr(A, 13) ^ require_utils.rotr(A, 22)) + require__md.Maj(A, B, C) | 0;
|
|
126
|
+
H = G;
|
|
127
|
+
G = F;
|
|
128
|
+
F = E;
|
|
129
|
+
E = D + T1 | 0;
|
|
130
|
+
D = C;
|
|
131
|
+
C = B;
|
|
132
|
+
B = A;
|
|
133
|
+
A = T1 + T2 | 0;
|
|
134
|
+
}
|
|
135
|
+
A = A + this.A | 0;
|
|
136
|
+
B = B + this.B | 0;
|
|
137
|
+
C = C + this.C | 0;
|
|
138
|
+
D = D + this.D | 0;
|
|
139
|
+
E = E + this.E | 0;
|
|
140
|
+
F = F + this.F | 0;
|
|
141
|
+
G = G + this.G | 0;
|
|
142
|
+
H = H + this.H | 0;
|
|
143
|
+
this.set(A, B, C, D, E, F, G, H);
|
|
144
|
+
}
|
|
145
|
+
roundClean() {
|
|
146
|
+
require_utils.clean(SHA256_W);
|
|
147
|
+
}
|
|
148
|
+
destroy() {
|
|
149
|
+
this.destroyed = true;
|
|
150
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
151
|
+
require_utils.clean(this.buffer);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
/** Internal SHA-256 hash class grounded in RFC 6234 §6.2. */
|
|
155
|
+
var _SHA256 = class extends SHA2_32B {
|
|
156
|
+
A = require__md.SHA256_IV[0] | 0;
|
|
157
|
+
B = require__md.SHA256_IV[1] | 0;
|
|
158
|
+
C = require__md.SHA256_IV[2] | 0;
|
|
159
|
+
D = require__md.SHA256_IV[3] | 0;
|
|
160
|
+
E = require__md.SHA256_IV[4] | 0;
|
|
161
|
+
F = require__md.SHA256_IV[5] | 0;
|
|
162
|
+
G = require__md.SHA256_IV[6] | 0;
|
|
163
|
+
H = require__md.SHA256_IV[7] | 0;
|
|
164
|
+
constructor() {
|
|
165
|
+
super(32);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
/** Internal SHA-224 hash class grounded in RFC 6234 §6.2 and §8.5. */
|
|
169
|
+
var _SHA224 = class extends SHA2_32B {
|
|
170
|
+
A = require__md.SHA224_IV[0] | 0;
|
|
171
|
+
B = require__md.SHA224_IV[1] | 0;
|
|
172
|
+
C = require__md.SHA224_IV[2] | 0;
|
|
173
|
+
D = require__md.SHA224_IV[3] | 0;
|
|
174
|
+
E = require__md.SHA224_IV[4] | 0;
|
|
175
|
+
F = require__md.SHA224_IV[5] | 0;
|
|
176
|
+
G = require__md.SHA224_IV[6] | 0;
|
|
177
|
+
H = require__md.SHA224_IV[7] | 0;
|
|
178
|
+
constructor() {
|
|
179
|
+
super(28);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
const K512 = /* @__PURE__ */ (() => require__u64.split([
|
|
183
|
+
"0x428a2f98d728ae22",
|
|
184
|
+
"0x7137449123ef65cd",
|
|
185
|
+
"0xb5c0fbcfec4d3b2f",
|
|
186
|
+
"0xe9b5dba58189dbbc",
|
|
187
|
+
"0x3956c25bf348b538",
|
|
188
|
+
"0x59f111f1b605d019",
|
|
189
|
+
"0x923f82a4af194f9b",
|
|
190
|
+
"0xab1c5ed5da6d8118",
|
|
191
|
+
"0xd807aa98a3030242",
|
|
192
|
+
"0x12835b0145706fbe",
|
|
193
|
+
"0x243185be4ee4b28c",
|
|
194
|
+
"0x550c7dc3d5ffb4e2",
|
|
195
|
+
"0x72be5d74f27b896f",
|
|
196
|
+
"0x80deb1fe3b1696b1",
|
|
197
|
+
"0x9bdc06a725c71235",
|
|
198
|
+
"0xc19bf174cf692694",
|
|
199
|
+
"0xe49b69c19ef14ad2",
|
|
200
|
+
"0xefbe4786384f25e3",
|
|
201
|
+
"0x0fc19dc68b8cd5b5",
|
|
202
|
+
"0x240ca1cc77ac9c65",
|
|
203
|
+
"0x2de92c6f592b0275",
|
|
204
|
+
"0x4a7484aa6ea6e483",
|
|
205
|
+
"0x5cb0a9dcbd41fbd4",
|
|
206
|
+
"0x76f988da831153b5",
|
|
207
|
+
"0x983e5152ee66dfab",
|
|
208
|
+
"0xa831c66d2db43210",
|
|
209
|
+
"0xb00327c898fb213f",
|
|
210
|
+
"0xbf597fc7beef0ee4",
|
|
211
|
+
"0xc6e00bf33da88fc2",
|
|
212
|
+
"0xd5a79147930aa725",
|
|
213
|
+
"0x06ca6351e003826f",
|
|
214
|
+
"0x142929670a0e6e70",
|
|
215
|
+
"0x27b70a8546d22ffc",
|
|
216
|
+
"0x2e1b21385c26c926",
|
|
217
|
+
"0x4d2c6dfc5ac42aed",
|
|
218
|
+
"0x53380d139d95b3df",
|
|
219
|
+
"0x650a73548baf63de",
|
|
220
|
+
"0x766a0abb3c77b2a8",
|
|
221
|
+
"0x81c2c92e47edaee6",
|
|
222
|
+
"0x92722c851482353b",
|
|
223
|
+
"0xa2bfe8a14cf10364",
|
|
224
|
+
"0xa81a664bbc423001",
|
|
225
|
+
"0xc24b8b70d0f89791",
|
|
226
|
+
"0xc76c51a30654be30",
|
|
227
|
+
"0xd192e819d6ef5218",
|
|
228
|
+
"0xd69906245565a910",
|
|
229
|
+
"0xf40e35855771202a",
|
|
230
|
+
"0x106aa07032bbd1b8",
|
|
231
|
+
"0x19a4c116b8d2d0c8",
|
|
232
|
+
"0x1e376c085141ab53",
|
|
233
|
+
"0x2748774cdf8eeb99",
|
|
234
|
+
"0x34b0bcb5e19b48a8",
|
|
235
|
+
"0x391c0cb3c5c95a63",
|
|
236
|
+
"0x4ed8aa4ae3418acb",
|
|
237
|
+
"0x5b9cca4f7763e373",
|
|
238
|
+
"0x682e6ff3d6b2b8a3",
|
|
239
|
+
"0x748f82ee5defb2fc",
|
|
240
|
+
"0x78a5636f43172f60",
|
|
241
|
+
"0x84c87814a1f0ab72",
|
|
242
|
+
"0x8cc702081a6439ec",
|
|
243
|
+
"0x90befffa23631e28",
|
|
244
|
+
"0xa4506cebde82bde9",
|
|
245
|
+
"0xbef9a3f7b2c67915",
|
|
246
|
+
"0xc67178f2e372532b",
|
|
247
|
+
"0xca273eceea26619c",
|
|
248
|
+
"0xd186b8c721c0c207",
|
|
249
|
+
"0xeada7dd6cde0eb1e",
|
|
250
|
+
"0xf57d4f7fee6ed178",
|
|
251
|
+
"0x06f067aa72176fba",
|
|
252
|
+
"0x0a637dc5a2c898a6",
|
|
253
|
+
"0x113f9804bef90dae",
|
|
254
|
+
"0x1b710b35131c471b",
|
|
255
|
+
"0x28db77f523047d84",
|
|
256
|
+
"0x32caab7b40c72493",
|
|
257
|
+
"0x3c9ebe0a15c9bebc",
|
|
258
|
+
"0x431d67c49c100d4c",
|
|
259
|
+
"0x4cc5d4becb3e42b6",
|
|
260
|
+
"0x597f299cfc657e2a",
|
|
261
|
+
"0x5fcb6fab3ad6faec",
|
|
262
|
+
"0x6c44198c4a475817"
|
|
263
|
+
].map((n) => BigInt(n))))();
|
|
264
|
+
const SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
|
|
265
|
+
const SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
|
|
266
|
+
const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
267
|
+
const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
268
|
+
/** Internal SHA-384 / SHA-512 compression engine from RFC 6234 §6.4. */
|
|
269
|
+
var SHA2_64B = class extends require__md.HashMD {
|
|
270
|
+
constructor(outputLen) {
|
|
271
|
+
super(128, outputLen, 16, false);
|
|
272
|
+
}
|
|
273
|
+
get() {
|
|
274
|
+
const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
275
|
+
return [
|
|
276
|
+
Ah,
|
|
277
|
+
Al,
|
|
278
|
+
Bh,
|
|
279
|
+
Bl,
|
|
280
|
+
Ch,
|
|
281
|
+
Cl,
|
|
282
|
+
Dh,
|
|
283
|
+
Dl,
|
|
284
|
+
Eh,
|
|
285
|
+
El,
|
|
286
|
+
Fh,
|
|
287
|
+
Fl,
|
|
288
|
+
Gh,
|
|
289
|
+
Gl,
|
|
290
|
+
Hh,
|
|
291
|
+
Hl
|
|
292
|
+
];
|
|
293
|
+
}
|
|
294
|
+
set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
|
|
295
|
+
this.Ah = Ah | 0;
|
|
296
|
+
this.Al = Al | 0;
|
|
297
|
+
this.Bh = Bh | 0;
|
|
298
|
+
this.Bl = Bl | 0;
|
|
299
|
+
this.Ch = Ch | 0;
|
|
300
|
+
this.Cl = Cl | 0;
|
|
301
|
+
this.Dh = Dh | 0;
|
|
302
|
+
this.Dl = Dl | 0;
|
|
303
|
+
this.Eh = Eh | 0;
|
|
304
|
+
this.El = El | 0;
|
|
305
|
+
this.Fh = Fh | 0;
|
|
306
|
+
this.Fl = Fl | 0;
|
|
307
|
+
this.Gh = Gh | 0;
|
|
308
|
+
this.Gl = Gl | 0;
|
|
309
|
+
this.Hh = Hh | 0;
|
|
310
|
+
this.Hl = Hl | 0;
|
|
311
|
+
}
|
|
312
|
+
process(view, offset) {
|
|
313
|
+
for (let i = 0; i < 16; i++, offset += 4) {
|
|
314
|
+
SHA512_W_H[i] = view.getUint32(offset);
|
|
315
|
+
SHA512_W_L[i] = view.getUint32(offset += 4);
|
|
316
|
+
}
|
|
317
|
+
for (let i = 16; i < 80; i++) {
|
|
318
|
+
const W15h = SHA512_W_H[i - 15] | 0;
|
|
319
|
+
const W15l = SHA512_W_L[i - 15] | 0;
|
|
320
|
+
const s0h = require__u64.rotrSH(W15h, W15l, 1) ^ require__u64.rotrSH(W15h, W15l, 8) ^ require__u64.shrSH(W15h, W15l, 7);
|
|
321
|
+
const s0l = require__u64.rotrSL(W15h, W15l, 1) ^ require__u64.rotrSL(W15h, W15l, 8) ^ require__u64.shrSL(W15h, W15l, 7);
|
|
322
|
+
const W2h = SHA512_W_H[i - 2] | 0;
|
|
323
|
+
const W2l = SHA512_W_L[i - 2] | 0;
|
|
324
|
+
const s1h = require__u64.rotrSH(W2h, W2l, 19) ^ require__u64.rotrBH(W2h, W2l, 61) ^ require__u64.shrSH(W2h, W2l, 6);
|
|
325
|
+
const s1l = require__u64.rotrSL(W2h, W2l, 19) ^ require__u64.rotrBL(W2h, W2l, 61) ^ require__u64.shrSL(W2h, W2l, 6);
|
|
326
|
+
const SUMl = require__u64.add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
|
|
327
|
+
SHA512_W_H[i] = require__u64.add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]) | 0;
|
|
328
|
+
SHA512_W_L[i] = SUMl | 0;
|
|
329
|
+
}
|
|
330
|
+
let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
331
|
+
for (let i = 0; i < 80; i++) {
|
|
332
|
+
const sigma1h = require__u64.rotrSH(Eh, El, 14) ^ require__u64.rotrSH(Eh, El, 18) ^ require__u64.rotrBH(Eh, El, 41);
|
|
333
|
+
const sigma1l = require__u64.rotrSL(Eh, El, 14) ^ require__u64.rotrSL(Eh, El, 18) ^ require__u64.rotrBL(Eh, El, 41);
|
|
334
|
+
const CHIh = Eh & Fh ^ ~Eh & Gh;
|
|
335
|
+
const CHIl = El & Fl ^ ~El & Gl;
|
|
336
|
+
const T1ll = require__u64.add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
|
|
337
|
+
const T1h = require__u64.add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
|
|
338
|
+
const T1l = T1ll | 0;
|
|
339
|
+
const sigma0h = require__u64.rotrSH(Ah, Al, 28) ^ require__u64.rotrBH(Ah, Al, 34) ^ require__u64.rotrBH(Ah, Al, 39);
|
|
340
|
+
const sigma0l = require__u64.rotrSL(Ah, Al, 28) ^ require__u64.rotrBL(Ah, Al, 34) ^ require__u64.rotrBL(Ah, Al, 39);
|
|
341
|
+
const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
|
|
342
|
+
const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
|
|
343
|
+
Hh = Gh | 0;
|
|
344
|
+
Hl = Gl | 0;
|
|
345
|
+
Gh = Fh | 0;
|
|
346
|
+
Gl = Fl | 0;
|
|
347
|
+
Fh = Eh | 0;
|
|
348
|
+
Fl = El | 0;
|
|
349
|
+
({h: Eh, l: El} = require__u64.add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
350
|
+
Dh = Ch | 0;
|
|
351
|
+
Dl = Cl | 0;
|
|
352
|
+
Ch = Bh | 0;
|
|
353
|
+
Cl = Bl | 0;
|
|
354
|
+
Bh = Ah | 0;
|
|
355
|
+
Bl = Al | 0;
|
|
356
|
+
const All = require__u64.add3L(T1l, sigma0l, MAJl);
|
|
357
|
+
Ah = require__u64.add3H(All, T1h, sigma0h, MAJh);
|
|
358
|
+
Al = All | 0;
|
|
359
|
+
}
|
|
360
|
+
({h: Ah, l: Al} = require__u64.add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
|
361
|
+
({h: Bh, l: Bl} = require__u64.add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
|
|
362
|
+
({h: Ch, l: Cl} = require__u64.add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
|
363
|
+
({h: Dh, l: Dl} = require__u64.add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
|
364
|
+
({h: Eh, l: El} = require__u64.add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
|
365
|
+
({h: Fh, l: Fl} = require__u64.add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
|
366
|
+
({h: Gh, l: Gl} = require__u64.add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
|
367
|
+
({h: Hh, l: Hl} = require__u64.add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
|
368
|
+
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
369
|
+
}
|
|
370
|
+
roundClean() {
|
|
371
|
+
require_utils.clean(SHA512_W_H, SHA512_W_L);
|
|
372
|
+
}
|
|
373
|
+
destroy() {
|
|
374
|
+
this.destroyed = true;
|
|
375
|
+
require_utils.clean(this.buffer);
|
|
376
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
/** Internal SHA-512 hash class grounded in RFC 6234 §6.3 and §6.4. */
|
|
380
|
+
var _SHA512 = class extends SHA2_64B {
|
|
381
|
+
Ah = require__md.SHA512_IV[0] | 0;
|
|
382
|
+
Al = require__md.SHA512_IV[1] | 0;
|
|
383
|
+
Bh = require__md.SHA512_IV[2] | 0;
|
|
384
|
+
Bl = require__md.SHA512_IV[3] | 0;
|
|
385
|
+
Ch = require__md.SHA512_IV[4] | 0;
|
|
386
|
+
Cl = require__md.SHA512_IV[5] | 0;
|
|
387
|
+
Dh = require__md.SHA512_IV[6] | 0;
|
|
388
|
+
Dl = require__md.SHA512_IV[7] | 0;
|
|
389
|
+
Eh = require__md.SHA512_IV[8] | 0;
|
|
390
|
+
El = require__md.SHA512_IV[9] | 0;
|
|
391
|
+
Fh = require__md.SHA512_IV[10] | 0;
|
|
392
|
+
Fl = require__md.SHA512_IV[11] | 0;
|
|
393
|
+
Gh = require__md.SHA512_IV[12] | 0;
|
|
394
|
+
Gl = require__md.SHA512_IV[13] | 0;
|
|
395
|
+
Hh = require__md.SHA512_IV[14] | 0;
|
|
396
|
+
Hl = require__md.SHA512_IV[15] | 0;
|
|
397
|
+
constructor() {
|
|
398
|
+
super(64);
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
/** Internal SHA-384 hash class grounded in RFC 6234 §6.3 and §6.4. */
|
|
402
|
+
var _SHA384 = class extends SHA2_64B {
|
|
403
|
+
Ah = require__md.SHA384_IV[0] | 0;
|
|
404
|
+
Al = require__md.SHA384_IV[1] | 0;
|
|
405
|
+
Bh = require__md.SHA384_IV[2] | 0;
|
|
406
|
+
Bl = require__md.SHA384_IV[3] | 0;
|
|
407
|
+
Ch = require__md.SHA384_IV[4] | 0;
|
|
408
|
+
Cl = require__md.SHA384_IV[5] | 0;
|
|
409
|
+
Dh = require__md.SHA384_IV[6] | 0;
|
|
410
|
+
Dl = require__md.SHA384_IV[7] | 0;
|
|
411
|
+
Eh = require__md.SHA384_IV[8] | 0;
|
|
412
|
+
El = require__md.SHA384_IV[9] | 0;
|
|
413
|
+
Fh = require__md.SHA384_IV[10] | 0;
|
|
414
|
+
Fl = require__md.SHA384_IV[11] | 0;
|
|
415
|
+
Gh = require__md.SHA384_IV[12] | 0;
|
|
416
|
+
Gl = require__md.SHA384_IV[13] | 0;
|
|
417
|
+
Hh = require__md.SHA384_IV[14] | 0;
|
|
418
|
+
Hl = require__md.SHA384_IV[15] | 0;
|
|
419
|
+
constructor() {
|
|
420
|
+
super(48);
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
/**
|
|
424
|
+
* SHA2-256 hash function from RFC 4634. In JS it's the fastest: even faster than Blake3. Some info:
|
|
425
|
+
*
|
|
426
|
+
* - Trying 2^128 hashes would get 50% chance of collision, using birthday attack.
|
|
427
|
+
* - BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
|
|
428
|
+
* - Each sha256 hash is executing 2^18 bit operations.
|
|
429
|
+
* - Good 2024 ASICs can do 200Th/sec with 3500 watts of power, corresponding to 2^36 hashes/joule.
|
|
430
|
+
* @param msg - message bytes to hash
|
|
431
|
+
* @returns Digest bytes.
|
|
432
|
+
* @example
|
|
433
|
+
* Hash a message with SHA2-256.
|
|
434
|
+
* ```ts
|
|
435
|
+
* sha256(new Uint8Array([97, 98, 99]));
|
|
436
|
+
* ```
|
|
437
|
+
*/
|
|
438
|
+
const sha256 = /* @__PURE__ */ require_utils.createHasher(() => new _SHA256(), /* @__PURE__ */ require_utils.oidNist(1));
|
|
439
|
+
/**
|
|
440
|
+
* SHA2-224 hash function from RFC 4634.
|
|
441
|
+
* @param msg - message bytes to hash
|
|
442
|
+
* @returns Digest bytes.
|
|
443
|
+
* @example
|
|
444
|
+
* Hash a message with SHA2-224.
|
|
445
|
+
* ```ts
|
|
446
|
+
* sha224(new Uint8Array([97, 98, 99]));
|
|
447
|
+
* ```
|
|
448
|
+
*/
|
|
449
|
+
const sha224 = /* @__PURE__ */ require_utils.createHasher(() => new _SHA224(), /* @__PURE__ */ require_utils.oidNist(4));
|
|
450
|
+
/**
|
|
451
|
+
* SHA2-512 hash function from RFC 4634.
|
|
452
|
+
* @param msg - message bytes to hash
|
|
453
|
+
* @returns Digest bytes.
|
|
454
|
+
* @example
|
|
455
|
+
* Hash a message with SHA2-512.
|
|
456
|
+
* ```ts
|
|
457
|
+
* sha512(new Uint8Array([97, 98, 99]));
|
|
458
|
+
* ```
|
|
459
|
+
*/
|
|
460
|
+
const sha512 = /* @__PURE__ */ require_utils.createHasher(() => new _SHA512(), /* @__PURE__ */ require_utils.oidNist(3));
|
|
461
|
+
/**
|
|
462
|
+
* SHA2-384 hash function from RFC 4634.
|
|
463
|
+
* @param msg - message bytes to hash
|
|
464
|
+
* @returns Digest bytes.
|
|
465
|
+
* @example
|
|
466
|
+
* Hash a message with SHA2-384.
|
|
467
|
+
* ```ts
|
|
468
|
+
* sha384(new Uint8Array([97, 98, 99]));
|
|
469
|
+
* ```
|
|
470
|
+
*/
|
|
471
|
+
const sha384 = /* @__PURE__ */ require_utils.createHasher(() => new _SHA384(), /* @__PURE__ */ require_utils.oidNist(2));
|
|
472
|
+
|
|
473
|
+
//#endregion
|
|
474
|
+
exports.sha224 = sha224;
|
|
475
|
+
exports.sha256 = sha256;
|
|
476
|
+
exports.sha384 = sha384;
|
|
477
|
+
exports.sha512 = sha512;
|