mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-22 22:33:48 -07:00
LRPIncCounter
This commit is contained in:
parent
c8813a0123
commit
ae3ba512f0
3 changed files with 54 additions and 0 deletions
|
@ -586,6 +586,37 @@ static bool TestLRPEval(void) {
|
|||
return res;
|
||||
}
|
||||
|
||||
static bool TestLRPIncCounter(void) {
|
||||
bool res = true;
|
||||
|
||||
uint8_t ctr1[] = {0x00, 0x01};
|
||||
LRPIncCounter(ctr1, 4);
|
||||
uint8_t ctrr1[] = {0x00, 0x02};
|
||||
res = res && (memcmp(ctr1, ctrr1, sizeof(ctrr1)) == 0);
|
||||
|
||||
uint8_t ctr2[] = {0x00, 0xf0};
|
||||
LRPIncCounter(ctr2, 3);
|
||||
uint8_t ctrr2[] = {0x01, 0x00};
|
||||
res = res && (memcmp(ctr2, ctrr2, sizeof(ctrr2)) == 0);
|
||||
|
||||
uint8_t ctr3[] = {0xff, 0xf0};
|
||||
LRPIncCounter(ctr3, 3);
|
||||
uint8_t ctrr3[] = {0x00, 0x00};
|
||||
res = res && (memcmp(ctr3, ctrr3, sizeof(ctrr3)) == 0);
|
||||
|
||||
uint8_t ctr4[] = {0xf0};
|
||||
LRPIncCounter(ctr4, 1);
|
||||
uint8_t ctrr4[] = {0x00};
|
||||
res = res && (memcmp(ctr4, ctrr4, sizeof(ctrr4)) == 0);
|
||||
|
||||
if (res)
|
||||
PrintAndLogEx(INFO, "LRP inc counter... " _GREEN_("passed"));
|
||||
else
|
||||
PrintAndLogEx(ERR, "LRP inc counter... " _RED_("fail"));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool DesfireTest(bool verbose) {
|
||||
bool res = true;
|
||||
|
||||
|
@ -607,6 +638,7 @@ bool DesfireTest(bool verbose) {
|
|||
res = res && TestLRPPlaintexts();
|
||||
res = res && TestLRPUpdatedKeys();
|
||||
res = res && TestLRPEval();
|
||||
res = res && TestLRPIncCounter();
|
||||
|
||||
PrintAndLogEx(INFO, "---------------------------");
|
||||
if (res)
|
||||
|
|
|
@ -100,3 +100,23 @@ void LRPEvalLRP(LRPContext *ctx, uint8_t *iv, size_t ivlen, bool final, uint8_t
|
|||
if (final)
|
||||
aes_encode(NULL, y, const00, y, CRYPTO_AES128_KEY_SIZE);
|
||||
}
|
||||
|
||||
void LRPIncCounter(uint8_t *ctr, size_t ctrlen) {
|
||||
bool carry = true;
|
||||
for (int i = ctrlen - 1; i >= 0; i--) {
|
||||
uint8_t nk = (i % 2) ? ctr[i / 2] & 0x0f : (ctr[i / 2] >> 4) & 0x0f;
|
||||
|
||||
if (carry)
|
||||
nk++;
|
||||
|
||||
carry = (nk > 0xf);
|
||||
if (i % 2)
|
||||
ctr[i / 2] = (ctr[i / 2] & 0xf0) | (nk & 0x0f);
|
||||
else
|
||||
ctr[i / 2] = (ctr[i / 2] & 0x0f) | ((nk << 4) & 0xf0);
|
||||
|
||||
if(!carry)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,5 +42,7 @@ void LRPSetKey(LRPContext *ctx, uint8_t *key, size_t updatedKeyNum, bool useBitP
|
|||
void LRPGeneratePlaintexts(LRPContext *ctx, size_t plaintextsCount);
|
||||
void LRPGenerateUpdatedKeys(LRPContext *ctx, size_t updatedKeysCount);
|
||||
void LRPEvalLRP(LRPContext *ctx, uint8_t *iv, size_t ivlen, bool final, uint8_t *y);
|
||||
void LRPIncCounter(uint8_t *ctr, size_t ctrlen);
|
||||
void LRPEncode(LRPContext *ctx, uint8_t *ctr, size_t ctrlen, uint8_t *resp, size_t *resplen);
|
||||
|
||||
#endif // __LRPCRYPTO_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue