1,159 changes: 0 additions & 1,159 deletions Source/Core/Common/Src/Crypto/aes_core.cpp

This file was deleted.

88 changes: 0 additions & 88 deletions Source/Core/Common/Src/Crypto/aes_locl.h

This file was deleted.

14 changes: 7 additions & 7 deletions Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.cpp
Expand Up @@ -38,7 +38,7 @@
#include "../PowerPC/PowerPC.h"
#include "../VolumeHandler.h"
#include "FileUtil.h"
#include "Crypto/aes.h"
#include <polarssl/aes.h>
#include "ConfigManager.h"

#include "../Boot/Boot_DOL.h"
Expand Down Expand Up @@ -860,10 +860,10 @@ bool 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);

AES_KEY AESKey;
AES_set_encrypt_key(keyTable[keyIndex], 128, &AESKey);
aes_context AES_ctx;
aes_setkey_enc(&AES_ctx, keyTable[keyIndex], 128);
memcpy(newIV, IV, 16);
AES_cbc_encrypt(source, destination, size, &AESKey, newIV, AES_ENCRYPT);
aes_crypt_cbc(&AES_ctx, AES_ENCRYPT, size, newIV, source, destination);

_dbg_assert_msg_(WII_IPC_ES, keyIndex == 6, "IOCTL_ES_ENCRYPT: Key type is not SD, data will be crap");
}
Expand All @@ -878,10 +878,10 @@ bool 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);

AES_KEY AESKey;
AES_set_decrypt_key(keyTable[keyIndex], 128, &AESKey);
aes_context AES_ctx;
aes_setkey_dec(&AES_ctx, keyTable[keyIndex], 128);
memcpy(newIV, IV, 16);
AES_cbc_encrypt(source, destination, size, &AESKey, newIV, AES_DECRYPT);
aes_crypt_cbc(&AES_ctx, AES_DECRYPT, size, newIV, source, destination);

_dbg_assert_msg_(WII_IPC_ES, keyIndex == 6, "IOCTL_ES_DECRYPT: Key type is not SD, data will be crap");
}
Expand Down
8 changes: 4 additions & 4 deletions Source/Core/DiscIO/Src/NANDContentLoader.cpp
Expand Up @@ -6,7 +6,7 @@

#include <algorithm>
#include <cctype>
#include "Crypto/aes.h"
#include <polarssl/aes.h>
#include "MathUtil.h"
#include "FileUtil.h"
#include "Log.h"
Expand Down Expand Up @@ -286,10 +286,10 @@ bool CNANDContentLoader::Initialize(const std::string& _rName)
}
void CNANDContentLoader::AESDecode(u8* _pKey, u8* _IV, u8* _pSrc, u32 _Size, u8* _pDest)
{
AES_KEY AESKey;
aes_context AES_ctx;

AES_set_decrypt_key(_pKey, 128, &AESKey);
AES_cbc_encrypt(_pSrc, _pDest, _Size, &AESKey, _IV, AES_DECRYPT);
aes_setkey_dec(&AES_ctx, _pKey, 128);
aes_crypt_cbc(&AES_ctx, AES_DECRYPT, _Size, _IV, _pSrc, _pDest);
}

void CNANDContentLoader::GetKeyFromTicket(u8* pTicket, u8* pTicketKey)
Expand Down
8 changes: 4 additions & 4 deletions Source/Core/DiscIO/Src/VolumeCreator.cpp
Expand Up @@ -4,7 +4,7 @@

#include <vector>

#include "Crypto/aes.h"
#include <polarssl/aes.h>

#include "VolumeCreator.h"

Expand Down Expand Up @@ -183,11 +183,11 @@ static IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _Part
memset(IV, 0, 16);
_rReader.Read(rPartition.Offset + 0x44c, 8, IV);

AES_KEY AES_KEY;
AES_set_decrypt_key((Korean ? g_MasterKeyK : g_MasterKey), 128, &AES_KEY);
aes_context AES_ctx;
aes_setkey_dec(&AES_ctx, (Korean ? g_MasterKeyK : g_MasterKey), 128);

u8 VolumeKey[16];
AES_cbc_encrypt(SubKey, VolumeKey, 16, &AES_KEY, IV, AES_DECRYPT);
aes_crypt_cbc(&AES_ctx, AES_DECRYPT, 16, IV, SubKey, VolumeKey);

// -1 means the caller just wanted the partition with matching type
if ((int)_VolumeNum == -1 || i == _VolumeNum)
Expand Down
10 changes: 7 additions & 3 deletions Source/Core/DiscIO/Src/VolumeWiiCrypted.cpp
Expand Up @@ -18,7 +18,8 @@ CVolumeWiiCrypted::CVolumeWiiCrypted(IBlobReader* _pReader, u64 _VolumeOffset,
dataOffset(0x20000),
m_LastDecryptedBlockOffset(-1)
{
AES_set_decrypt_key(_pVolumeKey, 128, &m_AES_KEY);
m_AES_ctx = new aes_context;
aes_setkey_dec(m_AES_ctx, _pVolumeKey, 128);
m_pBuffer = new u8[0x8000];
}

Expand All @@ -29,6 +30,8 @@ CVolumeWiiCrypted::~CVolumeWiiCrypted()
m_pReader = NULL;
delete[] m_pBuffer;
m_pBuffer = NULL;
delete m_AES_ctx;
m_AES_ctx = NULL;
}

bool CVolumeWiiCrypted::RAWRead( u64 _Offset, u64 _Length, u8* _pBuffer ) const
Expand Down Expand Up @@ -67,7 +70,7 @@ bool CVolumeWiiCrypted::Read(u64 _ReadOffset, u64 _Length, u8* _pBuffer) const
if (m_LastDecryptedBlockOffset != Block)
{
memcpy(IV, m_pBuffer + 0x3d0, 16);
AES_cbc_encrypt(m_pBuffer + 0x400, m_LastDecryptedBlock, 0x7C00, &m_AES_KEY, IV, AES_DECRYPT);
aes_crypt_cbc(m_AES_ctx, AES_DECRYPT, 0x7C00, IV, m_pBuffer + 0x400, m_LastDecryptedBlock);

m_LastDecryptedBlockOffset = Block;
}
Expand Down Expand Up @@ -250,7 +253,8 @@ bool CVolumeWiiCrypted::CheckIntegrity() const
NOTICE_LOG(DISCIO, "Integrity Check: fail at cluster %d: could not read metadata", clusterID);
return false;
}
AES_cbc_encrypt(clusterMDCrypted, clusterMD, 0x400, &m_AES_KEY, IV, AES_DECRYPT);
aes_crypt_cbc(m_AES_ctx, AES_DECRYPT, 0x400, IV, clusterMDCrypted, clusterMD);


// Some clusters have invalid data and metadata because they aren't
// meant to be read by the game (for example, holes between files). To
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DiscIO/Src/VolumeWiiCrypted.h
Expand Up @@ -7,7 +7,7 @@

#include "Volume.h"
#include "Blob.h"
#include "Crypto/aes.h"
#include <polarssl/aes.h>

// --- this volume type is used for encrypted Wii images ---

Expand Down Expand Up @@ -38,7 +38,7 @@ class CVolumeWiiCrypted : public IVolume
IBlobReader* m_pReader;

u8* m_pBuffer;
AES_KEY m_AES_KEY;
aes_context* m_AES_ctx;

u64 m_VolumeOffset;
u64 dataOffset;
Expand Down
12 changes: 6 additions & 6 deletions Source/Core/DolphinWX/Src/MemoryCards/WiiSaveCrypted.cpp
Expand Up @@ -78,7 +78,7 @@ CWiiSaveCrypted::CWiiSaveCrypted(const char* FileName, u64 TitleID)

if (!TitleID) // Import
{
AES_set_decrypt_key(SDKey, 128, &m_AES_KEY);
aes_setkey_dec(&m_AES_ctx, SDKey, 128);
b_valid = true;
ReadHDR();
ReadBKHDR();
Expand All @@ -95,7 +95,7 @@ CWiiSaveCrypted::CWiiSaveCrypted(const char* FileName, u64 TitleID)
}
else
{
AES_set_encrypt_key(SDKey, 128, &m_AES_KEY);
aes_setkey_enc(&m_AES_ctx, SDKey, 128);

if (getPaths(true))
{
Expand Down Expand Up @@ -133,7 +133,7 @@ void CWiiSaveCrypted::ReadHDR()
}
fpData_bin.Close();

AES_cbc_encrypt((const u8*)&_encryptedHeader, (u8*)&_header, HEADER_SZ, &m_AES_KEY, SD_IV, AES_DECRYPT);
aes_crypt_cbc(&m_AES_ctx, AES_DECRYPT, HEADER_SZ, SD_IV, (const u8*)&_encryptedHeader, (u8*)&_header);
u32 bannerSize = Common::swap32(_header.hdr.BannerSize);
if ((bannerSize < FULL_BNR_MIN) || (bannerSize > FULL_BNR_MAX) ||
(((bannerSize - BNR_SZ) % ICON_SZ) != 0))
Expand Down Expand Up @@ -197,7 +197,7 @@ void CWiiSaveCrypted::WriteHDR()
md5((u8*)&_header, HEADER_SZ, md5_calc);
memcpy(_header.hdr.Md5, md5_calc, 0x10);

AES_cbc_encrypt((const unsigned char *)&_header, (u8*)&_encryptedHeader, HEADER_SZ, &m_AES_KEY, SD_IV, AES_ENCRYPT);
aes_crypt_cbc(&m_AES_ctx, AES_ENCRYPT, HEADER_SZ, SD_IV, (const u8*)&_header, (u8*)&_encryptedHeader);

File::IOFile fpData_bin(encryptedSavePath, "wb");
if (!fpData_bin.WriteBytes(&_encryptedHeader, HEADER_SZ))
Expand Down Expand Up @@ -332,7 +332,7 @@ void CWiiSaveCrypted::ImportWiiSaveFiles()


memcpy(IV, _tmpFileHDR.IV, 0x10);
AES_cbc_encrypt((const unsigned char *)&_encryptedData[0], &_data[0], RoundedFileSize, &m_AES_KEY, IV, AES_DECRYPT);
aes_crypt_cbc(&m_AES_ctx, AES_DECRYPT, RoundedFileSize, IV, (const u8*)&_encryptedData[0], &_data[0]);

if (!File::Exists(fullFilePath) || AskYesNoT("%s already exists, overwrite?", fullFilePath.c_str()))
{
Expand Down Expand Up @@ -421,7 +421,7 @@ void CWiiSaveCrypted::ExportWiiSaveFiles()
b_valid = false;
}

AES_cbc_encrypt((const u8*)&_data[0], &_encryptedData[0], _roundedfileSize, &m_AES_KEY, tmpFileHDR.IV, AES_ENCRYPT);
aes_crypt_cbc(&m_AES_ctx, AES_ENCRYPT, _roundedfileSize, tmpFileHDR.IV, (const u8*)&_data[0], &_encryptedData[0]);

File::IOFile fpData_bin(encryptedSavePath, "ab");
if (!fpData_bin.WriteBytes(&_encryptedData[0], _roundedfileSize))
Expand Down
5 changes: 2 additions & 3 deletions Source/Core/DolphinWX/Src/MemoryCards/WiiSaveCrypted.h
Expand Up @@ -6,8 +6,8 @@
#define _WII_SAVE_CRYPTED

#include "StringUtil.h"
#include "Crypto/aes.h"
#include "Crypto/tools.h"
#include <polarssl/aes.h>
#include "polarssl/md5.h"

// --- this is used for encrypted Wii save files
Expand Down Expand Up @@ -35,8 +35,7 @@ class CWiiSaveCrypted
bool getPaths(bool forExport = false);
void ScanForFiles(std::string savDir, std::vector<std::string>&FilesList, u32 *_numFiles, u32 *_sizeFiles);


AES_KEY m_AES_KEY;
aes_context m_AES_ctx;
u8 SD_IV[0x10];
std::vector<std::string> FilesList;

Expand Down