sha1.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. (function() {
  2. var nodeEnv = typeof require !== 'undefined' && typeof process !== 'undefined';
  3. var __module = nodeEnv ? module : {exports:{}};
  4. var __filename = 'preview-scripts/__node_modules/sha.js/sha1.js';
  5. var __require = nodeEnv ? function (request) {
  6. return cc.require(request);
  7. } : function (request) {
  8. return __quick_compile_project__.require(request, __filename);
  9. };
  10. function __define (exports, require, module) {
  11. if (!nodeEnv) {__quick_compile_project__.registerModule(__filename, module);}/*
  12. * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
  13. * in FIPS PUB 180-1
  14. * Version 2.1a Copyright Paul Johnston 2000 - 2002.
  15. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  16. * Distributed under the BSD License
  17. * See http://pajhome.org.uk/crypt/md5 for details.
  18. */
  19. var inherits = require('inherits')
  20. var Hash = require('./hash')
  21. var Buffer = require('safe-buffer').Buffer
  22. var K = [
  23. 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
  24. ]
  25. var W = new Array(80)
  26. function Sha1 () {
  27. this.init()
  28. this._w = W
  29. Hash.call(this, 64, 56)
  30. }
  31. inherits(Sha1, Hash)
  32. Sha1.prototype.init = function () {
  33. this._a = 0x67452301
  34. this._b = 0xefcdab89
  35. this._c = 0x98badcfe
  36. this._d = 0x10325476
  37. this._e = 0xc3d2e1f0
  38. return this
  39. }
  40. function rotl1 (num) {
  41. return (num << 1) | (num >>> 31)
  42. }
  43. function rotl5 (num) {
  44. return (num << 5) | (num >>> 27)
  45. }
  46. function rotl30 (num) {
  47. return (num << 30) | (num >>> 2)
  48. }
  49. function ft (s, b, c, d) {
  50. if (s === 0) return (b & c) | ((~b) & d)
  51. if (s === 2) return (b & c) | (b & d) | (c & d)
  52. return b ^ c ^ d
  53. }
  54. Sha1.prototype._update = function (M) {
  55. var W = this._w
  56. var a = this._a | 0
  57. var b = this._b | 0
  58. var c = this._c | 0
  59. var d = this._d | 0
  60. var e = this._e | 0
  61. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
  62. for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16])
  63. for (var j = 0; j < 80; ++j) {
  64. var s = ~~(j / 20)
  65. var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
  66. e = d
  67. d = c
  68. c = rotl30(b)
  69. b = a
  70. a = t
  71. }
  72. this._a = (a + this._a) | 0
  73. this._b = (b + this._b) | 0
  74. this._c = (c + this._c) | 0
  75. this._d = (d + this._d) | 0
  76. this._e = (e + this._e) | 0
  77. }
  78. Sha1.prototype._hash = function () {
  79. var H = Buffer.allocUnsafe(20)
  80. H.writeInt32BE(this._a | 0, 0)
  81. H.writeInt32BE(this._b | 0, 4)
  82. H.writeInt32BE(this._c | 0, 8)
  83. H.writeInt32BE(this._d | 0, 12)
  84. H.writeInt32BE(this._e | 0, 16)
  85. return H
  86. }
  87. module.exports = Sha1
  88. }
  89. if (nodeEnv) {
  90. __define(__module.exports, __require, __module);
  91. }
  92. else {
  93. __quick_compile_project__.registerModuleFunc(__filename, function () {
  94. __define(__module.exports, __require, __module);
  95. });
  96. }
  97. })();