Revert "Merge pull request #32 from RfidResearchGroup/master"

This reverts commit 40d2a3c072, reversing
changes made to 15d584e060.
This commit is contained in:
mwalker33
2020-04-10 13:59:56 +10:00
parent 0542825567
commit 978f57b505
25 changed files with 666 additions and 1079 deletions

View File

@@ -204,7 +204,7 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
uint8_t decRndB[16] = {0x00};
uint8_t both[32] = {0x00};
//InitDesfireCard();
InitDesfireCard();
LED_A_ON();
LED_B_OFF();
@@ -455,12 +455,8 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
mbedtls_aes_init(&ctx);
cmd[0] = AUTHENTICATE_AES;
cmd[1] = 0x0;
cmd[2] = 0x0;
cmd[3] = 0x1;
cmd[4] = arg2; //keynumber
cmd[5] = 0x0;
len = DesfireAPDU(cmd, 6, resp);
cmd[1] = 0x00; //keynumber
len = DesfireAPDU(cmd, 2, resp);
if (!len) {
if (DBGLEVEL >= DBG_ERROR) {
DbpString("Authentication failed. Card timeout.");
@@ -469,7 +465,7 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
return;
}
memcpy(encRndB, resp + 1, 16);
memcpy(encRndB, resp + 3, 16);
// dekryptera tagnonce.
if (mbedtls_aes_setkey_dec(&ctx, key->data, 128) != 0) {
@@ -495,13 +491,9 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_ENCRYPT, 32, IV, both, encBoth);
cmd[0] = ADDITIONAL_FRAME;
cmd[1] = 0x00;
cmd[2] = 0x00;
cmd[3] = 0x20;
memcpy(cmd + 4, encBoth, 32);
cmd[36]=0x0;
memcpy(cmd + 1, encBoth, 32);
len = DesfireAPDU(cmd, 37, resp); // 4 + 32 + 1 == 37
len = DesfireAPDU(cmd, 33, resp); // 1 + 32 == 33
if (!len) {
if (DBGLEVEL >= DBG_ERROR) {
DbpString("Authentication failed. Card timeout.");
@@ -510,7 +502,7 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
return;
}
if ((resp[1+16] == 0x91)&&(resp[1+16+1] == 0x00)) {
if (resp[2] == 0x00) {
// Create AES Session key
struct desfire_key sessionKey = {0};
desfirekey_t skey = &sessionKey;
@@ -609,6 +601,6 @@ void OnSuccess() {
}
void OnError(uint8_t reason) {
reply_mix(CMD_ACK, 0, reason, 0, 0, 0);
reply_old(CMD_ACK, 0, reason, 0, 0, 0);
OnSuccess();
}