LRPGenerateUpdatedKeys ok

This commit is contained in:
merlokk 2021-08-14 00:34:38 +03:00
commit 5df6732a1b
2 changed files with 24 additions and 10 deletions

View file

@ -484,17 +484,17 @@ static bool TestLRPPlaintexts(void) {
LRPContext ctx = {0}; LRPContext ctx = {0};
LRPSetKey(&ctx, key, 0, false); LRPSetKey(&ctx, key, 0, false);
uint8_t key0[] = {0xAC, 0x20, 0xD3, 0x9F, 0x53, 0x41, 0xFE, 0x98, 0xDF, 0xCA, 0x21, 0xDA, 0x86, 0xBA, 0x79, 0x14}; uint8_t pt0[] = {0xAC, 0x20, 0xD3, 0x9F, 0x53, 0x41, 0xFE, 0x98, 0xDF, 0xCA, 0x21, 0xDA, 0x86, 0xBA, 0x79, 0x14};
res = res && (memcmp(ctx.plaintexts[0], key0, sizeof(key0)) == 0); res = res && (memcmp(ctx.plaintexts[0], pt0, sizeof(pt0)) == 0);
uint8_t key1[] = {0x90, 0x7D, 0xA0, 0x3D, 0x67, 0x24, 0x49, 0x16, 0x69, 0x15, 0xE4, 0x56, 0x3E, 0x08, 0x9D, 0x6D}; uint8_t pt1[] = {0x90, 0x7D, 0xA0, 0x3D, 0x67, 0x24, 0x49, 0x16, 0x69, 0x15, 0xE4, 0x56, 0x3E, 0x08, 0x9D, 0x6D};
res = res && (memcmp(ctx.plaintexts[1], key1, sizeof(key1)) == 0); res = res && (memcmp(ctx.plaintexts[1], pt1, sizeof(pt1)) == 0);
uint8_t key14[] = {0x37, 0xD7, 0x34, 0xA5, 0x1C, 0x07, 0x6E, 0xB8, 0x03, 0xBD, 0x53, 0x0E, 0x17, 0xEB, 0x87, 0xDC}; uint8_t pt14[] = {0x37, 0xD7, 0x34, 0xA5, 0x1C, 0x07, 0x6E, 0xB8, 0x03, 0xBD, 0x53, 0x0E, 0x17, 0xEB, 0x87, 0xDC};
res = res && (memcmp(ctx.plaintexts[14], key14, sizeof(key14)) == 0); res = res && (memcmp(ctx.plaintexts[14], pt14, sizeof(pt14)) == 0);
uint8_t key15[] = {0x71, 0xB4, 0x44, 0xAF, 0x25, 0x7A, 0x93, 0x21, 0x53, 0x11, 0xD7, 0x58, 0xDD, 0x33, 0x32, 0x47}; uint8_t pt15[] = {0x71, 0xB4, 0x44, 0xAF, 0x25, 0x7A, 0x93, 0x21, 0x53, 0x11, 0xD7, 0x58, 0xDD, 0x33, 0x32, 0x47};
res = res && (memcmp(ctx.plaintexts[15], key15, sizeof(key15)) == 0); res = res && (memcmp(ctx.plaintexts[15], pt15, sizeof(pt15)) == 0);
if (res) if (res)
PrintAndLogEx(INFO, "LRP plaintexts.... " _GREEN_("passed")); PrintAndLogEx(INFO, "LRP plaintexts.... " _GREEN_("passed"));
@ -504,9 +504,23 @@ static bool TestLRPPlaintexts(void) {
return res; return res;
} }
// https://www.nxp.com/docs/en/application-note/AN12304.pdf
// page 12
static bool TestLRPUpdatedKeys(void) { static bool TestLRPUpdatedKeys(void) {
bool res = true; bool res = true;
uint8_t key[] = {0x56, 0x78, 0x26, 0xB8, 0xDA, 0x8E, 0x76, 0x84, 0x32, 0xA9, 0x54, 0x8D, 0xBE, 0x4A, 0xA3, 0xA0};
LRPContext ctx = {0};
LRPSetKey(&ctx, key, 0, false);
uint8_t key0[] = {0x16, 0x3D, 0x14, 0xED, 0x24, 0xED, 0x93, 0x53, 0x73, 0x56, 0x8E, 0xC5, 0x21, 0xE9, 0x6C, 0xF4};
res = res && (memcmp(ctx.updatedKeys[0], key0, sizeof(key0)) == 0);
uint8_t key1[] = {0x1C, 0x51, 0x9C, 0x00, 0x02, 0x08, 0xB9, 0x5A, 0x39, 0xA6, 0x5D, 0xB0, 0x58, 0x32, 0x71, 0x88};
res = res && (memcmp(ctx.updatedKeys[1], key1, sizeof(key1)) == 0);
uint8_t key2[] = {0xFE, 0x30, 0xAB, 0x50, 0x46, 0x7E, 0x61, 0x78, 0x3B, 0xFE, 0x6B, 0x5E, 0x05, 0x60, 0x16, 0x0E};
res = res && (memcmp(ctx.updatedKeys[2], key2, sizeof(key2)) == 0);
if (res) if (res)
PrintAndLogEx(INFO, "LRP updated keys.. " _GREEN_("passed")); PrintAndLogEx(INFO, "LRP updated keys.. " _GREEN_("passed"));

View file

@ -76,10 +76,10 @@ void LRPGenerateUpdatedKeys(LRPContext *ctx, size_t updatedKeysCount) {
return; return;
uint8_t h[CRYPTO_AES128_KEY_SIZE] = {0}; uint8_t h[CRYPTO_AES128_KEY_SIZE] = {0};
aes_encode(NULL, ctx->key, const55, h, CRYPTO_AES128_KEY_SIZE); aes_encode(NULL, ctx->key, constAA, h, CRYPTO_AES128_KEY_SIZE);
for (int i = 0; i < updatedKeysCount; i++) { for (int i = 0; i < updatedKeysCount; i++) {
aes_encode(NULL, h, constAA, ctx->plaintexts[i], CRYPTO_AES128_KEY_SIZE); aes_encode(NULL, h, constAA, ctx->updatedKeys[i], CRYPTO_AES128_KEY_SIZE);
aes_encode(NULL, h, const55, h, CRYPTO_AES128_KEY_SIZE); aes_encode(NULL, h, const55, h, CRYPTO_AES128_KEY_SIZE);
} }