keeloq_common.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. /**
  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 keeloq encrypt data
  25. */
  26. uint32_t subghz_protocol_keeloq_common_encrypt(const uint32_t data, const uint64_t key);
  27. /**
  28. * Simple Learning Decrypt
  29. * @param data - keeloq 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. /**
  35. * Normal Learning
  36. * @param data - serial number (28bit)
  37. * @param key - manufacture (64bit)
  38. * @return manufacture for this serial number (64bit)
  39. */
  40. uint64_t subghz_protocol_keeloq_common_normal_learning(uint32_t data, const uint64_t key);
  41. /**
  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. /**
  51. * Magic_xor_type1 Learning
  52. * @param data - serial number (28bit)
  53. * @param xor - magic xor (64bit)
  54. * @return manufacture for this serial number (64bit)
  55. */
  56. uint64_t subghz_protocol_keeloq_common_magic_xor_type1_learning(uint32_t data, uint64_t xor);