/** * @dataProvider provideTestDecryptVectors * @group Vectors */ public function testDecrypt($cipher, $key, $initv, $data, $adata, $expected, $result, $asize, $psize, $nsize, $tsize) { $cipher = new \CryptLib\Cipher\Block\Cipher\AES($cipher); $cipher->setKey(pack('H*', $key)); if ($asize == 0) { $adata = ''; } if ($psize == 0) { $data = 0; } $options = array('adata' => pack('H*', $adata), 'lSize' => 15 - $nsize, 'aSize' => $tsize); $mode = new \CryptLib\Cipher\Block\Mode\CCM($cipher, pack('H*', $initv), $options); $mode->decrypt(pack('H*', $expected)); $enc = $mode->finish(); if ($enc === false) { $this->assertEquals('Fail', $result); } else { $this->assertEquals('Pass', $result); } }
public function testDecryptAuthFailure() { $factory = new \CryptLib\Cipher\Factory(); $aes = $factory->getBlockCipher('rijndael-128'); $key = '0123456789ABCDEFGHIJKLMNOPQRSTUV'; $aes->setKey($key); $iv = 'FEDCBA9876543210'; $data = 'Foo Bar Baz Biz '; $adata = 'Some Other Text'; $mode = new CryptLib\Cipher\Block\Mode\CCM($aes, $iv, array('adata' => $adata)); $mode->encrypt($data); $enc = $mode->finish(); $mode->reset(); $enc = substr($enc, 0, -1) . chr(255); $mode->decrypt($enc); $this->assertFalse($mode->finish()); }