From 09f884b7bd385779a127efa78b98d87020e54fae Mon Sep 17 00:00:00 2001
From: Lioncash <mathew1800@gmail.com>
Date: Thu, 6 Aug 2020 02:31:16 -0400
Subject: [PATCH 1/2] aes_util: Make use of non-template variant of Transcode

Same behavior, less template instantiations.
---
 src/core/crypto/aes_util.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/core/crypto/aes_util.cpp b/src/core/crypto/aes_util.cpp
index 330996b243..6a97348122 100644
--- a/src/core/crypto/aes_util.cpp
+++ b/src/core/crypto/aes_util.cpp
@@ -116,7 +116,7 @@ void AESCipher<Key, KeySize>::XTSTranscode(const u8* src, std::size_t size, u8*
 
     for (std::size_t i = 0; i < size; i += sector_size) {
         SetIV(CalculateNintendoTweak(sector_id++));
-        Transcode<u8, u8>(src + i, sector_size, dest + i, op);
+        Transcode(src + i, sector_size, dest + i, op);
     }
 }
 

From 04bb47f57f261e4e7a2280924d567683b9815c23 Mon Sep 17 00:00:00 2001
From: Lioncash <mathew1800@gmail.com>
Date: Thu, 6 Aug 2020 02:34:08 -0400
Subject: [PATCH 2/2] partition_data_manager: Eliminate magic value

We can use sizeof to make it obvious at the call site where the value is
coming from.
---
 src/core/crypto/partition_data_manager.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/core/crypto/partition_data_manager.cpp b/src/core/crypto/partition_data_manager.cpp
index b31a815607..c5c073e70b 100644
--- a/src/core/crypto/partition_data_manager.cpp
+++ b/src/core/crypto/partition_data_manager.cpp
@@ -349,8 +349,8 @@ static bool AttemptDecrypt(const std::array<u8, 16>& key, Package2Header& header
     Package2Header temp = header;
     AESCipher<Key128> cipher(key, Mode::CTR);
     cipher.SetIV(header.header_ctr);
-    cipher.Transcode(&temp.header_ctr, sizeof(Package2Header) - 0x100, &temp.header_ctr,
-                     Op::Decrypt);
+    cipher.Transcode(&temp.header_ctr, sizeof(Package2Header) - sizeof(Package2Header::signature),
+                     &temp.header_ctr, Op::Decrypt);
     if (temp.magic == Common::MakeMagic('P', 'K', '2', '1')) {
         header = temp;
         return true;