subghz_protocol_keeloq_common.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #pragma once
  2. #include "subghz_protocol_common.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. #define bit(x,n) (((x)>>(n))&1)
  12. #define g5(x,a,b,c,d,e) (bit(x,a)+bit(x,b)*2+bit(x,c)*4+bit(x,d)*8+bit(x,e)*16)
  13. /*
  14. * KeeLoq learning types
  15. * https://phreakerclub.com/forum/showthread.php?t=67
  16. */
  17. #define KEELOQ_LEARNING_UNKNOWN 0u
  18. #define KEELOQ_LEARNING_SIMPLE 1u
  19. #define KEELOQ_LEARNING_NORMAL 2u
  20. #define KEELOQ_LEARNING_SECURE 3u
  21. /** Simple Learning Encrypt
  22. * @param data - 0xBSSSCCCC, B(4bit) key, S(10bit) serial&0x3FF, C(16bit) counter
  23. * @param key - manufacture (64bit)
  24. * @return keelog encrypt data
  25. */
  26. uint32_t subghz_protocol_keeloq_common_encrypt(const uint32_t data, const uint64_t key);
  27. /** Simple Learning Decrypt
  28. * @param data - keelog encrypt data
  29. * @param key - manufacture (64bit)
  30. * @return 0xBSSSCCCC, B(4bit) key, S(10bit) serial&0x3FF, C(16bit) counter
  31. */
  32. uint32_t subghz_protocol_keeloq_common_decrypt(const uint32_t data, const uint64_t key);
  33. /** Normal Learning
  34. * @param data - serial number (28bit)
  35. * @param key - manufacture (64bit)
  36. * @return manufacture for this serial number (64bit)
  37. */
  38. uint64_t subghz_protocol_keeloq_common_normal_learning(uint32_t data, const uint64_t key);