Forgotten :(
authorBernard Blackham <[email protected]>
Thu, 24 Jun 2004 04:15:47 +0000 (04:15 +0000)
committerBernard Blackham <[email protected]>
Thu, 24 Jun 2004 04:15:47 +0000 (04:15 +0000)
ROM2/mic.c [new file with mode: 0644]
ROM2/mic.h [new file with mode: 0644]

diff --git a/ROM2/mic.c b/ROM2/mic.c
new file mode 100644 (file)
index 0000000..09f1f4e
--- /dev/null
@@ -0,0 +1,34 @@
+#include "mic.h"
+#include "types.h"
+#include "vend.h"
+#include "xmodem.h"
+
+void mic_set_secret(char newsecret[16]) {
+       my_strncpy(mic_secret, newsecret, 16);
+}
+
+bool mic_verify(void* msg) {
+       char *message, *p;
+       message = (char*)msg;
+       p = message;
+       while (*p != '\0' && *p != '|') p++;
+       if (*p == '\0') return 0;
+       u16 crc1 = docrc((char*)&current_challenge, 2, 0, 0);
+       crc1 = docrc(mic_secret, 16, 0, crc1);
+       crc1 = docrc(message, p-message, 0, crc1);
+       u16 crc2;
+       p++;
+       if (*(p) == '\0' ||
+               *(p+1) == '\0' ||
+               *(p+2) == '\0' ||
+               *(p+3) == '\0' ||
+               *(p+4) != '\0')
+               return 0;
+       crc2 = hex2u8(*p, *(p+1)) << 8;
+       crc2 |= hex2u8(*(p+2), *(p+3));
+
+       if (crc1 != crc2) return 0;
+
+       current_challenge++;
+       return 1;
+}
diff --git a/ROM2/mic.h b/ROM2/mic.h
new file mode 100644 (file)
index 0000000..8a4af8c
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef _MIC_H_
+#define _MIC_H_
+
+#include "types.h"
+
+#define current_challenge (*((u16*)(_nvram+0)))
+#define mic_secret (((char*)_nvram)+2)
+
+#define mic_challenge current_challenge
+void mic_set_secret(char newsecret[16]);
+bool mic_verify(void* message);
+
+#endif /* _MIC_H_ */

UCC git Repository :: git.ucc.asn.au