mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-12-24 09:20:58 +01:00
ctr_encryption_layer: Fix bug when transcoding small data
Fixes a bug where data lengths of less than size 0x10 will fail or have misleading return values.
This commit is contained in:
parent
a9dc5a3c10
commit
6dd369ab88
1 changed files with 3 additions and 5 deletions
|
@ -20,10 +20,8 @@ size_t CTREncryptionLayer::Read(u8* data, size_t length, size_t offset) const {
|
||||||
if (sector_offset == 0) {
|
if (sector_offset == 0) {
|
||||||
UpdateIV(base_offset + offset);
|
UpdateIV(base_offset + offset);
|
||||||
std::vector<u8> raw = base->ReadBytes(length, offset);
|
std::vector<u8> raw = base->ReadBytes(length, offset);
|
||||||
if (raw.size() != length)
|
cipher.Transcode(raw.data(), raw.size(), data, Op::Decrypt);
|
||||||
return Read(data, raw.size(), offset);
|
return raw.size();
|
||||||
cipher.Transcode(raw.data(), length, data, Op::Decrypt);
|
|
||||||
return length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// offset does not fall on block boundary (0x10)
|
// offset does not fall on block boundary (0x10)
|
||||||
|
@ -34,7 +32,7 @@ size_t CTREncryptionLayer::Read(u8* data, size_t length, size_t offset) const {
|
||||||
|
|
||||||
if (length + sector_offset < 0x10) {
|
if (length + sector_offset < 0x10) {
|
||||||
std::memcpy(data, block.data() + sector_offset, std::min<u64>(length, read));
|
std::memcpy(data, block.data() + sector_offset, std::min<u64>(length, read));
|
||||||
return read;
|
return std::min<u64>(length, read);
|
||||||
}
|
}
|
||||||
std::memcpy(data, block.data() + sector_offset, read);
|
std::memcpy(data, block.data() + sector_offset, read);
|
||||||
return read + Read(data + read, length - read, offset + read);
|
return read + Read(data + read, length - read, offset + read);
|
||||||
|
|
Loading…
Reference in a new issue