subghz_protocol_keeloq_common.h 1.4 KB

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