mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-20 01:37:50 -05:00
Brought up to date with the private repository (feea4c7)
This commit is contained in:
1 parent
1aa738d692
commit
1b1df1ae48
7925 files changed
+2617237
-20
No files matched your search
@@ -0,0 +1,115 @@
|
||||
package com.hurlant.crypto.prng
|
||||
{
|
||||
import com.hurlant.crypto.symmetric.IStreamCipher;
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class ARC4 implements IPRNG, IStreamCipher
|
||||
{
|
||||
|
||||
private var i:int = 0;
|
||||
|
||||
private var j:int = 0;
|
||||
|
||||
private var S:ByteArray;
|
||||
|
||||
private const psize:uint = 256;
|
||||
|
||||
public function ARC4(param1:ByteArray = null)
|
||||
{
|
||||
super();
|
||||
S = new ByteArray();
|
||||
if(param1)
|
||||
{
|
||||
init(param1);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPoolSize() : uint
|
||||
{
|
||||
return 256;
|
||||
}
|
||||
|
||||
public function init(param1:ByteArray) : void
|
||||
{
|
||||
var _loc3_:int = 0;
|
||||
var _loc4_:int = 0;
|
||||
var _loc2_:int = 0;
|
||||
_loc3_ = 0;
|
||||
while(_loc3_ < 256)
|
||||
{
|
||||
S[_loc3_] = _loc3_;
|
||||
_loc3_++;
|
||||
}
|
||||
_loc4_ = 0;
|
||||
_loc3_ = 0;
|
||||
while(_loc3_ < 256)
|
||||
{
|
||||
_loc4_ = _loc4_ + S[_loc3_] + param1[_loc3_ % param1.length] & 0xFF;
|
||||
_loc2_ = int(S[_loc3_]);
|
||||
S[_loc3_] = S[_loc4_];
|
||||
S[_loc4_] = _loc2_;
|
||||
_loc3_++;
|
||||
}
|
||||
this.i = 0;
|
||||
this.j = 0;
|
||||
}
|
||||
|
||||
public function next() : uint
|
||||
{
|
||||
var _loc1_:int = 0;
|
||||
i = i + 1 & 0xFF;
|
||||
j = j + S[i] & 0xFF;
|
||||
_loc1_ = int(S[i]);
|
||||
S[i] = S[j];
|
||||
S[j] = _loc1_;
|
||||
return S[_loc1_ + S[i] & 0xFF];
|
||||
}
|
||||
|
||||
public function getBlockSize() : uint
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function encrypt(param1:ByteArray) : void
|
||||
{
|
||||
var _loc2_:uint = 0;
|
||||
while(_loc2_ < param1.length)
|
||||
{
|
||||
var _loc3_:uint = _loc2_++;
|
||||
var _loc4_:int = param1[_loc3_] ^ next();
|
||||
param1[_loc3_] = _loc4_;
|
||||
}
|
||||
}
|
||||
|
||||
public function decrypt(param1:ByteArray) : void
|
||||
{
|
||||
encrypt(param1);
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
var _loc1_:uint = 0;
|
||||
if(S != null)
|
||||
{
|
||||
_loc1_ = 0;
|
||||
while(_loc1_ < S.length)
|
||||
{
|
||||
S[_loc1_] = Math.random() * 256;
|
||||
_loc1_++;
|
||||
}
|
||||
S.length = 0;
|
||||
S = null;
|
||||
}
|
||||
this.i = 0;
|
||||
this.j = 0;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "rc4";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.hurlant.crypto.prng
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public interface IPRNG
|
||||
{
|
||||
|
||||
function getPoolSize() : uint;
|
||||
|
||||
function init(param1:ByteArray) : void;
|
||||
|
||||
function next() : uint;
|
||||
|
||||
function dispose() : void;
|
||||
|
||||
function toString() : String;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.hurlant.crypto.prng
|
||||
{
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.system.Capabilities;
|
||||
import flash.system.System;
|
||||
import flash.text.Font;
|
||||
import flash.utils.ByteArray;
|
||||
import flash.utils.getTimer;
|
||||
|
||||
public class Random
|
||||
{
|
||||
|
||||
private var state:IPRNG;
|
||||
|
||||
private var ready:Boolean = false;
|
||||
|
||||
private var pool:ByteArray;
|
||||
|
||||
private var psize:int;
|
||||
|
||||
private var pptr:int;
|
||||
|
||||
private var seeded:Boolean = false;
|
||||
|
||||
public function Random(param1:Class = null)
|
||||
{
|
||||
var _loc2_:* = 0;
|
||||
super();
|
||||
if(param1 == null)
|
||||
{
|
||||
param1 = ARC4;
|
||||
}
|
||||
state = new param1() as IPRNG;
|
||||
psize = state.getPoolSize();
|
||||
pool = new ByteArray();
|
||||
pptr = 0;
|
||||
while(pptr < psize)
|
||||
{
|
||||
_loc2_ = uint(65536 * Math.random());
|
||||
pool[pptr++] = _loc2_ >>> 8;
|
||||
pool[pptr++] = _loc2_ & 0xFF;
|
||||
}
|
||||
pptr = 0;
|
||||
seed();
|
||||
}
|
||||
|
||||
public function seed(param1:int = 0) : void
|
||||
{
|
||||
if(param1 == 0)
|
||||
{
|
||||
param1 = new Date().getTime();
|
||||
}
|
||||
var _loc2_:Number = pptr++;
|
||||
var _loc3_:int = pool[_loc2_] ^ param1 & 0xFF;
|
||||
pool[_loc2_] = _loc3_;
|
||||
pool[pptr++] ^= param1 >> 8 & 0xFF;
|
||||
pool[pptr++] ^= param1 >> 16 & 0xFF;
|
||||
pool[pptr++] ^= param1 >> 24 & 0xFF;
|
||||
pptr %= psize;
|
||||
seeded = true;
|
||||
}
|
||||
|
||||
public function autoSeed() : void
|
||||
{
|
||||
var _loc2_:ByteArray = new ByteArray();
|
||||
_loc2_.writeUnsignedInt(System.totalMemory);
|
||||
_loc2_.writeUTF(Capabilities.serverString);
|
||||
_loc2_.writeUnsignedInt(getTimer());
|
||||
_loc2_.writeUnsignedInt(new Date().getTime());
|
||||
var _loc1_:Array = Font.enumerateFonts(true);
|
||||
for each(var _loc3_:Font in _loc1_)
|
||||
{
|
||||
_loc2_.writeUTF(_loc3_.fontName);
|
||||
_loc2_.writeUTF(_loc3_.fontStyle);
|
||||
_loc2_.writeUTF(_loc3_.fontType);
|
||||
}
|
||||
_loc2_.position = 0;
|
||||
while(_loc2_.bytesAvailable >= 4)
|
||||
{
|
||||
seed(_loc2_.readUnsignedInt());
|
||||
}
|
||||
}
|
||||
|
||||
public function nextBytes(param1:ByteArray, param2:int) : void
|
||||
{
|
||||
while(param2--)
|
||||
{
|
||||
param1.writeByte(nextByte());
|
||||
}
|
||||
}
|
||||
|
||||
public function nextByte() : int
|
||||
{
|
||||
if(!ready)
|
||||
{
|
||||
if(!seeded)
|
||||
{
|
||||
autoSeed();
|
||||
}
|
||||
state.init(pool);
|
||||
pool.length = 0;
|
||||
pptr = 0;
|
||||
ready = true;
|
||||
}
|
||||
return state.next();
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
var _loc1_:* = 0;
|
||||
_loc1_ = 0;
|
||||
while(_loc1_ < pool.length)
|
||||
{
|
||||
pool[_loc1_] = Math.random() * 256;
|
||||
_loc1_++;
|
||||
}
|
||||
pool.length = 0;
|
||||
pool = null;
|
||||
state.dispose();
|
||||
state = null;
|
||||
psize = 0;
|
||||
pptr = 0;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "random-" + state.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user