MCPcopy Create free account
hub / github.com/ClassiCube/ClassiCube / Platform_Decrypt

Function Platform_Decrypt

src/_PlatformBase.h:330–359  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

328}
329
330cc_result Platform_Decrypt(const void* data, int len, cc_string* dst) {
331 const cc_uint8* src = (const cc_uint8*)data;
332 cc_uint32 header[4], key[4] = { 0 };
333 cc_result res;
334 int dataLen;
335
336 /* Total size must be >= header size */
337 if (len < 16) return ERR_END_OF_STREAM;
338 if ((res = GetMachineID(key))) return res;
339
340 Mem_Copy(header, src, 16);
341 DecipherBlock(header + 0, key);
342 DecipherBlock(header + 2, key);
343
344 if (header[0] != ENC1 || header[1] != ENC2 || header[2] != ENC3) return ERR_INVALID_ARGUMENT;
345 len -= 16; src += 16;
346
347 if (header[3] > len) return ERR_INVALID_ARGUMENT;
348 dataLen = header[3];
349
350 for (; dataLen > 0; len -= ENC_SIZE, src += ENC_SIZE, dataLen -= ENC_SIZE)
351 {
352 header[0] = 0; header[1] = 0;
353 Mem_Copy(header, src, min(len, ENC_SIZE));
354
355 DecipherBlock(header, key);
356 String_AppendAll(dst, header, min(dataLen, ENC_SIZE));
357 }
358 return 0;
359}
360#endif
361
362

Callers 1

Options_GetSecureFunction · 0.70

Calls 4

Mem_CopyFunction · 0.85
DecipherBlockFunction · 0.85
String_AppendAllFunction · 0.85
GetMachineIDFunction · 0.70

Tested by

no test coverage detected