subghz_protocol_keeloq_common.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #include "subghz_protocol_common.h"
  3. #include "file_worker.h"
  4. #include <furi.h>
  5. /*
  6. * Keeloq
  7. * https://ru.wikipedia.org/wiki/KeeLoq
  8. * https://phreakerclub.com/forum/showthread.php?t=1094
  9. *
  10. */
  11. #define KEELOQ_NLF 0x3A5C742E
  12. #define bit(x, n) (((x) >> (n)) & 1)
  13. #define g5(x, a, b, c, d, e) \
  14. (bit(x, a) + bit(x, b) * 2 + bit(x, c) * 4 + bit(x, d) * 8 + bit(x, e) * 16)
  15. /*
  16. * KeeLoq learning types
  17. * https://phreakerclub.com/forum/showthread.php?t=67
  18. */
  19. #define KEELOQ_LEARNING_UNKNOWN 0u
  20. #define KEELOQ_LEARNING_SIMPLE 1u
  21. #define KEELOQ_LEARNING_NORMAL 2u
  22. #define KEELOQ_LEARNING_SECURE 3u
  23. #define KEELOQ_LEARNING_MAGIC_XOR_TYPE_1 4u
  24. /** Simple Learning Encrypt
  25. * @param data - 0xBSSSCCCC, B(4bit) key, S(10bit) serial&0x3FF, C(16bit) counter
  26. * @param key - manufacture (64bit)
  27. * @return keelog encrypt data
  28. */
  29. uint32_t subghz_protocol_keeloq_common_encrypt(const uint32_t data, const uint64_t key);
  30. /** Simple Learning Decrypt
  31. * @param data - keelog encrypt data
  32. * @param key - manufacture (64bit)
  33. * @return 0xBSSSCCCC, B(4bit) key, S(10bit) serial&0x3FF, C(16bit) counter
  34. */
  35. uint32_t subghz_protocol_keeloq_common_decrypt(const uint32_t data, const uint64_t key);
  36. /** Normal Learning
  37. * @param data - serial number (28bit)
  38. * @param key - manufacture (64bit)
  39. * @return manufacture for this serial number (64bit)
  40. */
  41. uint64_t subghz_protocol_keeloq_common_normal_learning(uint32_t data, const uint64_t key);
  42. /** Secure Learning
  43. * @param data - serial number (28bit)
  44. * @param seed - seed number (32bit)
  45. * @param key - manufacture (64bit)
  46. * @return manufacture for this serial number (64bit)
  47. */
  48. uint64_t
  49. subghz_protocol_keeloq_common_secure_learning(uint32_t data, uint32_t seed, const uint64_t key);
  50. /** Magic_xor_type1 Learning
  51. * @param data - serial number (28bit)
  52. * @param xor - magic xor (64bit)
  53. * @return manufacture for this serial number (64bit)
  54. */
  55. uint64_t subghz_protocol_keeloq_common_magic_xor_type1_learning(uint32_t data, uint64_t xor);