@hpke/common
Version:
A Hybrid Public Key Encryption (HPKE) internal-use common module for @hpke family modules.
674 lines (673 loc) • 25.5 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "./md.js", "./u64.js", "../utils/noble.js", "./hash.js"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sha384 = exports.sha512 = exports.sha256 = exports._SHA384 = exports._SHA512 = exports._SHA256 = void 0;
/**
* This file is based on noble-hashes (https://github.com/paulmillr/noble-hashes).
*
* noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com)
*
* The original file is located at:
* https://github.com/paulmillr/noble-hashes/blob/2e0c00e1aa134082ba1380bf3afb8b1641f60fed/src/sha2.ts
*/
/**
* SHA2 hash function. A.k.a. sha256, sha384, sha512, sha512_224, sha512_256.
* SHA256 is the fastest hash implementable in JS, even faster than Blake3.
* Check out [RFC 4634](https://www.rfc-editor.org/rfc/rfc4634) and
* [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).
* @module
*/
const md_js_1 = require("./md.js");
const u64 = __importStar(require("./u64.js"));
const noble_js_1 = require("../utils/noble.js");
const hash_js_1 = require("./hash.js");
/**
* Round constants:
* First 32 bits of fractional parts of the cube roots of the first 64 primes 2..311)
*/
const SHA256_K = /* @__PURE__ */ Uint32Array.from([
0x428a2f98,
0x71374491,
0xb5c0fbcf,
0xe9b5dba5,
0x3956c25b,
0x59f111f1,
0x923f82a4,
0xab1c5ed5,
0xd807aa98,
0x12835b01,
0x243185be,
0x550c7dc3,
0x72be5d74,
0x80deb1fe,
0x9bdc06a7,
0xc19bf174,
0xe49b69c1,
0xefbe4786,
0x0fc19dc6,
0x240ca1cc,
0x2de92c6f,
0x4a7484aa,
0x5cb0a9dc,
0x76f988da,
0x983e5152,
0xa831c66d,
0xb00327c8,
0xbf597fc7,
0xc6e00bf3,
0xd5a79147,
0x06ca6351,
0x14292967,
0x27b70a85,
0x2e1b2138,
0x4d2c6dfc,
0x53380d13,
0x650a7354,
0x766a0abb,
0x81c2c92e,
0x92722c85,
0xa2bfe8a1,
0xa81a664b,
0xc24b8b70,
0xc76c51a3,
0xd192e819,
0xd6990624,
0xf40e3585,
0x106aa070,
0x19a4c116,
0x1e376c08,
0x2748774c,
0x34b0bcb5,
0x391c0cb3,
0x4ed8aa4a,
0x5b9cca4f,
0x682e6ff3,
0x748f82ee,
0x78a5636f,
0x84c87814,
0x8cc70208,
0x90befffa,
0xa4506ceb,
0xbef9a3f7,
0xc67178f2,
]);
/** Reusable temporary buffer. "W" comes straight from spec. */
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
/** Internal 32-byte base SHA2 hash class. */
class SHA2_32B extends md_js_1.HashMD {
constructor(outputLen) {
super(64, outputLen, 8, false);
}
get() {
const { A, B, C, D, E, F, G, H } = this;
return [A, B, C, D, E, F, G, H];
}
set(A, B, C, D, E, F, G, H) {
this.A = A | 0;
this.B = B | 0;
this.C = C | 0;
this.D = D | 0;
this.E = E | 0;
this.F = F | 0;
this.G = G | 0;
this.H = H | 0;
}
process(view, offset) {
// Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array
for (let i = 0; i < 16; i++, offset += 4) {
SHA256_W[i] = view.getUint32(offset, false);
}
for (let i = 16; i < 64; i++) {
const W15 = SHA256_W[i - 15];
const W2 = SHA256_W[i - 2];
const s0 = (0, noble_js_1.rotr)(W15, 7) ^ (0, noble_js_1.rotr)(W15, 18) ^ (W15 >>> 3);
const s1 = (0, noble_js_1.rotr)(W2, 17) ^ (0, noble_js_1.rotr)(W2, 19) ^ (W2 >>> 10);
SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;
}
// Compression function main loop, 64 rounds
let { A, B, C, D, E, F, G, H } = this;
for (let i = 0; i < 64; i++) {
const sigma1 = (0, noble_js_1.rotr)(E, 6) ^ (0, noble_js_1.rotr)(E, 11) ^ (0, noble_js_1.rotr)(E, 25);
const T1 = (H + sigma1 + (0, md_js_1.Chi)(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
const sigma0 = (0, noble_js_1.rotr)(A, 2) ^ (0, noble_js_1.rotr)(A, 13) ^ (0, noble_js_1.rotr)(A, 22);
const T2 = (sigma0 + (0, md_js_1.Maj)(A, B, C)) | 0;
H = G;
G = F;
F = E;
E = (D + T1) | 0;
D = C;
C = B;
B = A;
A = (T1 + T2) | 0;
}
// Add the compressed chunk to the current hash value
A = (A + this.A) | 0;
B = (B + this.B) | 0;
C = (C + this.C) | 0;
D = (D + this.D) | 0;
E = (E + this.E) | 0;
F = (F + this.F) | 0;
G = (G + this.G) | 0;
H = (H + this.H) | 0;
this.set(A, B, C, D, E, F, G, H);
}
roundClean() {
(0, noble_js_1.clean)(SHA256_W);
}
destroy() {
this.set(0, 0, 0, 0, 0, 0, 0, 0);
(0, noble_js_1.clean)(this.buffer);
}
}
/** Internal SHA2-256 hash class. */
class _SHA256 extends SHA2_32B {
constructor() {
super(32);
// We cannot use array here since array allows indexing by variable
// which means optimizer/compiler cannot use registers.
Object.defineProperty(this, "A", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA256_IV[0] | 0
});
Object.defineProperty(this, "B", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA256_IV[1] | 0
});
Object.defineProperty(this, "C", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA256_IV[2] | 0
});
Object.defineProperty(this, "D", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA256_IV[3] | 0
});
Object.defineProperty(this, "E", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA256_IV[4] | 0
});
Object.defineProperty(this, "F", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA256_IV[5] | 0
});
Object.defineProperty(this, "G", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA256_IV[6] | 0
});
Object.defineProperty(this, "H", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA256_IV[7] | 0
});
}
}
exports._SHA256 = _SHA256;
// SHA2-512 is slower than sha256 in js because u64 operations are slow.
// Round contants
// First 32 bits of the fractional parts of the cube roots of the first 80 primes 2..409
const K512 = /* @__PURE__ */ (() => u64.split([
0x428a2f98d728ae22n,
0x7137449123ef65cdn,
0xb5c0fbcfec4d3b2fn,
0xe9b5dba58189dbbcn,
0x3956c25bf348b538n,
0x59f111f1b605d019n,
0x923f82a4af194f9bn,
0xab1c5ed5da6d8118n,
0xd807aa98a3030242n,
0x12835b0145706fben,
0x243185be4ee4b28cn,
0x550c7dc3d5ffb4e2n,
0x72be5d74f27b896fn,
0x80deb1fe3b1696b1n,
0x9bdc06a725c71235n,
0xc19bf174cf692694n,
0xe49b69c19ef14ad2n,
0xefbe4786384f25e3n,
0x0fc19dc68b8cd5b5n,
0x240ca1cc77ac9c65n,
0x2de92c6f592b0275n,
0x4a7484aa6ea6e483n,
0x5cb0a9dcbd41fbd4n,
0x76f988da831153b5n,
0x983e5152ee66dfabn,
0xa831c66d2db43210n,
0xb00327c898fb213fn,
0xbf597fc7beef0ee4n,
0xc6e00bf33da88fc2n,
0xd5a79147930aa725n,
0x06ca6351e003826fn,
0x142929670a0e6e70n,
0x27b70a8546d22ffcn,
0x2e1b21385c26c926n,
0x4d2c6dfc5ac42aedn,
0x53380d139d95b3dfn,
0x650a73548baf63den,
0x766a0abb3c77b2a8n,
0x81c2c92e47edaee6n,
0x92722c851482353bn,
0xa2bfe8a14cf10364n,
0xa81a664bbc423001n,
0xc24b8b70d0f89791n,
0xc76c51a30654be30n,
0xd192e819d6ef5218n,
0xd69906245565a910n,
0xf40e35855771202an,
0x106aa07032bbd1b8n,
0x19a4c116b8d2d0c8n,
0x1e376c085141ab53n,
0x2748774cdf8eeb99n,
0x34b0bcb5e19b48a8n,
0x391c0cb3c5c95a63n,
0x4ed8aa4ae3418acbn,
0x5b9cca4f7763e373n,
0x682e6ff3d6b2b8a3n,
0x748f82ee5defb2fcn,
0x78a5636f43172f60n,
0x84c87814a1f0ab72n,
0x8cc702081a6439ecn,
0x90befffa23631e28n,
0xa4506cebde82bde9n,
0xbef9a3f7b2c67915n,
0xc67178f2e372532bn,
0xca273eceea26619cn,
0xd186b8c721c0c207n,
0xeada7dd6cde0eb1en,
0xf57d4f7fee6ed178n,
0x06f067aa72176fban,
0x0a637dc5a2c898a6n,
0x113f9804bef90daen,
0x1b710b35131c471bn,
0x28db77f523047d84n,
0x32caab7b40c72493n,
0x3c9ebe0a15c9bebcn,
0x431d67c49c100d4cn,
0x4cc5d4becb3e42b6n,
0x597f299cfc657e2an,
0x5fcb6fab3ad6faecn,
0x6c44198c4a475817n,
]))();
const SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
const SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
// Reusable temporary buffers
const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
/** Internal 64-byte base SHA2 hash class. */
class SHA2_64B extends md_js_1.HashMD {
constructor(outputLen) {
super(128, outputLen, 16, false);
}
get() {
const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
}
set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
this.Ah = Ah | 0;
this.Al = Al | 0;
this.Bh = Bh | 0;
this.Bl = Bl | 0;
this.Ch = Ch | 0;
this.Cl = Cl | 0;
this.Dh = Dh | 0;
this.Dl = Dl | 0;
this.Eh = Eh | 0;
this.El = El | 0;
this.Fh = Fh | 0;
this.Fl = Fl | 0;
this.Gh = Gh | 0;
this.Gl = Gl | 0;
this.Hh = Hh | 0;
this.Hl = Hl | 0;
}
process(view, offset) {
// Extend the first 16 words into the remaining 64 words w[16..79] of the message schedule array
for (let i = 0; i < 16; i++, offset += 4) {
SHA512_W_H[i] = view.getUint32(offset);
SHA512_W_L[i] = view.getUint32(offset += 4);
}
for (let i = 16; i < 80; i++) {
// s0 := (w[i-15] rightrotate 1) xor (w[i-15] rightrotate 8) xor (w[i-15] rightshift 7)
const W15h = SHA512_W_H[i - 15] | 0;
const W15l = SHA512_W_L[i - 15] | 0;
const s0h = u64.rotrSH(W15h, W15l, 1) ^ u64.rotrSH(W15h, W15l, 8) ^
u64.shrSH(W15h, W15l, 7);
const s0l = u64.rotrSL(W15h, W15l, 1) ^ u64.rotrSL(W15h, W15l, 8) ^
u64.shrSL(W15h, W15l, 7);
// s1 := (w[i-2] rightrotate 19) xor (w[i-2] rightrotate 61) xor (w[i-2] rightshift 6)
const W2h = SHA512_W_H[i - 2] | 0;
const W2l = SHA512_W_L[i - 2] | 0;
const s1h = u64.rotrSH(W2h, W2l, 19) ^ u64.rotrBH(W2h, W2l, 61) ^
u64.shrSH(W2h, W2l, 6);
const s1l = u64.rotrSL(W2h, W2l, 19) ^ u64.rotrBL(W2h, W2l, 61) ^
u64.shrSL(W2h, W2l, 6);
// SHA256_W[i] = s0 + s1 + SHA256_W[i - 7] + SHA256_W[i - 16];
const SUMl = u64.add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
const SUMh = u64.add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
SHA512_W_H[i] = SUMh | 0;
SHA512_W_L[i] = SUMl | 0;
}
let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
// Compression function main loop, 80 rounds
for (let i = 0; i < 80; i++) {
// S1 := (e rightrotate 14) xor (e rightrotate 18) xor (e rightrotate 41)
const sigma1h = u64.rotrSH(Eh, El, 14) ^ u64.rotrSH(Eh, El, 18) ^
u64.rotrBH(Eh, El, 41);
const sigma1l = u64.rotrSL(Eh, El, 14) ^ u64.rotrSL(Eh, El, 18) ^
u64.rotrBL(Eh, El, 41);
//const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
const CHIh = (Eh & Fh) ^ (~Eh & Gh);
const CHIl = (El & Fl) ^ (~El & Gl);
// T1 = H + sigma1 + Chi(E, F, G) + SHA512_K[i] + SHA512_W[i]
const T1ll = u64.add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
const T1h = u64.add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
const T1l = T1ll | 0;
// S0 := (a rightrotate 28) xor (a rightrotate 34) xor (a rightrotate 39)
const sigma0h = u64.rotrSH(Ah, Al, 28) ^ u64.rotrBH(Ah, Al, 34) ^
u64.rotrBH(Ah, Al, 39);
const sigma0l = u64.rotrSL(Ah, Al, 28) ^ u64.rotrBL(Ah, Al, 34) ^
u64.rotrBL(Ah, Al, 39);
const MAJh = (Ah & Bh) ^ (Ah & Ch) ^ (Bh & Ch);
const MAJl = (Al & Bl) ^ (Al & Cl) ^ (Bl & Cl);
Hh = Gh | 0;
Hl = Gl | 0;
Gh = Fh | 0;
Gl = Fl | 0;
Fh = Eh | 0;
Fl = El | 0;
({ h: Eh, l: El } = u64.add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
Dh = Ch | 0;
Dl = Cl | 0;
Ch = Bh | 0;
Cl = Bl | 0;
Bh = Ah | 0;
Bl = Al | 0;
const All = u64.add3L(T1l, sigma0l, MAJl);
Ah = u64.add3H(All, T1h, sigma0h, MAJh);
Al = All | 0;
}
// Add the compressed chunk to the current hash value
({ h: Ah, l: Al } = u64.add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
({ h: Bh, l: Bl } = u64.add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
({ h: Ch, l: Cl } = u64.add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
({ h: Dh, l: Dl } = u64.add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
({ h: Eh, l: El } = u64.add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
({ h: Fh, l: Fl } = u64.add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
({ h: Gh, l: Gl } = u64.add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
({ h: Hh, l: Hl } = u64.add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
}
roundClean() {
(0, noble_js_1.clean)(SHA512_W_H, SHA512_W_L);
}
destroy() {
(0, noble_js_1.clean)(this.buffer);
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
}
/** Internal SHA2-512 hash class. */
class _SHA512 extends SHA2_64B {
constructor() {
super(64);
Object.defineProperty(this, "Ah", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA512_IV[0] | 0
});
Object.defineProperty(this, "Al", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA512_IV[1] | 0
});
Object.defineProperty(this, "Bh", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA512_IV[2] | 0
});
Object.defineProperty(this, "Bl", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA512_IV[3] | 0
});
Object.defineProperty(this, "Ch", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA512_IV[4] | 0
});
Object.defineProperty(this, "Cl", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA512_IV[5] | 0
});
Object.defineProperty(this, "Dh", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA512_IV[6] | 0
});
Object.defineProperty(this, "Dl", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA512_IV[7] | 0
});
Object.defineProperty(this, "Eh", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA512_IV[8] | 0
});
Object.defineProperty(this, "El", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA512_IV[9] | 0
});
Object.defineProperty(this, "Fh", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA512_IV[10] | 0
});
Object.defineProperty(this, "Fl", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA512_IV[11] | 0
});
Object.defineProperty(this, "Gh", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA512_IV[12] | 0
});
Object.defineProperty(this, "Gl", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA512_IV[13] | 0
});
Object.defineProperty(this, "Hh", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA512_IV[14] | 0
});
Object.defineProperty(this, "Hl", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA512_IV[15] | 0
});
}
}
exports._SHA512 = _SHA512;
class _SHA384 extends SHA2_64B {
constructor() {
super(48);
Object.defineProperty(this, "Ah", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA384_IV[0] | 0
});
Object.defineProperty(this, "Al", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA384_IV[1] | 0
});
Object.defineProperty(this, "Bh", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA384_IV[2] | 0
});
Object.defineProperty(this, "Bl", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA384_IV[3] | 0
});
Object.defineProperty(this, "Ch", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA384_IV[4] | 0
});
Object.defineProperty(this, "Cl", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA384_IV[5] | 0
});
Object.defineProperty(this, "Dh", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA384_IV[6] | 0
});
Object.defineProperty(this, "Dl", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA384_IV[7] | 0
});
Object.defineProperty(this, "Eh", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA384_IV[8] | 0
});
Object.defineProperty(this, "El", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA384_IV[9] | 0
});
Object.defineProperty(this, "Fh", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA384_IV[10] | 0
});
Object.defineProperty(this, "Fl", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA384_IV[11] | 0
});
Object.defineProperty(this, "Gh", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA384_IV[12] | 0
});
Object.defineProperty(this, "Gl", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA384_IV[13] | 0
});
Object.defineProperty(this, "Hh", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA384_IV[14] | 0
});
Object.defineProperty(this, "Hl", {
enumerable: true,
configurable: true,
writable: true,
value: md_js_1.SHA384_IV[15] | 0
});
}
}
exports._SHA384 = _SHA384;
/**
* SHA2-256 hash function from RFC 4634. In JS it's the fastest: even faster than Blake3. Some info:
*
* - Trying 2^128 hashes would get 50% chance of collision, using birthday attack.
* - BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
* - Each sha256 hash is executing 2^18 bit operations.
* - Good 2024 ASICs can do 200Th/sec with 3500 watts of power, corresponding to 2^36 hashes/joule.
*/
exports.sha256 = (0, hash_js_1.createHasher)(() => new _SHA256(),
/* @__PURE__ */ (0, noble_js_1.oidNist)(0x01));
/** SHA2-512 hash function from RFC 4634. */
exports.sha512 = (0, hash_js_1.createHasher)(() => new _SHA512(),
/* @__PURE__ */ (0, noble_js_1.oidNist)(0x03));
/** SHA2-384 hash function from RFC 4634. */
exports.sha384 = (0, hash_js_1.createHasher)(() => new _SHA384(),
/* @__PURE__ */ (0, noble_js_1.oidNist)(0x02));
});