X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Frng%2Fclass_RandomNumberGenerator.php;h=0820b457aefcfbe16c1f13124bca11ed50d671fc;hp=431b9d130bbe092b8133dafc9d7b543dcbfae61b;hb=a3fa89c7cbc54491fc74f13db0927d14acf550c8;hpb=3107989f93cfb5808ce9d75f1c7d2b7ee3d83d18 diff --git a/inc/classes/main/rng/class_RandomNumberGenerator.php b/inc/classes/main/rng/class_RandomNumberGenerator.php index 431b9d13..0820b457 100644 --- a/inc/classes/main/rng/class_RandomNumberGenerator.php +++ b/inc/classes/main/rng/class_RandomNumberGenerator.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007 - 2009 Roland Haeder, this is free software + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -56,10 +56,6 @@ class RandomNumberGenerator extends BaseFrameworkSystem { protected function __construct ($className = __CLASS__) { // Call parent constructor parent::__construct($className); - - // Clean up a little - $this->removeNumberFormaters(); - $this->removeSystemArray(); } /** @@ -68,7 +64,7 @@ class RandomNumberGenerator extends BaseFrameworkSystem { * @param $extraInstance An extra instance for more salt (default: null) * @return $rngInstance An instance of this random number generator */ - public final static function createRandomNumberGenerator (FrameworkInterface $extraInstance = null) { + public static final function createRandomNumberGenerator (FrameworkInterface $extraInstance = null) { // Get a new instance $rngInstance = new RandomNumberGenerator(); @@ -88,7 +84,7 @@ class RandomNumberGenerator extends BaseFrameworkSystem { */ protected function initRng ($extraInstance) { // Get the prime number from config - $this->prime = $this->getConfigInstance()->readConfig('math_prime'); + $this->prime = $this->getConfigInstance()->getConfigEntry('math_prime'); // Calculate the extra number which is always the same unless you give // a better prime number @@ -98,28 +94,28 @@ class RandomNumberGenerator extends BaseFrameworkSystem { mt_srand((double) sqrt(microtime() * 100000000 * $this->extraNumber)); // Set the server IP to cluster - $serverIp = "cluster"; + $serverIp = 'cluster'; // Do we have a single server? - if ($this->getConfigInstance()->readConfig('is_single_server') === "Y") { + if ($this->getConfigInstance()->getConfigEntry('is_single_server') == 'Y') { // Then use that IP for extra security - $serverIp = getenv('SERVER_ADDR'); + $serverIp = $this->getConfigInstance()->detectServerAddress(); } // END - if // Yet-another fixed salt. This is not dependend on server software or date if ($extraInstance instanceof FrameworkInterface) { // With extra instance information - $this->fixedSalt = sha1($serverIp . ":" . $extraInstance->__toString() . ":" . serialize($this->getDatabaseInstance()->getConnectionData())); + $this->fixedSalt = sha1($serverIp . ':' . $extraInstance->__toString() . ':' . serialize($this->getDatabaseInstance()->getConnectionData())); } else { // Without extra information - $this->fixedSalt = sha1($serverIp . ":" . serialize($this->getDatabaseInstance()->getConnectionData())); + $this->fixedSalt = sha1($serverIp . ':' . serialize($this->getDatabaseInstance()->getConnectionData())); } // One-way data we need for "extra-salting" the random number - $this->extraSalt = sha1($this->fixedSalt . ":" . getenv('SERVER_SOFTWARE') . ":" . $this->getConfigInstance()->readConfig('date_key') . $this->getConfigInstance()->readConfig('base_url')); + $this->extraSalt = sha1($this->fixedSalt . ':' . getenv('SERVER_SOFTWARE') . ':' . $this->getConfigInstance()->getConfigEntry('date_key') . $this->getConfigInstance()->getConfigEntry('base_url')); // Get config entry for max salt length - $this->rndStrLen = $this->getConfigInstance()->readConfig('rnd_str_length'); + $this->rndStrLen = $this->getConfigInstance()->getConfigEntry('rnd_str_length'); } /** @@ -174,6 +170,24 @@ class RandomNumberGenerator extends BaseFrameworkSystem { public final function getFixedSalt () { return $this->fixedSalt; } + + /** + * Generates a key based on if we have extra (default) or fixed salt enabled + * + * @return $key The generated key for encrypion + */ + public function generateKey () { + // Default is extra salt + $key = md5($this->getExtraSalt()); + + // Get key + if ($this->getConfigInstance()->getConfigEntry('crypt_fixed_salt') == 'Y') { + $key = md5($this->getFixedSalt()); + } // END - if + + // Return it + return $key; + } } // [EOF]