def test_func(): digest_type = digest.DigestType(libcrypto, 'SHA512') sha512 = digest.Digest(libcrypto, digest_type) sha512.update("test") assert binascii.hexlify( sha512.digest() ) == "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f5" for i in xrange(1, 1000): c = cipher.CipherType(libcrypto, 'AES-256', 'CBC') ce = cipher.Cipher(libcrypto, c, '11111111111111111111111111111111', '1111111111111111', encrypt=True) ce.update("a" * i) ce.update("b" * i) e_t = ce.finish('c' * i) c = cipher.CipherType(libcrypto, 'AES-256', 'CBC') cd = cipher.Cipher(libcrypto, c, '11111111111111111111111111111111', '1111111111111111', encrypt=False) assert cd.finish(e_t) == ("a" * i) + ("b" * i) + ("c" * i) ran = rand.bytes(libcrypto, 100) assert len(ran) == 100
def test_ciphdescbc(self): ct = cipher.CipherType("des-cbc") self.assertEqual(ct.block_size(), 8) self.assertEqual(ct.key_length(), 8) self.assertEqual(ct.iv_length(), 8) self.assertEqual(ct.algo(), 'DES-CBC') self.assertEqual(ct.oid().shortname(), "DES-CBC") self.assertEqual(ct.mode(), "CBC")
def test_ciphaesofb(self): ct = cipher.CipherType("aes-256-ofb") self.assertEqual(ct.block_size(), 1) self.assertEqual(ct.key_length(), 32) self.assertEqual(ct.iv_length(), 16) self.assertEqual(ct.algo(), 'AES-256-OFB') self.assertEqual(ct.oid().shortname(), "AES-256-OFB") self.assertEqual(ct.mode(), "OFB")
def test_cons_nokey(self): ct = cipher.CipherType("DES-CBC") with self.assertRaises(ValueError): c = cipher.Cipher(ct, None, None)
def test_unknowncipher(self): with self.assertRaises(cipher.CipherError): ct = cipher.CipherType("no-such-cipher")