diff options
| -rw-r--r-- | src/core/crypto/aes_util.cpp | 20 | ||||
| -rw-r--r-- | src/core/crypto/aes_util.h | 2 |
2 files changed, 10 insertions, 12 deletions
diff --git a/src/core/crypto/aes_util.cpp b/src/core/crypto/aes_util.cpp index e2dc4acb3..a9876c83e 100644 --- a/src/core/crypto/aes_util.cpp +++ b/src/core/crypto/aes_util.cpp | |||
| @@ -9,6 +9,16 @@ | |||
| 9 | #include "core/crypto/key_manager.h" | 9 | #include "core/crypto/key_manager.h" |
| 10 | 10 | ||
| 11 | namespace Core::Crypto { | 11 | namespace Core::Crypto { |
| 12 | namespace { | ||
| 13 | std::vector<u8> CalculateNintendoTweak(size_t sector_id) { | ||
| 14 | std::vector<u8> out(0x10); | ||
| 15 | for (size_t i = 0xF; i <= 0xF; --i) { | ||
| 16 | out[i] = sector_id & 0xFF; | ||
| 17 | sector_id >>= 8; | ||
| 18 | } | ||
| 19 | return out; | ||
| 20 | } | ||
| 21 | } // Anonymous namespace | ||
| 12 | 22 | ||
| 13 | static_assert(static_cast<size_t>(Mode::CTR) == static_cast<size_t>(MBEDTLS_CIPHER_AES_128_CTR), | 23 | static_assert(static_cast<size_t>(Mode::CTR) == static_cast<size_t>(MBEDTLS_CIPHER_AES_128_CTR), |
| 14 | "CTR has incorrect value."); | 24 | "CTR has incorrect value."); |
| @@ -100,16 +110,6 @@ void AESCipher<Key, KeySize>::XTSTranscode(const u8* src, size_t size, u8* dest, | |||
| 100 | } | 110 | } |
| 101 | } | 111 | } |
| 102 | 112 | ||
| 103 | template <typename Key, size_t KeySize> | ||
| 104 | std::vector<u8> AESCipher<Key, KeySize>::CalculateNintendoTweak(size_t sector_id) { | ||
| 105 | std::vector<u8> out(0x10); | ||
| 106 | for (size_t i = 0xF; i <= 0xF; --i) { | ||
| 107 | out[i] = sector_id & 0xFF; | ||
| 108 | sector_id >>= 8; | ||
| 109 | } | ||
| 110 | return out; | ||
| 111 | } | ||
| 112 | |||
| 113 | template class AESCipher<Key128>; | 113 | template class AESCipher<Key128>; |
| 114 | template class AESCipher<Key256>; | 114 | template class AESCipher<Key256>; |
| 115 | } // namespace Core::Crypto \ No newline at end of file | 115 | } // namespace Core::Crypto \ No newline at end of file |
diff --git a/src/core/crypto/aes_util.h b/src/core/crypto/aes_util.h index bda41b144..ce4947a04 100644 --- a/src/core/crypto/aes_util.h +++ b/src/core/crypto/aes_util.h | |||
| @@ -56,7 +56,5 @@ public: | |||
| 56 | 56 | ||
| 57 | private: | 57 | private: |
| 58 | std::unique_ptr<CipherContext> ctx; | 58 | std::unique_ptr<CipherContext> ctx; |
| 59 | |||
| 60 | static std::vector<u8> CalculateNintendoTweak(size_t sector_id); | ||
| 61 | }; | 59 | }; |
| 62 | } // namespace Core::Crypto | 60 | } // namespace Core::Crypto |