def test_gcm_decrypt():
    """ Tests decryption with AES-GCM """
    from Lab01Code import encrypt_message, decrypt_message
    from os import urandom
    K = urandom(16)
    message = u"Hello World!"
    iv, ciphertext, tag = encrypt_message(K, message)

    assert len(iv) == 16
    assert len(ciphertext) == len(message)
    assert len(tag) == 16

    m = decrypt_message(K, iv, ciphertext, tag)
    assert m == message
Exemplo n.º 2
0
def test_gcm_decrypt():
    """ Tests decryption with AES-GCM """
    from Lab01Code import encrypt_message, decrypt_message
    from os import urandom
    K = urandom(16)
    message = u"Hello World!"
    iv, ciphertext, tag = encrypt_message(K, message)

    assert len(iv) == 16
    assert len(ciphertext) == len(message)
    assert len(tag) == 16

    m = decrypt_message(K, iv, ciphertext, tag)
    assert m == message
def test_gcm_fails():
    from pytest import raises

    from Lab01Code import encrypt_message, decrypt_message
    from os import urandom
    K = urandom(16)
    message = u"Hello World!"
    iv, ciphertext, tag = encrypt_message(K, message)

    with raises(Exception) as excinfo:
        decrypt_message(K, iv, urandom(len(ciphertext)), tag)
    assert 'decryption failed' in str(excinfo.value)

    with raises(Exception) as excinfo:
        decrypt_message(K, iv, ciphertext, urandom(len(tag)))
    assert 'decryption failed' in str(excinfo.value)

    with raises(Exception) as excinfo:
        decrypt_message(K, urandom(len(iv)), ciphertext, tag)
    assert 'decryption failed' in str(excinfo.value)

    with raises(Exception) as excinfo:
        decrypt_message(urandom(len(K)), iv, ciphertext, tag)
    assert 'decryption failed' in str(excinfo.value)
Exemplo n.º 4
0
def test_gcm_fails():
    from pytest import raises

    from Lab01Code import encrypt_message, decrypt_message
    from os import urandom
    K = urandom(16)
    message = u"Hello World!"
    iv, ciphertext, tag = encrypt_message(K, message)

    with raises(Exception) as excinfo:
        decrypt_message(K, iv, urandom(len(ciphertext)), tag)
    assert 'decryption failed' in str(excinfo.value)

    with raises(Exception) as excinfo:
        decrypt_message(K, iv, ciphertext, urandom(len(tag)))
    assert 'decryption failed' in str(excinfo.value)

    with raises(Exception) as excinfo:
        decrypt_message(K, urandom(len(iv)), ciphertext, tag)
    assert 'decryption failed' in str(excinfo.value)

    with raises(Exception) as excinfo:
        decrypt_message(urandom(len(K)), iv, ciphertext, tag)
    assert 'decryption failed' in str(excinfo.value)