Fixed AES-NI decrypting

This commit is contained in:
Jack Andersen 2015-06-28 22:59:54 -10:00
parent f297c7ff37
commit 3f31ad21a0
5 changed files with 33 additions and 28 deletions

View File

@ -8,6 +8,7 @@ namespace NOD
class DiscBase;
std::unique_ptr<DiscBase> OpenDiscFromImage(const char* path);
std::unique_ptr<DiscBase> OpenDiscFromImage(const char* path, bool& isWii);
}

View File

@ -67,8 +67,9 @@ public:
size_t i,j;
if (len%16)
len = len/16+1;
else len /= 16;
feedback = _mm_loadu_si128((__m128i*)iv);
else
len /= 16;
feedback = _mm_loadu_si128((__m128i*)iv);
for (i=0 ; i<len ; i++)
{
data = _mm_loadu_si128(&((__m128i*)inbuf)[i]);

View File

@ -63,5 +63,11 @@ std::unique_ptr<DiscBase> OpenDiscFromImage(const char* path, bool& isWii)
}
std::unique_ptr<DiscBase> OpenDiscFromImage(const char* path)
{
bool isWii;
return OpenDiscFromImage(path, isWii);
}
}

View File

@ -471,52 +471,50 @@ static inline __m128i AES_128_ASSIST (__m128i temp1, __m128i temp2)
void NiAES::setKey(const uint8_t* key)
{
__m128i temp1, temp2;
__m128i* Key_Schedule = m_ekey;
__m128i* Dec_Key_Schedule = m_dkey;
temp1 = _mm_loadu_si128((__m128i*)key);
Key_Schedule[0] = temp1;
Dec_Key_Schedule[0] = temp1;
m_ekey[0] = temp1;
m_dkey[10] = temp1;
temp2 = _mm_aeskeygenassist_si128 (temp1,0x1);
temp1 = AES_128_ASSIST(temp1, temp2);
Key_Schedule[1] = temp1;
Dec_Key_Schedule[1] = _mm_aesimc_si128(temp1);
m_ekey[1] = temp1;
m_dkey[9] = _mm_aesimc_si128(temp1);
temp2 = _mm_aeskeygenassist_si128 (temp1,0x2);
temp1 = AES_128_ASSIST(temp1, temp2);
Key_Schedule[2] = temp1;
Dec_Key_Schedule[2] = _mm_aesimc_si128(temp1);
m_ekey[2] = temp1;
m_dkey[8] = _mm_aesimc_si128(temp1);
temp2 = _mm_aeskeygenassist_si128 (temp1,0x4);
temp1 = AES_128_ASSIST(temp1, temp2);
Key_Schedule[3] = temp1;
Dec_Key_Schedule[3] = _mm_aesimc_si128(temp1);
m_ekey[3] = temp1;
m_dkey[7] = _mm_aesimc_si128(temp1);
temp2 = _mm_aeskeygenassist_si128 (temp1,0x8);
temp1 = AES_128_ASSIST(temp1, temp2);
Key_Schedule[4] = temp1;
Dec_Key_Schedule[4] = _mm_aesimc_si128(temp1);
m_ekey[4] = temp1;
m_dkey[6] = _mm_aesimc_si128(temp1);
temp2 = _mm_aeskeygenassist_si128 (temp1,0x10);
temp1 = AES_128_ASSIST(temp1, temp2);
Key_Schedule[5] = temp1;
Dec_Key_Schedule[5] = _mm_aesimc_si128(temp1);
m_ekey[5] = temp1;
m_dkey[5] = _mm_aesimc_si128(temp1);
temp2 = _mm_aeskeygenassist_si128 (temp1,0x20);
temp1 = AES_128_ASSIST(temp1, temp2);
Key_Schedule[6] = temp1;
Dec_Key_Schedule[6] = _mm_aesimc_si128(temp1);
m_ekey[6] = temp1;
m_dkey[4] = _mm_aesimc_si128(temp1);
temp2 = _mm_aeskeygenassist_si128 (temp1,0x40);
temp1 = AES_128_ASSIST(temp1, temp2);
Key_Schedule[7] = temp1;
Dec_Key_Schedule[7] = _mm_aesimc_si128(temp1);
m_ekey[7] = temp1;
m_dkey[3] = _mm_aesimc_si128(temp1);
temp2 = _mm_aeskeygenassist_si128 (temp1,0x80);
temp1 = AES_128_ASSIST(temp1, temp2);
Key_Schedule[8] = temp1;
Dec_Key_Schedule[8] = _mm_aesimc_si128(temp1);
m_ekey[8] = temp1;
m_dkey[2] = _mm_aesimc_si128(temp1);
temp2 = _mm_aeskeygenassist_si128 (temp1,0x1b);
temp1 = AES_128_ASSIST(temp1, temp2);
Key_Schedule[9] = temp1;
Dec_Key_Schedule[9] = _mm_aesimc_si128(temp1);
m_ekey[9] = temp1;
m_dkey[1] = _mm_aesimc_si128(temp1);
temp2 = _mm_aeskeygenassist_si128 (temp1,0x36);
temp1 = AES_128_ASSIST(temp1, temp2);
Key_Schedule[10] = temp1;
Dec_Key_Schedule[10] = temp1;
m_ekey[10] = temp1;
m_dkey[0] = temp1;
}

View File

@ -10,8 +10,7 @@ int main(int argc, char* argv[])
return -1;
}
bool isWii;
std::unique_ptr<NOD::DiscBase> disc = NOD::OpenDiscFromImage(argv[1], isWii);
std::unique_ptr<NOD::DiscBase> disc = NOD::OpenDiscFromImage(argv[1]);
if (!disc)
return -1;