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
+27
View File
@@ -0,0 +1,27 @@
#include "PearsonHash.h"
// Permutation function for Pearson hashing (uses less space than a lookup table)
// Needs to be bijective, which it is
uint8_t PearsonHash::_pearsonPermutation(uint8_t n) {
return (n*121) % 256;
}
uint16_t PearsonHash::calcHash16(const void* data, uint16_t len) {
uint8_t h[2] = { _pearsonPermutation((((uint8_t*)data)[0]+1)%256), _pearsonPermutation(((uint8_t*)data)[0]) };
for (uint16_t i = 0; i < len; i++) {
auto _tmp = h[0];
h[0] = _pearsonPermutation(h[1] ^ ((uint8_t*)data)[i]);
h[1] = _pearsonPermutation(_tmp ^ ((uint8_t*)data)[i]);
}
void* _tmp = h; // To avoid the type punning warning
return *((uint16_t*)_tmp);
}
bool PearsonHash::checkHash16(uint16_t crc, const void* data, uint16_t len) {
return crc == calcHash16(data, len);
}