Wipe all traces of OpenSSL's AES implementation. Use polarssl instead.

This commit is contained in:
Ryan Houdek
2013-10-27 18:27:07 +00:00
parent 0791a9ef80
commit 8e73e8ae5f
14 changed files with 32 additions and 1568 deletions

View File

@ -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"
@ -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)

View File

@ -4,7 +4,7 @@
#include <vector>
#include "Crypto/aes.h"
#include <polarssl/aes.h>
#include "VolumeCreator.h"
@ -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)

View File

@ -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];
}
@ -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
@ -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;
}
@ -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

View File

@ -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 ---
@ -38,7 +38,7 @@ private:
IBlobReader* m_pReader;
u8* m_pBuffer;
AES_KEY m_AES_KEY;
aes_context* m_AES_ctx;
u64 m_VolumeOffset;
u64 dataOffset;