sha384.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. ;(function (root, factory, undef) {
  2. if (typeof exports === "object") {
  3. // CommonJS
  4. module.exports = exports = factory(require("./core"), require("./x64-core"), require("./sha512"));
  5. } else if (typeof define === "function" && define.amd) {
  6. // AMD
  7. define(["./core", "./x64-core", "./sha512"], factory);
  8. } else {
  9. // Global (browser)
  10. factory(root.CryptoJS);
  11. }
  12. }(this, function (CryptoJS) {
  13. (function () {
  14. // Shortcuts
  15. var C = CryptoJS;
  16. var C_x64 = C.x64;
  17. var X64Word = C_x64.Word;
  18. var X64WordArray = C_x64.WordArray;
  19. var C_algo = C.algo;
  20. var SHA512 = C_algo.SHA512;
  21. /**
  22. * SHA-384 hash algorithm.
  23. */
  24. var SHA384 = C_algo.SHA384 = SHA512.extend({
  25. _doReset: function () {
  26. this._hash = new X64WordArray.init([
  27. new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507),
  28. new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939),
  29. new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511),
  30. new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4)
  31. ]);
  32. },
  33. _doFinalize: function () {
  34. var hash = SHA512._doFinalize.call(this);
  35. hash.sigBytes -= 16;
  36. return hash;
  37. }
  38. });
  39. /**
  40. * Shortcut function to the hasher's object interface.
  41. *
  42. * @param {WordArray|string} message The message to hash.
  43. *
  44. * @return {WordArray} The hash.
  45. *
  46. * @static
  47. *
  48. * @example
  49. *
  50. * var hash = CryptoJS.SHA384('message');
  51. * var hash = CryptoJS.SHA384(wordArray);
  52. */
  53. C.SHA384 = SHA512._createHelper(SHA384);
  54. /**
  55. * Shortcut function to the HMAC's object interface.
  56. *
  57. * @param {WordArray|string} message The message to hash.
  58. * @param {WordArray|string} key The secret key.
  59. *
  60. * @return {WordArray} The HMAC.
  61. *
  62. * @static
  63. *
  64. * @example
  65. *
  66. * var hmac = CryptoJS.HmacSHA384(message, key);
  67. */
  68. C.HmacSHA384 = SHA512._createHmacHelper(SHA384);
  69. }());
  70. return CryptoJS.SHA384;
  71. }));