From 0343e5f895156c175ff9726d7288b5eded89685b Mon Sep 17 00:00:00 2001 From: schneider Date: Mon, 18 Jul 2011 10:31:20 +0200 Subject: [PATCH 1/2] added stupid network byte order shuffel to xxtea --- firmware/basic/xxtea.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/firmware/basic/xxtea.c b/firmware/basic/xxtea.c index d126793..c59e3f4 100644 --- a/firmware/basic/xxtea.c +++ b/firmware/basic/xxtea.c @@ -9,16 +9,35 @@ */ #include +#include "xxtea.h" + +uint32_t htonl(uint32_t v) +{ + uint32_t r; + r |= (v>> 0)&0xFF; r<<=8; + r |= (v>> 8)&0xFF; r<<=8; + r |= (v>>16)&0xFF; r<<=8; + r |= (v>>24)&0xFF; + return r; +} + +void htonlp(uint32_t *v, uint8_t n) +{ + while(n--){ + v[n] = htonl(v[n]); + } +} #define DELTA 0x9e3779b9 #define MX (((z>>5^y<<2) + (y>>3^z<<4)) ^ ((sum^y) + (k[(p&3)^e] ^ z))) -#include "xxtea.h" void xxtea_encode_words(uint32_t *v, int n, uint32_t const k[4]) { if(k[0] == 0 && k[1] == 0 && k[2] == 0 && k[3] == 0) return; uint32_t y, z, sum; unsigned p, rounds, e; + + htonlp(v ,n); rounds = 6 + 52/n; sum = 0; z = v[n-1]; @@ -32,6 +51,7 @@ void xxtea_encode_words(uint32_t *v, int n, uint32_t const k[4]) y = v[0]; z = v[n-1] += MX; } while (--rounds); + htonlp(v ,n); } void xxtea_decode_words(uint32_t *v, int n, uint32_t const k[4]) @@ -39,6 +59,7 @@ void xxtea_decode_words(uint32_t *v, int n, uint32_t const k[4]) if(k[0] == 0 && k[1] == 0 && k[2] == 0 && k[3] == 0) return; uint32_t y, z, sum; unsigned p, rounds, e; + htonlp(v ,n); rounds = 6 + 52/n; sum = rounds*DELTA; @@ -52,5 +73,6 @@ void xxtea_decode_words(uint32_t *v, int n, uint32_t const k[4]) z = v[n-1]; y = v[0] -= MX; } while ((sum -= DELTA) != 0); + htonlp(v ,n); } From a6848990160ea3804030ffc8db763b0e55c02a19 Mon Sep 17 00:00:00 2001 From: schneider Date: Mon, 18 Jul 2011 10:31:58 +0200 Subject: [PATCH 2/2] openbeacon: use 24c3 key --- firmware/funk/openbeacon.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/firmware/funk/openbeacon.c b/firmware/funk/openbeacon.c index 7cebfec..835d89d 100644 --- a/firmware/funk/openbeacon.c +++ b/firmware/funk/openbeacon.c @@ -5,8 +5,9 @@ #include "sysdefs.h" #include "filesystem/ff.h" -const uint32_t key[4] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF}; -const uint8_t useencryption = 0; +//const uint32_t key[4] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF}; +const uint32_t key[4] = { 0xB4595344,0xD3E119B6,0xA814D0EC,0xEFF5A24E }; +const uint8_t useencryption = 1; const uint8_t mac[5] = {1,2,3,2,1}; uint32_t oid = 0; @@ -70,7 +71,7 @@ uint8_t openbeaconSendPacket(uint32_t id, uint32_t seq, buf[12]=0xff; // salt (0xffff always?) buf[13]=0xff; - return nrf_snd_pkt_crc_encr(32,buf,useencryption?key:NULL); + return nrf_snd_pkt_crc_encr(16,buf,useencryption?key:NULL); } uint8_t openbeaconSend(void)