Skip to content

Commit 548584b

Browse files
committed
add unit test to demonstrate null padding
1 parent 5ccf766 commit 548584b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/MCryptCompatTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,21 @@ public function testPhpseclibNCFB()
7070
list($v1, $v2) = $this->ncfbHelper('phpseclib_');
7171
$this->assertSame($v1, $v2);
7272
}
73+
74+
/**
75+
* mcrypt and phpseclib 1.0/2.0 null-pad plaintext's and ciphertext's
76+
*/
77+
public function testNullPadding()
78+
{
79+
$key = str_repeat('z', 16);
80+
$iv = str_repeat('z', 16);
81+
// a plaintext of length 1 is of an insufficient length for cbc mode
82+
$mcrypt = bin2hex(mcrypt_encrypt('rijndael-128', $key, 'a', 'cbc', $iv));
83+
$compat = bin2hex(phpseclib_mcrypt_encrypt('rijndael-128', $key, 'a', 'cbc', $iv));
84+
$this->assertEquals($mcrypt, $compat);
85+
86+
$mcrypt = bin2hex(mcrypt_decrypt('rijndael-128', $key, 'a', 'cbc', $iv));
87+
$compat = bin2hex(phpseclib_mcrypt_decrypt('rijndael-128', $key, 'a', 'cbc', $iv));
88+
$this->assertEquals($mcrypt, $compat);
89+
}
7390
}

0 commit comments

Comments
 (0)