Added XTEA and Pearson Hashing.

Improved message encryption for RF24.
This commit is contained in:
2018-09-22 22:05:53 +02:00
committed by matzman
parent 15351cdd5b
commit b37cd045d5
12 changed files with 270 additions and 7 deletions
+22
View File
@@ -19,10 +19,15 @@
#include "drivers/RF24/RF24.h"
#if defined(MY_RF24_ENABLE_ENCRYPTION)
#include "drivers/AES/AES.cpp"
AES RF24_aes;
uint8_t RF24_dataenc[32] = {0};
#elif defined(MY_RF24_ENABLE_XTEA)
#include "drivers/XTEA/XTEA.cpp"
XTEA RF24_xtea;
uint8_t RF24_dataenc[32] = {0};
#endif
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
@@ -74,6 +79,9 @@ bool transportInit(void)
RF24_aes.set_key(RF24_psk, 16);
// Make sure it is purged from memory when set
(void)memset(RF24_psk, 0, 16);
#elif defined(MY_RF24_ENABLE_XTEA)
uint8_t key[16] = MY_RF24_XTEA_KEY;
RF24_xtea.setKey(key);
#endif
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
@@ -104,6 +112,13 @@ bool transportSend(const uint8_t to, const void *data, const uint8_t len, const
//encrypt data
RF24_aes.cbc_encrypt(RF24_dataenc, RF24_dataenc, finalLength / 16);
return RF24_sendMessage(to, RF24_dataenc, finalLength, noACK);
#elif defined(MY_RF24_ENABLE_XTEA)
// has to be adjusted, WIP!
RF24_xtea.setIV(0, 0);
const uint8_t finalLength = len > 16 ? 32 : 16;
//encrypt data
RF24_xtea.cbc_encrypt(RF24_dataenc, data, finalLength / 8);
return RF24_sendMessage(to, RF24_dataenc, finalLength, noACK);
#else
return RF24_sendMessage(to, data, len, noACK);
#endif
@@ -144,6 +159,13 @@ uint8_t transportReceive(void *data)
if (RF24_aes.cbc_decrypt((uint8_t *)data, (uint8_t *)data, len > 16 ? 2 : 1) != AES_SUCCESS) {
len = 0;
}
#elif defined(MY_RF24_ENABLE_XTEA)
// has to be adjusted, WIP!
RF24_xtea.setIV(0, 0);
const uint8_t finalLength = len > 16 ? 32 : 16;
// decrypt data
RF24_xtea.cbc_decrypt((uint8_t*)(RF24_dataenc), (uint8_t*)(data), finalLength / 8);
(void)memcpy(data,RF24_dataenc,len);
#endif
return len;
}