<commit_before>package dse{
	import com.hurlant.crypto.prng.Random;
	import com.hurlant.crypto.rsa.RSAKey;
	import com.hurlant.util.Hex;
	
	import flash.external.ExternalInterface;
	import flash.utils.ByteArray;
	public class KeyGenerator
	{
		public static function generateKeys():void{
			var exp:String = "10001";
			var rsa:RSAKey = RSAKey.generate(1024, exp);
			ExternalInterface.call("setvalue", "publickey", rsa.n.toString());
			ExternalInterface.call("setvalue", "d", rsa.d.toString());
			ExternalInterface.call("setvalue", "p", rsa.p.toString());
			ExternalInterface.call("setvalue", "q", rsa.q.toString());
			ExternalInterface.call("setvalue", "dmp", rsa.dmp1.toString());
			ExternalInterface.call("setvalue", "dmq", rsa.dmq1.toString());
			ExternalInterface.call("setvalue", "qinv", rsa.coeff.toString());
				
			var r:Random = new Random;
			var rankey:ByteArray = new ByteArray; var discard:ByteArray = new ByteArray;
			r.nextBytes(discard, 32);
			r.nextBytes(rankey, 32);
			ExternalInterface.call("setvalue", "rk", Hex.fromArray(rankey));
		}
	}
}
<commit_msg>improve randomness of random aes key generation by seeding with passphrase hash<commit_after>package dse{
	import com.hurlant.crypto.Crypto;
	import com.hurlant.crypto.hash.IHash;
	import com.hurlant.crypto.prng.Random;
	import com.hurlant.crypto.rsa.RSAKey;
	import com.hurlant.util.Hex;
	
	import flash.external.ExternalInterface;
	import flash.utils.ByteArray;
	
	public class KeyGenerator
	{
		public static function generateKeys(passphrase:String):void{
			var exp:String = "10001";
			var rsa:RSAKey = RSAKey.generate(1024, exp);
			ExternalInterface.call("setvalue", "publickey", rsa.n.toString());
			ExternalInterface.call("setvalue", "d", rsa.d.toString());
			ExternalInterface.call("setvalue", "p", rsa.p.toString());
			ExternalInterface.call("setvalue", "q", rsa.q.toString());
			ExternalInterface.call("setvalue", "dmp", rsa.dmp1.toString());
			ExternalInterface.call("setvalue", "dmq", rsa.dmq1.toString());
			ExternalInterface.call("setvalue", "qinv", rsa.coeff.toString());
				
			var r:Random = new Random;
			var rankey:ByteArray = new ByteArray; var discard:ByteArray = new ByteArray;

			//incorporate passphrase into seeding process
			var hash:IHash = Crypto.getHash("sha256");
			var p:ByteArray = hash.hash(Hex.toArray(Hex.fromString(passphrase)));
			r.autoSeed();
			while (p.bytesAvailable>=4) {
				r.seed(p.readUnsignedInt());
			}

			r.nextBytes(discard, 1024);
			r.nextBytes(rankey, 32);
			ExternalInterface.call("setvalue", "rk", Hex.fromArray(rankey));
		}
	}
}

{'fraction_non_alphanumeric': 0.1537273078408652, 'fraction_numerical': 0.013904982618771726, 'mean_word_length': 4.967741935483871, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6150538', 'n_tokens_mistral': 997, 'n_tokens_neox': 866, 'n_words': 162}