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); } 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)