PageRenderTime 24ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA1.as

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
ActionScript | 106 lines | 68 code | 12 blank | 26 comment | 8 complexity | ba97b95bebda5bdd3fe2063e9c7e21cd MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /**
  2. * SHA1
  3. *
  4. * An ActionScript 3 implementation of Secure Hash Algorithm, SHA-1, as defined
  5. * in FIPS PUB 180-1
  6. * Copyright (c) 2007 Henri Torgemane
  7. *
  8. * Derived from:
  9. * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
  10. * in FIPS PUB 180-1
  11. * Version 2.1a Copyright Paul Johnston 2000 - 2002.
  12. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  13. *
  14. * See LICENSE.txt for full license information.
  15. */
  16. package com.hurlant.crypto.hash
  17. {
  18. public class SHA1 extends SHABase implements IHash
  19. {
  20. public static const HASH_SIZE:int = 20;
  21. public override function getHashSize():uint {
  22. return HASH_SIZE;
  23. }
  24. protected override function core(x:Array, len:uint):Array
  25. {
  26. /* append padding */
  27. x[len >> 5] |= 0x80 << (24 - len % 32);
  28. x[((len + 64 >> 9) << 4) + 15] = len;
  29. var w:Array = [];
  30. var a:uint = 0x67452301; //1732584193;
  31. var b:uint = 0xEFCDAB89; //-271733879;
  32. var c:uint = 0x98BADCFE; //-1732584194;
  33. var d:uint = 0x10325476; //271733878;
  34. var e:uint = 0xC3D2E1F0; //-1009589776;
  35. for(var i:uint = 0; i < x.length; i += 16)
  36. {
  37. var olda:uint = a;
  38. var oldb:uint = b;
  39. var oldc:uint = c;
  40. var oldd:uint = d;
  41. var olde:uint = e;
  42. for(var j:uint = 0; j < 80; j++)
  43. {
  44. if (j < 16) {
  45. w[j] = x[i + j] || 0;
  46. } else {
  47. w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
  48. }
  49. var t:uint = rol(a,5) + ft(j,b,c,d) + e + w[j] + kt(j);
  50. e = d;
  51. d = c;
  52. c = rol(b, 30);
  53. b = a;
  54. a = t;
  55. }
  56. a += olda;
  57. b += oldb;
  58. c += oldc;
  59. d += oldd;
  60. e += olde;
  61. }
  62. return [ a, b, c, d, e ];
  63. }
  64. /*
  65. * Bitwise rotate a 32-bit number to the left.
  66. */
  67. private function rol(num:uint, cnt:uint):uint
  68. {
  69. return (num << cnt) | (num >>> (32 - cnt));
  70. }
  71. /*
  72. * Perform the appropriate triplet combination function for the current
  73. * iteration
  74. */
  75. private function ft(t:uint, b:uint, c:uint, d:uint):uint
  76. {
  77. if(t < 20) return (b & c) | ((~b) & d);
  78. if(t < 40) return b ^ c ^ d;
  79. if(t < 60) return (b & c) | (b & d) | (c & d);
  80. return b ^ c ^ d;
  81. }
  82. /*
  83. * Determine the appropriate additive constant for the current iteration
  84. */
  85. private function kt(t:uint):uint
  86. {
  87. return (t < 20) ? 0x5A827999 : (t < 40) ? 0x6ED9EBA1 :
  88. (t < 60) ? 0x8F1BBCDC : 0xCA62C1D6;
  89. }
  90. public override function toString():String {
  91. return "sha1";
  92. }
  93. }
  94. }