summaryrefslogtreecommitdiffstats
path: root/door_lock/cmd.c
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2024-11-06 12:22:12 +0800
committerSadeep Madurange <sadeep@asciimx.com>2024-11-06 12:22:12 +0800
commitbb2e665a5be55d479e45b7ed8672a0219a336760 (patch)
treef3c424b667b9584541c31008ca6907ef60fe38ae /door_lock/cmd.c
parent50381c06244e944390de382f6bdd85cc8b9a3332 (diff)
downloadsmart-home-bb2e665a5be55d479e45b7ed8672a0219a336760.tar.gz
Move crypt code to separate file.
Diffstat (limited to 'door_lock/cmd.c')
-rw-r--r--door_lock/cmd.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/door_lock/cmd.c b/door_lock/cmd.c
new file mode 100644
index 0000000..ccfbafb
--- /dev/null
+++ b/door_lock/cmd.c
@@ -0,0 +1,33 @@
+#include <stdint.h>
+#include <string.h>
+
+#include "cmd.h"
+
+#define XORLEN 32
+#define KEY "dM>}jdb,6gsnC$J^K 8(I5vyPemPs%;K"
+#define ULOCK_CMD "43iqr5$NB8SpN?Z/52{iVl>o|i!.'dsT"
+
+static char ulock_crypt_cmd[XORLEN];
+
+static inline void xor(const char *s, char *d, uint8_t n)
+{
+ int i;
+
+ for (i = 0; i < n && s[i]; i++)
+ d[i] = s[i] ^ KEY[i];
+}
+
+int is_ulock_cmd(const char *s)
+{
+ char buf[XORLEN + 1];
+
+ xor(s, buf, XORLEN);
+ buf[XORLEN] = 0;
+ return !strcmp(ULOCK_CMD, buf);
+}
+
+char * get_encrypted_ulock_cmd(void)
+{
+ xor(ULOCK_CMD, ulock_crypt_cmd, XORLEN);
+ return ulock_crypt_cmd;
+}