mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-05-14 08:12:16 +00:00
externals: Remove need for cryptopp build. (#2707)
This commit is contained in:
parent
78c8bca2bb
commit
be7d646e83
9 changed files with 1398 additions and 55 deletions
8
.gitmodules
vendored
8
.gitmodules
vendored
|
@ -1,11 +1,3 @@
|
||||||
[submodule "externals/cryptopp-cmake"]
|
|
||||||
path = externals/cryptopp-cmake
|
|
||||||
url = https://github.com/shadps4-emu/ext-cryptopp-cmake.git
|
|
||||||
shallow = true
|
|
||||||
[submodule "externals/cryptopp"]
|
|
||||||
path = externals/cryptopp
|
|
||||||
url = https://github.com/shadps4-emu/ext-cryptopp.git
|
|
||||||
shallow = true
|
|
||||||
[submodule "externals/zlib-ng"]
|
[submodule "externals/zlib-ng"]
|
||||||
path = externals/zlib-ng
|
path = externals/zlib-ng
|
||||||
url = https://github.com/shadps4-emu/ext-zlib-ng.git
|
url = https://github.com/shadps4-emu/ext-zlib-ng.git
|
||||||
|
|
|
@ -583,6 +583,7 @@ set(COMMON src/common/logging/backend.cpp
|
||||||
src/common/logging/text_formatter.cpp
|
src/common/logging/text_formatter.cpp
|
||||||
src/common/logging/text_formatter.h
|
src/common/logging/text_formatter.h
|
||||||
src/common/logging/types.h
|
src/common/logging/types.h
|
||||||
|
src/common/aes.h
|
||||||
src/common/alignment.h
|
src/common/alignment.h
|
||||||
src/common/arch.h
|
src/common/arch.h
|
||||||
src/common/assert.cpp
|
src/common/assert.cpp
|
||||||
|
@ -614,6 +615,7 @@ set(COMMON src/common/logging/backend.cpp
|
||||||
src/common/polyfill_thread.h
|
src/common/polyfill_thread.h
|
||||||
src/common/rdtsc.cpp
|
src/common/rdtsc.cpp
|
||||||
src/common/rdtsc.h
|
src/common/rdtsc.h
|
||||||
|
src/common/sha1.h
|
||||||
src/common/signal_context.h
|
src/common/signal_context.h
|
||||||
src/common/signal_context.cpp
|
src/common/signal_context.cpp
|
||||||
src/common/singleton.h
|
src/common/singleton.h
|
||||||
|
@ -1022,7 +1024,7 @@ endif()
|
||||||
create_target_directory_groups(shadps4)
|
create_target_directory_groups(shadps4)
|
||||||
|
|
||||||
target_link_libraries(shadps4 PRIVATE magic_enum::magic_enum fmt::fmt toml11::toml11 tsl::robin_map xbyak::xbyak Tracy::TracyClient RenderDoc::API FFmpeg::ffmpeg Dear_ImGui gcn half::half ZLIB::ZLIB PNG::PNG)
|
target_link_libraries(shadps4 PRIVATE magic_enum::magic_enum fmt::fmt toml11::toml11 tsl::robin_map xbyak::xbyak Tracy::TracyClient RenderDoc::API FFmpeg::ffmpeg Dear_ImGui gcn half::half ZLIB::ZLIB PNG::PNG)
|
||||||
target_link_libraries(shadps4 PRIVATE Boost::headers GPUOpen::VulkanMemoryAllocator LibAtrac9 sirit Vulkan::Headers xxHash::xxhash Zydis::Zydis glslang::glslang SDL3::SDL3 pugixml::pugixml stb::headers cryptopp::cryptopp)
|
target_link_libraries(shadps4 PRIVATE Boost::headers GPUOpen::VulkanMemoryAllocator LibAtrac9 sirit Vulkan::Headers xxHash::xxhash Zydis::Zydis glslang::glslang SDL3::SDL3 pugixml::pugixml stb::headers)
|
||||||
|
|
||||||
target_compile_definitions(shadps4 PRIVATE IMGUI_USER_CONFIG="imgui/imgui_config.h")
|
target_compile_definitions(shadps4 PRIVATE IMGUI_USER_CONFIG="imgui/imgui_config.h")
|
||||||
target_compile_definitions(Dear_ImGui PRIVATE IMGUI_USER_CONFIG="${PROJECT_SOURCE_DIR}/src/imgui/imgui_config.h")
|
target_compile_definitions(Dear_ImGui PRIVATE IMGUI_USER_CONFIG="${PROJECT_SOURCE_DIR}/src/imgui/imgui_config.h")
|
||||||
|
|
16
externals/CMakeLists.txt
vendored
16
externals/CMakeLists.txt
vendored
|
@ -26,21 +26,7 @@ if (NOT TARGET fmt::fmt)
|
||||||
add_subdirectory(fmt)
|
add_subdirectory(fmt)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# CryptoPP
|
# FFmpeg
|
||||||
if (NOT TARGET cryptopp::cryptopp)
|
|
||||||
set(CRYPTOPP_INSTALL OFF)
|
|
||||||
set(CRYPTOPP_BUILD_TESTING OFF)
|
|
||||||
set(CRYPTOPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp)
|
|
||||||
# cryptopp instruction set checks do not account for added compile options,
|
|
||||||
# so disable extensions in the library config to match our chosen target CPU.
|
|
||||||
set(CRYPTOPP_DISABLE_AESNI ON)
|
|
||||||
set(CRYPTOPP_DISABLE_AVX2 ON)
|
|
||||||
add_subdirectory(cryptopp-cmake)
|
|
||||||
file(COPY cryptopp DESTINATION cryptopp FILES_MATCHING PATTERN "*.h")
|
|
||||||
# remove externals/cryptopp from include directories because it contains a conflicting zlib.h file
|
|
||||||
set_target_properties(cryptopp PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/cryptopp")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (NOT TARGET FFmpeg::ffmpeg)
|
if (NOT TARGET FFmpeg::ffmpeg)
|
||||||
add_subdirectory(ffmpeg-core)
|
add_subdirectory(ffmpeg-core)
|
||||||
add_library(FFmpeg::ffmpeg ALIAS ffmpeg)
|
add_library(FFmpeg::ffmpeg ALIAS ffmpeg)
|
||||||
|
|
1
externals/cryptopp
vendored
1
externals/cryptopp
vendored
|
@ -1 +0,0 @@
|
||||||
Subproject commit effed0d0b865afc23ed67e0916f83734e4b9b3b7
|
|
1
externals/cryptopp-cmake
vendored
1
externals/cryptopp-cmake
vendored
|
@ -1 +0,0 @@
|
||||||
Subproject commit 2c384c28265a93358a2455e610e76393358794df
|
|
1195
src/common/aes.h
Normal file
1195
src/common/aes.h
Normal file
File diff suppressed because it is too large
Load diff
180
src/common/sha1.h
Normal file
180
src/common/sha1.h
Normal file
|
@ -0,0 +1,180 @@
|
||||||
|
// SPDX-FileCopyrightText: 2012 SAURAV MOHAPATRA <mohaps@gmail.com>
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
namespace sha1 {
|
||||||
|
class SHA1 {
|
||||||
|
public:
|
||||||
|
typedef uint32_t digest32_t[5];
|
||||||
|
typedef uint8_t digest8_t[20];
|
||||||
|
inline static uint32_t LeftRotate(uint32_t value, size_t count) {
|
||||||
|
return (value << count) ^ (value >> (32 - count));
|
||||||
|
}
|
||||||
|
SHA1() {
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
virtual ~SHA1() {}
|
||||||
|
SHA1(const SHA1& s) {
|
||||||
|
*this = s;
|
||||||
|
}
|
||||||
|
const SHA1& operator=(const SHA1& s) {
|
||||||
|
memcpy(m_digest, s.m_digest, 5 * sizeof(uint32_t));
|
||||||
|
memcpy(m_block, s.m_block, 64);
|
||||||
|
m_blockByteIndex = s.m_blockByteIndex;
|
||||||
|
m_byteCount = s.m_byteCount;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
SHA1& reset() {
|
||||||
|
m_digest[0] = 0x67452301;
|
||||||
|
m_digest[1] = 0xEFCDAB89;
|
||||||
|
m_digest[2] = 0x98BADCFE;
|
||||||
|
m_digest[3] = 0x10325476;
|
||||||
|
m_digest[4] = 0xC3D2E1F0;
|
||||||
|
m_blockByteIndex = 0;
|
||||||
|
m_byteCount = 0;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
SHA1& processByte(uint8_t octet) {
|
||||||
|
this->m_block[this->m_blockByteIndex++] = octet;
|
||||||
|
++this->m_byteCount;
|
||||||
|
if (m_blockByteIndex == 64) {
|
||||||
|
this->m_blockByteIndex = 0;
|
||||||
|
processBlock();
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
SHA1& processBlock(const void* const start, const void* const end) {
|
||||||
|
const uint8_t* begin = static_cast<const uint8_t*>(start);
|
||||||
|
const uint8_t* finish = static_cast<const uint8_t*>(end);
|
||||||
|
while (begin != finish) {
|
||||||
|
processByte(*begin);
|
||||||
|
begin++;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
SHA1& processBytes(const void* const data, size_t len) {
|
||||||
|
const uint8_t* block = static_cast<const uint8_t*>(data);
|
||||||
|
processBlock(block, block + len);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
const uint32_t* getDigest(digest32_t digest) {
|
||||||
|
size_t bitCount = this->m_byteCount * 8;
|
||||||
|
processByte(0x80);
|
||||||
|
if (this->m_blockByteIndex > 56) {
|
||||||
|
while (m_blockByteIndex != 0) {
|
||||||
|
processByte(0);
|
||||||
|
}
|
||||||
|
while (m_blockByteIndex < 56) {
|
||||||
|
processByte(0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
while (m_blockByteIndex < 56) {
|
||||||
|
processByte(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
processByte(0);
|
||||||
|
processByte(0);
|
||||||
|
processByte(0);
|
||||||
|
processByte(0);
|
||||||
|
processByte(static_cast<unsigned char>((bitCount >> 24) & 0xFF));
|
||||||
|
processByte(static_cast<unsigned char>((bitCount >> 16) & 0xFF));
|
||||||
|
processByte(static_cast<unsigned char>((bitCount >> 8) & 0xFF));
|
||||||
|
processByte(static_cast<unsigned char>((bitCount) & 0xFF));
|
||||||
|
|
||||||
|
memcpy(digest, m_digest, 5 * sizeof(uint32_t));
|
||||||
|
return digest;
|
||||||
|
}
|
||||||
|
const uint8_t* getDigestBytes(digest8_t digest) {
|
||||||
|
digest32_t d32;
|
||||||
|
getDigest(d32);
|
||||||
|
size_t di = 0;
|
||||||
|
digest[di++] = ((d32[0] >> 24) & 0xFF);
|
||||||
|
digest[di++] = ((d32[0] >> 16) & 0xFF);
|
||||||
|
digest[di++] = ((d32[0] >> 8) & 0xFF);
|
||||||
|
digest[di++] = ((d32[0]) & 0xFF);
|
||||||
|
|
||||||
|
digest[di++] = ((d32[1] >> 24) & 0xFF);
|
||||||
|
digest[di++] = ((d32[1] >> 16) & 0xFF);
|
||||||
|
digest[di++] = ((d32[1] >> 8) & 0xFF);
|
||||||
|
digest[di++] = ((d32[1]) & 0xFF);
|
||||||
|
|
||||||
|
digest[di++] = ((d32[2] >> 24) & 0xFF);
|
||||||
|
digest[di++] = ((d32[2] >> 16) & 0xFF);
|
||||||
|
digest[di++] = ((d32[2] >> 8) & 0xFF);
|
||||||
|
digest[di++] = ((d32[2]) & 0xFF);
|
||||||
|
|
||||||
|
digest[di++] = ((d32[3] >> 24) & 0xFF);
|
||||||
|
digest[di++] = ((d32[3] >> 16) & 0xFF);
|
||||||
|
digest[di++] = ((d32[3] >> 8) & 0xFF);
|
||||||
|
digest[di++] = ((d32[3]) & 0xFF);
|
||||||
|
|
||||||
|
digest[di++] = ((d32[4] >> 24) & 0xFF);
|
||||||
|
digest[di++] = ((d32[4] >> 16) & 0xFF);
|
||||||
|
digest[di++] = ((d32[4] >> 8) & 0xFF);
|
||||||
|
digest[di++] = ((d32[4]) & 0xFF);
|
||||||
|
return digest;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void processBlock() {
|
||||||
|
uint32_t w[80];
|
||||||
|
for (size_t i = 0; i < 16; i++) {
|
||||||
|
w[i] = (m_block[i * 4 + 0] << 24);
|
||||||
|
w[i] |= (m_block[i * 4 + 1] << 16);
|
||||||
|
w[i] |= (m_block[i * 4 + 2] << 8);
|
||||||
|
w[i] |= (m_block[i * 4 + 3]);
|
||||||
|
}
|
||||||
|
for (size_t i = 16; i < 80; i++) {
|
||||||
|
w[i] = LeftRotate((w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16]), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t a = m_digest[0];
|
||||||
|
uint32_t b = m_digest[1];
|
||||||
|
uint32_t c = m_digest[2];
|
||||||
|
uint32_t d = m_digest[3];
|
||||||
|
uint32_t e = m_digest[4];
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < 80; ++i) {
|
||||||
|
uint32_t f = 0;
|
||||||
|
uint32_t k = 0;
|
||||||
|
|
||||||
|
if (i < 20) {
|
||||||
|
f = (b & c) | (~b & d);
|
||||||
|
k = 0x5A827999;
|
||||||
|
} else if (i < 40) {
|
||||||
|
f = b ^ c ^ d;
|
||||||
|
k = 0x6ED9EBA1;
|
||||||
|
} else if (i < 60) {
|
||||||
|
f = (b & c) | (b & d) | (c & d);
|
||||||
|
k = 0x8F1BBCDC;
|
||||||
|
} else {
|
||||||
|
f = b ^ c ^ d;
|
||||||
|
k = 0xCA62C1D6;
|
||||||
|
}
|
||||||
|
uint32_t temp = LeftRotate(a, 5) + f + e + k + w[i];
|
||||||
|
e = d;
|
||||||
|
d = c;
|
||||||
|
c = LeftRotate(b, 30);
|
||||||
|
b = a;
|
||||||
|
a = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_digest[0] += a;
|
||||||
|
m_digest[1] += b;
|
||||||
|
m_digest[2] += c;
|
||||||
|
m_digest[3] += d;
|
||||||
|
m_digest[4] += e;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
digest32_t m_digest;
|
||||||
|
uint8_t m_block[64];
|
||||||
|
size_t m_blockByteIndex;
|
||||||
|
size_t m_byteCount;
|
||||||
|
};
|
||||||
|
} // namespace sha1
|
|
@ -1,35 +1,24 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include <cryptopp/aes.h>
|
#include "common/aes.h"
|
||||||
#include <cryptopp/modes.h>
|
|
||||||
|
|
||||||
#include "common/config.h"
|
#include "common/config.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/path_util.h"
|
#include "common/path_util.h"
|
||||||
#include "core/file_format/trp.h"
|
#include "core/file_format/trp.h"
|
||||||
|
|
||||||
static void DecryptEFSM(std::span<CryptoPP::byte, 16> trophyKey,
|
static void DecryptEFSM(std::span<u8, 16> trophyKey, std::span<u8, 16> NPcommID,
|
||||||
std::span<CryptoPP::byte, 16> NPcommID,
|
std::span<u8, 16> efsmIv, std::span<u8> ciphertext,
|
||||||
std::span<CryptoPP::byte, 16> efsmIv, std::span<CryptoPP::byte> ciphertext,
|
std::span<u8> decrypted) {
|
||||||
std::span<CryptoPP::byte> decrypted) {
|
// Step 1: Encrypt NPcommID
|
||||||
|
std::array<u8, 16> trophyIv{};
|
||||||
|
std::array<u8, 16> trpKey;
|
||||||
|
aes::encrypt_cbc(NPcommID.data(), NPcommID.size(), trophyKey.data(), trophyKey.size(),
|
||||||
|
trophyIv.data(), trpKey.data(), trpKey.size(), false);
|
||||||
|
|
||||||
// step 1: Encrypt NPcommID
|
// Step 2: Decrypt EFSM
|
||||||
CryptoPP::CBC_Mode<CryptoPP::AES>::Encryption encrypt;
|
aes::decrypt_cbc(ciphertext.data(), ciphertext.size(), trpKey.data(), trpKey.size(),
|
||||||
|
efsmIv.data(), decrypted.data(), decrypted.size(), nullptr);
|
||||||
std::vector<CryptoPP::byte> trophyIv(16, 0);
|
|
||||||
std::vector<CryptoPP::byte> trpKey(16);
|
|
||||||
|
|
||||||
encrypt.SetKeyWithIV(trophyKey.data(), trophyKey.size(), trophyIv.data());
|
|
||||||
encrypt.ProcessData(trpKey.data(), NPcommID.data(), 16);
|
|
||||||
|
|
||||||
// step 2: decrypt efsm.
|
|
||||||
CryptoPP::CBC_Mode<CryptoPP::AES>::Decryption decrypt;
|
|
||||||
decrypt.SetKeyWithIV(trpKey.data(), trpKey.size(), efsmIv.data());
|
|
||||||
|
|
||||||
for (size_t i = 0; i < decrypted.size(); i += CryptoPP::AES::BLOCKSIZE) {
|
|
||||||
decrypt.ProcessData(decrypted.data() + i, ciphertext.data() + i, CryptoPP::AES::BLOCKSIZE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TRP::TRP() = default;
|
TRP::TRP() = default;
|
||||||
|
@ -80,7 +69,7 @@ bool TRP::Extract(const std::filesystem::path& trophyPath, const std::string tit
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<CryptoPP::byte, 16> user_key{};
|
std::array<u8, 16> user_key{};
|
||||||
hexToBytes(user_key_str.c_str(), user_key.data());
|
hexToBytes(user_key_str.c_str(), user_key.data());
|
||||||
|
|
||||||
for (int index = 0; const auto& it : std::filesystem::directory_iterator(gameSysDir)) {
|
for (int index = 0; const auto& it : std::filesystem::directory_iterator(gameSysDir)) {
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include <cryptopp/sha.h>
|
|
||||||
|
|
||||||
#include "common/alignment.h"
|
#include "common/alignment.h"
|
||||||
#include "common/arch.h"
|
#include "common/arch.h"
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/memory_patcher.h"
|
#include "common/memory_patcher.h"
|
||||||
|
#include "common/sha1.h"
|
||||||
#include "common/string_util.h"
|
#include "common/string_util.h"
|
||||||
#include "core/aerolib/aerolib.h"
|
#include "core/aerolib/aerolib.h"
|
||||||
#include "core/cpu_patches.h"
|
#include "core/cpu_patches.h"
|
||||||
|
@ -65,11 +64,13 @@ static std::string StringToNid(std::string_view symbol) {
|
||||||
std::memcpy(input.data(), symbol.data(), symbol.size());
|
std::memcpy(input.data(), symbol.data(), symbol.size());
|
||||||
std::memcpy(input.data() + symbol.size(), Salt.data(), Salt.size());
|
std::memcpy(input.data() + symbol.size(), Salt.data(), Salt.size());
|
||||||
|
|
||||||
std::array<u8, CryptoPP::SHA1::DIGESTSIZE> hash;
|
sha1::SHA1::digest8_t hash;
|
||||||
CryptoPP::SHA1().CalculateDigest(hash.data(), input.data(), input.size());
|
sha1::SHA1 sha;
|
||||||
|
sha.processBytes(input.data(), input.size());
|
||||||
|
sha.getDigestBytes(hash);
|
||||||
|
|
||||||
u64 digest;
|
u64 digest;
|
||||||
std::memcpy(&digest, hash.data(), sizeof(digest));
|
std::memcpy(&digest, hash, sizeof(digest));
|
||||||
|
|
||||||
static constexpr std::string_view codes =
|
static constexpr std::string_view codes =
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-";
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-";
|
||||||
|
|
Loading…
Add table
Reference in a new issue