示例#1
0
class TestAES_OFB(object):
    test_KAT = generate_encrypt_test(
        lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
        os.path.join("AES", "KAT"),
        [
            "OFBGFSbox128.rsp",
            "OFBGFSbox192.rsp",
            "OFBGFSbox256.rsp",
            "OFBKeySbox128.rsp",
            "OFBKeySbox192.rsp",
            "OFBKeySbox256.rsp",
            "OFBVarKey128.rsp",
            "OFBVarKey192.rsp",
            "OFBVarKey256.rsp",
            "OFBVarTxt128.rsp",
            "OFBVarTxt192.rsp",
            "OFBVarTxt256.rsp",
        ],
        lambda key, iv: ciphers.AES(binascii.unhexlify(key)),
        lambda key, iv: modes.OFB(binascii.unhexlify(iv)),
    )

    test_MMT = generate_encrypt_test(
        lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
        os.path.join("AES", "MMT"),
        [
            "OFBMMT128.rsp",
            "OFBMMT192.rsp",
            "OFBMMT256.rsp",
        ],
        lambda key, iv: ciphers.AES(binascii.unhexlify(key)),
        lambda key, iv: modes.OFB(binascii.unhexlify(iv)),
    )
class TestAESCTR(object):
    test_OpenSSL = generate_encrypt_test(
        load_openssl_vectors_from_file,
        "AES",
        ["aes-128-ctr.txt", "aes-192-ctr.txt", "aes-256-ctr.txt"],
        lambda key, iv: ciphers.AES(binascii.unhexlify(key)),
        lambda key, iv: modes.CTR(binascii.unhexlify(iv)),
        only_if=lambda backend: backend.ciphers.supported(
            ciphers.AES("\x00" * 16), modes.CTR("\x00" * 16)),
        skip_message="Does not support AES CTR",
    )
示例#3
0
 def test_unaligned_block_encryption(self, backend):
     cipher = BlockCipher(ciphers.AES(binascii.unhexlify(b"0" * 32)),
                          modes.ECB(), backend)
     encryptor = cipher.encryptor()
     ct = encryptor.update(b"a" * 15)
     assert ct == b""
     ct += encryptor.update(b"a" * 65)
     assert len(ct) == 80
     ct += encryptor.finalize()
     decryptor = cipher.decryptor()
     pt = decryptor.update(ct[:3])
     assert pt == b""
     pt += decryptor.update(ct[3:])
     assert len(pt) == 80
     assert pt == b"a" * 80
     decryptor.finalize()
示例#4
0
 def test_use_after_finalize(self, backend):
     cipher = BlockCipher(ciphers.AES(binascii.unhexlify(b"0" * 32)),
                          modes.CBC(binascii.unhexlify(b"0" * 32)), backend)
     encryptor = cipher.encryptor()
     encryptor.update(b"a" * 16)
     encryptor.finalize()
     with pytest.raises(ValueError):
         encryptor.update(b"b" * 16)
     with pytest.raises(ValueError):
         encryptor.finalize()
     decryptor = cipher.decryptor()
     decryptor.update(b"a" * 16)
     decryptor.finalize()
     with pytest.raises(ValueError):
         decryptor.update(b"b" * 16)
     with pytest.raises(ValueError):
         decryptor.finalize()
示例#5
0
 def test_creates_decryptor(self):
     cipher = BlockCipher(ciphers.AES(binascii.unhexlify(b"0" * 32)),
                          modes.CBC(binascii.unhexlify(b"0" * 32)))
     assert isinstance(cipher.decryptor(), interfaces.CipherContext)
示例#6
0
 def test_instantiate_without_backend(self):
     BlockCipher(ciphers.AES(binascii.unhexlify(b"0" * 32)),
                 modes.CBC(binascii.unhexlify(b"0" * 32)))