Exemplo n.º 1
0
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
Exemplo n.º 2
0
def test_cfb_raises_value_error_without_iv(mode):
    with pytest.raises(ValueError):
        Cipher(b"AES-512-CFB", b"", mode, b"")
Exemplo n.º 3
0
def test_zero_length_raises_exception():
    with pytest.raises(NotImplementedError):
        Cipher(b"", b"", mb.Mode.ECB, b"")
Exemplo n.º 4
0
def test_random_name_raises_exception():
    with pytest.raises(NotImplementedError):
        Cipher(b"RANDOM TEXT IS NOT A CIPHER", b"", mb.Mode.ECB, b"")
Exemplo n.º 5
0
def test_wrong_size_raises_exception():
    with pytest.raises(NotImplementedError):
        Cipher(b"AES-512-ECB", b"", mb.Mode.ECB, b"")
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
def test_cbc_raises_value_error_without_iv():
    with pytest.raises(ValueError):
        Cipher(b"AES-512-CBC", b"", MODE_CBC, b"")
Exemplo n.º 8
0
def test_zero_length_raises_exception():
    with pytest.raises(TLSError):
        Cipher(b"", b"", 0, b"")
Exemplo n.º 9
0
def test_random_name_raises_exception():
    with pytest.raises(TLSError):
        Cipher(b"RANDOM TEXT IS NOT A CIPHER", b"", 0, b"")
Exemplo n.º 10
0
def test_wrong_size_raises_exception():
    with pytest.raises(TLSError):
        Cipher(b"AES-512-ECB", b"", 0, b"")
Exemplo n.º 11
0
def test_cfb_raises_value_error_without_iv():
    Cipher(b"AES-512-CFB", b"", MODE_CFB, b"")
Exemplo n.º 12
0
def test_zero_length_raises_cipher_error():
    Cipher(b"", b"", 0, b"")
Exemplo n.º 13
0
def test_random_name_raises_cipher_error():
    Cipher(b"RANDOM TEXT IS NOT A CIPHER", b"", 0, b"")
Exemplo n.º 14
0
def test_wrong_size_raises_cipher_error():
    Cipher(b"AES-512-ECB", b"", 0, b"")