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