sha384.js 1.4 KB

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