nested.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #pragma once
  2. #include "../nfclegacy/protocols/nfc_util.h"
  3. #include "../nfclegacy/protocols/mifare_classic.h"
  4. #include "../nfclegacy/protocols/crypto1.h"
  5. #include <storage/storage.h>
  6. #include <stream/stream.h>
  7. #include <stream/buffered_file_stream.h>
  8. typedef enum {
  9. MifareNestedNonceNoTag,
  10. MifareNestedNonceWeak,
  11. MifareNestedNonceStatic,
  12. MifareNestedNonceHard,
  13. } MifareNestedNonceType;
  14. MifareNestedNonceType nested_check_nonce_type(FurryHalNfcTxRxContext* tx_rx, uint8_t blockNo);
  15. struct nonce_info_static {
  16. uint32_t cuid;
  17. uint32_t target_nt[2];
  18. uint32_t target_ks[2];
  19. bool full;
  20. };
  21. struct nonce_info_hard {
  22. uint32_t cuid;
  23. bool static_encrypted;
  24. bool full;
  25. };
  26. struct nonce_info {
  27. uint32_t cuid;
  28. uint32_t target_nt[2];
  29. uint32_t target_ks[2];
  30. uint8_t parity[2][4];
  31. bool full;
  32. };
  33. struct distance_info {
  34. uint32_t min_prng;
  35. uint32_t max_prng;
  36. uint32_t mid_prng;
  37. };
  38. struct nonce_info_static nested_static_nonce_attack(
  39. FurryHalNfcTxRxContext* tx_rx,
  40. uint8_t blockNo,
  41. uint8_t keyType,
  42. uint8_t targetBlockNo,
  43. uint8_t targetKeyType,
  44. uint64_t ui64Key);
  45. struct nonce_info nested_attack(
  46. FurryHalNfcTxRxContext* tx_rx,
  47. uint8_t blockNo,
  48. uint8_t keyType,
  49. uint8_t targetBlockNo,
  50. uint8_t targetKeyType,
  51. uint64_t ui64Key,
  52. uint32_t distance,
  53. uint32_t delay);
  54. struct nonce_info_hard nested_hard_nonce_attack(
  55. FurryHalNfcTxRxContext* tx_rx,
  56. uint8_t blockNo,
  57. uint8_t keyType,
  58. uint8_t targetBlockNo,
  59. uint8_t targetKeyType,
  60. uint64_t ui64Key,
  61. uint32_t* found,
  62. uint32_t* first_byte_sum,
  63. Stream* file_stream);
  64. uint32_t nested_calibrate_distance(
  65. FurryHalNfcTxRxContext* tx_rx,
  66. uint8_t blockNo,
  67. uint8_t keyType,
  68. uint64_t ui64Key,
  69. uint32_t delay,
  70. bool full);
  71. struct distance_info nested_calibrate_distance_info(
  72. FurryHalNfcTxRxContext* tx_rx,
  73. uint8_t blockNo,
  74. uint8_t keyType,
  75. uint64_t ui64Key);
  76. typedef enum {
  77. NestedCheckKeyNoTag,
  78. NestedCheckKeyValid,
  79. NestedCheckKeyInvalid,
  80. } NestedCheckKeyResult;
  81. NestedCheckKeyResult nested_check_key(
  82. FurryHalNfcTxRxContext* tx_rx,
  83. uint8_t blockNo,
  84. uint8_t keyType,
  85. uint64_t ui64Key);
  86. bool nested_check_block(FurryHalNfcTxRxContext* tx_rx, uint8_t blockNo, uint8_t keyType);
  87. void nested_get_data();
  88. bool mifare_classic_authex(
  89. Crypto1* crypto,
  90. FurryHalNfcTxRxContext* tx_rx,
  91. uint32_t uid,
  92. uint32_t blockNo,
  93. uint32_t keyType,
  94. uint64_t ui64Key,
  95. bool isNested,
  96. uint32_t* ntptr);
  97. void nfc_activate();
  98. void nfc_deactivate();