]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/mifaredesfire.c
code to check RndA' from PICC was unreachable
[proxmark3-svn] / armsrc / mifaredesfire.c
index 85e3175149fcebb2aebc2bf70976cdae97a21fec..e5a2289b29993db88019dc27f7101557c6df7696 100644 (file)
@@ -218,6 +218,8 @@ void MifareDES_Auth1(uint8_t mode, uint8_t algo, uint8_t keyno,  uint8_t *datain
        // des, nyckel 0, 
        switch (mode){
         case 1:{
+            if (algo == 1) {
+
             uint8_t keybytes[8];
             uint8_t RndA[8] = {0x00};
             uint8_t RndB[8] = {0x00};
@@ -256,6 +258,7 @@ void MifareDES_Auth1(uint8_t mode, uint8_t algo, uint8_t keyno,  uint8_t *datain
             memcpy(RndB, decRndB, 8);
             rol(decRndB,8);
             
+            // This should be random
             uint8_t decRndA[8] = {0x00};
             memcpy(RndA, decRndA, 8);
             uint8_t encRndA[8] = {0x00};
@@ -290,7 +293,21 @@ void MifareDES_Auth1(uint8_t mode, uint8_t algo, uint8_t keyno,  uint8_t *datain
                 struct desfire_key sessionKey = {0};
                 desfirekey_t skey = &sessionKey;
                 Desfire_session_key_new( RndA, RndB , key, skey );
-                print_result("SESSION : ", skey->data, 8);
+                //print_result("SESSION : ", skey->data, 8);
+                
+                memcpy(encRndA, resp+3, 8);
+                des_dec(&encRndA, &encRndA, key->data);
+                rol(decRndA,8);
+                for (int x = 0; x < 8; x++) {
+                    if (decRndA[x] != encRndA[x]) {
+                        DbpString("Authetication failed. Cannot varify PICC.");
+                        OnError();
+                        return;
+                    }
+                }
+                
+                OnSuccess();
+                cmd_send(CMD_ACK,1,0,0,skey->data,8);
                 
             } else {
                 DbpString("Authetication failed.");
@@ -298,18 +315,7 @@ void MifareDES_Auth1(uint8_t mode, uint8_t algo, uint8_t keyno,  uint8_t *datain
                 return;
             }
             
-            memcpy(encRndA, resp+3, 8);
-            des_dec(&encRndA, &encRndA, key->data);
-            rol(decRndA,8);
-            for (int x = 0; x < 8; x++) {
-                if (decRndA[x] != encRndA[x]) {
-                    DbpString("Authetication failed. Cannot varify PICC.");
-                    OnError();
-                    return;
-                }
             }
-            
-            
             }
                        break;
                case 2:
Impressum, Datenschutz