sha2.d.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 { HashMD } from './_md.ts';
  9. import { type CHash } from './utils.ts';
  10. export declare class SHA256 extends HashMD<SHA256> {
  11. protected A: number;
  12. protected B: number;
  13. protected C: number;
  14. protected D: number;
  15. protected E: number;
  16. protected F: number;
  17. protected G: number;
  18. protected H: number;
  19. constructor(outputLen?: number);
  20. protected get(): [number, number, number, number, number, number, number, number];
  21. protected set(A: number, B: number, C: number, D: number, E: number, F: number, G: number, H: number): void;
  22. protected process(view: DataView, offset: number): void;
  23. protected roundClean(): void;
  24. destroy(): void;
  25. }
  26. export declare class SHA224 extends SHA256 {
  27. protected A: number;
  28. protected B: number;
  29. protected C: number;
  30. protected D: number;
  31. protected E: number;
  32. protected F: number;
  33. protected G: number;
  34. protected H: number;
  35. constructor();
  36. }
  37. export declare class SHA512 extends HashMD<SHA512> {
  38. protected Ah: number;
  39. protected Al: number;
  40. protected Bh: number;
  41. protected Bl: number;
  42. protected Ch: number;
  43. protected Cl: number;
  44. protected Dh: number;
  45. protected Dl: number;
  46. protected Eh: number;
  47. protected El: number;
  48. protected Fh: number;
  49. protected Fl: number;
  50. protected Gh: number;
  51. protected Gl: number;
  52. protected Hh: number;
  53. protected Hl: number;
  54. constructor(outputLen?: number);
  55. protected get(): [
  56. number,
  57. number,
  58. number,
  59. number,
  60. number,
  61. number,
  62. number,
  63. number,
  64. number,
  65. number,
  66. number,
  67. number,
  68. number,
  69. number,
  70. number,
  71. number
  72. ];
  73. protected set(Ah: number, Al: number, Bh: number, Bl: number, Ch: number, Cl: number, Dh: number, Dl: number, Eh: number, El: number, Fh: number, Fl: number, Gh: number, Gl: number, Hh: number, Hl: number): void;
  74. protected process(view: DataView, offset: number): void;
  75. protected roundClean(): void;
  76. destroy(): void;
  77. }
  78. export declare class SHA384 extends SHA512 {
  79. protected Ah: number;
  80. protected Al: number;
  81. protected Bh: number;
  82. protected Bl: number;
  83. protected Ch: number;
  84. protected Cl: number;
  85. protected Dh: number;
  86. protected Dl: number;
  87. protected Eh: number;
  88. protected El: number;
  89. protected Fh: number;
  90. protected Fl: number;
  91. protected Gh: number;
  92. protected Gl: number;
  93. protected Hh: number;
  94. protected Hl: number;
  95. constructor();
  96. }
  97. export declare class SHA512_224 extends SHA512 {
  98. protected Ah: number;
  99. protected Al: number;
  100. protected Bh: number;
  101. protected Bl: number;
  102. protected Ch: number;
  103. protected Cl: number;
  104. protected Dh: number;
  105. protected Dl: number;
  106. protected Eh: number;
  107. protected El: number;
  108. protected Fh: number;
  109. protected Fl: number;
  110. protected Gh: number;
  111. protected Gl: number;
  112. protected Hh: number;
  113. protected Hl: number;
  114. constructor();
  115. }
  116. export declare class SHA512_256 extends SHA512 {
  117. protected Ah: number;
  118. protected Al: number;
  119. protected Bh: number;
  120. protected Bl: number;
  121. protected Ch: number;
  122. protected Cl: number;
  123. protected Dh: number;
  124. protected Dl: number;
  125. protected Eh: number;
  126. protected El: number;
  127. protected Fh: number;
  128. protected Fl: number;
  129. protected Gh: number;
  130. protected Gl: number;
  131. protected Hh: number;
  132. protected Hl: number;
  133. constructor();
  134. }
  135. /**
  136. * SHA2-256 hash function from RFC 4634.
  137. *
  138. * It is the fastest JS hash, even faster than Blake3.
  139. * To break sha256 using birthday attack, attackers need to try 2^128 hashes.
  140. * BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
  141. */
  142. export declare const sha256: CHash;
  143. /** SHA2-224 hash function from RFC 4634 */
  144. export declare const sha224: CHash;
  145. /** SHA2-512 hash function from RFC 4634. */
  146. export declare const sha512: CHash;
  147. /** SHA2-384 hash function from RFC 4634. */
  148. export declare const sha384: CHash;
  149. /**
  150. * SHA2-512/256 "truncated" hash function, with improved resistance to length extension attacks.
  151. * See the paper on [truncated SHA512](https://eprint.iacr.org/2010/548.pdf).
  152. */
  153. export declare const sha512_256: CHash;
  154. /**
  155. * SHA2-512/224 "truncated" hash function, with improved resistance to length extension attacks.
  156. * See the paper on [truncated SHA512](https://eprint.iacr.org/2010/548.pdf).
  157. */
  158. export declare const sha512_224: CHash;
  159. //# sourceMappingURL=sha2.d.ts.map