ESPHome 2025.5.0
Loading...
Searching...
No Matches
xxtea.cpp
Go to the documentation of this file.
1#include "xxtea.h"
2
3namespace esphome {
4namespace xxtea {
5
6static const uint32_t DELTA = 0x9e3779b9;
7#define MX ((((z >> 5) ^ (y << 2)) + ((y >> 3) ^ (z << 4))) ^ ((sum ^ y) + (k[(p ^ e) & 7] ^ z)))
8
9void encrypt(uint32_t *v, size_t n, const uint32_t *k) {
10 uint32_t z, y, sum, e;
11 size_t p;
12 size_t q = 6 + 52 / n;
13 sum = 0;
14 z = v[n - 1];
15 while (q-- != 0) {
16 sum += DELTA;
17 e = (sum >> 2);
18 for (p = 0; p != n - 1; p++) {
19 y = v[p + 1];
20 z = v[p] += MX;
21 }
22 y = v[0];
23 z = v[n - 1] += MX;
24 }
25}
26
27void decrypt(uint32_t *v, size_t n, const uint32_t *k) {
28 uint32_t z, y, sum, e;
29 size_t p;
30 size_t q = 6 + 52 / n;
31 sum = q * DELTA;
32 y = v[0];
33 while (q-- != 0) {
34 e = (sum >> 2);
35 for (p = n - 1; p != 0; p--) {
36 z = v[p - 1];
37 y = v[p] -= MX;
38 }
39 z = v[n - 1];
40 y = v[0] -= MX;
41 sum -= DELTA;
42 }
43}
44
45} // namespace xxtea
46} // namespace esphome
bool z
Definition msa3xx.h:1
void encrypt(uint32_t *v, size_t n, const uint32_t *k)
Encrypt a block of data in-place using XXTEA algorithm with 256-bit key.
Definition xxtea.cpp:9
void decrypt(uint32_t *v, size_t n, const uint32_t *k)
Decrypt a block of data in-place using XXTEA algorithm with 256-bit key.
Definition xxtea.cpp:27
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t y
Definition tt21100.cpp:6