keeloq_common.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #pragma once
  2. #include "base.h"
  3. #include <furi.h>
  4. /*
  5. * Keeloq
  6. * https://ru.wikipedia.org/wiki/KeeLoq
  7. * https://phreakerclub.com/forum/showthread.php?t=1094
  8. *
  9. */
  10. #define KEELOQ_NLF 0x3A5C742E
  11. /*
  12. * KeeLoq learning types
  13. * https://phreakerclub.com/forum/showthread.php?t=67
  14. */
  15. #define KEELOQ_LEARNING_UNKNOWN 0u
  16. #define KEELOQ_LEARNING_SIMPLE 1u
  17. #define KEELOQ_LEARNING_NORMAL 2u
  18. #define KEELOQ_LEARNING_SECURE 3u
  19. #define KEELOQ_LEARNING_MAGIC_XOR_TYPE_1 4u
  20. #define KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_1 5u
  21. #define KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_2 6u
  22. #define KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_3 7u
  23. /**
  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 keeloq encrypt data
  28. */
  29. uint32_t subghz_protocol_keeloq_common_encrypt(const uint32_t data, const uint64_t key);
  30. /**
  31. * Simple Learning Decrypt
  32. * @param data - keeloq encrypt data
  33. * @param key - manufacture (64bit)
  34. * @return 0xBSSSCCCC, B(4bit) key, S(10bit) serial&0x3FF, C(16bit) counter
  35. */
  36. uint32_t subghz_protocol_keeloq_common_decrypt(const uint32_t data, const uint64_t key);
  37. /**
  38. * Normal Learning
  39. * @param data - serial number (28bit)
  40. * @param key - manufacture (64bit)
  41. * @return manufacture for this serial number (64bit)
  42. */
  43. uint64_t subghz_protocol_keeloq_common_normal_learning(uint32_t data, const uint64_t key);
  44. /**
  45. * Secure Learning
  46. * @param data - serial number (28bit)
  47. * @param seed - seed number (32bit)
  48. * @param key - manufacture (64bit)
  49. * @return manufacture for this serial number (64bit)
  50. */
  51. uint64_t
  52. subghz_protocol_keeloq_common_secure_learning(uint32_t data, uint32_t seed, const uint64_t key);
  53. /**
  54. * Magic_xor_type1 Learning
  55. * @param data - serial number (28bit)
  56. * @param xor - magic xor (64bit)
  57. * @return manufacture for this serial number (64bit)
  58. */
  59. uint64_t subghz_protocol_keeloq_common_magic_xor_type1_learning(uint32_t data, uint64_t xor);
  60. /** Magic_serial_type1 Learning
  61. * @param data - serial number (28bit)
  62. * @param man - magic man (64bit)
  63. * @return manufacture for this serial number (64bit)
  64. */
  65. uint64_t subghz_protocol_keeloq_common_magic_serial_type1_learning(uint32_t data, uint64_t man);
  66. /** Magic_serial_type2 Learning
  67. * @param data - btn+serial number (32bit)
  68. * @param man - magic man (64bit)
  69. * @return manufacture for this serial number (64bit)
  70. */
  71. uint64_t subghz_protocol_keeloq_common_magic_serial_type2_learning(uint32_t data, uint64_t man);
  72. /** Magic_serial_type3 Learning
  73. * @param data - btn+serial number (32bit)
  74. * @param man - magic man (64bit)
  75. * @return manufacture for this serial number (64bit)
  76. */
  77. uint64_t subghz_protocol_keeloq_common_magic_serial_type3_learning(uint32_t data, uint64_t man);