fix: MAX_RNG_SUPPORT_BIT warning

This commit is contained in:
2023-06-08 23:23:05 +09:00
parent 44c2323883
commit 1f8812c939
2 changed files with 13 additions and 12 deletions
+10 -10
View File
@@ -2,12 +2,6 @@
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
* float: bit를 강제로 채움
@@ -16,7 +10,9 @@ if (PHP_INT_SIZE * 8 < MAX_RNG_SUPPORT_BIT) {
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
protected string $buffer;
@@ -182,7 +178,7 @@ class LiteHashDRBG implements RNG
public function nextInt(?int $max = null): 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);
}
@@ -207,9 +203,9 @@ class LiteHashDRBG implements RNG
public function nextFloat1(): float
{
$max = 1 << MAX_RNG_SUPPORT_BIT;
$max = 1 << self::MAX_RNG_SUPPORT_BIT;
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);
if ($nInt <= $max) {
break;
@@ -223,3 +219,7 @@ class LiteHashDRBG implements RNG
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
View File
@@ -2,14 +2,15 @@
namespace sammo;
const MAX_RNG_SUPPORT_BIT = 53;
/**
* 내부에 랜덤 값을 호출하지 않을 것이 확실할 때 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()
{
}