Beispiel #1
0
 /**
  * @dataProvider provideTestEncryptVectors
  * @group Vectors
  */
 public function testDecrypt($cipher, $key, $iv, $expected, $data)
 {
     $cipher = new \CryptLib\Cipher\Block\Cipher\AES($cipher);
     $cipher->setKey(pack('H*', $key));
     $mode = new \CryptLib\Cipher\Block\Mode\NOFB($cipher, pack('H*', $iv));
     $dec = $mode->decrypt(pack('H*', $data));
     $dec .= $mode->finish();
     $this->assertEquals($expected, strtoupper(bin2hex($dec)));
 }
Beispiel #2
0
 /**
  * @dataProvider provideTestEncryptVectors
  * @group Vectors
  */
 public function testDecrypt(array $vectors)
 {
     list($cipher, $key, $iv) = $vectors[0];
     $cipher = new \CryptLib\Cipher\Block\Cipher\AES($cipher);
     $cipher->setKey(pack('H*', $key));
     $mode = new \CryptLib\Cipher\Block\Mode\CTR($cipher, pack('H*', $iv));
     foreach ($vectors as $vector) {
         list(, , , $data, $expected) = $vector;
         $dec = $mode->decrypt(pack('H*', $data));
         $dec .= $mode->finish();
         $this->assertEquals($expected, strtoupper(bin2hex($dec)));
     }
 }
Beispiel #3
0
 /**
  * @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);
     }
 }
Beispiel #4
0
 public function testGetCipher()
 {
     $cipher = new \CryptLib\Cipher\Block\Cipher\AES('aes-128');
     $this->assertEquals('aes-128', $cipher->getCipher());
 }