sha224.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { WordArray } from './core.js';
  2. import { SHA256Algo } from './sha256.js';
  3. /**
  4. * SHA-224 hash algorithm.
  5. */
  6. export class SHA224Algo extends SHA256Algo {
  7. _doReset() {
  8. this._hash = new WordArray([
  9. 0xc1059ed8,
  10. 0x367cd507,
  11. 0x3070dd17,
  12. 0xf70e5939,
  13. 0xffc00b31,
  14. 0x68581511,
  15. 0x64f98fa7,
  16. 0xbefa4fa4,
  17. ]);
  18. }
  19. _doFinalize() {
  20. const hash = super._doFinalize.call(this);
  21. hash.sigBytes -= 4;
  22. return hash;
  23. }
  24. }
  25. /**
  26. * Shortcut function to the hasher's object interface.
  27. *
  28. * @param {WordArray|string} message The message to hash.
  29. *
  30. * @return {WordArray} The hash.
  31. *
  32. * @static
  33. *
  34. * @example
  35. *
  36. * var hash = CryptoJS.SHA224('message');
  37. * var hash = CryptoJS.SHA224(wordArray);
  38. */
  39. export const SHA224 = SHA256Algo._createHelper(SHA224Algo);
  40. /**
  41. * Shortcut function to the HMAC's object interface.
  42. *
  43. * @param {WordArray|string} message The message to hash.
  44. * @param {WordArray|string} key The secret key.
  45. *
  46. * @return {WordArray} The HMAC.
  47. *
  48. * @static
  49. *
  50. * @example
  51. *
  52. * var hmac = CryptoJS.HmacSHA224(message, key);
  53. */
  54. export const HmacSHA224 = SHA256Algo._createHmacHelper(SHA224Algo);