feat: LiteHashDRBG 생성시 상세 지정

This commit is contained in:
2022-03-12 20:31:13 +09:00
parent a2498506c3
commit 7ef9e67f5d
2 changed files with 23 additions and 2 deletions
+12 -1
View File
@@ -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 {
+11 -1
View File
@@ -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