AI销管
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

pirms 2 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. ;(function (root, factory) {
  2. if (typeof exports === "object") {
  3. // CommonJS
  4. module.exports = exports = factory(require("./core"));
  5. }
  6. else if (typeof define === "function" && define.amd) {
  7. // AMD
  8. define(["./core"], 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 Hasher = C_lib.Hasher;
  21. var C_algo = C.algo;
  22. // Reusable object
  23. var W = [];
  24. /**
  25. * SHA-1 hash algorithm.
  26. */
  27. var SHA1 = C_algo.SHA1 = Hasher.extend({
  28. _doReset: function () {
  29. this._hash = new WordArray.init([
  30. 0x67452301, 0xefcdab89,
  31. 0x98badcfe, 0x10325476,
  32. 0xc3d2e1f0
  33. ]);
  34. },
  35. _doProcessBlock: function (M, offset) {
  36. // Shortcut
  37. var H = this._hash.words;
  38. // Working variables
  39. var a = H[0];
  40. var b = H[1];
  41. var c = H[2];
  42. var d = H[3];
  43. var e = H[4];
  44. // Computation
  45. for (var i = 0; i < 80; i++) {
  46. if (i < 16) {
  47. W[i] = M[offset + i] | 0;
  48. } else {
  49. var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
  50. W[i] = (n << 1) | (n >>> 31);
  51. }
  52. var t = ((a << 5) | (a >>> 27)) + e + W[i];
  53. if (i < 20) {
  54. t += ((b & c) | (~b & d)) + 0x5a827999;
  55. } else if (i < 40) {
  56. t += (b ^ c ^ d) + 0x6ed9eba1;
  57. } else if (i < 60) {
  58. t += ((b & c) | (b & d) | (c & d)) - 0x70e44324;
  59. } else /* if (i < 80) */ {
  60. t += (b ^ c ^ d) - 0x359d3e2a;
  61. }
  62. e = d;
  63. d = c;
  64. c = (b << 30) | (b >>> 2);
  65. b = a;
  66. a = t;
  67. }
  68. // Intermediate hash value
  69. H[0] = (H[0] + a) | 0;
  70. H[1] = (H[1] + b) | 0;
  71. H[2] = (H[2] + c) | 0;
  72. H[3] = (H[3] + d) | 0;
  73. H[4] = (H[4] + e) | 0;
  74. },
  75. _doFinalize: function () {
  76. // Shortcuts
  77. var data = this._data;
  78. var dataWords = data.words;
  79. var nBitsTotal = this._nDataBytes * 8;
  80. var nBitsLeft = data.sigBytes * 8;
  81. // Add padding
  82. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  83. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
  84. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
  85. data.sigBytes = dataWords.length * 4;
  86. // Hash final blocks
  87. this._process();
  88. // Return final computed hash
  89. return this._hash;
  90. },
  91. clone: function () {
  92. var clone = Hasher.clone.call(this);
  93. clone._hash = this._hash.clone();
  94. return clone;
  95. }
  96. });
  97. /**
  98. * Shortcut function to the hasher's object interface.
  99. *
  100. * @param {WordArray|string} message The message to hash.
  101. *
  102. * @return {WordArray} The hash.
  103. *
  104. * @static
  105. *
  106. * @example
  107. *
  108. * var hash = CryptoJS.SHA1('message');
  109. * var hash = CryptoJS.SHA1(wordArray);
  110. */
  111. C.SHA1 = Hasher._createHelper(SHA1);
  112. /**
  113. * Shortcut function to the HMAC's object interface.
  114. *
  115. * @param {WordArray|string} message The message to hash.
  116. * @param {WordArray|string} key The secret key.
  117. *
  118. * @return {WordArray} The HMAC.
  119. *
  120. * @static
  121. *
  122. * @example
  123. *
  124. * var hmac = CryptoJS.HmacSHA1(message, key);
  125. */
  126. C.HmacSHA1 = Hasher._createHmacHelper(SHA1);
  127. }());
  128. return CryptoJS.SHA1;
  129. }));