mfkey.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #ifndef MFKEY_H
  2. #define MFKEY_H
  3. #include <furi_hal.h>
  4. #include <gui/gui.h>
  5. #include <gui/elements.h>
  6. #include <inttypes.h>
  7. #include <toolbox/keys_dict.h>
  8. #include <toolbox/stream/buffered_file_stream.h>
  9. #include <nfc/protocols/mf_classic/mf_classic.h>
  10. struct Crypto1State {
  11. uint32_t odd, even;
  12. };
  13. struct Msb {
  14. int tail;
  15. uint32_t states[768];
  16. };
  17. typedef enum {
  18. MissingNonces,
  19. ZeroNonces,
  20. InsufficientRAM,
  21. } MFKeyError;
  22. typedef enum {
  23. Ready,
  24. Initializing,
  25. DictionaryAttack,
  26. MFKeyAttack,
  27. Complete,
  28. Error,
  29. Help,
  30. } MFKeyState;
  31. // TODO: Can we eliminate any of the members of this struct?
  32. typedef struct {
  33. FuriMutex* mutex;
  34. MFKeyError err;
  35. MFKeyState mfkey_state;
  36. int cracked;
  37. int unique_cracked;
  38. int num_completed;
  39. int num_candidates;
  40. int total;
  41. int dict_count;
  42. int search;
  43. int eta_timestamp;
  44. int eta_total;
  45. int eta_round;
  46. bool mfkey32_present;
  47. bool nested_present;
  48. bool is_thread_running;
  49. bool close_thread_please;
  50. FuriThread* mfkeythread;
  51. KeysDict* cuid_dict;
  52. } ProgramState;
  53. typedef enum {
  54. mfkey32,
  55. static_nested,
  56. static_encrypted
  57. } AttackType;
  58. typedef struct {
  59. AttackType attack;
  60. MfClassicKey key; // key
  61. uint32_t uid; // serial number
  62. uint32_t nt0; // tag challenge first
  63. uint32_t nt1; // tag challenge second
  64. uint32_t uid_xor_nt0; // uid ^ nt0
  65. uint32_t uid_xor_nt1; // uid ^ nt1
  66. // Mfkey32
  67. uint32_t p64; // 64th successor of nt0
  68. uint32_t p64b; // 64th successor of nt1
  69. uint32_t nr0_enc; // first encrypted reader challenge
  70. uint32_t ar0_enc; // first encrypted reader response
  71. uint32_t nr1_enc; // second encrypted reader challenge
  72. uint32_t ar1_enc; // second encrypted reader response
  73. // Nested
  74. uint32_t ks1_1_enc; // first encrypted keystream
  75. uint32_t ks1_2_enc; // second encrypted keystream
  76. char par_1_str[5]; // first parity bits (string representation)
  77. char par_2_str[5]; // second parity bits (string representation)
  78. uint8_t par_1; // first parity bits
  79. uint8_t par_2; // second parity bits
  80. } MfClassicNonce;
  81. typedef struct {
  82. Stream* stream;
  83. uint32_t total_nonces;
  84. MfClassicNonce* remaining_nonce_array;
  85. size_t remaining_nonces;
  86. } MfClassicNonceArray;
  87. struct KeysDict {
  88. Stream* stream;
  89. size_t key_size;
  90. size_t key_size_symbols;
  91. size_t total_keys;
  92. };
  93. #endif // MFKEY_H