summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Zach Hilman2018-08-16 16:58:49 -0400
committerGravatar Zach Hilman2018-08-23 11:52:44 -0400
commit6dd369ab88efa9f183104cf26304afc940b462cf (patch)
tree107ff7e41430300a4d05cf00f216e830b252087b /src/core
parentxci: Fix error masking issue (diff)
downloadyuzu-6dd369ab88efa9f183104cf26304afc940b462cf.tar.gz
yuzu-6dd369ab88efa9f183104cf26304afc940b462cf.tar.xz
yuzu-6dd369ab88efa9f183104cf26304afc940b462cf.zip
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.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/crypto/ctr_encryption_layer.cpp8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/core/crypto/ctr_encryption_layer.cpp b/src/core/crypto/ctr_encryption_layer.cpp
index 106db02b3..3ea60dbd0 100644
--- a/src/core/crypto/ctr_encryption_layer.cpp
+++ b/src/core/crypto/ctr_encryption_layer.cpp
@@ -20,10 +20,8 @@ size_t CTREncryptionLayer::Read(u8* data, size_t length, size_t offset) const {
20 if (sector_offset == 0) { 20 if (sector_offset == 0) {
21 UpdateIV(base_offset + offset); 21 UpdateIV(base_offset + offset);
22 std::vector<u8> raw = base->ReadBytes(length, offset); 22 std::vector<u8> raw = base->ReadBytes(length, offset);
23 if (raw.size() != length) 23 cipher.Transcode(raw.data(), raw.size(), data, Op::Decrypt);
24 return Read(data, raw.size(), offset); 24 return raw.size();
25 cipher.Transcode(raw.data(), length, data, Op::Decrypt);
26 return length;
27 } 25 }
28 26
29 // offset does not fall on block boundary (0x10) 27 // 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 {
34 32
35 if (length + sector_offset < 0x10) { 33 if (length + sector_offset < 0x10) {
36 std::memcpy(data, block.data() + sector_offset, std::min<u64>(length, read)); 34 std::memcpy(data, block.data() + sector_offset, std::min<u64>(length, read));
37 return read; 35 return std::min<u64>(length, read);
38 } 36 }
39 std::memcpy(data, block.data() + sector_offset, read); 37 std::memcpy(data, block.data() + sector_offset, read);
40 return read + Read(data + read, length - read, offset + read); 38 return read + Read(data + read, length - read, offset + read);