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

Function codec_decode

Source/codec.cpp:92–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90} // namespace
91
92std::size_t codec_decode(byte *pbSrcDst, std::size_t size, const char *pszPassword)
93{
94 uint32_t buf[BlockSize];
95 uint32_t dst[SHA1HashSize];
96
97 SHA1Context context = CodecInitKey(pszPassword);
98 if (size <= SignatureSize)
99 return 0;
100 size -= SignatureSize;
101 if (size % BlockSize != 0)
102 return 0;
103 for (size_t i = 0; i < size; pbSrcDst += BlockSizeBytes, i += BlockSizeBytes) {
104 memcpy(buf, pbSrcDst, BlockSizeBytes);
105 ByteSwapBlock(buf);
106 SHA1Result(context, dst);
107 XorBlock(dst, buf);
108 SHA1Calculate(context, buf);
109 ByteSwapBlock(buf);
110 memcpy(pbSrcDst, buf, BlockSizeBytes);
111 }
112
113 memset(buf, 0, sizeof(buf));
114 const CodecSignature sig = GetCodecSignature(pbSrcDst);
115 if (sig.error > 0) {
116 return 0;
117 }
118
119 SHA1Result(context, dst);
120 if (sig.checksum != dst[0]) {
121 LogError("Checksum mismatch signature={} vs calculated={}", sig.checksum, dst[0]);
122 memset(dst, 0, sizeof(dst));
123 return 0;
124 }
125
126 size += sig.lastChunkSize - BlockSizeBytes;
127 return size;
128}
129
130std::size_t codec_get_encoded_len(std::size_t dwSrcBytes)
131{

Callers 1

ReadArchiveFunction · 0.85

Calls 7

CodecInitKeyFunction · 0.85
ByteSwapBlockFunction · 0.85
SHA1ResultFunction · 0.85
XorBlockFunction · 0.85
SHA1CalculateFunction · 0.85
GetCodecSignatureFunction · 0.85
LogErrorFunction · 0.85

Tested by

no test coverage detected