diff options
| author | Pierre Bourdon <delroth@gmail.com> | 2017-01-02 05:32:08 +0100 |
|---|---|---|
| committer | Pierre Bourdon <delroth@gmail.com> | 2017-01-14 17:06:40 +0100 |
| commit | 334ddf754eac2e92e35e82eff6572b6a73a8a061 (patch) | |
| tree | d54a9162097bdadd4b82a7473e03aac8c717b36a /Source/Core/DiscIO | |
| parent | 650a1fdb1f750c631d5b5b700679b13aedb4d432 (diff) | |
DiscIO: Export GetKeyFromTicket
This function has more uses than just in DiscIO (e.g. WFS).
Diffstat (limited to 'Source/Core/DiscIO')
| -rw-r--r-- | Source/Core/DiscIO/NANDContentLoader.cpp | 42 | ||||
| -rw-r--r-- | Source/Core/DiscIO/NANDContentLoader.h | 4 |
2 files changed, 22 insertions, 24 deletions
diff --git a/Source/Core/DiscIO/NANDContentLoader.cpp b/Source/Core/DiscIO/NANDContentLoader.cpp index 6089c735b3..f87e0e31c0 100644 --- a/Source/Core/DiscIO/NANDContentLoader.cpp +++ b/Source/Core/DiscIO/NANDContentLoader.cpp @@ -60,6 +60,17 @@ std::vector<u8> SignedTicketToTicket(const std::vector<u8>& signed_ticket) std::copy(signed_ticket.begin() + entry_offset, signed_ticket.end(), ticket.begin()); return ticket; } + +std::vector<u8> AESDecode(const u8* key, u8* iv, const u8* src, u32 size) +{ + mbedtls_aes_context aes_ctx; + std::vector<u8> buffer(size); + + mbedtls_aes_setkey_dec(&aes_ctx, key, 128); + mbedtls_aes_crypt_cbc(&aes_ctx, MBEDTLS_AES_DECRYPT, size, iv, src, buffer.data()); + + return buffer; +} } CNANDContentData::~CNANDContentData() = default; @@ -323,27 +334,6 @@ void CNANDContentLoader::InitializeContentEntries(const std::vector<u8>& tmd, } } -std::vector<u8> CNANDContentLoader::AESDecode(const u8* key, u8* iv, const u8* src, u32 size) -{ - mbedtls_aes_context aes_ctx; - std::vector<u8> buffer(size); - - mbedtls_aes_setkey_dec(&aes_ctx, key, 128); - mbedtls_aes_crypt_cbc(&aes_ctx, MBEDTLS_AES_DECRYPT, size, iv, src, buffer.data()); - - return buffer; -} - -std::vector<u8> CNANDContentLoader::GetKeyFromTicket(const std::vector<u8>& ticket) -{ - const u8 common_key[16] = {0xeb, 0xe4, 0x2a, 0x22, 0x5e, 0x85, 0x93, 0xe4, - 0x48, 0xd9, 0xc5, 0x45, 0x73, 0x81, 0xaa, 0xf7}; - u8 iv[16] = {}; - - std::copy(&ticket[0x01DC], &ticket[0x01DC + 8], iv); - return AESDecode(common_key, iv, &ticket[0x01BF], 16); -} - DiscIO::Region CNANDContentLoader::GetRegion() const { if (!IsValid()) @@ -606,4 +596,14 @@ std::vector<u8> FindTicket(u64 title_id) return SignedTicketToTicket(signed_ticket); } +std::vector<u8> GetKeyFromTicket(const std::vector<u8>& signed_ticket) +{ + const u8 common_key[16] = {0xeb, 0xe4, 0x2a, 0x22, 0x5e, 0x85, 0x93, 0xe4, + 0x48, 0xd9, 0xc5, 0x45, 0x73, 0x81, 0xaa, 0xf7}; + u8 iv[16] = {}; + + std::copy(&signed_ticket[0x01DC], &signed_ticket[0x01DC + 8], iv); + return AESDecode(common_key, iv, &signed_ticket[0x01BF], 16); +} + } // namespace end diff --git a/Source/Core/DiscIO/NANDContentLoader.h b/Source/Core/DiscIO/NANDContentLoader.h index ebf42d919a..193bee596f 100644 --- a/Source/Core/DiscIO/NANDContentLoader.h +++ b/Source/Core/DiscIO/NANDContentLoader.h @@ -25,6 +25,7 @@ enum class Region; bool AddTicket(const std::vector<u8>& signed_ticket); std::vector<u8> FindSignedTicket(u64 title_id); std::vector<u8> FindTicket(u64 title_id); +std::vector<u8> GetKeyFromTicket(const std::vector<u8>& ticket); class CNANDContentData { @@ -112,9 +113,6 @@ private: const std::vector<u8>& decrypted_title_key, const std::vector<u8>& data_app); - static std::vector<u8> AESDecode(const u8* key, u8* iv, const u8* src, u32 size); - static std::vector<u8> GetKeyFromTicket(const std::vector<u8>& ticket); - bool m_Valid; bool m_IsWAD; std::string m_Path; |
