sha224.js 1.9 KB

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