fix: MAX_RNG_SUPPORT_BIT warning
This commit is contained in:
+10
-10
@@ -2,12 +2,6 @@
|
|||||||
|
|
||||||
namespace sammo;
|
namespace sammo;
|
||||||
|
|
||||||
//NOTE: JavaScript 버전과 일치
|
|
||||||
const MAX_RNG_SUPPORT_BIT = 53;
|
|
||||||
if (PHP_INT_SIZE * 8 < MAX_RNG_SUPPORT_BIT) {
|
|
||||||
throw new \RangeException('PHP not support '.MAX_RNG_SUPPORT_BIT.' bit integer');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reseed를 하지 않는 단순한 형태의 sha512 drbg
|
* Reseed를 하지 않는 단순한 형태의 sha512 drbg
|
||||||
* float: bit를 강제로 채움
|
* float: bit를 강제로 채움
|
||||||
@@ -16,7 +10,9 @@ if (PHP_INT_SIZE * 8 < MAX_RNG_SUPPORT_BIT) {
|
|||||||
|
|
||||||
class LiteHashDRBG implements RNG
|
class LiteHashDRBG implements RNG
|
||||||
{
|
{
|
||||||
const MAX_INT = (1 << MAX_RNG_SUPPORT_BIT) - 1;
|
//NOTE: JavaScript 버전과 일치
|
||||||
|
const MAX_RNG_SUPPORT_BIT = 53;
|
||||||
|
const MAX_INT = (1 << self::MAX_RNG_SUPPORT_BIT) - 1;
|
||||||
const BUFFER_BYTE_SIZE = 512 / 8; //SHA512
|
const BUFFER_BYTE_SIZE = 512 / 8; //SHA512
|
||||||
|
|
||||||
protected string $buffer;
|
protected string $buffer;
|
||||||
@@ -182,7 +178,7 @@ class LiteHashDRBG implements RNG
|
|||||||
public function nextInt(?int $max = null): int
|
public function nextInt(?int $max = null): int
|
||||||
{
|
{
|
||||||
if ($max === null || $max === self::MAX_INT) {
|
if ($max === null || $max === self::MAX_INT) {
|
||||||
$buffer = $this->nextBits(MAX_RNG_SUPPORT_BIT) . "\x00";
|
$buffer = $this->nextBits(self::MAX_RNG_SUPPORT_BIT) . "\x00";
|
||||||
return self::parseU64($buffer);
|
return self::parseU64($buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,9 +203,9 @@ class LiteHashDRBG implements RNG
|
|||||||
|
|
||||||
public function nextFloat1(): float
|
public function nextFloat1(): float
|
||||||
{
|
{
|
||||||
$max = 1 << MAX_RNG_SUPPORT_BIT;
|
$max = 1 << self::MAX_RNG_SUPPORT_BIT;
|
||||||
while (true) {
|
while (true) {
|
||||||
$buffer = $this->nextBits(MAX_RNG_SUPPORT_BIT + 1) . "\x00";
|
$buffer = $this->nextBits(self::MAX_RNG_SUPPORT_BIT + 1) . "\x00";
|
||||||
$nInt = self::parseU64($buffer);
|
$nInt = self::parseU64($buffer);
|
||||||
if ($nInt <= $max) {
|
if ($nInt <= $max) {
|
||||||
break;
|
break;
|
||||||
@@ -223,3 +219,7 @@ class LiteHashDRBG implements RNG
|
|||||||
return new LiteHashDRBG($seed, $idx);
|
return new LiteHashDRBG($seed, $idx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (PHP_INT_SIZE * 8 < LiteHashDRBG::MAX_RNG_SUPPORT_BIT) {
|
||||||
|
throw new \RangeException('PHP not support '.LiteHashDRBG::MAX_RNG_SUPPORT_BIT.' bit integer');
|
||||||
|
}
|
||||||
+3
-2
@@ -2,14 +2,15 @@
|
|||||||
|
|
||||||
namespace sammo;
|
namespace sammo;
|
||||||
|
|
||||||
const MAX_RNG_SUPPORT_BIT = 53;
|
|
||||||
/**
|
/**
|
||||||
* 내부에 랜덤 값을 호출하지 않을 것이 확실할 때 RNG 대용으로 사용
|
* 내부에 랜덤 값을 호출하지 않을 것이 확실할 때 RNG 대용으로 사용
|
||||||
* 어떤 함수를 호출하든 에러 발생
|
* 어떤 함수를 호출하든 에러 발생
|
||||||
*/
|
*/
|
||||||
class NoRNG implements RNG
|
class NoRNG implements RNG
|
||||||
{
|
{
|
||||||
const MAX_INT = (1 << MAX_RNG_SUPPORT_BIT) - 1;
|
const MAX_RNG_SUPPORT_BIT = 53;
|
||||||
|
const MAX_INT = (1 << self::MAX_RNG_SUPPORT_BIT) - 1;
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user