mfkey.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 total;
  40. int dict_count;
  41. int search;
  42. int eta_timestamp;
  43. int eta_total;
  44. int eta_round;
  45. bool mfkey32_present;
  46. bool nested_present;
  47. bool is_thread_running;
  48. bool close_thread_please;
  49. FuriThread* mfkeythread;
  50. } ProgramState;
  51. typedef enum {
  52. mfkey32,
  53. static_nested
  54. } AttackType;
  55. typedef struct {
  56. AttackType attack;
  57. MfClassicKey key; // key
  58. uint32_t uid; // serial number
  59. uint32_t nt0; // tag challenge first
  60. uint32_t nt1; // tag challenge second
  61. uint32_t uid_xor_nt0; // uid ^ nt0
  62. uint32_t uid_xor_nt1; // uid ^ nt1
  63. // Mfkey32
  64. uint32_t p64; // 64th successor of nt0
  65. uint32_t p64b; // 64th successor of nt1
  66. uint32_t nr0_enc; // first encrypted reader challenge
  67. uint32_t ar0_enc; // first encrypted reader response
  68. uint32_t nr1_enc; // second encrypted reader challenge
  69. uint32_t ar1_enc; // second encrypted reader response
  70. // Nested
  71. uint32_t ks1_1_enc; // first encrypted keystream
  72. uint32_t ks1_2_enc; // second encrypted keystream
  73. char par_1_str[5]; // first parity bits (string representation)
  74. char par_2_str[5]; // second parity bits (string representation)
  75. uint8_t par_1; // first parity bits
  76. uint8_t par_2; // second parity bits
  77. } MfClassicNonce;
  78. typedef struct {
  79. Stream* stream;
  80. uint32_t total_nonces;
  81. MfClassicNonce* remaining_nonce_array;
  82. size_t remaining_nonces;
  83. } MfClassicNonceArray;
  84. struct KeysDict {
  85. Stream* stream;
  86. size_t key_size;
  87. size_t key_size_symbols;
  88. size_t total_keys;
  89. };
  90. #endif // MFKEY_H