MCPcopy Create free account
hub / github.com/diasurgical/devilution / EncryptMpqBlock

Function EncryptMpqBlock

3rdParty/StormLib/src/SBaseCommon.cpp:394–415  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

392// Encrypting/Decrypting MPQ data block
393
394void EncryptMpqBlock(void * pvDataBlock, DWORD dwLength, DWORD dwKey1)
395{
396 LPDWORD DataBlock = (LPDWORD)pvDataBlock;
397 DWORD dwValue32;
398 DWORD dwKey2 = 0xEEEEEEEE;
399
400 // Round to DWORDs
401 dwLength >>= 2;
402
403 // Encrypt the data block at array of DWORDs
404 for(DWORD i = 0; i < dwLength; i++)
405 {
406 // Modify the second key
407 dwKey2 += StormBuffer[MPQ_HASH_KEY2_MIX + (dwKey1 & 0xFF)];
408
409 dwValue32 = DataBlock[i];
410 DataBlock[i] = DataBlock[i] ^ (dwKey1 + dwKey2);
411
412 dwKey1 = ((~dwKey1 << 0x15) + 0x11111111) | (dwKey1 >> 0x0B);
413 dwKey2 = dwValue32 + dwKey2 + (dwKey2 << 5) + 3;
414 }
415}
416
417void DecryptMpqBlock(void * pvDataBlock, DWORD dwLength, DWORD dwKey1)
418{

Callers 3

SaveMpqTableFunction · 0.85
SaveExtTableFunction · 0.85
WriteSectorOffsetsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected