Skip to content

Commit 3829c77

Browse files
authored
chore: increase mutation score (#696)
1 parent 99f40d1 commit 3829c77

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/unit/StreamCipher/ContextTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,4 +403,28 @@ public function testAesCtrChunkedMatchesOpenssl(): void
403403

404404
static::assertSame($reference, $chunked);
405405
}
406+
407+
public function testKeystreamBufferSubstrCorrectness(): void
408+
{
409+
$keyBytes = SecureRandom\bytes(32);
410+
$key = new StreamCipher\Key($keyBytes);
411+
$iv = SecureRandom\bytes(16);
412+
413+
$ctx = new StreamCipher\Context($key, $iv, StreamCipher\Algorithm::Aes256Ctr);
414+
415+
$result = $ctx->apply('A');
416+
static::assertSame(1, Byte\length($result), 'Applying 1 byte should produce exactly 1 byte of output');
417+
418+
$result2 = $ctx->apply('BC');
419+
static::assertSame(2, Byte\length($result2), 'Applying 2 bytes should produce exactly 2 bytes of output');
420+
421+
// Verify correctness: single-pass vs byte-by-byte should match
422+
$ctx2 = new StreamCipher\Context($key, $iv, StreamCipher\Algorithm::Aes256Ctr);
423+
$singlePass = $ctx2->apply('ABC');
424+
static::assertSame(
425+
$singlePass,
426+
$result . $result2,
427+
'Byte-by-byte encryption must match single-pass encryption',
428+
);
429+
}
406430
}

0 commit comments

Comments
 (0)