keeloq_common.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. /**
  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 keeloq encrypt data
  26. */
  27. uint32_t subghz_protocol_keeloq_common_encrypt(const uint32_t data, const uint64_t key);
  28. /**
  29. * Simple Learning Decrypt
  30. * @param data - keeloq encrypt data
  31. * @param key - manufacture (64bit)
  32. * @return 0xBSSSCCCC, B(4bit) key, S(10bit) serial&0x3FF, C(16bit) counter
  33. */
  34. uint32_t subghz_protocol_keeloq_common_decrypt(const uint32_t data, const uint64_t key);
  35. /**
  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. /**
  43. * Secure Learning
  44. * @param data - serial number (28bit)
  45. * @param seed - seed number (32bit)
  46. * @param key - manufacture (64bit)
  47. * @return manufacture for this serial number (64bit)
  48. */
  49. uint64_t
  50. subghz_protocol_keeloq_common_secure_learning(uint32_t data, uint32_t seed, const uint64_t key);
  51. /**
  52. * Magic_xor_type1 Learning
  53. * @param data - serial number (28bit)
  54. * @param xor - magic xor (64bit)
  55. * @return manufacture for this serial number (64bit)
  56. */
  57. uint64_t subghz_protocol_keeloq_common_magic_xor_type1_learning(uint32_t data, uint64_t xor);
  58. /** Magic_serial_type1 Learning
  59. * @param data - serial number (28bit)
  60. * @param man - magic man (64bit)
  61. * @return manufacture for this serial number (64bit)
  62. */
  63. uint64_t subghz_protocol_keeloq_common_magic_serial_type1_learning(uint32_t data, uint64_t man);