Rework jagged crypt operation

Fixes checksums for Colo

Closes #3803
This commit is contained in:
Kurt
2023-02-26 15:18:32 -08:00
parent 839a76d6a3
commit b4b1310934

View File

@@ -165,8 +165,10 @@ private static byte[] EncryptColosseum(ReadOnlySpan<byte> input, Span<byte> dige
for (int i = 0; i < digest.Length; i++)
digest[i] = (byte)~digest[i];
var crypt = output.AsSpan(0x18, SLOT_SIZE - (2 * sha1HashSize));
for (int i = 0; i < crypt.Length; i += sha1HashSize)
const int start = 0x18;
const int end = (SLOT_SIZE - (2 * sha1HashSize));
var crypt = output.AsSpan();
for (int i = start; i < end; i += sha1HashSize)
{
var slice = crypt.Slice(i, digest.Length);
for (int j = 0; j < digest.Length; j++)
@@ -188,12 +190,14 @@ private static byte[] DecryptColosseum(ReadOnlySpan<byte> input, Span<byte> dige
digest[i] = (byte)~digest[i];
Span<byte> hash = stackalloc byte[sha1HashSize];
var crypt = output.AsSpan(0x18, SLOT_SIZE - (2 * sha1HashSize));
for (int i = 0; i < crypt.Length; i += sha1HashSize)
const int start = 0x18;
const int end = (SLOT_SIZE - (2 * sha1HashSize));
var crypt = output.AsSpan();
for (int i = start; i < end; i += sha1HashSize)
{
var slice = crypt.Slice(i, sha1HashSize);
var slice = crypt.Slice(i, Math.Min(crypt.Length - i, sha1HashSize));
SHA1.HashData(slice, hash); // update digest
for (int j = 0; j < digest.Length; j++)
for (int j = 0; j < slice.Length; j++)
slice[j] ^= digest[j];
hash.CopyTo(digest); // for use in next loop
}