diff options
| author | 2018-01-12 19:36:41 -0500 | |
|---|---|---|
| committer | 2018-01-12 19:36:41 -0500 | |
| commit | 8e51c61dbce925e0992e27c2c33311583645bd6f (patch) | |
| tree | 2e868c243b15eaa63b953696775e0b84bab2fd22 /src | |
| parent | dynarmic: Update to 83afe435 (diff) | |
| download | yuzu-8e51c61dbce925e0992e27c2c33311583645bd6f.tar.gz yuzu-8e51c61dbce925e0992e27c2c33311583645bd6f.tar.xz yuzu-8e51c61dbce925e0992e27c2c33311583645bd6f.zip | |
core: Gut out cryptop, since it doesn't compile with C++17.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/core/file_sys/title_metadata.cpp | 51 | ||||
| -rw-r--r-- | src/core/hw/aes/ccm.cpp | 77 | ||||
| -rw-r--r-- | src/core/telemetry_session.cpp | 3 |
4 files changed, 7 insertions, 126 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index e8e98a095..90772d0db 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -172,7 +172,7 @@ set(HEADERS | |||
| 172 | create_directory_groups(${SRCS} ${HEADERS}) | 172 | create_directory_groups(${SRCS} ${HEADERS}) |
| 173 | add_library(core STATIC ${SRCS} ${HEADERS}) | 173 | add_library(core STATIC ${SRCS} ${HEADERS}) |
| 174 | target_link_libraries(core PUBLIC common PRIVATE audio_core dynarmic network video_core) | 174 | target_link_libraries(core PUBLIC common PRIVATE audio_core dynarmic network video_core) |
| 175 | target_link_libraries(core PUBLIC Boost::boost PRIVATE cryptopp fmt lz4_static unicorn) | 175 | target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt lz4_static unicorn) |
| 176 | if (ENABLE_WEB_SERVICE) | 176 | if (ENABLE_WEB_SERVICE) |
| 177 | target_link_libraries(core PUBLIC json-headers web_service) | 177 | target_link_libraries(core PUBLIC json-headers web_service) |
| 178 | endif() | 178 | endif() |
diff --git a/src/core/file_sys/title_metadata.cpp b/src/core/file_sys/title_metadata.cpp index 1ef8840a0..e29ba6064 100644 --- a/src/core/file_sys/title_metadata.cpp +++ b/src/core/file_sys/title_metadata.cpp | |||
| @@ -3,7 +3,6 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <cinttypes> | 5 | #include <cinttypes> |
| 6 | #include <cryptopp/sha.h> | ||
| 7 | #include "common/alignment.h" | 6 | #include "common/alignment.h" |
| 8 | #include "common/file_util.h" | 7 | #include "common/file_util.h" |
| 9 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| @@ -69,55 +68,7 @@ Loader::ResultStatus TitleMetadata::Load() { | |||
| 69 | } | 68 | } |
| 70 | 69 | ||
| 71 | Loader::ResultStatus TitleMetadata::Save() { | 70 | Loader::ResultStatus TitleMetadata::Save() { |
| 72 | FileUtil::IOFile file(filepath, "wb"); | 71 | UNIMPLEMENTED(); |
| 73 | if (!file.IsOpen()) | ||
| 74 | return Loader::ResultStatus::Error; | ||
| 75 | |||
| 76 | if (!file.WriteBytes(&signature_type, sizeof(u32_be))) | ||
| 77 | return Loader::ResultStatus::Error; | ||
| 78 | |||
| 79 | // Signature lengths are variable, and the body follows the signature | ||
| 80 | u32 signature_size = GetSignatureSize(signature_type); | ||
| 81 | |||
| 82 | if (!file.WriteBytes(tmd_signature.data(), signature_size)) | ||
| 83 | return Loader::ResultStatus::Error; | ||
| 84 | |||
| 85 | // The TMD body start position is rounded to the nearest 0x40 after the signature | ||
| 86 | size_t body_start = Common::AlignUp(signature_size + sizeof(u32), 0x40); | ||
| 87 | file.Seek(body_start, SEEK_SET); | ||
| 88 | |||
| 89 | // Update our TMD body values and hashes | ||
| 90 | tmd_body.content_count = static_cast<u16>(tmd_chunks.size()); | ||
| 91 | |||
| 92 | // TODO(shinyquagsire23): Do TMDs with more than one contentinfo exist? | ||
| 93 | // For now we'll just adjust the first index to hold all content chunks | ||
| 94 | // and ensure that no further content info data exists. | ||
| 95 | tmd_body.contentinfo = {}; | ||
| 96 | tmd_body.contentinfo[0].index = 0; | ||
| 97 | tmd_body.contentinfo[0].command_count = static_cast<u16>(tmd_chunks.size()); | ||
| 98 | |||
| 99 | CryptoPP::SHA256 chunk_hash; | ||
| 100 | for (u16 i = 0; i < tmd_body.content_count; i++) { | ||
| 101 | chunk_hash.Update(reinterpret_cast<u8*>(&tmd_chunks[i]), sizeof(ContentChunk)); | ||
| 102 | } | ||
| 103 | chunk_hash.Final(tmd_body.contentinfo[0].hash.data()); | ||
| 104 | |||
| 105 | CryptoPP::SHA256 contentinfo_hash; | ||
| 106 | for (size_t i = 0; i < tmd_body.contentinfo.size(); i++) { | ||
| 107 | chunk_hash.Update(reinterpret_cast<u8*>(&tmd_body.contentinfo[i]), sizeof(ContentInfo)); | ||
| 108 | } | ||
| 109 | chunk_hash.Final(tmd_body.contentinfo_hash.data()); | ||
| 110 | |||
| 111 | // Write our TMD body, then write each of our ContentChunks | ||
| 112 | if (file.WriteBytes(&tmd_body, sizeof(TitleMetadata::Body)) != sizeof(TitleMetadata::Body)) | ||
| 113 | return Loader::ResultStatus::Error; | ||
| 114 | |||
| 115 | for (u16 i = 0; i < tmd_body.content_count; i++) { | ||
| 116 | ContentChunk chunk = tmd_chunks[i]; | ||
| 117 | if (file.WriteBytes(&chunk, sizeof(ContentChunk)) != sizeof(ContentChunk)) | ||
| 118 | return Loader::ResultStatus::Error; | ||
| 119 | } | ||
| 120 | |||
| 121 | return Loader::ResultStatus::Success; | 72 | return Loader::ResultStatus::Success; |
| 122 | } | 73 | } |
| 123 | 74 | ||
diff --git a/src/core/hw/aes/ccm.cpp b/src/core/hw/aes/ccm.cpp index dc7035ab6..1ee37aaa4 100644 --- a/src/core/hw/aes/ccm.cpp +++ b/src/core/hw/aes/ccm.cpp | |||
| @@ -3,11 +3,8 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <cryptopp/aes.h> | ||
| 7 | #include <cryptopp/ccm.h> | ||
| 8 | #include <cryptopp/cryptlib.h> | ||
| 9 | #include <cryptopp/filters.h> | ||
| 10 | #include "common/alignment.h" | 6 | #include "common/alignment.h" |
| 7 | #include "common/assert.h" | ||
| 11 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 12 | #include "core/hw/aes/ccm.h" | 9 | #include "core/hw/aes/ccm.h" |
| 13 | #include "core/hw/aes/key.h" | 10 | #include "core/hw/aes/key.h" |
| @@ -15,80 +12,16 @@ | |||
| 15 | namespace HW { | 12 | namespace HW { |
| 16 | namespace AES { | 13 | namespace AES { |
| 17 | 14 | ||
| 18 | namespace { | ||
| 19 | |||
| 20 | // 3DS uses a non-standard AES-CCM algorithm, so we need to derive a sub class from the standard one | ||
| 21 | // and override with the non-standard part. | ||
| 22 | using CryptoPP::lword; | ||
| 23 | using CryptoPP::AES; | ||
| 24 | using CryptoPP::CCM_Final; | ||
| 25 | using CryptoPP::CCM_Base; | ||
| 26 | template <bool T_IsEncryption> | ||
| 27 | class CCM_3DSVariant_Final : public CCM_Final<AES, CCM_MAC_SIZE, T_IsEncryption> { | ||
| 28 | public: | ||
| 29 | void UncheckedSpecifyDataLengths(lword header_length, lword message_length, | ||
| 30 | lword footer_length) override { | ||
| 31 | // 3DS uses the aligned size to generate B0 for authentication, instead of the original size | ||
| 32 | lword aligned_message_length = Common::AlignUp(message_length, AES_BLOCK_SIZE); | ||
| 33 | CCM_Base::UncheckedSpecifyDataLengths(header_length, aligned_message_length, footer_length); | ||
| 34 | CCM_Base::m_messageLength = message_length; // restore the actual message size | ||
| 35 | } | ||
| 36 | }; | ||
| 37 | |||
| 38 | class CCM_3DSVariant { | ||
| 39 | public: | ||
| 40 | using Encryption = CCM_3DSVariant_Final<true>; | ||
| 41 | using Decryption = CCM_3DSVariant_Final<false>; | ||
| 42 | }; | ||
| 43 | |||
| 44 | } // namespace | ||
| 45 | |||
| 46 | std::vector<u8> EncryptSignCCM(const std::vector<u8>& pdata, const CCMNonce& nonce, | 15 | std::vector<u8> EncryptSignCCM(const std::vector<u8>& pdata, const CCMNonce& nonce, |
| 47 | size_t slot_id) { | 16 | size_t slot_id) { |
| 48 | if (!IsNormalKeyAvailable(slot_id)) { | 17 | UNIMPLEMENTED(); |
| 49 | LOG_ERROR(HW_AES, "Key slot %d not available. Will use zero key.", slot_id); | 18 | return {}; |
| 50 | } | ||
| 51 | const AESKey normal = GetNormalKey(slot_id); | ||
| 52 | std::vector<u8> cipher(pdata.size() + CCM_MAC_SIZE); | ||
| 53 | |||
| 54 | try { | ||
| 55 | CCM_3DSVariant::Encryption e; | ||
| 56 | e.SetKeyWithIV(normal.data(), AES_BLOCK_SIZE, nonce.data(), CCM_NONCE_SIZE); | ||
| 57 | e.SpecifyDataLengths(0, pdata.size(), 0); | ||
| 58 | CryptoPP::ArraySource as(pdata.data(), pdata.size(), true, | ||
| 59 | new CryptoPP::AuthenticatedEncryptionFilter( | ||
| 60 | e, new CryptoPP::ArraySink(cipher.data(), cipher.size()))); | ||
| 61 | } catch (const CryptoPP::Exception& e) { | ||
| 62 | LOG_ERROR(HW_AES, "FAILED with: %s", e.what()); | ||
| 63 | } | ||
| 64 | return cipher; | ||
| 65 | } | 19 | } |
| 66 | 20 | ||
| 67 | std::vector<u8> DecryptVerifyCCM(const std::vector<u8>& cipher, const CCMNonce& nonce, | 21 | std::vector<u8> DecryptVerifyCCM(const std::vector<u8>& cipher, const CCMNonce& nonce, |
| 68 | size_t slot_id) { | 22 | size_t slot_id) { |
| 69 | if (!IsNormalKeyAvailable(slot_id)) { | 23 | UNIMPLEMENTED(); |
| 70 | LOG_ERROR(HW_AES, "Key slot %d not available. Will use zero key.", slot_id); | 24 | return {}; |
| 71 | } | ||
| 72 | const AESKey normal = GetNormalKey(slot_id); | ||
| 73 | const std::size_t pdata_size = cipher.size() - CCM_MAC_SIZE; | ||
| 74 | std::vector<u8> pdata(pdata_size); | ||
| 75 | |||
| 76 | try { | ||
| 77 | CCM_3DSVariant::Decryption d; | ||
| 78 | d.SetKeyWithIV(normal.data(), AES_BLOCK_SIZE, nonce.data(), CCM_NONCE_SIZE); | ||
| 79 | d.SpecifyDataLengths(0, pdata_size, 0); | ||
| 80 | CryptoPP::AuthenticatedDecryptionFilter df( | ||
| 81 | d, new CryptoPP::ArraySink(pdata.data(), pdata_size)); | ||
| 82 | CryptoPP::ArraySource as(cipher.data(), cipher.size(), true, new CryptoPP::Redirector(df)); | ||
| 83 | if (!df.GetLastResult()) { | ||
| 84 | LOG_ERROR(HW_AES, "FAILED"); | ||
| 85 | return {}; | ||
| 86 | } | ||
| 87 | } catch (const CryptoPP::Exception& e) { | ||
| 88 | LOG_ERROR(HW_AES, "FAILED with: %s", e.what()); | ||
| 89 | return {}; | ||
| 90 | } | ||
| 91 | return pdata; | ||
| 92 | } | 25 | } |
| 93 | 26 | ||
| 94 | } // namespace AES | 27 | } // namespace AES |
diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp index f9725b590..560c8af55 100644 --- a/src/core/telemetry_session.cpp +++ b/src/core/telemetry_session.cpp | |||
| @@ -3,7 +3,6 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <cstring> | 5 | #include <cstring> |
| 6 | #include <cryptopp/osrng.h> | ||
| 7 | 6 | ||
| 8 | #include "common/assert.h" | 7 | #include "common/assert.h" |
| 9 | #include "common/file_util.h" | 8 | #include "common/file_util.h" |
| @@ -34,8 +33,6 @@ static const char* CpuVendorToStr(Common::CPUVendor vendor) { | |||
| 34 | 33 | ||
| 35 | static u64 GenerateTelemetryId() { | 34 | static u64 GenerateTelemetryId() { |
| 36 | u64 telemetry_id{}; | 35 | u64 telemetry_id{}; |
| 37 | CryptoPP::AutoSeededRandomPool rng; | ||
| 38 | rng.GenerateBlock(reinterpret_cast<CryptoPP::byte*>(&telemetry_id), sizeof(u64)); | ||
| 39 | return telemetry_id; | 36 | return telemetry_id; |
| 40 | } | 37 | } |
| 41 | 38 | ||