def test_encrypt_raises_exception_if_step_is_incorrect(aes_data): key_128 = aes_data['128_key'] plain = aes_data['plaintext'] with pytest.raises(ValueError): aes.encrypt(plaintext=plain, key=key_128, after_step=-1) with pytest.raises(ValueError): aes.encrypt(plaintext=plain, key=key_128, after_step=4)
def test_encrypt_raises_exception_if_improper_round_or_step_type(aes_data): key = aes_data['128_key'] plain = aes_data['plaintext'] with pytest.raises(TypeError): aes.encrypt(plaintext=plain, key=key, at_round='foo') with pytest.raises(TypeError): aes.encrypt(plaintext=plain, key=key, after_step='foo')
def test_encrypt_raises_exception_if_plaintext_and_keys_multiple_are_incompatible(): with pytest.raises(ValueError): aes.encrypt( plaintext=np.random.randint(0, 255, (10, 16), dtype='uint8'), key=np.random.randint(0, 255, (9, 16), dtype='uint8') ) with pytest.raises(ValueError): aes.encrypt( plaintext=np.random.randint(0, 255, (2, 10, 16), dtype='uint8'), key=np.random.randint(0, 255, (16), dtype='uint8') )
def test_encrypt_stop_at_intermediate_value(aes_datas): int_values = aes_datas['128_encrypt_intermediate_outputs'] key = aes_datas['128_key'] plain = aes_datas['plaintext'] for _round, vals in enumerate(int_values): for step, expected in enumerate(vals): value = aes.encrypt(plaintext=plain, key=key, at_round=_round, after_step=step) assert np.array_equal(expected, value)
def test_encrypt_raises_exception_if_round_is_negative_or_too_high(aes_data): key_128 = aes_data['128_key'] key_192 = aes_data['192_key'] key_256 = aes_data['256_key'] plain = aes_data['plaintext'] with pytest.raises(ValueError): aes.encrypt(plaintext=plain, key=key_128, at_round=-1) with pytest.raises(ValueError): aes.encrypt(plaintext=plain, key=key_128, at_round=12) with pytest.raises(ValueError): aes.encrypt(plaintext=plain, key=key_192, at_round=14) with pytest.raises(ValueError): aes.encrypt(plaintext=plain, key=key_256, at_round=17)
def test_simple_encrypt_with_128_key(aes_data): key = aes_data['128_key'] plain = aes_data['plaintext'] expected_cipher = aes_data['128_ciphertext'] cipher = aes.encrypt(key=key, plaintext=plain) assert np.array_equal(expected_cipher, cipher)
def test_full_encrypt(encrypt_cases): assert np.array_equal( encrypt_cases['expected'], aes.encrypt(plaintext=encrypt_cases['state'], key=encrypt_cases['keys']))
def test_encrypt_raises_exception_if_plaintext_or_key_is_not_a_byte_array_of_appropriate_length( ): with pytest.raises(TypeError): aes.encrypt(plaintext='foo', key=np.random.randint(0, 255, (16), dtype='uint8')) with pytest.raises(TypeError): aes.encrypt(plaintext=12, key=np.random.randint(0, 255, (16), dtype='uint8')) with pytest.raises(ValueError): aes.encrypt(plaintext=np.random.randint(0, 255, (12), dtype='uint8'), key=np.random.randint(0, 255, (16), dtype='uint8')) with pytest.raises(ValueError): aes.encrypt(plaintext=np.random.randint(0, 255, (16), dtype='uint16'), key=np.random.randint(0, 255, (16), dtype='uint8')) with pytest.raises(TypeError): aes.encrypt(key='foo', plaintext=np.random.randint(0, 255, (16), dtype='uint8')) with pytest.raises(TypeError): aes.encrypt(key=12, plaintext=np.random.randint(0, 255, (16), dtype='uint8')) with pytest.raises(ValueError): aes.encrypt(key=np.random.randint(0, 255, (12), dtype='uint8'), plaintext=np.random.randint(0, 255, (16), dtype='uint8')) with pytest.raises(ValueError): aes.encrypt(key=np.random.randint(0, 255, (16), dtype='uint16'), plaintext=np.random.randint(0, 255, (16), dtype='uint8'))