def test_gcm_encrypt():
    """ Tests encryption with AES-GCM """
    from Lab01Code import encrypt_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
示例#2
0
def test_gcm_encrypt():
    """ Tests encryption with AES-GCM """
    from Lab01Code import encrypt_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
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)
示例#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)