Brought up to date with the private repository (feea4c7)

This commit is contained in:
S committed 2026-10-14 20:57:33 +03:00
1 parent 1aa738d692
commit 1b1df1ae48
7925 files changed
+2617237 -20

No files matched your search

@@ -0,0 +1,109 @@
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(key:ByteArray = null)
{
super();
this.S = new ByteArray();
if(Boolean(key))
{
this.init(key);
}
}
public function getPoolSize() : uint
{
return this.psize;
}
public function init(key:ByteArray) : void
{
var i:int = 0;
var j:int = 0;
var t:int = 0;
for(i = 0; i < 256; i++)
{
this.S[i] = i;
}
j = 0;
for(i = 0; i < 256; i++)
{
j = j + this.S[i] + key[i % key.length] & 0xFF;
t = int(this.S[i]);
this.S[i] = this.S[j];
this.S[j] = t;
}
this.i = 0;
this.j = 0;
}
public function next() : uint
{
var t:int = 0;
this.i = this.i + 1 & 0xFF;
this.j = this.j + this.S[this.i] & 0xFF;
t = int(this.S[this.i]);
this.S[this.i] = this.S[this.j];
this.S[this.j] = t;
return this.S[t + this.S[this.i] & 0xFF];
}
public function getBlockSize() : uint
{
return 1;
}
public function encrypt(block:ByteArray) : void
{
var i:uint = 0;
while(i < block.length)
{
var _temp_2:* = block;
var _loc3_:uint = i++;
_temp_2[_loc3_] ^= this.next();
}
}
public function decrypt(block:ByteArray) : void
{
this.encrypt(block);
}
public function dispose() : void
{
var i:uint = 0;
if(this.S != null)
{
for(i = 0; i < this.S.length; i++)
{
this.S[i] = Math.random() * 256;
}
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,136 @@
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(prng:Class = null)
{
var t:uint = 0;
super();
if(prng == null)
{
prng = ARC4;
}
this.state = new prng() as IPRNG;
this.psize = this.state.getPoolSize();
this.pool = new ByteArray();
this.pptr = 0;
while(this.pptr < this.psize)
{
t = 65536 * Math.random();
this.pool[this.pptr++] = t >>> 8;
this.pool[this.pptr++] = t & 0xFF;
}
this.pptr = 0;
this.seed();
}
public function seed(x:int = 0) : void
{
if(x == 0)
{
x = new Date().getTime();
}
var _temp_3:* = this.pool;
var _loc2_:Number = this.pptr++;
_temp_3[_loc2_] ^= x & 0xFF;
var _temp_6:* = this.pool;
var _loc3_:Number = this.pptr++;
_temp_6[_loc3_] ^= x >> 8 & 0xFF;
var _temp_9:* = this.pool;
var _loc4_:Number = this.pptr++;
_temp_9[_loc4_] ^= x >> 16 & 0xFF;
var _temp_12:* = this.pool;
var _loc5_:Number = this.pptr++;
_temp_12[_loc5_] ^= x >> 24 & 0xFF;
this.pptr %= this.psize;
this.seeded = true;
}
public function autoSeed() : void
{
var f:Font = null;
var b:ByteArray = new ByteArray();
b.writeUnsignedInt(System.totalMemory);
b.writeUTF(Capabilities.serverString);
b.writeUnsignedInt(getTimer());
b.writeUnsignedInt(new Date().getTime());
var a:Array = Font.enumerateFonts(true);
for each(f in a)
{
b.writeUTF(f.fontName);
b.writeUTF(f.fontStyle);
b.writeUTF(f.fontType);
}
b.position = 0;
while(b.bytesAvailable >= 4)
{
this.seed(b.readUnsignedInt());
}
}
public function nextBytes(buffer:ByteArray, length:int) : void
{
while(Boolean(length--))
{
buffer.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
{
for(var i:uint = 0; i < this.pool.length; i++)
{
this.pool[i] = Math.random() * 256;
}
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();
}
}
}