rocket-js 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +5 -52
- data/spec/ruby/spec_helper.rb +2 -1
- metadata +7 -129
- data/src/vendor/web-socket-js/FABridge.js +0 -604
- data/src/vendor/web-socket-js/README.txt +0 -109
- data/src/vendor/web-socket-js/WebSocketMain.swf +0 -0
- data/src/vendor/web-socket-js/WebSocketMainInsecure.zip +0 -0
- data/src/vendor/web-socket-js/flash-src/WebSocket.as +0 -473
- data/src/vendor/web-socket-js/flash-src/WebSocketMain.as +0 -88
- data/src/vendor/web-socket-js/flash-src/WebSocketMainInsecure.as +0 -19
- data/src/vendor/web-socket-js/flash-src/WebSocketStateEvent.as +0 -32
- data/src/vendor/web-socket-js/flash-src/bridge/FABridge.as +0 -943
- data/src/vendor/web-socket-js/flash-src/build.sh +0 -10
- data/src/vendor/web-socket-js/flash-src/com/adobe/net/proxies/RFC2817Socket.as +0 -204
- data/src/vendor/web-socket-js/flash-src/com/gsolo/encryption/MD5.as +0 -375
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/Crypto.as +0 -287
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/MozillaRootCertificates.as +0 -3235
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/X509Certificate.as +0 -218
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/X509CertificateCollection.as +0 -57
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/HMAC.as +0 -82
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/IHMAC.as +0 -27
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/IHash.as +0 -21
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MAC.as +0 -137
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MD2.as +0 -124
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MD5.as +0 -204
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA1.as +0 -106
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA224.as +0 -28
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA256.as +0 -115
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHABase.as +0 -71
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/prng/ARC4.as +0 -90
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/prng/IPRNG.as +0 -20
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/prng/Random.as +0 -119
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/prng/TLSPRF.as +0 -142
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/rsa/RSAKey.as +0 -339
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/AESKey.as +0 -2797
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/BlowFishKey.as +0 -375
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CBCMode.as +0 -55
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CFB8Mode.as +0 -61
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CFBMode.as +0 -64
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CTRMode.as +0 -58
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/DESKey.as +0 -365
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/ECBMode.as +0 -86
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/ICipher.as +0 -21
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/IMode.as +0 -15
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/IPad.as +0 -32
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/IStreamCipher.as +0 -21
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/ISymmetricKey.as +0 -35
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/IVMode.as +0 -110
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/NullPad.as +0 -34
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/OFBMode.as +0 -52
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/PKCS5.as +0 -44
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/SSLPad.as +0 -44
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/SimpleIVMode.as +0 -60
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/TLSPad.as +0 -42
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/TripleDESKey.as +0 -88
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/XTeaKey.as +0 -94
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/aeskey.pl +0 -29
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/dump.txt +0 -2304
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/AESKeyTest.as +0 -1220
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/ARC4Test.as +0 -58
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/BigIntegerTest.as +0 -39
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/BlowFishKeyTest.as +0 -148
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/CBCModeTest.as +0 -160
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/CFB8ModeTest.as +0 -71
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/CFBModeTest.as +0 -98
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/CTRModeTest.as +0 -109
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/DESKeyTest.as +0 -112
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/ECBModeTest.as +0 -151
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/HMACTest.as +0 -184
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/ITestHarness.as +0 -20
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/MD2Test.as +0 -56
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/MD5Test.as +0 -58
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/OFBModeTest.as +0 -101
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/RSAKeyTest.as +0 -92
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/SHA1Test.as +0 -198
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/SHA224Test.as +0 -58
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/SHA256Test.as +0 -60
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/TLSPRFTest.as +0 -51
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/TestCase.as +0 -42
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/TripleDESKeyTest.as +0 -59
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/XTeaKeyTest.as +0 -66
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/BulkCiphers.as +0 -102
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/CipherSuites.as +0 -117
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/IConnectionState.as +0 -14
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/ISecurityParameters.as +0 -29
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/KeyExchanges.as +0 -24
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/MACs.as +0 -38
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/SSLConnectionState.as +0 -171
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/SSLEvent.as +0 -26
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/SSLSecurityParameters.as +0 -340
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSConfig.as +0 -70
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSConnectionState.as +0 -151
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSEngine.as +0 -895
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSError.as +0 -39
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSEvent.as +0 -27
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSSecurityParameters.as +0 -197
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSSocket.as +0 -370
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSSocketEvent.as +0 -26
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSTest.as +0 -180
- data/src/vendor/web-socket-js/flash-src/com/hurlant/math/BarrettReduction.as +0 -90
- data/src/vendor/web-socket-js/flash-src/com/hurlant/math/BigInteger.as +0 -1543
- data/src/vendor/web-socket-js/flash-src/com/hurlant/math/ClassicReduction.as +0 -35
- data/src/vendor/web-socket-js/flash-src/com/hurlant/math/IReduction.as +0 -11
- data/src/vendor/web-socket-js/flash-src/com/hurlant/math/MontgomeryReduction.as +0 -85
- data/src/vendor/web-socket-js/flash-src/com/hurlant/math/NullReduction.as +0 -34
- data/src/vendor/web-socket-js/flash-src/com/hurlant/math/bi_internal.as +0 -11
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/ArrayUtil.as +0 -25
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/Base64.as +0 -189
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/Hex.as +0 -66
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/Memory.as +0 -28
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/ByteString.as +0 -43
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/DER.as +0 -210
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/IAsn1Type.as +0 -21
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/Integer.as +0 -44
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/OID.as +0 -35
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/ObjectIdentifier.as +0 -112
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/PEM.as +0 -118
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/PrintableString.as +0 -49
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/Sequence.as +0 -90
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/Set.as +0 -27
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/Type.as +0 -94
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/UTCTime.as +0 -60
- data/src/vendor/web-socket-js/sample.html +0 -76
- data/src/vendor/web-socket-js/swfobject.js +0 -4
- data/src/vendor/web-socket-js/web_socket.js +0 -388
@@ -1,115 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* SHA256
|
3
|
-
*
|
4
|
-
* An ActionScript 3 implementation of Secure Hash Algorithm, SHA-256, as defined
|
5
|
-
* in FIPS PUB 180-2
|
6
|
-
* Copyright (c) 2007 Henri Torgemane
|
7
|
-
*
|
8
|
-
* Derived from:
|
9
|
-
* A JavaScript implementation of the Secure Hash Standard
|
10
|
-
* Version 0.3 Copyright Angel Marin 2003-2004 - http://anmar.eu.org/
|
11
|
-
* Derived from:
|
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
|
-
*
|
17
|
-
* See LICENSE.txt for full license information.
|
18
|
-
*/
|
19
|
-
package com.hurlant.crypto.hash
|
20
|
-
{
|
21
|
-
|
22
|
-
|
23
|
-
public class SHA256 extends SHABase implements IHash
|
24
|
-
{
|
25
|
-
|
26
|
-
protected static const k:Array = [
|
27
|
-
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
28
|
-
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
29
|
-
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
30
|
-
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
31
|
-
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
32
|
-
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
33
|
-
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
34
|
-
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
|
35
|
-
protected var h:Array = [
|
36
|
-
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
37
|
-
];
|
38
|
-
|
39
|
-
public function SHA256(){
|
40
|
-
}
|
41
|
-
|
42
|
-
public override function getHashSize():uint
|
43
|
-
{
|
44
|
-
return 32;
|
45
|
-
}
|
46
|
-
|
47
|
-
protected override function core(x:Array, len:uint):Array {
|
48
|
-
/* append padding */
|
49
|
-
x[len >> 5] |= 0x80 << (24 - len % 32);
|
50
|
-
x[((len + 64 >> 9) << 4) + 15] = len;
|
51
|
-
|
52
|
-
var w:Array = [];
|
53
|
-
var a:uint = h[0];
|
54
|
-
var b:uint = h[1];
|
55
|
-
var c:uint = h[2];
|
56
|
-
var d:uint = h[3];
|
57
|
-
var e:uint = h[4];
|
58
|
-
var f:uint = h[5];
|
59
|
-
var g:uint = h[6];
|
60
|
-
var h:uint = h[7];
|
61
|
-
|
62
|
-
for (var i:uint=0; i<x.length; i+=16) {
|
63
|
-
var olda:uint = a;
|
64
|
-
var oldb:uint = b;
|
65
|
-
var oldc:uint = c;
|
66
|
-
var oldd:uint = d;
|
67
|
-
var olde:uint = e;
|
68
|
-
var oldf:uint = f;
|
69
|
-
var oldg:uint = g;
|
70
|
-
var oldh:uint = h;
|
71
|
-
|
72
|
-
for (var j:uint=0; j<64; j++) {
|
73
|
-
if (j<16) {
|
74
|
-
w[j] = x[i+j] || 0;
|
75
|
-
} else {
|
76
|
-
var s0:uint = rrol(w[j-15],7)^rrol(w[j-15],18)^(w[j-15]>>>3);
|
77
|
-
var s1:uint = rrol(w[j-2], 17)^rrol(w[j-2],19)^(w[j-2]>>>10);
|
78
|
-
w[j] = w[j-16] + s0 + w[j-7] + s1;
|
79
|
-
}
|
80
|
-
var t2:uint = (rrol(a,2) ^ rrol(a,13) ^ rrol(a,22)) + ((a&b) ^ (a&c) ^ (b&c));
|
81
|
-
var t1:uint = h + (rrol(e,6) ^ rrol(e,11) ^ rrol(e,25)) + ((e&f)^(g&~e)) + k[j] + w[j]
|
82
|
-
h = g;
|
83
|
-
g = f;
|
84
|
-
f = e;
|
85
|
-
e = d + t1;
|
86
|
-
d = c;
|
87
|
-
c = b;
|
88
|
-
b = a;
|
89
|
-
a = t1 + t2;
|
90
|
-
|
91
|
-
}
|
92
|
-
a += olda;
|
93
|
-
b += oldb;
|
94
|
-
c += oldc;
|
95
|
-
d += oldd;
|
96
|
-
e += olde;
|
97
|
-
f += oldf;
|
98
|
-
g += oldg;
|
99
|
-
h += oldh;
|
100
|
-
}
|
101
|
-
return [ a,b,c,d,e,f,g,h ];
|
102
|
-
}
|
103
|
-
|
104
|
-
/*
|
105
|
-
* Bitwise rotate a 32-bit number to the right.
|
106
|
-
*/
|
107
|
-
protected function rrol(num:uint, cnt:uint):uint {
|
108
|
-
return (num << (32-cnt)) | (num >>> cnt);
|
109
|
-
}
|
110
|
-
|
111
|
-
public override function toString():String {
|
112
|
-
return "sha256";
|
113
|
-
}
|
114
|
-
}
|
115
|
-
}
|
@@ -1,71 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* SHABase
|
3
|
-
*
|
4
|
-
* An ActionScript 3 abstract class for the SHA family of hash functions
|
5
|
-
* Copyright (c) 2007 Henri Torgemane
|
6
|
-
*
|
7
|
-
* See LICENSE.txt for full license information.
|
8
|
-
*/
|
9
|
-
package com.hurlant.crypto.hash
|
10
|
-
{
|
11
|
-
import flash.utils.ByteArray;
|
12
|
-
import flash.utils.Endian;
|
13
|
-
|
14
|
-
public class SHABase implements IHash
|
15
|
-
{
|
16
|
-
|
17
|
-
public function SHABase() { }
|
18
|
-
|
19
|
-
public var pad_size:int = 40;
|
20
|
-
public function getInputSize():uint
|
21
|
-
{
|
22
|
-
return 64;
|
23
|
-
}
|
24
|
-
|
25
|
-
public function getHashSize():uint
|
26
|
-
{
|
27
|
-
return 0;
|
28
|
-
}
|
29
|
-
|
30
|
-
public function getPadSize():int
|
31
|
-
{
|
32
|
-
return pad_size;
|
33
|
-
}
|
34
|
-
|
35
|
-
public function hash(src:ByteArray):ByteArray
|
36
|
-
{
|
37
|
-
var savedLength:uint = src.length;
|
38
|
-
var savedEndian:String = src.endian;
|
39
|
-
|
40
|
-
src.endian = Endian.BIG_ENDIAN;
|
41
|
-
var len:uint = savedLength *8;
|
42
|
-
// pad to nearest int.
|
43
|
-
while (src.length%4!=0) {
|
44
|
-
src[src.length]=0;
|
45
|
-
}
|
46
|
-
// convert ByteArray to an array of uint
|
47
|
-
src.position=0;
|
48
|
-
var a:Array = [];
|
49
|
-
for (var i:uint=0;i<src.length;i+=4) {
|
50
|
-
a.push(src.readUnsignedInt());
|
51
|
-
}
|
52
|
-
var h:Array = core(a, len);
|
53
|
-
var out:ByteArray = new ByteArray;
|
54
|
-
var words:uint = getHashSize()/4;
|
55
|
-
for (i=0;i<words;i++) {
|
56
|
-
out.writeUnsignedInt(h[i]);
|
57
|
-
}
|
58
|
-
// unpad, to leave the source untouched.
|
59
|
-
src.length = savedLength;
|
60
|
-
src.endian = savedEndian;
|
61
|
-
return out;
|
62
|
-
}
|
63
|
-
protected function core(x:Array, len:uint):Array {
|
64
|
-
return null;
|
65
|
-
}
|
66
|
-
|
67
|
-
public function toString():String {
|
68
|
-
return "sha";
|
69
|
-
}
|
70
|
-
}
|
71
|
-
}
|
@@ -1,90 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* ARC4
|
3
|
-
*
|
4
|
-
* An ActionScript 3 implementation of RC4
|
5
|
-
* Copyright (c) 2007 Henri Torgemane
|
6
|
-
*
|
7
|
-
* Derived from:
|
8
|
-
* The jsbn library, Copyright (c) 2003-2005 Tom Wu
|
9
|
-
*
|
10
|
-
* See LICENSE.txt for full license information.
|
11
|
-
*/
|
12
|
-
package com.hurlant.crypto.prng
|
13
|
-
{
|
14
|
-
import com.hurlant.crypto.symmetric.IStreamCipher;
|
15
|
-
import com.hurlant.util.Memory;
|
16
|
-
|
17
|
-
import flash.utils.ByteArray;
|
18
|
-
|
19
|
-
public class ARC4 implements IPRNG, IStreamCipher {
|
20
|
-
private var i:int = 0;
|
21
|
-
private var j:int = 0;
|
22
|
-
private var S:ByteArray;
|
23
|
-
private const psize:uint = 256;
|
24
|
-
public function ARC4(key:ByteArray = null){
|
25
|
-
S = new ByteArray;
|
26
|
-
if (key) {
|
27
|
-
init(key);
|
28
|
-
}
|
29
|
-
}
|
30
|
-
public function getPoolSize():uint {
|
31
|
-
return psize;
|
32
|
-
}
|
33
|
-
public function init(key:ByteArray):void {
|
34
|
-
var i:int;
|
35
|
-
var j:int;
|
36
|
-
var t:int;
|
37
|
-
for (i=0; i<256; ++i) {
|
38
|
-
S[i] = i;
|
39
|
-
}
|
40
|
-
j=0;
|
41
|
-
for (i=0; i<256; ++i) {
|
42
|
-
j = (j + S[i] + key[i%key.length]) & 255;
|
43
|
-
t = S[i];
|
44
|
-
S[i] = S[j];
|
45
|
-
S[j] = t;
|
46
|
-
}
|
47
|
-
this.i=0;
|
48
|
-
this.j=0;
|
49
|
-
}
|
50
|
-
public function next():uint {
|
51
|
-
var t:int;
|
52
|
-
i = (i+1)&255;
|
53
|
-
j = (j+S[i])&255;
|
54
|
-
t = S[i];
|
55
|
-
S[i] = S[j];
|
56
|
-
S[j] = t;
|
57
|
-
return S[(t+S[i])&255];
|
58
|
-
}
|
59
|
-
|
60
|
-
public function getBlockSize():uint {
|
61
|
-
return 1;
|
62
|
-
}
|
63
|
-
|
64
|
-
public function encrypt(block:ByteArray):void {
|
65
|
-
var i:uint = 0;
|
66
|
-
while (i<block.length) {
|
67
|
-
block[i++] ^= next();
|
68
|
-
}
|
69
|
-
}
|
70
|
-
public function decrypt(block:ByteArray):void {
|
71
|
-
encrypt(block); // the beauty of XOR.
|
72
|
-
}
|
73
|
-
public function dispose():void {
|
74
|
-
var i:uint = 0;
|
75
|
-
if (S!=null) {
|
76
|
-
for (i=0;i<S.length;i++) {
|
77
|
-
S[i] = Math.random()*256;
|
78
|
-
}
|
79
|
-
S.length=0;
|
80
|
-
S = null;
|
81
|
-
}
|
82
|
-
this.i = 0;
|
83
|
-
this.j = 0;
|
84
|
-
Memory.gc();
|
85
|
-
}
|
86
|
-
public function toString():String {
|
87
|
-
return "rc4";
|
88
|
-
}
|
89
|
-
}
|
90
|
-
}
|
@@ -1,20 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* IPRNG
|
3
|
-
*
|
4
|
-
* An interface for classes that can be used a pseudo-random number generators
|
5
|
-
* Copyright (c) 2007 Henri Torgemane
|
6
|
-
*
|
7
|
-
* See LICENSE.txt for full license information.
|
8
|
-
*/
|
9
|
-
package com.hurlant.crypto.prng
|
10
|
-
{
|
11
|
-
import flash.utils.ByteArray;
|
12
|
-
|
13
|
-
public interface IPRNG {
|
14
|
-
function getPoolSize():uint;
|
15
|
-
function init(key:ByteArray):void;
|
16
|
-
function next():uint;
|
17
|
-
function dispose():void;
|
18
|
-
function toString():String;
|
19
|
-
}
|
20
|
-
}
|
@@ -1,119 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Random
|
3
|
-
*
|
4
|
-
* An ActionScript 3 implementation of a Random Number Generator
|
5
|
-
* Copyright (c) 2007 Henri Torgemane
|
6
|
-
*
|
7
|
-
* Derived from:
|
8
|
-
* The jsbn library, Copyright (c) 2003-2005 Tom Wu
|
9
|
-
*
|
10
|
-
* See LICENSE.txt for full license information.
|
11
|
-
*/
|
12
|
-
package com.hurlant.crypto.prng
|
13
|
-
{
|
14
|
-
import flash.utils.ByteArray;
|
15
|
-
import com.hurlant.util.Memory;
|
16
|
-
import flash.system.System;
|
17
|
-
import flash.system.Capabilities;
|
18
|
-
import flash.accessibility.AccessibilityProperties;
|
19
|
-
import flash.display.SWFVersion;
|
20
|
-
import flash.display.Stage;
|
21
|
-
import flash.utils.getTimer;
|
22
|
-
import flash.text.Font;
|
23
|
-
|
24
|
-
public class Random
|
25
|
-
{
|
26
|
-
private var state:IPRNG;
|
27
|
-
private var ready:Boolean = false;
|
28
|
-
private var pool:ByteArray;
|
29
|
-
private var psize:int;
|
30
|
-
private var pptr:int;
|
31
|
-
private var seeded:Boolean = false;
|
32
|
-
|
33
|
-
public function Random(prng:Class = null) {
|
34
|
-
if (prng==null) prng = ARC4;
|
35
|
-
state = new prng as IPRNG;
|
36
|
-
psize= state.getPoolSize();
|
37
|
-
pool = new ByteArray;
|
38
|
-
pptr = 0;
|
39
|
-
while (pptr <psize) {
|
40
|
-
var t:uint = 65536*Math.random();
|
41
|
-
pool[pptr++] = t >>> 8;
|
42
|
-
pool[pptr++] = t&255;
|
43
|
-
}
|
44
|
-
pptr=0;
|
45
|
-
seed();
|
46
|
-
}
|
47
|
-
|
48
|
-
public function seed(x:int = 0):void {
|
49
|
-
if (x==0) {
|
50
|
-
x = new Date().getTime();
|
51
|
-
}
|
52
|
-
pool[pptr++] ^= x & 255;
|
53
|
-
pool[pptr++] ^= (x>>8)&255;
|
54
|
-
pool[pptr++] ^= (x>>16)&255;
|
55
|
-
pool[pptr++] ^= (x>>24)&255;
|
56
|
-
pptr %= psize;
|
57
|
-
seeded = true;
|
58
|
-
}
|
59
|
-
|
60
|
-
/**
|
61
|
-
* Gather anything we have that isn't entirely predictable:
|
62
|
-
* - memory used
|
63
|
-
* - system capabilities
|
64
|
-
* - timing stuff
|
65
|
-
* - installed fonts
|
66
|
-
*/
|
67
|
-
public function autoSeed():void {
|
68
|
-
var b:ByteArray = new ByteArray;
|
69
|
-
b.writeUnsignedInt(System.totalMemory);
|
70
|
-
b.writeUTF(Capabilities.serverString);
|
71
|
-
b.writeUnsignedInt(getTimer());
|
72
|
-
b.writeUnsignedInt((new Date).getTime());
|
73
|
-
var a:Array = Font.enumerateFonts(true);
|
74
|
-
for each (var f:Font in a) {
|
75
|
-
b.writeUTF(f.fontName);
|
76
|
-
b.writeUTF(f.fontStyle);
|
77
|
-
b.writeUTF(f.fontType);
|
78
|
-
}
|
79
|
-
b.position=0;
|
80
|
-
while (b.bytesAvailable>=4) {
|
81
|
-
seed(b.readUnsignedInt());
|
82
|
-
}
|
83
|
-
}
|
84
|
-
|
85
|
-
|
86
|
-
public function nextBytes(buffer:ByteArray, length:int):void {
|
87
|
-
while (length--) {
|
88
|
-
buffer.writeByte(nextByte());
|
89
|
-
}
|
90
|
-
}
|
91
|
-
public function nextByte():int {
|
92
|
-
if (!ready) {
|
93
|
-
if (!seeded) {
|
94
|
-
autoSeed();
|
95
|
-
}
|
96
|
-
state.init(pool);
|
97
|
-
pool.length = 0;
|
98
|
-
pptr = 0;
|
99
|
-
ready = true;
|
100
|
-
}
|
101
|
-
return state.next();
|
102
|
-
}
|
103
|
-
public function dispose():void {
|
104
|
-
for (var i:uint=0;i<pool.length;i++) {
|
105
|
-
pool[i] = Math.random()*256;
|
106
|
-
}
|
107
|
-
pool.length=0;
|
108
|
-
pool = null;
|
109
|
-
state.dispose();
|
110
|
-
state = null;
|
111
|
-
psize = 0;
|
112
|
-
pptr = 0;
|
113
|
-
Memory.gc();
|
114
|
-
}
|
115
|
-
public function toString():String {
|
116
|
-
return "random-"+state.toString();
|
117
|
-
}
|
118
|
-
}
|
119
|
-
}
|
@@ -1,142 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* TLSPRF
|
3
|
-
*
|
4
|
-
* An ActionScript 3 implementation of a pseudo-random generator
|
5
|
-
* that follows the TLS specification
|
6
|
-
* Copyright (c) 2007 Henri Torgemane
|
7
|
-
*
|
8
|
-
* See LICENSE.txt for full license information.
|
9
|
-
*/
|
10
|
-
package com.hurlant.crypto.prng
|
11
|
-
{
|
12
|
-
import flash.utils.ByteArray;
|
13
|
-
import com.hurlant.crypto.hash.HMAC;
|
14
|
-
import com.hurlant.crypto.hash.MD5;
|
15
|
-
import com.hurlant.crypto.hash.SHA1;
|
16
|
-
import com.hurlant.util.Memory;
|
17
|
-
import com.hurlant.util.Hex;
|
18
|
-
import flash.utils.IDataOutput;
|
19
|
-
|
20
|
-
/**
|
21
|
-
* There's "Random", and then there's TLS Random.
|
22
|
-
* .
|
23
|
-
* Still Pseudo-random, though.
|
24
|
-
*/
|
25
|
-
public class TLSPRF
|
26
|
-
{
|
27
|
-
// XXX WAY TOO MANY STRUCTURES HERE
|
28
|
-
|
29
|
-
// seed
|
30
|
-
private var seed:ByteArray;
|
31
|
-
// P_MD5's secret
|
32
|
-
private var s1:ByteArray;
|
33
|
-
// P_SHA-1's secret
|
34
|
-
private var s2:ByteArray;
|
35
|
-
// HMAC_MD5's A
|
36
|
-
private var a1:ByteArray;
|
37
|
-
// HMAC_SHA1's A
|
38
|
-
private var a2:ByteArray;
|
39
|
-
// Pool for P_MD5
|
40
|
-
private var p1:ByteArray;
|
41
|
-
// Pool for P_SHA1
|
42
|
-
private var p2:ByteArray;
|
43
|
-
// Data for HMAC_MD5
|
44
|
-
private var d1:ByteArray;
|
45
|
-
// Data for HMAC_SHA1
|
46
|
-
private var d2:ByteArray;
|
47
|
-
|
48
|
-
|
49
|
-
private var hmac_md5:HMAC;
|
50
|
-
private var hmac_sha1:HMAC;
|
51
|
-
|
52
|
-
public function TLSPRF(secret:ByteArray, label:String, seed:ByteArray) {
|
53
|
-
var l:int = Math.ceil(secret.length/2);
|
54
|
-
var s1:ByteArray = new ByteArray;
|
55
|
-
var s2:ByteArray = new ByteArray;
|
56
|
-
s1.writeBytes(secret, 0, l);
|
57
|
-
s2.writeBytes(secret, secret.length-l, l);
|
58
|
-
var s:ByteArray = new ByteArray;
|
59
|
-
s.writeUTFBytes(label);
|
60
|
-
s.writeBytes(seed);
|
61
|
-
this.seed = s;
|
62
|
-
this.s1 = s1;
|
63
|
-
this.s2 = s2;
|
64
|
-
hmac_md5 = new HMAC(new MD5);
|
65
|
-
hmac_sha1 = new HMAC(new SHA1);
|
66
|
-
|
67
|
-
this.a1 = hmac_md5.compute(s1, this.seed);
|
68
|
-
this.a2 = hmac_sha1.compute(s2, this.seed);
|
69
|
-
|
70
|
-
p1 = new ByteArray;
|
71
|
-
p2 = new ByteArray;
|
72
|
-
|
73
|
-
d1 = new ByteArray;
|
74
|
-
d2 = new ByteArray;
|
75
|
-
d1.position = MD5.HASH_SIZE;
|
76
|
-
d1.writeBytes(this.seed);
|
77
|
-
d2.position = SHA1.HASH_SIZE;
|
78
|
-
d2.writeBytes(this.seed);
|
79
|
-
}
|
80
|
-
|
81
|
-
// XXX HORRIBLY SLOW. REWRITE.
|
82
|
-
public function nextBytes(buffer:IDataOutput, length:int):void {
|
83
|
-
while (length--) {
|
84
|
-
buffer.writeByte(nextByte());
|
85
|
-
}
|
86
|
-
}
|
87
|
-
public function nextByte():int {
|
88
|
-
if (p1.bytesAvailable==0) {
|
89
|
-
more_md5();
|
90
|
-
}
|
91
|
-
if (p2.bytesAvailable==0) {
|
92
|
-
more_sha1();
|
93
|
-
}
|
94
|
-
return p1.readUnsignedByte()^p2.readUnsignedByte();
|
95
|
-
}
|
96
|
-
public function dispose():void {
|
97
|
-
seed = dba(seed);
|
98
|
-
s1 = dba(s1);
|
99
|
-
s2 = dba(s2);
|
100
|
-
a1 = dba(a1);
|
101
|
-
a2 = dba(a2);
|
102
|
-
p1 = dba(p1);
|
103
|
-
p2 = dba(p2);
|
104
|
-
d1 = dba(d1);
|
105
|
-
d2 = dba(d2);
|
106
|
-
hmac_md5.dispose();
|
107
|
-
hmac_md5 = null;
|
108
|
-
hmac_sha1.dispose();
|
109
|
-
hmac_sha1 = null;
|
110
|
-
Memory.gc();
|
111
|
-
}
|
112
|
-
public function toString():String {
|
113
|
-
return "tls-prf";
|
114
|
-
}
|
115
|
-
private function dba(ba:ByteArray):ByteArray {
|
116
|
-
for (var i:uint=0;i<ba.length;i++) {
|
117
|
-
ba[i]=0;
|
118
|
-
}
|
119
|
-
ba.length=0;
|
120
|
-
return null;
|
121
|
-
}
|
122
|
-
private function more_md5():void {
|
123
|
-
d1.position=0;
|
124
|
-
d1.writeBytes(a1);
|
125
|
-
var p:int = p1.position;
|
126
|
-
var more:ByteArray = hmac_md5.compute(s1, d1);
|
127
|
-
a1 = hmac_md5.compute(s1, a1);
|
128
|
-
p1.writeBytes(more);
|
129
|
-
p1.position=p;
|
130
|
-
}
|
131
|
-
private function more_sha1():void {
|
132
|
-
d2.position=0;
|
133
|
-
d2.writeBytes(a2);
|
134
|
-
var p:int = p2.position;
|
135
|
-
var more:ByteArray = hmac_sha1.compute(s2, d2);
|
136
|
-
a2 = hmac_sha1.compute(s2, a2);
|
137
|
-
p2.writeBytes(more);
|
138
|
-
p2.position=p;
|
139
|
-
}
|
140
|
-
|
141
|
-
}
|
142
|
-
}
|