sha224.js 2.1 KB

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