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

Function codec_encode

Source/codec.cpp:137–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135}
136
137void codec_encode(byte *pbSrcDst, std::size_t size, std::size_t size64, const char *pszPassword)
138{
139 uint32_t buf[BlockSize];
140 uint32_t tmp[SHA1HashSize];
141 uint32_t dst[SHA1HashSize];
142
143 if (size64 != codec_get_encoded_len(size))
144 app_fatal("Invalid encode parameters");
145 SHA1Context context = CodecInitKey(pszPassword);
146
147 size_t lastChunk = 0;
148 while (size != 0) {
149 const size_t chunk = std::min(size, BlockSizeBytes);
150 memset(buf, 0, sizeof(buf));
151 memcpy(buf, pbSrcDst, chunk);
152 ByteSwapBlock(buf);
153 SHA1Result(context, dst);
154 SHA1Calculate(context, buf);
155 XorBlock(dst, buf);
156 ByteSwapBlock(buf);
157 memcpy(pbSrcDst, buf, BlockSizeBytes);
158 pbSrcDst += BlockSizeBytes;
159 lastChunk = chunk;
160 size -= chunk;
161 }
162 memset(buf, 0, sizeof(buf));
163 SHA1Result(context, tmp);
164 SetCodecSignature(pbSrcDst, CodecSignature { /*.checksum=*/*reinterpret_cast<uint32_t *>(tmp),
165 /*.error=*/0,
166 // lastChunk is at most 64 so will always fit in an 8 bit var
167 /*.lastChunkSize=*/static_cast<uint8_t>(lastChunk) });
168}
169
170} // namespace devilution

Callers 2

~SaveHelperMethod · 0.85
EncodeHeroFunction · 0.85

Calls 8

codec_get_encoded_lenFunction · 0.85
app_fatalFunction · 0.85
CodecInitKeyFunction · 0.85
ByteSwapBlockFunction · 0.85
SHA1ResultFunction · 0.85
SHA1CalculateFunction · 0.85
XorBlockFunction · 0.85
SetCodecSignatureFunction · 0.85

Tested by

no test coverage detected