You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mfcuk.h 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. Package:
  3. MiFare Classic Universal toolKit (MFCUK)
  4. Filename:
  5. mfcuk_keyrecovery_darkside.h
  6. Description:
  7. MFCUK DarkSide Key Recovery specific typedefs and defines
  8. Contact, bug-reports:
  9. http://andreicostin.com/
  10. mailto:zveriu@gmail.com
  11. License:
  12. GPL2 (see below), Copyright (C) 2009, Andrei Costin
  13. * @file mfcuk_keyrecovery_darkside.h
  14. * @brief
  15. */
  16. /*
  17. VERSION HISTORY
  18. --------------------------------------------------------------------------------
  19. | Number : 0.1
  20. | dd/mm/yyyy : 23/11/2009
  21. | Author : zveriu@gmail.com, http://andreicostin.com
  22. | Description: Moved bulk of defines and things from "mfcuk_keyrecovery_darkside.c"
  23. --------------------------------------------------------------------------------
  24. */
  25. /*
  26. LICENSE
  27. This program is free software: you can redistribute it and/or modify
  28. it under the terms of the GNU General Public License as published by
  29. the Free Software Foundation, either version 2 of the License, or
  30. (at your option) any later version.
  31. This program is distributed in the hope that it will be useful,
  32. but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34. GNU General Public License for more details.
  35. You should have received a copy of the GNU General Public License
  36. along with this program. If not, see <http://www.gnu.org/licenses/>.
  37. */
  38. #ifndef _MFCUK_KEYRECOVERY_DARKSIDE_H_
  39. #define _MFCUK_KEYRECOVERY_DARKSIDE_H_
  40. // Define package and executable related info
  41. #define BUILD_NAME "Mifare Classic DarkSide Key Recovery Tool"
  42. #define BUILD_VERSION "0.3"
  43. #define BUILD_AUTHOR "Andrei Costin, zveriu@gmail.com, http://andreicostin.com"
  44. // Define return statuses
  45. #define MFCUK_SUCCESS 0x0
  46. #define MFCUK_OK_KEY_RECOVERED (MFCUK_SUCCESS+1)
  47. #define MFCUK_FAIL_AUTH (MFCUK_OK_KEY_RECOVERED+1)
  48. #define MFCUK_FAIL_CRAPTO (MFCUK_FAIL_AUTH+1)
  49. #define MFCUK_FAIL_TAGTYPE_INVALID (MFCUK_FAIL_CRAPTO+1)
  50. #define MFCUK_FAIL_KEYTYPE_INVALID (MFCUK_FAIL_TAGTYPE_INVALID+1)
  51. #define MFCUK_FAIL_BLOCK_INVALID (MFCUK_FAIL_KEYTYPE_INVALID+1)
  52. #define MFCUK_FAIL_SECTOR_INVALID (MFCUK_FAIL_BLOCK_INVALID+1)
  53. #define MFCUK_FAIL_COMM (MFCUK_FAIL_SECTOR_INVALID+1)
  54. #define MFCUK_FAIL_MEMORY (MFCUK_FAIL_COMM+1)
  55. // There are 4 bytes in ACBITS, use each byte as below
  56. #define ACTIONS_KEY_A 0 // Specifies the byte index where actions for key A are stored
  57. #define RESULTS_KEY_A 1 // Specifies the byte index where results for key A are stored
  58. #define ACTIONS_KEY_B 2 // Specifies the byte index where actions for key B are stored
  59. #define RESULTS_KEY_B 3 // Specifies the byte index where results for key B are stored
  60. // The action/result byte can contain any combination of these
  61. #define ACTIONS_VERIFY 0x1 // Specifies whether the key should be first verified
  62. #define ACTIONS_RECOVER 0x2 // Specifies whether the key should be recovered. If a key has verify action and the key was verified, RESULTS_ byte will indicate that and recovery will not take place
  63. #define ACTIONS_KEYSET 0x4 // Specifies whether the key was set from command line rather that should be loaded from the eventual -i/-I dump
  64. // Implementation specific, since we are not 100% sure we can fix the tag nonce
  65. // Suppose from 2^32, only MAX 2^16 tag nonces will appear given current SLEEP_ values
  66. #define MAX_TAG_NONCES 65536
  67. // Maximum possible states allocated and returned by lsfr_common_prefix(). Used this value in the looping
  68. #define MAX_COMMON_PREFIX_STATES (1<<20)
  69. // 10 ms, though {WPMCC09} claims 30 us is enough
  70. #define SLEEP_AT_FIELD_OFF 10
  71. // 50 ms, seems pretty good constant, though if you don't like it - make it even 3.1415..., we don't care
  72. #define SLEEP_AFTER_FIELD_ON 50
  73. // Since the 29 bits of {Nr} are constant, darkside varies only "last" (0xFFFFFF1F) 3 bits, thus we have 8 possible parity bits arrays
  74. #define MFCUK_DARKSIDE_MAX_LEVELS 8
  75. #define MFCUK_DARKSIDE_START_NR 0xDEADBEEF
  76. #define MFCUK_DARKSIDE_START_AR 0xFACECAFE
  77. typedef struct tag_nonce_entry {
  78. uint32_t tagNonce; // Tag nonce we target for fixation
  79. uint8_t spoofFlag; // No spoofing until we have a successful auth with this tagNonce. Once we have, we want to spoof to get the encrypted 0x5 value
  80. uint32_t num_of_appearances; // For statistics, how many times this tag nonce appeared for the given SLEEP_ values
  81. // STAGE1 data for "dark side" and lsfr_common_prefix()
  82. uint32_t spoofNrPfx; // PARAM: used as pfx, calculated from (spoofNrEnc & 0xFFFFFF1F). BUG: weird way to denote "first 29 prefix bits" in "dark side" paper. Perhaps I see the world different
  83. uint32_t spoofNrEnc; // {Nr} value which we will be using to make the tag respond with 4 bits
  84. uint32_t spoofArEnc; // PARAM: used as rr
  85. uint8_t spoofParBitsEnc; // parity bits we are trying to guess for the first time
  86. uint8_t spoofNackEnc; // store here the encrypted NACK returned first time we match the parity bits
  87. uint8_t spoofKs; // store here the keystream ks used for encryptying spoofNackEnc, specifically spoofKs = spoofNackEnc ^ 0x5
  88. // STAGE2 data for "dark side" and lsfr_common_prefix()
  89. int current_out_of_8; // starting from -1 until we find parity for chosen spoofNrEnc,spoofArEnc
  90. uint8_t parBitsCrntCombination[MFCUK_DARKSIDE_MAX_LEVELS]; // Loops over 32 combinations of the last 5 parity bits which generated the 4 bit NACK in STAGE1
  91. uint32_t nrEnc[MFCUK_DARKSIDE_MAX_LEVELS]; // the 29 bits constant prefix, varying only 3 bits, thus 8 possible values
  92. uint32_t arEnc[MFCUK_DARKSIDE_MAX_LEVELS]; // the same reader response as spoofArEnc; redundant but... :)
  93. uint8_t ks[MFCUK_DARKSIDE_MAX_LEVELS]; // PARAM: used as ks, obtained as (ks[i] = nackEnc[i] ^ 0x5)
  94. uint8_t nackEnc[MFCUK_DARKSIDE_MAX_LEVELS]; // store here the encrypted 4 bits values which tag responded
  95. uint8_t parBits[MFCUK_DARKSIDE_MAX_LEVELS]; // store here the values based on spoofParBitsEnc, varying only last 5 bits
  96. uint8_t parBitsArr[MFCUK_DARKSIDE_MAX_LEVELS][8]; // PARAM: used as par, contains value of parBits byte-bit values just splitted out one bit per byte thus second pair of braces [8]
  97. } tag_nonce_entry_t;
  98. #endif // _MFCUK_KEYRECOVERY_DARKSIDE_H_