def execute_test(KEY, IV, FINALIZE, UPDATEDKEY, RES): KEY = binascii.unhexlify(KEY) RES = binascii.unhexlify(RES) FINALIZE = FINALIZE == 1 assert LRP.eval_lrp(LRP.generate_plaintexts(KEY), LRP.generate_updated_keys(KEY)[UPDATEDKEY], IV, FINALIZE)\ .hex().upper() == RES.hex().upper()
def test_cmac_subkeys(): k = binascii.unhexlify("8195088CE6C393708EBBE6C7914ECB0B") kx = binascii.unhexlify("2D22571A33B2965A9B49FF4395A43046") k0 = LRP.eval_lrp(LRP.generate_plaintexts(k), LRP.generate_updated_keys(k)[0], b"\x00" * 16, True) assert (_Element(k0) * _Element(4)).encode().hex() == kx.hex()
def test_vectors_generate_updated_keys(): uk = LRP.generate_updated_keys( b"\x56\x78\x26\xB8\xDA\x8E\x76\x84\x32\xA9\x54\x8D\xBE\x4A\xA3\xA0") assert uk[ 0] == b"\x16\x3D\x14\xED\x24\xED\x93\x53\x73\x56\x8E\xC5\x21\xE9\x6C\xF4" assert uk[ 2] == b"\xFE\x30\xAB\x50\x46\x7E\x61\x78\x3B\xFE\x6B\x5E\x05\x60\x16\x0E"
def test_eval_lrp(): p = LRP.generate_plaintexts( binascii.unhexlify("567826B8DA8E768432A9548DBE4AA3A0")) uk = LRP.generate_updated_keys( binascii.unhexlify("567826B8DA8E768432A9548DBE4AA3A0")) assert LRP.eval_lrp(p, uk[2], b"\x13\x59", final=True).hex() \ == "1ba2c0c578996bc497dd181c6885a9dd" p = LRP.generate_plaintexts( binascii.unhexlify("88B95581002057A93E421EFE4076338B")) uk = LRP.generate_updated_keys( binascii.unhexlify("88B95581002057A93E421EFE4076338B")) assert LRP.eval_lrp(p, uk[2], b"\x77\x29\x9D", final=True).hex() \ == "E9C04556A214AC3297B83E4BDF46F142".lower() p = LRP.generate_plaintexts( binascii.unhexlify("9AFF3EF56FFEC3153B1CADB48B445409")) uk = LRP.generate_updated_keys( binascii.unhexlify("9AFF3EF56FFEC3153B1CADB48B445409")) assert LRP.eval_lrp(p, uk[3], b"\x4B\x07\x3B\x24\x7C\xD4\x8F\x7E\x0A", final=False).hex() \ == "909415E5C8BE77563050F2227E17C0E4".lower()