MCPcopy Create free account
hub / github.com/defold/defold / EncryptXTeaCTR

Function EncryptXTeaCTR

engine/dlib/src/dlib/crypt.cpp:42–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40 }
41
42 static void EncryptXTeaCTR(uint8_t* data, uint32_t datalen, const uint8_t* key, uint32_t keylen)
43 {
44 assert(keylen <= 16);
45 const uint32_t block_len = 8;
46 uint8_t paddedkey[16] = {0};
47 memcpy(paddedkey, key, keylen);
48 uint32_t key_words[4];
49 memcpy(key_words, paddedkey, sizeof(key_words));
50
51 uint64_t counter = 0;
52
53 uint32_t i = 0;
54 for (i = 0; i < datalen / block_len; i++)
55 {
56 uint64_t enc_counter = EncryptXTea(counter, key_words);
57 uint64_t block;
58 memcpy(&block, data, sizeof(block));
59 block ^= enc_counter;
60 memcpy(data, &block, sizeof(block));
61 data += block_len;
62 counter++;
63 }
64
65 uint64_t enc_counter = EncryptXTea(counter, key_words);
66 uint32_t rest = datalen & (block_len - 1);
67 uint8_t* ec = (uint8_t*) &enc_counter;
68 for (uint32_t j = 0; j < rest; j++)
69 {
70 data[j] ^= ec[j];
71 }
72 }
73
74 Result Encrypt(Algorithm algo, uint8_t* data, uint32_t datalen, const uint8_t* key, uint32_t keylen)
75 {

Callers 2

EncryptFunction · 0.85
DecryptFunction · 0.85

Calls 3

EncryptXTeaFunction · 0.85
EncryptFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected