From: Bernard Blackham Date: Thu, 24 Jun 2004 04:15:47 +0000 (+0000) Subject: Forgotten :( X-Git-Tag: ROMW~3 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=f641f3af8218c05edb5e46f0851efba100d11640;p=uccvend-snackrom.git Forgotten :( --- diff --git a/ROM2/mic.c b/ROM2/mic.c new file mode 100644 index 0000000..09f1f4e --- /dev/null +++ b/ROM2/mic.c @@ -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*)¤t_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 index 0000000..8a4af8c --- /dev/null +++ b/ROM2/mic.h @@ -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_ */