feat: 해시 기반 간이 DRBG, 그에 기반한 RandUtil (#208)

기존의 Util 내의 함수는 mt_rand에 기반하고 있어서 일반적으론 충분하지만,
게임 내부에서 랜덤 값을 정교하게 제어하고 싶은 경우에는 적절하지 않았음.

따라서 직접 seed를 제어할 수 있는 난수생성기를 추가.
SHA512(seed || blockIdx) 의 형태로 동작하는 DRBG이며, FIPS 표준을 따르는 RNG는 아니지만 암호학적으로 안전한 형태로 구현함.

PHP, TS 두가지 형태로 구현.

Reviewed-on: https://storage.hided.net/gitea/devsam/core/pulls/208
Co-authored-by: hide_d <hided62@gmail.com>
Co-committed-by: hide_d <hided62@gmail.com>
This commit is contained in:
2022-03-12 23:53:16 +09:00
parent c220b3d511
commit 0ab485f122
15 changed files with 1620 additions and 4 deletions
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace sammo;
interface RNG
{
/**
* @return int nextInt()가 반환 가능한 최대값
*/
public static function getMaxInt(): int;
/**
*
* @param int $bytes
* @return string Little Endian 형태로 채워진 binary 값
*/
public function nextBytes(int $bytes): string;
public function nextBits(int $bits): string;
/**
* @param ?int $max 최대치(해당 값 포함)
* @return int 0과 최대치 사이의 임의의 정수
*/
public function nextInt(?int $max = null): int;
public function nextFloat1(): float;
}