/** * @preserveGlobalState disabled * @runInSeparateProcess */ public function test_random_bytes_check() { $this->assertTrue(Hm_Crypt::random_bytes_check()); Hm_Crypt::$strong = false; $this->assertFalse(Hm_Crypt::random_bytes_check()); }
/** * Generate a random string * @param int $size * @return string */ public static function random($size = 128) { if (function_exists('mcrypt_create_iv') && defined('MCRYPT_DEV_URANDOM')) { $res = mcrypt_create_iv($size, MCRYPT_DEV_URANDOM); self::$strong = true; } else { $res = openssl_random_pseudo_bytes(128, $strong); self::$strong = $strong; } return $res; }
/** * Generate a strong random salt (hopefully) * @return string */ public static function generate_salt() { /* generate random bytes */ $res = openssl_random_pseudo_bytes(128, $strong); self::$strong = $strong; return $res; }