feat: LiteHashDRBG 생성시 상세 지정
This commit is contained in:
@@ -85,7 +85,17 @@ export class LiteHashDRBG implements RNG {
|
||||
protected hq: DataView;
|
||||
protected hqIdxPos: number;
|
||||
|
||||
public constructor(protected seed: MaybeBytes, protected stateIdx = 0) {
|
||||
public constructor(protected seed: MaybeBytes, protected stateIdx = 0, bufferIdx = 0) {
|
||||
if(bufferIdx < 0){
|
||||
throw new Error(`bufferIdx ${bufferIdx} < 0`);
|
||||
}
|
||||
if(bufferIdx >= bufferByteSize){
|
||||
throw new Error(`bufferidx ${bufferIdx} >= ${bufferByteSize}`);
|
||||
}
|
||||
if(stateIdx < 0){
|
||||
throw new Error(`stateIdx ${stateIdx} < 0`);
|
||||
}
|
||||
|
||||
const seedU8 = (() => {
|
||||
if (seed instanceof Uint8Array) {
|
||||
return seed;
|
||||
@@ -106,6 +116,7 @@ export class LiteHashDRBG implements RNG {
|
||||
this.hqIdxPos = seedU8.byteLength;
|
||||
|
||||
this.genNextBlock();
|
||||
this.bufferIdx = bufferIdx;
|
||||
}
|
||||
|
||||
protected genNextBlock(): void {
|
||||
|
||||
@@ -21,9 +21,19 @@ class LiteHashDRBG implements RNG
|
||||
|
||||
protected string $buffer;
|
||||
protected int $bufferIdx;
|
||||
public function __construct(protected string $seed, protected int $stateIdx = 0)
|
||||
public function __construct(protected string $seed, protected int $stateIdx = 0, int $bufferIdx = 0)
|
||||
{
|
||||
if($bufferIdx < 0){
|
||||
throw new \InvalidArgumentException("bufferIdx {$bufferIdx} < 0");
|
||||
}
|
||||
if($bufferIdx >= self::BUFFER_BYTE_SIZE){
|
||||
throw new \InvalidArgumentException("bufferIdx {$bufferIdx} >= ".self::BUFFER_BYTE_SIZE);
|
||||
}
|
||||
if($stateIdx < 0){
|
||||
throw new \InvalidArgumentException("stateIdx {$stateIdx} < 0");
|
||||
}
|
||||
$this->genNextBlock();
|
||||
$this->bufferIdx = $bufferIdx;
|
||||
}
|
||||
|
||||
protected function genNextBlock(): void
|
||||
|
||||
Reference in New Issue
Block a user