]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/mifarehost.c
Update mifarehost.h
[proxmark3-svn] / client / mifarehost.c
index cbd79cf7536d5475288f1d02518f09075889de49..51dd73744609e9543924eeadb9e77ae1032220b1 100644 (file)
@@ -8,6 +8,8 @@
 // mifare commands\r
 //-----------------------------------------------------------------------------\r
 \r
+#include "mifarehost.h"\r
+\r
 #include <stdio.h>\r
 #include <stdlib.h> \r
 #include <string.h>\r
@@ -20,7 +22,6 @@
 #include "ui.h"\r
 #include "util.h"\r
 #include "iso14443crc.h"\r
-#include "mifarehost.h"\r
 \r
 // mifare tracer flags used in mfTraceDecode()\r
 #define TRACE_IDLE                                             0x00\r
@@ -223,7 +224,7 @@ int mfDarkside(uint64_t *key)
 \r
 int mfCheckKeys (uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t keycnt, uint8_t * keyBlock, uint64_t * key){\r
 \r
-       *key = 0;\r
+       *key = -1;\r
 \r
        UsbCommand c = {CMD_MIFARE_CHKKEYS, {((blockNo & 0xff) | ((keyType&0xff)<<8)), clear_trace, keycnt}};\r
        memcpy(c.d.asBytes, keyBlock, 6 * keycnt);\r
@@ -819,3 +820,33 @@ int tryDecryptWord(uint32_t nt, uint32_t ar_enc, uint32_t at_enc, uint8_t *data,
        crypto1_destroy(traceCrypto1);\r
        return 0;\r
 }\r
+/* Detect Tag Prng, \r
+* function performs a partial AUTH,  where it tries to authenticate against block0, key A, but only collects tag nonce.\r
+* the tag nonce is check to see if it has a predictable PRNG.\r
+* @returns \r
+*      TRUE if tag uses WEAK prng (ie Darkside attack possible)\r
+*   FALSE is tag uses HARDEND prng (ie hardnested attack possible, with known key)\r
+*/\r
+bool detect_classic_prng(){\r
+\r
+       UsbCommand resp, respA; \r
+       uint8_t cmd[] = {MIFARE_AUTH_KEYA, 0x00};\r
+       uint32_t flags = ISO14A_CONNECT | ISO14A_RAW | ISO14A_APPEND_CRC;\r
+       \r
+       UsbCommand cAuth = {CMD_READER_ISO_14443a, {flags, sizeof(cmd), 0}};\r
+       memcpy(cAuth.d.asBytes, cmd, sizeof(cmd));\r
+\r
+       clearCommandBuffer();\r
+       SendCommand(&cAuth);\r
+       WaitForResponse(CMD_ACK, &resp);\r
+       WaitForResponse(CMD_ACK, &respA);\r
+               \r
+       // if select tag failed.\r
+       if ( resp.arg[0] == 0 ) {\r
+               printf("Error:  selecting tag failed,  can't detect prng\n");\r
+               return false;\r
+       }\r
+\r
+       uint32_t nonce = bytes_to_num(respA.d.asBytes, respA.arg[0]);\r
+       return validate_prng_nonce(nonce);\r
+}\r
Impressum, Datenschutz