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

Function codec_decode

Source/codec.cpp:12–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10};
11
12int codec_decode(BYTE *pbSrcDst, DWORD size, char *pszPassword)
13{
14 char buf[128];
15 char dst[SHA1HashSize];
16 int i;
17 CodecSignature *sig;
18
19 codec_init_key(0, pszPassword);
20 if (size <= 8)
21 return 0;
22 size = size - 8;
23 if (size % 64 != 0)
24 return 0;
25 for (i = size; i != 0; pbSrcDst += 64, i -= 64) {
26 memcpy(buf, pbSrcDst, 64);
27 SHA1Result(0, dst);
28 for (int j = 0; j < 64; j++) {
29 buf[j] ^= dst[j % SHA1HashSize];
30 }
31 SHA1Calculate(0, buf, NULL);
32 memset(dst, 0, sizeof(dst));
33 memcpy(pbSrcDst, buf, 64);
34 }
35
36 memset(buf, 0, sizeof(buf));
37 sig = (CodecSignature *)pbSrcDst;
38 if (sig->error > 0) {
39 goto error;
40 }
41
42 SHA1Result(0, dst);
43 if (sig->checksum != *(DWORD *)dst) {
44 memset(dst, 0, sizeof(dst));
45 goto error;
46 }
47
48 size += sig->last_chunk_size - 64;
49 SHA1Clear();
50 return size;
51error:
52 SHA1Clear();
53 return 0;
54}
55
56void codec_init_key(int unused, char *pszPassword)
57{

Callers 2

pfile_read_heroFunction · 0.85
pfile_readFunction · 0.85

Calls 4

codec_init_keyFunction · 0.85
SHA1ResultFunction · 0.85
SHA1CalculateFunction · 0.85
SHA1ClearFunction · 0.85

Tested by

no test coverage detected