Skip to content

Commit

Permalink
Merge pull request #38 from luigoalma/master
Browse files Browse the repository at this point in the history
Taking out EVP_CipherFinal_ex and tiny extra checks
  • Loading branch information
ihaveamac authored Apr 16, 2019
2 parents f070d49 + f5ecae3 commit 292454b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions fuse3ds/hac/_crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ int (WINAPI *EVP_CipherInit_ex)(void*, void*, void*, const void*, void*, int) =
int (WINAPI *EVP_CIPHER_CTX_key_length)(void*) = NULL;
void (WINAPI *EVP_CIPHER_CTX_set_padding)(void*, int) = NULL;
int (WINAPI *EVP_CipherUpdate)(void*, void*, int*, const void*, int) = NULL;
int (WINAPI *EVP_CipherFinal_ex)(void*, void*, int*) = NULL;
void (WINAPI *EVP_CIPHER_CTX_free)(void*) = NULL;
unsigned long (WINAPI *OpenSSL_version_num)() = NULL;

Expand All @@ -270,7 +269,7 @@ bool openssl_crypt(const u8* key, const u8* data, u8* out) {
if(EVP_CIPHER_CTX_key_length(ctx) != 16) break;
EVP_CIPHER_CTX_set_padding(ctx, 0);
int foo;
if(!EVP_CipherUpdate(ctx, out, &foo, data, 16) && !EVP_CipherFinal_ex(ctx, out + foo, &foo)) break;
if(!EVP_CipherUpdate(ctx, out, &foo, data, 16)) break;
ret = true;
} while(0);
EVP_CIPHER_CTX_free(ctx);
Expand Down Expand Up @@ -530,7 +529,11 @@ static void load_lcrypto() {
#else
static const char* const names[] = {};
#endif
loadlock.lock();
try {loadlock.lock();} catch(...) {return;}
if(!lib_to_load) {
loadlock.unlock();
return;
}
bool found = false;
try {
std::string *paths[2] = {nullptr, nullptr};
Expand All @@ -553,14 +556,12 @@ static void load_lcrypto() {
lcrypto.GetFunctionPtr("EVP_CIPHER_CTX_key_length", (void**)&EVP_CIPHER_CTX_key_length);
lcrypto.GetFunctionPtr("EVP_CIPHER_CTX_set_padding", (void**)&EVP_CIPHER_CTX_set_padding);
lcrypto.GetFunctionPtr("EVP_CipherUpdate", (void**)&EVP_CipherUpdate);
lcrypto.GetFunctionPtr("EVP_CipherFinal_ex", (void**)&EVP_CipherFinal_ex);
lcrypto.GetFunctionPtr("EVP_CIPHER_CTX_free", (void**)&EVP_CIPHER_CTX_free);
lcrypto.GetFunctionPtr("OpenSSL_version_num", (void**)&OpenSSL_version_num);

if(!EVP_CIPHER_CTX_new || !EVP_aes_128_ecb || !EVP_CipherInit_ex ||
!EVP_CIPHER_CTX_key_length || !EVP_CIPHER_CTX_set_padding ||
!EVP_CipherUpdate || !EVP_CipherFinal_ex || !EVP_CIPHER_CTX_free ||
!OpenSSL_version_num) {
!EVP_CipherUpdate || !EVP_CIPHER_CTX_free || !OpenSSL_version_num) {
lcrypto.Unload();
continue;
}
Expand Down

0 comments on commit 292454b

Please sign in to comment.