// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #pragma once #include #include #include #include #include #include #include #include #include "common/types.h" #include "keys.h" class Crypto { public: PkgDerivedKey3Keyset pkg_derived_key3_keyset; FakeKeyset FakeKeyset_keyset; DebugRifKeyset DebugRifKeyset_keyset; CryptoPP::RSA::PrivateKey key_pkg_derived_key3_keyset_init(); CryptoPP::RSA::PrivateKey FakeKeyset_keyset_init(); CryptoPP::RSA::PrivateKey DebugRifKeyset_init(); void RSA2048Decrypt(std::span dk3, std::span ciphertext, bool is_dk3); // RSAES_PKCS1v15_ void ivKeyHASH256(std::span cipher_input, std::span ivkey_result); void aesCbcCfb128Decrypt(std::span ivkey, std::span ciphertext, std::span decrypted); void aesCbcCfb128DecryptEntry(std::span ivkey, std::span ciphertext, std::span decrypted); void decryptEFSM(std::span, std::span efsmIv, std::span ciphertext, std::span decrypted); void PfsGenCryptoKey(std::span ekpfs, std::span seed, std::span dataKey, std::span tweakKey); void decryptPFS(std::span dataKey, std::span tweakKey, std::span src_image, std::span dst_image, u64 sector); void xtsXorBlock(CryptoPP::byte* x, const CryptoPP::byte* a, const CryptoPP::byte* b) { for (int i = 0; i < 16; i++) { x[i] = a[i] ^ b[i]; } } void xtsMult(std::span encryptedTweak) { int feedback = 0; for (int k = 0; k < encryptedTweak.size(); k++) { const auto tmp = (encryptedTweak[k] >> 7) & 1; encryptedTweak[k] = ((encryptedTweak[k] << 1) + feedback) & 0xFF; feedback = tmp; } if (feedback != 0) { encryptedTweak[0] ^= 0x87; } } };