diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2025-04-11 11:39:53 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2025-04-11 11:39:53 +0800 |
| commit | 31f41ecf75678e41a03f5aaf32e8e17ee81286e1 (patch) | |
| tree | 024778e5a8e20d2dbae4dbc778b593b503a38bf7 /lock/util.c | |
| parent | 014040f33f914a82031e15940924bc9c92236fec (diff) | |
| download | smart-home-31f41ecf75678e41a03f5aaf32e8e17ee81286e1.tar.gz | |
Add keygen() to utils.
Diffstat (limited to 'lock/util.c')
| -rw-r--r-- | lock/util.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lock/util.c b/lock/util.c index 95bef77..bc62438 100644 --- a/lock/util.c +++ b/lock/util.c @@ -1,5 +1,35 @@ +#include <avr/io.h> +#include <avr/interrupt.h> + #include "util.h" +static char tab[] = { + '0', '8', '3', '6', 'a', 'Z', '$', '4', 'v', 'R', '@', + 'E', '1', 'o', '#', ')', '2', '5', 'q', ';', '.', 'I', + 'c', '7', '9', '*', 'L', 'V', '&', 'k', 'K', '!', 'm', + 'N', '(', 'O', 'Q', 'A', '>', 'T', 't', '?', 'S', 'h', + 'w', '/', 'n', 'W', 'l', 'M', 'e', 'H', 'j', 'g', '[', + 'P', 'f', ':', 'B', ']', 'Y', '^', 'F', '%', 'C', 'x' +}; + +static uint16_t tablen = sizeof(tab) / sizeof(tab[0]); + +void keygen(char *buf, uint8_t n) +{ + int i, imax; + uint8_t sreg; + uint16_t idx; + + sreg = SREG; + cli(); + idx = TCNT1; + SREG = sreg; + + for (i = 0, imax = n - 1; i < imax; i++, idx++) + buf[i] = tab[(idx % tablen)]; + buf[imax] = '\0'; +} + void xor(const char *k, const char *s, char *d, uint8_t n) { int i; @@ -7,3 +37,4 @@ void xor(const char *k, const char *s, char *d, uint8_t n) for (i = 0; i < n; i++) d[i] = s[i] ^ k[i]; } + |
