def setup_cipher(name): cipher = Cipher(name, key=None, mode=None, iv=b"\x00") key = _rnd(cipher.key_size) iv = _rnd(cipher.iv_size) block = _rnd(cipher.block_size) if name.startswith(b"AES"): mod = mb.AES elif name.startswith(b"ARC4"): mod = mb.ARC4 elif name.startswith(b"BLOWFISH"): mod = mb.Blowfish elif name.startswith(b"CAMELLIA"): mod = mb.Camellia elif name.startswith(b"DES-EDE3"): mod = mb.DES3 elif name.startswith(b"DES-EDE"): mod = mb.DES3dbl elif name.startswith(b"DES"): mod = mb.DES else: raise NotImplementedError return mod, key, cipher.mode, iv, block
def test_cfb_raises_value_error_without_iv(mode): with pytest.raises(ValueError): Cipher(b"AES-512-CFB", b"", mode, b"")
def test_zero_length_raises_exception(): with pytest.raises(NotImplementedError): Cipher(b"", b"", mb.Mode.ECB, b"")
def test_random_name_raises_exception(): with pytest.raises(NotImplementedError): Cipher(b"RANDOM TEXT IS NOT A CIPHER", b"", mb.Mode.ECB, b"")
def test_wrong_size_raises_exception(): with pytest.raises(NotImplementedError): Cipher(b"AES-512-ECB", b"", mb.Mode.ECB, b"")
def cipher(request, randbytes): name = request.param cipher = Cipher(name, key=None, mode=None, iv=b"\x00") key = randbytes(cipher.key_size) iv = randbytes(cipher.iv_size) return module_from_name(name).new(key, cipher.mode, iv)
def test_cbc_raises_value_error_without_iv(): with pytest.raises(ValueError): Cipher(b"AES-512-CBC", b"", MODE_CBC, b"")
def test_zero_length_raises_exception(): with pytest.raises(TLSError): Cipher(b"", b"", 0, b"")
def test_random_name_raises_exception(): with pytest.raises(TLSError): Cipher(b"RANDOM TEXT IS NOT A CIPHER", b"", 0, b"")
def test_wrong_size_raises_exception(): with pytest.raises(TLSError): Cipher(b"AES-512-ECB", b"", 0, b"")
def test_cfb_raises_value_error_without_iv(): Cipher(b"AES-512-CFB", b"", MODE_CFB, b"")
def test_zero_length_raises_cipher_error(): Cipher(b"", b"", 0, b"")
def test_random_name_raises_cipher_error(): Cipher(b"RANDOM TEXT IS NOT A CIPHER", b"", 0, b"")
def test_wrong_size_raises_cipher_error(): Cipher(b"AES-512-ECB", b"", 0, b"")