IOS/ES: Factor out the ES_Decrypt implementation.

WFSI calls into ES to perform this operation, so expose a way for us to
do the same thing.
This commit is contained in:
Pierre Bourdon 2017-01-01 20:29:15 +01:00
parent c8a054d234
commit c30635c70a
2 changed files with 13 additions and 4 deletions

View File

@ -105,6 +105,15 @@ void CWII_IPC_HLE_Device_es::LoadWAD(const std::string& _rContentFile)
m_ContentFile = _rContentFile;
}
void CWII_IPC_HLE_Device_es::DecryptContent(u32 key_index, u8* iv, u8* input, u32 size, u8* new_iv,
u8* output)
{
mbedtls_aes_context AES_ctx;
mbedtls_aes_setkey_dec(&AES_ctx, keyTable[key_index], 128);
memcpy(new_iv, iv, 16);
mbedtls_aes_crypt_cbc(&AES_ctx, MBEDTLS_AES_DECRYPT, size, new_iv, input, output);
}
void CWII_IPC_HLE_Device_es::OpenInternal()
{
auto& contentLoader = DiscIO::CNANDContentManager::Access().GetNANDLoader(m_ContentFile);
@ -914,10 +923,7 @@ IPCCommandResult CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress)
u8* newIV = Memory::GetPointer(Buffer.PayloadBuffer[0].m_Address);
u8* destination = Memory::GetPointer(Buffer.PayloadBuffer[1].m_Address);
mbedtls_aes_context AES_ctx;
mbedtls_aes_setkey_dec(&AES_ctx, keyTable[keyIndex], 128);
memcpy(newIV, IV, 16);
mbedtls_aes_crypt_cbc(&AES_ctx, MBEDTLS_AES_DECRYPT, size, newIV, source, destination);
DecryptContent(keyIndex, IV, source, size, newIV, destination);
_dbg_assert_msg_(WII_IPC_ES, keyIndex == 6,
"IOCTL_ES_DECRYPT: Key type is not SD, data will be crap");

View File

@ -30,6 +30,9 @@ public:
void LoadWAD(const std::string& _rContentFile);
// Internal implementation of the ES_DECRYPT ioctlv.
void DecryptContent(u32 key_index, u8* iv, u8* input, u32 size, u8* new_iv, u8* output);
void OpenInternal();
void DoState(PointerWrap& p) override;