mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-21 09: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();
|
||||
this.S = new ByteArray();
|
||||
if(param1)
|
||||
{
|
||||
this.init(param1);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPoolSize() : uint
|
||||
{
|
||||
return this.psize;
|
||||
}
|
||||
|
||||
public function init(param1:ByteArray) : void
|
||||
{
|
||||
var _loc2_:int = 0;
|
||||
var _loc3_:int = 0;
|
||||
var _loc4_:int = 0;
|
||||
_loc2_ = 0;
|
||||
while(_loc2_ < 256)
|
||||
{
|
||||
this.S[_loc2_] = _loc2_;
|
||||
_loc2_++;
|
||||
}
|
||||
_loc3_ = 0;
|
||||
_loc2_ = 0;
|
||||
while(_loc2_ < 256)
|
||||
{
|
||||
_loc3_ = _loc3_ + this.S[_loc2_] + param1[_loc2_ % param1.length] & 0xFF;
|
||||
_loc4_ = int(this.S[_loc2_]);
|
||||
this.S[_loc2_] = this.S[_loc3_];
|
||||
this.S[_loc3_] = _loc4_;
|
||||
_loc2_++;
|
||||
}
|
||||
this.i = 0;
|
||||
this.j = 0;
|
||||
}
|
||||
|
||||
public function next() : uint
|
||||
{
|
||||
var _loc1_:int = 0;
|
||||
this.i = this.i + 1 & 0xFF;
|
||||
this.j = this.j + this.S[this.i] & 0xFF;
|
||||
_loc1_ = int(this.S[this.i]);
|
||||
this.S[this.i] = this.S[this.j];
|
||||
this.S[this.j] = _loc1_;
|
||||
return this.S[_loc1_ + this.S[this.i] & 0xFF];
|
||||
}
|
||||
|
||||
public function getBlockSize() : uint
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function encrypt(param1:ByteArray) : void
|
||||
{
|
||||
var _loc2_:uint = 0;
|
||||
while(_loc2_ < param1.length)
|
||||
{
|
||||
var _temp_2:* = param1;
|
||||
var _loc3_:uint = _loc2_++;
|
||||
_temp_2[_loc3_] ^= this.next();
|
||||
}
|
||||
}
|
||||
|
||||
public function decrypt(param1:ByteArray) : void
|
||||
{
|
||||
this.encrypt(param1);
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
var _loc1_:uint = 0;
|
||||
if(this.S != null)
|
||||
{
|
||||
_loc1_ = 0;
|
||||
while(_loc1_ < this.S.length)
|
||||
{
|
||||
this.S[_loc1_] = Math.random() * 256;
|
||||
_loc1_++;
|
||||
}
|
||||
this.S.length = 0;
|
||||
this.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,137 @@
|
||||
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_:uint = 0;
|
||||
super();
|
||||
if(param1 == null)
|
||||
{
|
||||
param1 = ARC4;
|
||||
}
|
||||
this.state = new param1() as IPRNG;
|
||||
this.psize = this.state.getPoolSize();
|
||||
this.pool = new ByteArray();
|
||||
this.pptr = 0;
|
||||
while(this.pptr < this.psize)
|
||||
{
|
||||
_loc2_ = 65536 * Math.random();
|
||||
this.pool[this.pptr++] = _loc2_ >>> 8;
|
||||
var _loc4_:Number;
|
||||
this.pool[_loc4_ = this.pptr++] = _loc2_ & 0xFF;
|
||||
}
|
||||
this.pptr = 0;
|
||||
this.seed();
|
||||
}
|
||||
|
||||
public function seed(param1:int = 0) : void
|
||||
{
|
||||
if(param1 == 0)
|
||||
{
|
||||
param1 = new Date().getTime();
|
||||
}
|
||||
var _temp_3:* = this.pool;
|
||||
var _loc2_:Number = this.pptr++;
|
||||
_temp_3[_loc2_] ^= param1 & 0xFF;
|
||||
var _temp_6:* = this.pool;
|
||||
var _loc3_:Number = this.pptr++;
|
||||
_temp_6[_loc3_] ^= param1 >> 8 & 0xFF;
|
||||
var _loc4_:Number;
|
||||
this.pool[_loc4_ = this.pptr++] = this.pool[_loc4_] ^ param1 >> 16 & 0xFF;
|
||||
var _loc5_:Number;
|
||||
this.pool[_loc5_ = this.pptr++] = this.pool[_loc5_] ^ param1 >> 24 & 0xFF;
|
||||
this.pptr %= this.psize;
|
||||
this.seeded = true;
|
||||
}
|
||||
|
||||
public function autoSeed() : void
|
||||
{
|
||||
var _loc3_:Font = null;
|
||||
var _loc1_:ByteArray = new ByteArray();
|
||||
_loc1_.writeUnsignedInt(System.totalMemory);
|
||||
_loc1_.writeUTF(Capabilities.serverString);
|
||||
_loc1_.writeUnsignedInt(getTimer());
|
||||
_loc1_.writeUnsignedInt(new Date().getTime());
|
||||
var _loc2_:Array = Font.enumerateFonts(true);
|
||||
for each(_loc3_ in _loc2_)
|
||||
{
|
||||
_loc1_.writeUTF(_loc3_.fontName);
|
||||
_loc1_.writeUTF(_loc3_.fontStyle);
|
||||
_loc1_.writeUTF(_loc3_.fontType);
|
||||
}
|
||||
_loc1_.position = 0;
|
||||
while(_loc1_.bytesAvailable >= 4)
|
||||
{
|
||||
this.seed(_loc1_.readUnsignedInt());
|
||||
}
|
||||
}
|
||||
|
||||
public function nextBytes(param1:ByteArray, param2:int) : void
|
||||
{
|
||||
while(param2--)
|
||||
{
|
||||
param1.writeByte(this.nextByte());
|
||||
}
|
||||
}
|
||||
|
||||
public function nextByte() : int
|
||||
{
|
||||
if(!this.ready)
|
||||
{
|
||||
if(!this.seeded)
|
||||
{
|
||||
this.autoSeed();
|
||||
}
|
||||
this.state.init(this.pool);
|
||||
this.pool.length = 0;
|
||||
this.pptr = 0;
|
||||
this.ready = true;
|
||||
}
|
||||
return this.state.next();
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
var _loc1_:uint = 0;
|
||||
while(_loc1_ < this.pool.length)
|
||||
{
|
||||
this.pool[_loc1_] = Math.random() * 256;
|
||||
_loc1_++;
|
||||
}
|
||||
this.pool.length = 0;
|
||||
this.pool = null;
|
||||
this.state.dispose();
|
||||
this.state = null;
|
||||
this.psize = 0;
|
||||
this.pptr = 0;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "random-" + this.state.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user