File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments