コード例 #1
0
ファイル: AES_Testbench_v3.py プロジェクト: mirko314/Crypto
def test_192bit_encryption():
    akey = aes_key()
    plain = bytearray([0x76,0x77,0x74,0x75,0xF1,0xF2,0xF3,0xF4,0xF8,0xF9,0xE6,0xE7,0x77,0x70,0x71,0x72])
    cipher = bytearray([0x5d,0x1e,0xf2,0x0d,0xce,0xd6,0xbc,0xbc,0x12,0x13,0x1a,0xc7,0xc5,0x47,0x88,0xaa])
    byte_key = bytearray([0x04,0x05,0x06,0x07,0x09,0x0A,0x0B,0x0C,0x0E,0x0F,0x10,0x11,0x13,0x14,0x15,0x16,0x18,0x19,0x1A,0x1B,0x1D,0x1E,0x1F,0x20])
    aes.set_key(akey, byte_key, len(byte_key))
    ciphertext = aes.block_encrypt(plain, akey)
    plaintext = aes.block_decrypt(cipher, akey)
    return arraycompare(ciphertext, cipher) and arraycompare(plaintext, plain)
コード例 #2
0
ファイル: AES_Testbench_v3.py プロジェクト: mirko314/Crypto
def test_256bit_encryption():
    akey = aes_key()
    cipher = ([0x8e,0xa2,0xb7,0xca,0x51,0x67,0x45,0xbf,0xea,0xfc,0x49,0x90,0x4b,0x49,0x60,0x89])
    plain = bytearray([0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff])
    byte_key = bytearray([0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f])
    aes.set_key(akey, byte_key, len(byte_key))
    ciphertext = aes.block_encrypt(plain, akey)
    plaintext = aes.block_decrypt(cipher, akey)
    return arraycompare(ciphertext, cipher) and arraycompare(plaintext, plain)
コード例 #3
0
ファイル: AES_Testbench_v3.py プロジェクト: mirko314/Crypto
def test_256keybit():
    akey = aes_key()
    byte_key = bytearray([0x00] * 16)
    aes_o = AES()
    aes_o.set_key(akey, byte_key, len(byte_key))
    print(akey.round_keys)
コード例 #4
0
ファイル: AES_Testbench_v3.py プロジェクト: mirko314/Crypto
#################################################################################
# Tests the first two rounds of your aes implementation for the correct states  #
#                                                                               #
#                <b>DO NOT MODIFY ANYTHING INSIDE THIS FILE!!</b>               #
#                                                                               #
#################################################################################

from AES_class import AES
from AES_class import aes_key

global aes, aeskey, AES_BIT_BLOCK_SIZE, AES_BYTE_BLOCK_SIZE, ptx, state, ctx
global key, result

aes = AES()
aeskey = aes_key()
AES_BIT_BLOCK_SIZE = 128
AES_BYTE_BLOCK_SIZE = int(AES_BIT_BLOCK_SIZE / 8)
aesround = 0

ptx = bytearray([0x46,0x72,0x6F,0x68,0x65,0x57,0x65,0x69,0x68,0x6E,0x61,0x63,0x68,0x74,0x65,0x6E])
state = bytearray([0x46,0x72,0x6F,0x68,0x65,0x57,0x65,0x69,0x68,0x6E,0x61,0x63,0x68,0x74,0x65,0x6E])
ctx = bytearray([0x11,0xD4,0x6C,0x57,0xD0,0xD0,0x40,0x14,0xA6,0x87,0x61,0xEE,0x0D,0x79,0x5E,0x51])
key = bytearray([0x57,0x75,0x65,0x6E,0x73,0x63,0x68,0x74,0x45,0x6D,0x73,0x65,0x63,0x3A,0x2D,0x29])


def test_subbytes():
    return arraycompare(aes.subbytes(state), bytearray([0x82,0xC5,0x67,0x6F, 0x47,0x18,0xD7,0xA4,0xD8,0x7B,0xC9,0x6F, 0x2B,0x2F,0x52,0xA0]))
    #return arraycompare(aes.subbytes(state), bytearray([0x82,0xC5,0x67,0x6F, 0x47,0x18,0xD7,0xA4,0xD8,0x7B,0xC9,0x6F, 0x2B,0x2F,0x52,0xA0]))