mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -07:00
fix multi-block cmac, remove debug
This commit is contained in:
parent
8558ba639f
commit
9f0e973ad5
2 changed files with 19 additions and 14 deletions
|
@ -818,7 +818,7 @@ static bool TestLRPCMAC(void) {
|
|||
uint8_t cmacres3[] = {0xF7, 0xC8, 0x55, 0x3D, 0xED, 0x57, 0x48, 0x29, 0xE6, 0xEE, 0x68, 0x11, 0x2C, 0xB3, 0x81, 0x7B};
|
||||
res = res && (memcmp(cmac, cmacres3, sizeof(cmacres3)) == 0);
|
||||
|
||||
/*uint8_t key4[] = {0x2A, 0x47, 0x3E, 0x38, 0xBB, 0xF4, 0x53, 0x7C, 0x53, 0x97, 0xF4, 0x5A, 0xE4, 0x98, 0xCD, 0x4D};
|
||||
uint8_t key4[] = {0x2A, 0x47, 0x3E, 0x38, 0xBB, 0xF4, 0x53, 0x7C, 0x53, 0x97, 0xF4, 0x5A, 0xE4, 0x98, 0xCD, 0x4D};
|
||||
LRPSetKey(&ctx, key4, 0, true);
|
||||
uint8_t data4[] = {0xC2, 0xAC, 0x3D, 0x72, 0x50, 0xEE, 0xF0, 0x23, 0x18, 0xBC, 0x08, 0x4F, 0x29, 0x4B, 0x1A, 0xC7,
|
||||
0x22, 0x91, 0xEE, 0x1D, 0xC0, 0x2A, 0xF4, 0x24, 0x94, 0x1C, 0xAA, 0xC6, 0x85, 0xFC, 0xA5, 0x9D,
|
||||
|
@ -826,13 +826,21 @@ static bool TestLRPCMAC(void) {
|
|||
LRPCMAC(&ctx, data4, sizeof(data4), cmac);
|
||||
uint8_t cmacres4[] = {0x66, 0xDC, 0x2B, 0xCE, 0x26, 0x9B, 0x79, 0x3B, 0x4A, 0xCA, 0x1A, 0x4D, 0x04, 0xDD, 0xD6, 0x68};
|
||||
res = res && (memcmp(cmac, cmacres4, sizeof(cmacres4)) == 0);
|
||||
*/
|
||||
|
||||
uint8_t key5[] = {0x63, 0xA0, 0x16, 0x9B, 0x4D, 0x9F, 0xE4, 0x2C, 0x72, 0xB2, 0x78, 0x4C, 0x80, 0x6E, 0xAC, 0x21};
|
||||
LRPSetKey(&ctx, key5, 0, true);
|
||||
LRPCMAC(&ctx, NULL, 0, cmac);
|
||||
uint8_t cmacres5[] = {0x0E, 0x07, 0xC6, 0x01, 0x97, 0x08, 0x14, 0xA4, 0x17, 0x6F, 0xDA, 0x63, 0x3C, 0x6F, 0xC3, 0xDE};
|
||||
res = res && (memcmp(cmac, cmacres5, sizeof(cmacres5)) == 0);
|
||||
|
||||
uint8_t key6[] = {0x95, 0x2F, 0xDE, 0x83, 0x93, 0xC4, 0x5D, 0x23, 0x0A, 0x5B, 0xE9, 0xB3, 0x86, 0x36, 0xD1, 0x54};
|
||||
LRPSetKey(&ctx, key6, 0, true);
|
||||
uint8_t data6[] = {0xD7, 0x80, 0x0E, 0x25, 0x70, 0x01, 0xA7, 0x74, 0xAE, 0x7B, 0xCF, 0xB2, 0xCE, 0x13, 0x07, 0xB5,
|
||||
0xB0, 0x44};
|
||||
LRPCMAC(&ctx, data6, sizeof(data6), cmac);
|
||||
uint8_t cmacres6[] = {0x05, 0xF1, 0xCE, 0x30, 0x45, 0x1A, 0x03, 0xA6, 0xE4, 0x68, 0xB3, 0xA5, 0x90, 0x33, 0xA5, 0x54};
|
||||
res = res && (memcmp(cmac, cmacres6, sizeof(cmacres6)) == 0);
|
||||
|
||||
if (res)
|
||||
PrintAndLogEx(INFO, "LRP CMAC.......... " _GREEN_("passed"));
|
||||
else
|
||||
|
|
|
@ -107,15 +107,17 @@ void LRPGenerateUpdatedKeys(LRPContext *ctx, size_t updatedKeysCount) {
|
|||
// https://www.nxp.com/docs/en/application-note/AN12304.pdf
|
||||
// Algorithm 3
|
||||
void LRPEvalLRP(LRPContext *ctx, uint8_t *iv, size_t ivlen, bool final, uint8_t *y) {
|
||||
memcpy(y, ctx->updatedKeys[ctx->useUpdatedKeyNum], CRYPTO_AES128_KEY_SIZE);
|
||||
uint8_t ry[CRYPTO_AES128_KEY_SIZE] = {0};
|
||||
memcpy(ry, ctx->updatedKeys[ctx->useUpdatedKeyNum], CRYPTO_AES128_KEY_SIZE);
|
||||
|
||||
for (int i = 0; i < ivlen; i++) {
|
||||
uint8_t nk = (i % 2) ? iv[i / 2] & 0x0f : (iv[i / 2] >> 4) & 0x0f;
|
||||
aes_encode(NULL, y, ctx->plaintexts[nk], y, CRYPTO_AES128_KEY_SIZE);
|
||||
aes_encode(NULL, ry, ctx->plaintexts[nk], ry, CRYPTO_AES128_KEY_SIZE);
|
||||
}
|
||||
|
||||
if (final)
|
||||
aes_encode(NULL, y, const00, y, CRYPTO_AES128_KEY_SIZE);
|
||||
aes_encode(NULL, ry, const00, ry, CRYPTO_AES128_KEY_SIZE);
|
||||
memcpy(y, ry, CRYPTO_AES128_KEY_SIZE);
|
||||
}
|
||||
|
||||
void LRPIncCounter(uint8_t *ctr, size_t ctrlen) {
|
||||
|
@ -218,14 +220,12 @@ void LRPGenSubkeys(uint8_t *key, uint8_t *sk1, uint8_t *sk2) {
|
|||
|
||||
uint8_t y[CRYPTO_AES128_KEY_SIZE] = {0};
|
||||
LRPEvalLRP(&ctx, const00, CRYPTO_AES128_KEY_SIZE * 2, true, y);
|
||||
PrintAndLogEx(ERR, "--k %s", sprint_hex(key, 16));
|
||||
PrintAndLogEx(ERR, "--y %s", sprint_hex(y, 16));
|
||||
|
||||
mulPolyX(y);
|
||||
memcpy(sk1, y, CRYPTO_AES128_KEY_SIZE);
|
||||
PrintAndLogEx(ERR, "--sk1 %s", sprint_hex(y, 16));
|
||||
|
||||
mulPolyX(y);
|
||||
memcpy(sk2, y, CRYPTO_AES128_KEY_SIZE);
|
||||
PrintAndLogEx(ERR, "--sk2 %s", sprint_hex(y, 16));
|
||||
}
|
||||
|
||||
// https://www.nxp.com/docs/en/application-note/AN12304.pdf
|
||||
|
@ -248,11 +248,9 @@ void LRPCMAC(LRPContext *ctx, uint8_t *data, size_t datalen, uint8_t *cmac) {
|
|||
|
||||
size_t bllen = datalen - clen;
|
||||
uint8_t bl[CRYPTO_AES128_KEY_SIZE] = {0};
|
||||
memcpy(bl, &data[clen * CRYPTO_AES128_KEY_SIZE], bllen);
|
||||
memcpy(bl, &data[clen], bllen);
|
||||
|
||||
PrintAndLogEx(ERR, "--bllen %d", bllen);
|
||||
PrintAndLogEx(ERR, "--y %s", sprint_hex(y, 16));
|
||||
// if there is more data
|
||||
// last block
|
||||
if (bllen == 16) {
|
||||
bin_xor(y, bl, CRYPTO_AES128_KEY_SIZE);
|
||||
|
||||
|
@ -266,5 +264,4 @@ PrintAndLogEx(ERR, "--y %s", sprint_hex(y, 16));
|
|||
}
|
||||
|
||||
LRPEvalLRP(ctx, y, CRYPTO_AES128_KEY_SIZE * 2, true, cmac);
|
||||
PrintAndLogEx(ERR, "--cmac %s", sprint_hex(cmac, 16));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue