sha2.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. /**
  2. * SHA2 hash function. A.k.a. sha256, sha384, sha512, sha512_224, sha512_256.
  3. * SHA256 is the fastest hash implementable in JS, even faster than Blake3.
  4. * Check out [RFC 4634](https://datatracker.ietf.org/doc/html/rfc4634) and
  5. * [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).
  6. * @module
  7. */
  8. import { Chi, HashMD, Maj, SHA224_IV, SHA256_IV, SHA384_IV, SHA512_IV } from "./_md.js";
  9. import * as u64 from "./_u64.js";
  10. import { clean, createHasher, rotr } from "./utils.js";
  11. /**
  12. * Round constants:
  13. * First 32 bits of fractional parts of the cube roots of the first 64 primes 2..311)
  14. */
  15. // prettier-ignore
  16. const SHA256_K = /* @__PURE__ */ Uint32Array.from([
  17. 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  18. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  19. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  20. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  21. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  22. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  23. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  24. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
  25. ]);
  26. /** Reusable temporary buffer. "W" comes straight from spec. */
  27. const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
  28. export class SHA256 extends HashMD {
  29. constructor(outputLen = 32) {
  30. super(64, outputLen, 8, false);
  31. // We cannot use array here since array allows indexing by variable
  32. // which means optimizer/compiler cannot use registers.
  33. this.A = SHA256_IV[0] | 0;
  34. this.B = SHA256_IV[1] | 0;
  35. this.C = SHA256_IV[2] | 0;
  36. this.D = SHA256_IV[3] | 0;
  37. this.E = SHA256_IV[4] | 0;
  38. this.F = SHA256_IV[5] | 0;
  39. this.G = SHA256_IV[6] | 0;
  40. this.H = SHA256_IV[7] | 0;
  41. }
  42. get() {
  43. const { A, B, C, D, E, F, G, H } = this;
  44. return [A, B, C, D, E, F, G, H];
  45. }
  46. // prettier-ignore
  47. set(A, B, C, D, E, F, G, H) {
  48. this.A = A | 0;
  49. this.B = B | 0;
  50. this.C = C | 0;
  51. this.D = D | 0;
  52. this.E = E | 0;
  53. this.F = F | 0;
  54. this.G = G | 0;
  55. this.H = H | 0;
  56. }
  57. process(view, offset) {
  58. // Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array
  59. for (let i = 0; i < 16; i++, offset += 4)
  60. SHA256_W[i] = view.getUint32(offset, false);
  61. for (let i = 16; i < 64; i++) {
  62. const W15 = SHA256_W[i - 15];
  63. const W2 = SHA256_W[i - 2];
  64. const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ (W15 >>> 3);
  65. const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ (W2 >>> 10);
  66. SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;
  67. }
  68. // Compression function main loop, 64 rounds
  69. let { A, B, C, D, E, F, G, H } = this;
  70. for (let i = 0; i < 64; i++) {
  71. const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
  72. const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
  73. const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
  74. const T2 = (sigma0 + Maj(A, B, C)) | 0;
  75. H = G;
  76. G = F;
  77. F = E;
  78. E = (D + T1) | 0;
  79. D = C;
  80. C = B;
  81. B = A;
  82. A = (T1 + T2) | 0;
  83. }
  84. // Add the compressed chunk to the current hash value
  85. A = (A + this.A) | 0;
  86. B = (B + this.B) | 0;
  87. C = (C + this.C) | 0;
  88. D = (D + this.D) | 0;
  89. E = (E + this.E) | 0;
  90. F = (F + this.F) | 0;
  91. G = (G + this.G) | 0;
  92. H = (H + this.H) | 0;
  93. this.set(A, B, C, D, E, F, G, H);
  94. }
  95. roundClean() {
  96. clean(SHA256_W);
  97. }
  98. destroy() {
  99. this.set(0, 0, 0, 0, 0, 0, 0, 0);
  100. clean(this.buffer);
  101. }
  102. }
  103. export class SHA224 extends SHA256 {
  104. constructor() {
  105. super(28);
  106. this.A = SHA224_IV[0] | 0;
  107. this.B = SHA224_IV[1] | 0;
  108. this.C = SHA224_IV[2] | 0;
  109. this.D = SHA224_IV[3] | 0;
  110. this.E = SHA224_IV[4] | 0;
  111. this.F = SHA224_IV[5] | 0;
  112. this.G = SHA224_IV[6] | 0;
  113. this.H = SHA224_IV[7] | 0;
  114. }
  115. }
  116. // SHA2-512 is slower than sha256 in js because u64 operations are slow.
  117. // Round contants
  118. // First 32 bits of the fractional parts of the cube roots of the first 80 primes 2..409
  119. // prettier-ignore
  120. const K512 = /* @__PURE__ */ (() => u64.split([
  121. '0x428a2f98d728ae22', '0x7137449123ef65cd', '0xb5c0fbcfec4d3b2f', '0xe9b5dba58189dbbc',
  122. '0x3956c25bf348b538', '0x59f111f1b605d019', '0x923f82a4af194f9b', '0xab1c5ed5da6d8118',
  123. '0xd807aa98a3030242', '0x12835b0145706fbe', '0x243185be4ee4b28c', '0x550c7dc3d5ffb4e2',
  124. '0x72be5d74f27b896f', '0x80deb1fe3b1696b1', '0x9bdc06a725c71235', '0xc19bf174cf692694',
  125. '0xe49b69c19ef14ad2', '0xefbe4786384f25e3', '0x0fc19dc68b8cd5b5', '0x240ca1cc77ac9c65',
  126. '0x2de92c6f592b0275', '0x4a7484aa6ea6e483', '0x5cb0a9dcbd41fbd4', '0x76f988da831153b5',
  127. '0x983e5152ee66dfab', '0xa831c66d2db43210', '0xb00327c898fb213f', '0xbf597fc7beef0ee4',
  128. '0xc6e00bf33da88fc2', '0xd5a79147930aa725', '0x06ca6351e003826f', '0x142929670a0e6e70',
  129. '0x27b70a8546d22ffc', '0x2e1b21385c26c926', '0x4d2c6dfc5ac42aed', '0x53380d139d95b3df',
  130. '0x650a73548baf63de', '0x766a0abb3c77b2a8', '0x81c2c92e47edaee6', '0x92722c851482353b',
  131. '0xa2bfe8a14cf10364', '0xa81a664bbc423001', '0xc24b8b70d0f89791', '0xc76c51a30654be30',
  132. '0xd192e819d6ef5218', '0xd69906245565a910', '0xf40e35855771202a', '0x106aa07032bbd1b8',
  133. '0x19a4c116b8d2d0c8', '0x1e376c085141ab53', '0x2748774cdf8eeb99', '0x34b0bcb5e19b48a8',
  134. '0x391c0cb3c5c95a63', '0x4ed8aa4ae3418acb', '0x5b9cca4f7763e373', '0x682e6ff3d6b2b8a3',
  135. '0x748f82ee5defb2fc', '0x78a5636f43172f60', '0x84c87814a1f0ab72', '0x8cc702081a6439ec',
  136. '0x90befffa23631e28', '0xa4506cebde82bde9', '0xbef9a3f7b2c67915', '0xc67178f2e372532b',
  137. '0xca273eceea26619c', '0xd186b8c721c0c207', '0xeada7dd6cde0eb1e', '0xf57d4f7fee6ed178',
  138. '0x06f067aa72176fba', '0x0a637dc5a2c898a6', '0x113f9804bef90dae', '0x1b710b35131c471b',
  139. '0x28db77f523047d84', '0x32caab7b40c72493', '0x3c9ebe0a15c9bebc', '0x431d67c49c100d4c',
  140. '0x4cc5d4becb3e42b6', '0x597f299cfc657e2a', '0x5fcb6fab3ad6faec', '0x6c44198c4a475817'
  141. ].map(n => BigInt(n))))();
  142. const SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
  143. const SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
  144. // Reusable temporary buffers
  145. const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
  146. const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
  147. export class SHA512 extends HashMD {
  148. constructor(outputLen = 64) {
  149. super(128, outputLen, 16, false);
  150. // We cannot use array here since array allows indexing by variable
  151. // which means optimizer/compiler cannot use registers.
  152. // h -- high 32 bits, l -- low 32 bits
  153. this.Ah = SHA512_IV[0] | 0;
  154. this.Al = SHA512_IV[1] | 0;
  155. this.Bh = SHA512_IV[2] | 0;
  156. this.Bl = SHA512_IV[3] | 0;
  157. this.Ch = SHA512_IV[4] | 0;
  158. this.Cl = SHA512_IV[5] | 0;
  159. this.Dh = SHA512_IV[6] | 0;
  160. this.Dl = SHA512_IV[7] | 0;
  161. this.Eh = SHA512_IV[8] | 0;
  162. this.El = SHA512_IV[9] | 0;
  163. this.Fh = SHA512_IV[10] | 0;
  164. this.Fl = SHA512_IV[11] | 0;
  165. this.Gh = SHA512_IV[12] | 0;
  166. this.Gl = SHA512_IV[13] | 0;
  167. this.Hh = SHA512_IV[14] | 0;
  168. this.Hl = SHA512_IV[15] | 0;
  169. }
  170. // prettier-ignore
  171. get() {
  172. const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
  173. return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
  174. }
  175. // prettier-ignore
  176. set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
  177. this.Ah = Ah | 0;
  178. this.Al = Al | 0;
  179. this.Bh = Bh | 0;
  180. this.Bl = Bl | 0;
  181. this.Ch = Ch | 0;
  182. this.Cl = Cl | 0;
  183. this.Dh = Dh | 0;
  184. this.Dl = Dl | 0;
  185. this.Eh = Eh | 0;
  186. this.El = El | 0;
  187. this.Fh = Fh | 0;
  188. this.Fl = Fl | 0;
  189. this.Gh = Gh | 0;
  190. this.Gl = Gl | 0;
  191. this.Hh = Hh | 0;
  192. this.Hl = Hl | 0;
  193. }
  194. process(view, offset) {
  195. // Extend the first 16 words into the remaining 64 words w[16..79] of the message schedule array
  196. for (let i = 0; i < 16; i++, offset += 4) {
  197. SHA512_W_H[i] = view.getUint32(offset);
  198. SHA512_W_L[i] = view.getUint32((offset += 4));
  199. }
  200. for (let i = 16; i < 80; i++) {
  201. // s0 := (w[i-15] rightrotate 1) xor (w[i-15] rightrotate 8) xor (w[i-15] rightshift 7)
  202. const W15h = SHA512_W_H[i - 15] | 0;
  203. const W15l = SHA512_W_L[i - 15] | 0;
  204. const s0h = u64.rotrSH(W15h, W15l, 1) ^ u64.rotrSH(W15h, W15l, 8) ^ u64.shrSH(W15h, W15l, 7);
  205. const s0l = u64.rotrSL(W15h, W15l, 1) ^ u64.rotrSL(W15h, W15l, 8) ^ u64.shrSL(W15h, W15l, 7);
  206. // s1 := (w[i-2] rightrotate 19) xor (w[i-2] rightrotate 61) xor (w[i-2] rightshift 6)
  207. const W2h = SHA512_W_H[i - 2] | 0;
  208. const W2l = SHA512_W_L[i - 2] | 0;
  209. const s1h = u64.rotrSH(W2h, W2l, 19) ^ u64.rotrBH(W2h, W2l, 61) ^ u64.shrSH(W2h, W2l, 6);
  210. const s1l = u64.rotrSL(W2h, W2l, 19) ^ u64.rotrBL(W2h, W2l, 61) ^ u64.shrSL(W2h, W2l, 6);
  211. // SHA256_W[i] = s0 + s1 + SHA256_W[i - 7] + SHA256_W[i - 16];
  212. const SUMl = u64.add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
  213. const SUMh = u64.add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
  214. SHA512_W_H[i] = SUMh | 0;
  215. SHA512_W_L[i] = SUMl | 0;
  216. }
  217. let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
  218. // Compression function main loop, 80 rounds
  219. for (let i = 0; i < 80; i++) {
  220. // S1 := (e rightrotate 14) xor (e rightrotate 18) xor (e rightrotate 41)
  221. const sigma1h = u64.rotrSH(Eh, El, 14) ^ u64.rotrSH(Eh, El, 18) ^ u64.rotrBH(Eh, El, 41);
  222. const sigma1l = u64.rotrSL(Eh, El, 14) ^ u64.rotrSL(Eh, El, 18) ^ u64.rotrBL(Eh, El, 41);
  223. //const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
  224. const CHIh = (Eh & Fh) ^ (~Eh & Gh);
  225. const CHIl = (El & Fl) ^ (~El & Gl);
  226. // T1 = H + sigma1 + Chi(E, F, G) + SHA512_K[i] + SHA512_W[i]
  227. // prettier-ignore
  228. const T1ll = u64.add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
  229. const T1h = u64.add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
  230. const T1l = T1ll | 0;
  231. // S0 := (a rightrotate 28) xor (a rightrotate 34) xor (a rightrotate 39)
  232. const sigma0h = u64.rotrSH(Ah, Al, 28) ^ u64.rotrBH(Ah, Al, 34) ^ u64.rotrBH(Ah, Al, 39);
  233. const sigma0l = u64.rotrSL(Ah, Al, 28) ^ u64.rotrBL(Ah, Al, 34) ^ u64.rotrBL(Ah, Al, 39);
  234. const MAJh = (Ah & Bh) ^ (Ah & Ch) ^ (Bh & Ch);
  235. const MAJl = (Al & Bl) ^ (Al & Cl) ^ (Bl & Cl);
  236. Hh = Gh | 0;
  237. Hl = Gl | 0;
  238. Gh = Fh | 0;
  239. Gl = Fl | 0;
  240. Fh = Eh | 0;
  241. Fl = El | 0;
  242. ({ h: Eh, l: El } = u64.add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
  243. Dh = Ch | 0;
  244. Dl = Cl | 0;
  245. Ch = Bh | 0;
  246. Cl = Bl | 0;
  247. Bh = Ah | 0;
  248. Bl = Al | 0;
  249. const All = u64.add3L(T1l, sigma0l, MAJl);
  250. Ah = u64.add3H(All, T1h, sigma0h, MAJh);
  251. Al = All | 0;
  252. }
  253. // Add the compressed chunk to the current hash value
  254. ({ h: Ah, l: Al } = u64.add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
  255. ({ h: Bh, l: Bl } = u64.add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
  256. ({ h: Ch, l: Cl } = u64.add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
  257. ({ h: Dh, l: Dl } = u64.add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
  258. ({ h: Eh, l: El } = u64.add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
  259. ({ h: Fh, l: Fl } = u64.add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
  260. ({ h: Gh, l: Gl } = u64.add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
  261. ({ h: Hh, l: Hl } = u64.add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
  262. this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
  263. }
  264. roundClean() {
  265. clean(SHA512_W_H, SHA512_W_L);
  266. }
  267. destroy() {
  268. clean(this.buffer);
  269. this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  270. }
  271. }
  272. export class SHA384 extends SHA512 {
  273. constructor() {
  274. super(48);
  275. this.Ah = SHA384_IV[0] | 0;
  276. this.Al = SHA384_IV[1] | 0;
  277. this.Bh = SHA384_IV[2] | 0;
  278. this.Bl = SHA384_IV[3] | 0;
  279. this.Ch = SHA384_IV[4] | 0;
  280. this.Cl = SHA384_IV[5] | 0;
  281. this.Dh = SHA384_IV[6] | 0;
  282. this.Dl = SHA384_IV[7] | 0;
  283. this.Eh = SHA384_IV[8] | 0;
  284. this.El = SHA384_IV[9] | 0;
  285. this.Fh = SHA384_IV[10] | 0;
  286. this.Fl = SHA384_IV[11] | 0;
  287. this.Gh = SHA384_IV[12] | 0;
  288. this.Gl = SHA384_IV[13] | 0;
  289. this.Hh = SHA384_IV[14] | 0;
  290. this.Hl = SHA384_IV[15] | 0;
  291. }
  292. }
  293. /**
  294. * Truncated SHA512/256 and SHA512/224.
  295. * SHA512_IV is XORed with 0xa5a5a5a5a5a5a5a5, then used as "intermediary" IV of SHA512/t.
  296. * Then t hashes string to produce result IV.
  297. * See `test/misc/sha2-gen-iv.js`.
  298. */
  299. /** SHA512/224 IV */
  300. const T224_IV = /* @__PURE__ */ Uint32Array.from([
  301. 0x8c3d37c8, 0x19544da2, 0x73e19966, 0x89dcd4d6, 0x1dfab7ae, 0x32ff9c82, 0x679dd514, 0x582f9fcf,
  302. 0x0f6d2b69, 0x7bd44da8, 0x77e36f73, 0x04c48942, 0x3f9d85a8, 0x6a1d36c8, 0x1112e6ad, 0x91d692a1,
  303. ]);
  304. /** SHA512/256 IV */
  305. const T256_IV = /* @__PURE__ */ Uint32Array.from([
  306. 0x22312194, 0xfc2bf72c, 0x9f555fa3, 0xc84c64c2, 0x2393b86b, 0x6f53b151, 0x96387719, 0x5940eabd,
  307. 0x96283ee2, 0xa88effe3, 0xbe5e1e25, 0x53863992, 0x2b0199fc, 0x2c85b8aa, 0x0eb72ddc, 0x81c52ca2,
  308. ]);
  309. export class SHA512_224 extends SHA512 {
  310. constructor() {
  311. super(28);
  312. this.Ah = T224_IV[0] | 0;
  313. this.Al = T224_IV[1] | 0;
  314. this.Bh = T224_IV[2] | 0;
  315. this.Bl = T224_IV[3] | 0;
  316. this.Ch = T224_IV[4] | 0;
  317. this.Cl = T224_IV[5] | 0;
  318. this.Dh = T224_IV[6] | 0;
  319. this.Dl = T224_IV[7] | 0;
  320. this.Eh = T224_IV[8] | 0;
  321. this.El = T224_IV[9] | 0;
  322. this.Fh = T224_IV[10] | 0;
  323. this.Fl = T224_IV[11] | 0;
  324. this.Gh = T224_IV[12] | 0;
  325. this.Gl = T224_IV[13] | 0;
  326. this.Hh = T224_IV[14] | 0;
  327. this.Hl = T224_IV[15] | 0;
  328. }
  329. }
  330. export class SHA512_256 extends SHA512 {
  331. constructor() {
  332. super(32);
  333. this.Ah = T256_IV[0] | 0;
  334. this.Al = T256_IV[1] | 0;
  335. this.Bh = T256_IV[2] | 0;
  336. this.Bl = T256_IV[3] | 0;
  337. this.Ch = T256_IV[4] | 0;
  338. this.Cl = T256_IV[5] | 0;
  339. this.Dh = T256_IV[6] | 0;
  340. this.Dl = T256_IV[7] | 0;
  341. this.Eh = T256_IV[8] | 0;
  342. this.El = T256_IV[9] | 0;
  343. this.Fh = T256_IV[10] | 0;
  344. this.Fl = T256_IV[11] | 0;
  345. this.Gh = T256_IV[12] | 0;
  346. this.Gl = T256_IV[13] | 0;
  347. this.Hh = T256_IV[14] | 0;
  348. this.Hl = T256_IV[15] | 0;
  349. }
  350. }
  351. /**
  352. * SHA2-256 hash function from RFC 4634.
  353. *
  354. * It is the fastest JS hash, even faster than Blake3.
  355. * To break sha256 using birthday attack, attackers need to try 2^128 hashes.
  356. * BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
  357. */
  358. export const sha256 = /* @__PURE__ */ createHasher(() => new SHA256());
  359. /** SHA2-224 hash function from RFC 4634 */
  360. export const sha224 = /* @__PURE__ */ createHasher(() => new SHA224());
  361. /** SHA2-512 hash function from RFC 4634. */
  362. export const sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
  363. /** SHA2-384 hash function from RFC 4634. */
  364. export const sha384 = /* @__PURE__ */ createHasher(() => new SHA384());
  365. /**
  366. * SHA2-512/256 "truncated" hash function, with improved resistance to length extension attacks.
  367. * See the paper on [truncated SHA512](https://eprint.iacr.org/2010/548.pdf).
  368. */
  369. export const sha512_256 = /* @__PURE__ */ createHasher(() => new SHA512_256());
  370. /**
  371. * SHA2-512/224 "truncated" hash function, with improved resistance to length extension attacks.
  372. * See the paper on [truncated SHA512](https://eprint.iacr.org/2010/548.pdf).
  373. */
  374. export const sha512_224 = /* @__PURE__ */ createHasher(() => new SHA512_224());
  375. //# sourceMappingURL=sha2.js.map