From 3f31ad21a0b6cfdbbd1c6caa44cde246026149a5 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 28 Jun 2015 22:59:54 -1000 Subject: [PATCH] Fixed AES-NI decrypting --- include/NODLib.hpp | 1 + include/aes.hpp | 5 +++-- lib/NODLib.cpp | 6 ++++++ lib/aes.cpp | 46 ++++++++++++++++++++++------------------------ main.cpp | 3 +-- 5 files changed, 33 insertions(+), 28 deletions(-) diff --git a/include/NODLib.hpp b/include/NODLib.hpp index 631b619..d5ed09b 100644 --- a/include/NODLib.hpp +++ b/include/NODLib.hpp @@ -8,6 +8,7 @@ namespace NOD class DiscBase; +std::unique_ptr OpenDiscFromImage(const char* path); std::unique_ptr OpenDiscFromImage(const char* path, bool& isWii); } diff --git a/include/aes.hpp b/include/aes.hpp index 46b4244..80531fb 100644 --- a/include/aes.hpp +++ b/include/aes.hpp @@ -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 OpenDiscFromImage(const char* path, bool& isWii) } +std::unique_ptr OpenDiscFromImage(const char* path) +{ + bool isWii; + return OpenDiscFromImage(path, isWii); +} + } diff --git a/lib/aes.cpp b/lib/aes.cpp index 02ee58f..0c6c0db 100644 --- a/lib/aes.cpp +++ b/lib/aes.cpp @@ -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; } diff --git a/main.cpp b/main.cpp index e2404c2..0d85ec0 100644 --- a/main.cpp +++ b/main.cpp @@ -10,8 +10,7 @@ int main(int argc, char* argv[]) return -1; } - bool isWii; - std::unique_ptr disc = NOD::OpenDiscFromImage(argv[1], isWii); + std::unique_ptr disc = NOD::OpenDiscFromImage(argv[1]); if (!disc) return -1;