summaryrefslogtreecommitdiffstats
path: root/lock/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'lock/util.c')
-rw-r--r--lock/util.c31
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];
}
+