From c065d22ddaf0ac7b0e1efd99795ede0ac4dbd9f0 Mon Sep 17 00:00:00 2001 From: Tom Lally Date: Tue, 30 Aug 2022 05:10:33 +0100 Subject: [PATCH 1/5] Removed THREAD_LOCAL macro. (#101) --- src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp | 4 ++-- src/Cafe/OS/libs/nlibcurl/nlibcurl.cpp | 4 ++-- src/Common/precompiled.h | 8 -------- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp b/src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp index a57b4473..e01fda73 100644 --- a/src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp +++ b/src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp @@ -45,8 +45,8 @@ namespace coreinit bool g_isMulticoreMode; - THREAD_LOCAL uint32 t_assignedCoreIndex; - THREAD_LOCAL Fiber* t_schedulerFiber; + thread_local uint32 t_assignedCoreIndex; + thread_local Fiber* t_schedulerFiber; struct OSHostThread { diff --git a/src/Cafe/OS/libs/nlibcurl/nlibcurl.cpp b/src/Cafe/OS/libs/nlibcurl/nlibcurl.cpp index 4923eae2..907ed67c 100644 --- a/src/Cafe/OS/libs/nlibcurl/nlibcurl.cpp +++ b/src/Cafe/OS/libs/nlibcurl/nlibcurl.cpp @@ -201,8 +201,8 @@ static_assert(sizeof(CURLMsg_t) <= 0xC, "sizeof(CURLMsg_t)"); size_t header_callback(char* buffer, size_t size, size_t nitems, void* userdata); -THREAD_LOCAL PPCConcurrentQueue* g_callerQueue; -THREAD_LOCAL ConcurrentQueue* g_threadQueue; +thread_local PPCConcurrentQueue* g_callerQueue; +thread_local ConcurrentQueue* g_threadQueue; void CurlWorkerThread(CURL_t* curl, PPCConcurrentQueue* callerQueue, ConcurrentQueue* threadQueue) { g_callerQueue = callerQueue; diff --git a/src/Common/precompiled.h b/src/Common/precompiled.h index dfc02dda..bb78f020 100644 --- a/src/Common/precompiled.h +++ b/src/Common/precompiled.h @@ -225,14 +225,6 @@ typedef union _LARGE_INTEGER { #define DEBUG_BREAK raise(SIGTRAP) #endif -#if defined(_MSC_VER) - #define THREAD_LOCAL __declspec(thread) -#elif defined(__GNUC__) - #define THREAD_LOCAL __thread -#else - #define THREAD_LOCAL thread_local -#endif - #if defined(_MSC_VER) #define DLLEXPORT __declspec(dllexport) #elif defined(__GNUC__) From 5b9483f7d835f95fba75728dc4296ed068c68852 Mon Sep 17 00:00:00 2001 From: Stefano Calabrese Date: Tue, 30 Aug 2022 05:14:17 +0100 Subject: [PATCH 2/5] Add Italian translation for Linux distributions (#116) --- dist/linux/info.cemu.Cemu.desktop | 1 + dist/linux/info.cemu.Cemu.metainfo.xml | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/dist/linux/info.cemu.Cemu.desktop b/dist/linux/info.cemu.Cemu.desktop index 74fd48a8..186cefaf 100644 --- a/dist/linux/info.cemu.Cemu.desktop +++ b/dist/linux/info.cemu.Cemu.desktop @@ -12,6 +12,7 @@ Comment[ru]=Программа для эмуляции игр и приложе Comment[fr]=Application pour émuler des jeux et des applications Wii U sur PC Comment[nl]=Applicatie om Wii U spellen en applicaties te emuleren op PC Comment[es]=Software para emular juegos y aplicaciones de Wii U en PC +Comment[it]=Software per emulare giochi ed applicazioni del Wii U su PC Categories=Game;Emulator; Keywords=Nintendo; MimeType=application/x-wii-u-rom; diff --git a/dist/linux/info.cemu.Cemu.metainfo.xml b/dist/linux/info.cemu.Cemu.metainfo.xml index bfea493e..dfc08db1 100644 --- a/dist/linux/info.cemu.Cemu.metainfo.xml +++ b/dist/linux/info.cemu.Cemu.metainfo.xml @@ -8,6 +8,7 @@ Application pour émuler des jeux et applications Wii U sur PC Applicatie om Wii U spellen en applicaties te emuleren op PC Software para emular juegos y aplicaciones de Wii U en PC + Software per emulare giochi ed applicazioni del Wii U su PC Cemu Project info.cemu.Cemu.desktop CC0-1.0 @@ -18,16 +19,19 @@

Cemu est un émulateur de Wii U capable de lancer la plupart des jeux Wii U et des homebrews en interface de jeu. Crée par Exzap, et développé en C/C++.

Cemu is een Nintendo Wii U emulator die de meeste Wii U en Homebrew games speelbaar kan runnen. Het project is begonnen door Exzap, en het is geschreven in C/C++.

Cemu es un emulador de Nintendo Wii U que es capaz de ejecutar la mayoría de los juegos de Wii U y homebrew en un estado jugable. Creado por Exzap, y escrito en C y C++.

+

Cemu è un emulatore del Nintendo Wii U capace di riprodurre la maggior parte dei giochi ed homebrew Wii U in stato giocabile. Creato da Exzap, e scritto in C/C++.

This emulator aims at providing both high-accuracy and performance, and is actively being developed with new features and fixes to increase compatibility, convenience and usability.

Dieser Emulator zielt darauf ab, sowohl hohe Genauigkeit als auch Leistung zu bieten, und wird aktiv mit neuen Funktionen und Korrekturen weiterentwickelt, um Kompatibilität, Komfort und Benutzerfreundlichkeit zu verbessern.

Cet émulateur vise à la fois à offrir fidélité et performance, il est activement développé avec des nouvelles fonctionnalités et des correctifs pour augmenter la compatibilité, la commodité et la facilité d'utilisation.

De emulator richt zich op integriteit en snelheid, en wordt continu verder ontwikkeld met nieuwe toevoegingen en fixes om de compatibiliteit, het gemak en de gebruiksvriendelijkheid te verbeteren.

Este emulador tiene como objetivo proporcionar tanto alta precisión como rendimiento y se desarrolla activamente con nuevas características y correcciones para mejorar la compatibilidad, la comodidad y la usabilidad.

+

Questo emulatore ha l'obiettivo di fornire sia alta precisione che alte prestazioni, ed è in continuo sviluppo con nuove funzionalità e correzioni per aumentare la compatibilità, la comodità e la fuibilità.

It was written from scratch and development on the project began roughly early 2015.

Er wird seit Anfang 2015 entwickelt.

Il a été écrit à partir de zéro et son développement a débuté vers le début de l'année 2015.

Ontwikkeling van Cemu begon ongeveer in het voorjaar van 2015.

Fue escrito desde cero y el desarrollo del proyecto comenzó aproximadamente a principios de 2015.

+

È stato scritto da zero e lo sviluppo del progetto è iniziato circa all'inizio del 2015.

From 1fba15a4c502d19dec47a2319b299146a55b7182 Mon Sep 17 00:00:00 2001 From: William <31864305+baduhai@users.noreply.github.com> Date: Tue, 30 Aug 2022 06:17:53 +0200 Subject: [PATCH 3/5] Add pt_BR to desktop and metainfo files (#110) --- dist/linux/info.cemu.Cemu.desktop | 2 ++ dist/linux/info.cemu.Cemu.metainfo.xml | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/dist/linux/info.cemu.Cemu.desktop b/dist/linux/info.cemu.Cemu.desktop index 186cefaf..6983e5cb 100644 --- a/dist/linux/info.cemu.Cemu.desktop +++ b/dist/linux/info.cemu.Cemu.desktop @@ -6,12 +6,14 @@ Icon=info.cemu.Cemu Exec=cemu GenericName=Wii U Emulator GenericName[es]=Emulador de Wii U +GenericName[pt_BR]=Emulador de Wii U Comment=Software to emulate Wii U games and applications on PC Comment[de]=Software zum emulieren von Wii U Spielen und Anwendungen auf dem PC Comment[ru]=Программа для эмуляции игр и приложений Wii U на PC Comment[fr]=Application pour émuler des jeux et des applications Wii U sur PC Comment[nl]=Applicatie om Wii U spellen en applicaties te emuleren op PC Comment[es]=Software para emular juegos y aplicaciones de Wii U en PC +Comment[pt_BR]=Software para emular jogos e aplicativos de Wii U no PC Comment[it]=Software per emulare giochi ed applicazioni del Wii U su PC Categories=Game;Emulator; Keywords=Nintendo; diff --git a/dist/linux/info.cemu.Cemu.metainfo.xml b/dist/linux/info.cemu.Cemu.metainfo.xml index dfc08db1..29e31506 100644 --- a/dist/linux/info.cemu.Cemu.metainfo.xml +++ b/dist/linux/info.cemu.Cemu.metainfo.xml @@ -8,6 +8,7 @@ Application pour émuler des jeux et applications Wii U sur PC Applicatie om Wii U spellen en applicaties te emuleren op PC Software para emular juegos y aplicaciones de Wii U en PC + Software para emular jogos e aplicativos de Wii U no PC Software per emulare giochi ed applicazioni del Wii U su PC Cemu Project info.cemu.Cemu.desktop @@ -19,18 +20,21 @@

Cemu est un émulateur de Wii U capable de lancer la plupart des jeux Wii U et des homebrews en interface de jeu. Crée par Exzap, et développé en C/C++.

Cemu is een Nintendo Wii U emulator die de meeste Wii U en Homebrew games speelbaar kan runnen. Het project is begonnen door Exzap, en het is geschreven in C/C++.

Cemu es un emulador de Nintendo Wii U que es capaz de ejecutar la mayoría de los juegos de Wii U y homebrew en un estado jugable. Creado por Exzap, y escrito en C y C++.

+

Cemu é um emulador de Nintendo Wii U que é capaz de executar a maioría dos jogos de Wii U e homebrew em um estado jogavel. Criado por Exzap, e escrito em C e C++.

Cemu è un emulatore del Nintendo Wii U capace di riprodurre la maggior parte dei giochi ed homebrew Wii U in stato giocabile. Creato da Exzap, e scritto in C/C++.

This emulator aims at providing both high-accuracy and performance, and is actively being developed with new features and fixes to increase compatibility, convenience and usability.

Dieser Emulator zielt darauf ab, sowohl hohe Genauigkeit als auch Leistung zu bieten, und wird aktiv mit neuen Funktionen und Korrekturen weiterentwickelt, um Kompatibilität, Komfort und Benutzerfreundlichkeit zu verbessern.

Cet émulateur vise à la fois à offrir fidélité et performance, il est activement développé avec des nouvelles fonctionnalités et des correctifs pour augmenter la compatibilité, la commodité et la facilité d'utilisation.

De emulator richt zich op integriteit en snelheid, en wordt continu verder ontwikkeld met nieuwe toevoegingen en fixes om de compatibiliteit, het gemak en de gebruiksvriendelijkheid te verbeteren.

Este emulador tiene como objetivo proporcionar tanto alta precisión como rendimiento y se desarrolla activamente con nuevas características y correcciones para mejorar la compatibilidad, la comodidad y la usabilidad.

+

Esse emulador visa proporcionar tanto alta precisão como rendimento e está sendo ativamente desenvolvido com novas características e correções para melhorar a compatibilidade, a comodidade e a usabilidade.

Questo emulatore ha l'obiettivo di fornire sia alta precisione che alte prestazioni, ed è in continuo sviluppo con nuove funzionalità e correzioni per aumentare la compatibilità, la comodità e la fuibilità.

It was written from scratch and development on the project began roughly early 2015.

Er wird seit Anfang 2015 entwickelt.

Il a été écrit à partir de zéro et son développement a débuté vers le début de l'année 2015.

Ontwikkeling van Cemu begon ongeveer in het voorjaar van 2015.

Fue escrito desde cero y el desarrollo del proyecto comenzó aproximadamente a principios de 2015.

+

Foi escrito do zero e o desenvolvimento do projeto começou aproximadamente a princípio de 2015.

È stato scritto da zero e lo sviluppo del progetto è iniziato circa all'inizio del 2015.

From 86c0a8f698994693e98b4b13efd044f374682afe Mon Sep 17 00:00:00 2001 From: "P. \"Ivory\" Vasilopoulos" Date: Tue, 30 Aug 2022 06:24:23 +0200 Subject: [PATCH 4/5] Add Greek translation for Linux distributions (#106) --- dist/linux/info.cemu.Cemu.desktop | 2 ++ dist/linux/info.cemu.Cemu.metainfo.xml | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/dist/linux/info.cemu.Cemu.desktop b/dist/linux/info.cemu.Cemu.desktop index 6983e5cb..85b10cd8 100644 --- a/dist/linux/info.cemu.Cemu.desktop +++ b/dist/linux/info.cemu.Cemu.desktop @@ -5,6 +5,7 @@ Terminal=false Icon=info.cemu.Cemu Exec=cemu GenericName=Wii U Emulator +GenericName[el]=Πρόγραμμα προσομοίωσης Wii U GenericName[es]=Emulador de Wii U GenericName[pt_BR]=Emulador de Wii U Comment=Software to emulate Wii U games and applications on PC @@ -12,6 +13,7 @@ Comment[de]=Software zum emulieren von Wii U Spielen und Anwendungen auf dem PC Comment[ru]=Программа для эмуляции игр и приложений Wii U на PC Comment[fr]=Application pour émuler des jeux et des applications Wii U sur PC Comment[nl]=Applicatie om Wii U spellen en applicaties te emuleren op PC +Comment[el]=Πρόγραμμα προσομοίωσης παιχνιδιών και εφαρμογών Wii U στον υπολογιστή Comment[es]=Software para emular juegos y aplicaciones de Wii U en PC Comment[pt_BR]=Software para emular jogos e aplicativos de Wii U no PC Comment[it]=Software per emulare giochi ed applicazioni del Wii U su PC diff --git a/dist/linux/info.cemu.Cemu.metainfo.xml b/dist/linux/info.cemu.Cemu.metainfo.xml index 29e31506..5a361cdc 100644 --- a/dist/linux/info.cemu.Cemu.metainfo.xml +++ b/dist/linux/info.cemu.Cemu.metainfo.xml @@ -7,6 +7,7 @@ Software zum emulieren von Wii U Spielen und Anwendungen auf dem PC Application pour émuler des jeux et applications Wii U sur PC Applicatie om Wii U spellen en applicaties te emuleren op PC + Πρόγραμμα προσομοίωσης παιχνιδιών και εφαρμογών Wii U στον υπολογιστή Software para emular juegos y aplicaciones de Wii U en PC Software para emular jogos e aplicativos de Wii U no PC Software per emulare giochi ed applicazioni del Wii U su PC @@ -19,6 +20,7 @@

Cemu ist ein Nintendo Wii U-Emulator, der die meisten Wii U Spiele und Homebrew in einem spielbaren Zustand ausführen kann. Erstellt von Exzap, und geschrieben in C/C++.

Cemu est un émulateur de Wii U capable de lancer la plupart des jeux Wii U et des homebrews en interface de jeu. Crée par Exzap, et développé en C/C++.

Cemu is een Nintendo Wii U emulator die de meeste Wii U en Homebrew games speelbaar kan runnen. Het project is begonnen door Exzap, en het is geschreven in C/C++.

+

Το Cemu είναι ένας προσομοιωτής της κονσόλας Nintendo Wii U που υποστηρίζει τεπίσημα παιχνίδια, καθώς και μη επίσημα προγράμματα ("homebrew"), για το Wii U. Δημιουργήθηκε από τον Exzap σε C/C++.

Cemu es un emulador de Nintendo Wii U que es capaz de ejecutar la mayoría de los juegos de Wii U y homebrew en un estado jugable. Creado por Exzap, y escrito en C y C++.

Cemu é um emulador de Nintendo Wii U que é capaz de executar a maioría dos jogos de Wii U e homebrew em um estado jogavel. Criado por Exzap, e escrito em C e C++.

Cemu è un emulatore del Nintendo Wii U capace di riprodurre la maggior parte dei giochi ed homebrew Wii U in stato giocabile. Creato da Exzap, e scritto in C/C++.

@@ -26,6 +28,7 @@

Dieser Emulator zielt darauf ab, sowohl hohe Genauigkeit als auch Leistung zu bieten, und wird aktiv mit neuen Funktionen und Korrekturen weiterentwickelt, um Kompatibilität, Komfort und Benutzerfreundlichkeit zu verbessern.

Cet émulateur vise à la fois à offrir fidélité et performance, il est activement développé avec des nouvelles fonctionnalités et des correctifs pour augmenter la compatibilité, la commodité et la facilité d'utilisation.

De emulator richt zich op integriteit en snelheid, en wordt continu verder ontwikkeld met nieuwe toevoegingen en fixes om de compatibiliteit, het gemak en de gebruiksvriendelijkheid te verbeteren.

+

Ο προσομοιωτής αυτός στοχεύει τόσο στην ακρίβεια, όσο και στην ταχύτητα. Βελτιώνεται συνεχώς με νέες δυνατότητες και διορθώσεις που τον καθιστούν πιο βολικό, εύκολο στην χρήση και συμβατό με περισσότερα παιχνίδια.

Este emulador tiene como objetivo proporcionar tanto alta precisión como rendimiento y se desarrolla activamente con nuevas características y correcciones para mejorar la compatibilidad, la comodidad y la usabilidad.

Esse emulador visa proporcionar tanto alta precisão como rendimento e está sendo ativamente desenvolvido com novas características e correções para melhorar a compatibilidade, a comodidade e a usabilidade.

Questo emulatore ha l'obiettivo di fornire sia alta precisione che alte prestazioni, ed è in continuo sviluppo con nuove funzionalità e correzioni per aumentare la compatibilità, la comodità e la fuibilità.

@@ -33,6 +36,7 @@

Er wird seit Anfang 2015 entwickelt.

Il a été écrit à partir de zéro et son développement a débuté vers le début de l'année 2015.

Ontwikkeling van Cemu begon ongeveer in het voorjaar van 2015.

+

Το Cemu βρίσκεται υπό ανάπτυξη από το 2015.

Fue escrito desde cero y el desarrollo del proyecto comenzó aproximadamente a principios de 2015.

Foi escrito do zero e o desenvolvimento do projeto começou aproximadamente a princípio de 2015.

È stato scritto da zero e lo sviluppo del progetto è iniziato circa all'inizio del 2015.

From 2d42c885da07a52075623d72181143e1c7925dbc Mon Sep 17 00:00:00 2001 From: bitscher Date: Tue, 30 Aug 2022 00:27:25 -0700 Subject: [PATCH 5/5] Fix various compiler warnings and update OpenSSL hash functions (#119) * Update OpenSSL hash functions to OpenSSL 3.0 * Fix invalid sscanf format in DownloadManager * Fix unset return value warning * Fix erroneous check on otpMem in iosu_crypto --- src/Cafe/Account/Account.cpp | 4 +- src/Cafe/Filesystem/FST/FST.cpp | 47 +++++++------------ src/Cafe/HW/Latte/Core/FetchShader.cpp | 17 ++++--- src/Cafe/HW/Latte/Renderer/Vulkan/VKRBase.h | 1 + .../Vulkan/VulkanPipelineStableCache.cpp | 7 +-- src/Cafe/IOSU/legacy/iosu_act.cpp | 36 +++++++------- src/Cafe/IOSU/legacy/iosu_crypto.cpp | 13 +---- src/Cafe/OS/libs/nn_idbe/nn_idbe.cpp | 8 ++-- .../Tools/DownloadManager/DownloadManager.cpp | 2 +- src/Cemu/napi/napi_idbe.cpp | 9 ++-- src/Cemu/ncrypto/ncrypto.cpp | 30 ++++-------- src/Cemu/ncrypto/ncrypto.h | 2 +- src/gui/ChecksumTool.cpp | 17 ++++--- 13 files changed, 79 insertions(+), 114 deletions(-) diff --git a/src/Cafe/Account/Account.cpp b/src/Cafe/Account/Account.cpp index bf049bf6..b8d3d52e 100644 --- a/src/Cafe/Account/Account.cpp +++ b/src/Cafe/Account/Account.cpp @@ -562,9 +562,9 @@ void makePWHash(uint8* input, sint32 length, uint32 magic, uint8* output) buffer[2] = (magic >> 16) & 0xFF; buffer[3] = (magic >> 24) & 0xFF; memcpy(buffer + 8, input, length); - uint8 md[32]; + uint8 md[SHA256_DIGEST_LENGTH]; SHA256(buffer, 8 + length, md); - memcpy(output, md, 32); + memcpy(output, md, SHA256_DIGEST_LENGTH); } void actPwTest() diff --git a/src/Cafe/Filesystem/FST/FST.cpp b/src/Cafe/Filesystem/FST/FST.cpp index a230a3a6..0a28c251 100644 --- a/src/Cafe/Filesystem/FST/FST.cpp +++ b/src/Cafe/Filesystem/FST/FST.cpp @@ -3,7 +3,8 @@ #include "Cemu/ncrypto/ncrypto.h" #include "Cafe/Filesystem/WUD/wud.h" #include "util/crypto/aes128.h" -#include "openssl/sha.h" +#include "openssl/evp.h" /* EVP_Digest */ +#include "openssl/sha.h" /* SHA1 / SHA256_DIGEST_LENGTH */ #include "fstUtil.h" #include "FST.h" @@ -1021,12 +1022,11 @@ bool FSTVerifier::VerifyContentFile(FileStream* fileContent, const NCrypto::AesK iv[1] = (contentIndex >> 0) & 0xFF; // raw content uint64 remainingBytes = contentSize; - SHA_CTX sha1Ctx; - SHA256_CTX sha256Ctx; - if (isSHA1) - SHA1_Init(&sha1Ctx); - else - SHA256_Init(&sha256Ctx); + uint8 calculatedHash[SHA256_DIGEST_LENGTH]; + + EVP_MD_CTX *ctx = EVP_MD_CTX_new(); + EVP_DigestInit(ctx, isSHA1 ? EVP_sha1() : EVP_sha256()); + while (remainingBytes > 0) { uint32 bytesToRead = (uint32)std::min(remainingBytes, (uint64)buffer.size()); @@ -1035,26 +1035,13 @@ bool FSTVerifier::VerifyContentFile(FileStream* fileContent, const NCrypto::AesK if (bytesRead != bytesToReadPadded) return false; AES128_CBC_decrypt_updateIV(buffer.data(), buffer.data(), bytesToReadPadded, key->b, iv); - if (isSHA1) - SHA1_Update(&sha1Ctx, buffer.data(), bytesToRead); - else - SHA256_Update(&sha256Ctx, buffer.data(), bytesToRead); + EVP_DigestUpdate(ctx, buffer.data(), bytesToRead); remainingBytes -= bytesToRead; } - uint8 calculatedHash[32]; - if (isSHA1) - SHA1_Final(calculatedHash, &sha1Ctx); - else - SHA256_Final(calculatedHash, &sha256Ctx); - return memcmp(calculatedHash, tmdContentHash, isSHA1 ? 20 : 32) == 0; -} - -void _SHA1Hash(void* data, size_t length, NCrypto::CHash160& hashOut) -{ - SHA_CTX sha1Ctx; - SHA1_Init(&sha1Ctx); - SHA1_Update(&sha1Ctx, data, length); - SHA1_Final(hashOut.b, &sha1Ctx); + unsigned int md_len; + EVP_DigestFinal_ex(ctx, calculatedHash, &md_len); + EVP_MD_CTX_free(ctx); + return memcmp(calculatedHash, tmdContentHash, md_len) == 0; } bool FSTVerifier::VerifyHashedContentFile(FileStream* fileContent, const NCrypto::AesKey* key, uint32 contentIndex, uint32 contentSize, uint32 contentSizePadded, bool isSHA1, const uint8* tmdContentHash) @@ -1083,10 +1070,10 @@ bool FSTVerifier::VerifyHashedContentFile(FileStream* fileContent, const NCrypto // generate H0 hash and compare NCrypto::CHash160 h0; - _SHA1Hash(block.getFileData(), BLOCK_FILE_SIZE, h0); - if (memcmp(h0.b, block.getH0Hash(h0Index & 0xF), 20) != 0) + SHA1(block.getFileData(), BLOCK_FILE_SIZE, h0.b); + if (memcmp(h0.b, block.getH0Hash(h0Index & 0xF), sizeof(h0.b)) != 0) return false; - std::memcpy(h0List[h0Index].b, h0.b, 20); + std::memcpy(h0List[h0Index].b, h0.b, sizeof(h0.b)); // Sixteen H0 hashes become one H1 hash if (((h0Index + 1) % 16) == 0 && h0Index > 0) @@ -1094,8 +1081,8 @@ bool FSTVerifier::VerifyHashedContentFile(FileStream* fileContent, const NCrypto uint32 h1Index = ((h0Index - 15) / 16); NCrypto::CHash160 h1; - _SHA1Hash(h0List.data() + h1Index * 16, sizeof(NCrypto::CHash160) * 16, h1); - if (memcmp(h1.b, block.getH1Hash(h1Index&0xF), 20) != 0) + SHA1((unsigned char *) (h0List.data() + h1Index * 16), sizeof(NCrypto::CHash160) * 16, h1.b); + if (memcmp(h1.b, block.getH1Hash(h1Index&0xF), sizeof(h1.b)) != 0) return false; } // todo - repeat same for H1 and H2 diff --git a/src/Cafe/HW/Latte/Core/FetchShader.cpp b/src/Cafe/HW/Latte/Core/FetchShader.cpp index d6bbc217..a7e9d3ef 100644 --- a/src/Cafe/HW/Latte/Core/FetchShader.cpp +++ b/src/Cafe/HW/Latte/Core/FetchShader.cpp @@ -10,7 +10,8 @@ #include "Cafe/HW/Latte/ISA/LatteInstructions.h" #include "util/containers/LookupTableL3.h" #include "util/helpers/fspinlock.h" -#include +#include /* SHA1_DIGEST_LENGTH */ +#include /* EVP_Digest */ uint32 LatteShaderRecompiler_getAttributeSize(LatteParsedFetchShaderAttribute_t* attrib) { @@ -122,20 +123,22 @@ uint32 LatteParsedFetchShaderBufferGroup_t::getCurrentBufferStride(uint32* conte void LatteFetchShader::CalculateFetchShaderVkHash() { // calculate SHA1 of all states that are part of the Vulkan graphics pipeline - SHA_CTX ctx; - SHA1_Init(&ctx); + EVP_MD_CTX *ctx = EVP_MD_CTX_new(); + EVP_DigestInit(ctx, EVP_sha1()); for(auto& group : bufferGroups) { // offsets for (sint32 t = 0; t < group.attribCount; t++) { uint32 offset = group.attrib[t].offset; - SHA1_Update(&ctx, &t, sizeof(t)); - SHA1_Update(&ctx, &offset, sizeof(offset)); + EVP_DigestUpdate(ctx, &t, sizeof(t)); + EVP_DigestUpdate(ctx, &offset, sizeof(offset)); } } - uint8 shaDigest[20]; - SHA1_Final(shaDigest, &ctx); + uint8 shaDigest[SHA_DIGEST_LENGTH]; + EVP_DigestFinal_ex(ctx, shaDigest, NULL); + EVP_MD_CTX_free(ctx); + // fold SHA1 hash into a 64bit value uint64 h = *(uint64*)(shaDigest + 0); h += *(uint64*)(shaDigest + 8); diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/VKRBase.h b/src/Cafe/HW/Latte/Renderer/Vulkan/VKRBase.h index 89eabdc1..a8a1376f 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/VKRBase.h +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/VKRBase.h @@ -50,6 +50,7 @@ public: VKRMoveableRefCounter& operator=(VKRMoveableRefCounter&& rhs) noexcept { cemu_assert(false); + return *this; } void addRef(VKRMoveableRefCounter* refTarget) diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanPipelineStableCache.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanPipelineStableCache.cpp index ddf5e273..4fab241b 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanPipelineStableCache.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanPipelineStableCache.cpp @@ -420,11 +420,8 @@ void VulkanPipelineStableCache::WorkerThread() SerializePipeline(memWriter, *job); auto blob = memWriter.getResult(); // file name is derived from data hash - uint8 hash[256 / 8]; - SHA256_CTX sha256; - SHA256_Init(&sha256); - SHA256_Update(&sha256, blob.data(), blob.size()); - SHA256_Final(hash, &sha256); + uint8 hash[SHA256_DIGEST_LENGTH]; + SHA256(blob.data(), blob.size(), hash); uint64 nameA = *(uint64be*)(hash + 0); uint64 nameB = *(uint64be*)(hash + 8); s_cache->AddFileAsync({ nameA, nameB }, blob.data(), blob.size()); diff --git a/src/Cafe/IOSU/legacy/iosu_act.cpp b/src/Cafe/IOSU/legacy/iosu_act.cpp index 9510a547..7c5ea37d 100644 --- a/src/Cafe/IOSU/legacy/iosu_act.cpp +++ b/src/Cafe/IOSU/legacy/iosu_act.cpp @@ -7,7 +7,8 @@ #include #include -#include "openssl/sha.h" +#include "openssl/evp.h" /* EVP_Digest */ +#include "openssl/sha.h" /* SHA256_DIGEST_LENGTH */ #include "Cafe/Account/Account.h" #include "config/ActiveSettings.h" #include "util/helpers/helpers.h" @@ -557,24 +558,25 @@ int iosuAct_thread() // 6 bytes from the end of UUID // bytes 10-15 are used from the hash and replace the last 6 bytes of the UUID - SHA256_CTX ctx_sha256; - SHA256_Init(&ctx_sha256); + EVP_MD_CTX *ctx_sha256 = EVP_MD_CTX_new(); + EVP_DigestInit(ctx_sha256, EVP_sha256()); - uint8 tempArray[4]; uint32 name = (uint32)actCemuRequest->uuidName; - tempArray[0] = (name >> 24) & 0xFF; - tempArray[1] = (name >> 16) & 0xFF; - tempArray[2] = (name >> 8) & 0xFF; - tempArray[3] = (name >> 0) & 0xFF; - SHA256_Update(&ctx_sha256, tempArray, 4); - tempArray[0] = 0x3A; - tempArray[1] = 0x27; - tempArray[2] = 0x5E; - tempArray[3] = 0x09; - SHA256_Update(&ctx_sha256, tempArray, 4); - SHA256_Update(&ctx_sha256, actCemuRequest->resultBinary.binBuffer+10, 6); - uint8 h[32]; - SHA256_Final(h, &ctx_sha256); + uint8 tempArray[] = { + (name >> 24) & 0xFF, + (name >> 16) & 0xFF, + (name >> 8) & 0xFF, + (name >> 0) & 0xFF, + 0x3A, + 0x27, + 0x5E, + 0x09, + }; + EVP_DigestUpdate(ctx_sha256, tempArray, sizeof(tempArray)); + EVP_DigestUpdate(ctx_sha256, actCemuRequest->resultBinary.binBuffer+10, 6); + uint8 h[SHA256_DIGEST_LENGTH]; + EVP_DigestFinal_ex(ctx_sha256, h, NULL); + EVP_MD_CTX_free(ctx_sha256); memcpy(actCemuRequest->resultBinary.binBuffer + 0xA, h + 0xA, 6); } diff --git a/src/Cafe/IOSU/legacy/iosu_crypto.cpp b/src/Cafe/IOSU/legacy/iosu_crypto.cpp index 28419e85..0433995c 100644 --- a/src/Cafe/IOSU/legacy/iosu_crypto.cpp +++ b/src/Cafe/IOSU/legacy/iosu_crypto.cpp @@ -6,7 +6,6 @@ #include "openssl/ec.h" #include "openssl/x509.h" #include "openssl/ssl.h" -#include "openssl/sha.h" #include "openssl/ecdsa.h" #include "util/crypto/aes128.h" @@ -54,7 +53,7 @@ bool iosuCrypto_getDeviceId(uint32* deviceId) { uint32be deviceIdBE; *deviceId = 0; - if (otpMem == nullptr) + if (!hasOtpMem) return false; iosuCrypto_readOtpData(&deviceIdBE, 0x87, sizeof(uint32)); *deviceId = (uint32)deviceIdBE; @@ -228,7 +227,7 @@ void iosuCrypto_generateDeviceCertificate() { static_assert(sizeof(g_wiiuDeviceCert) == 0x180); memset(&g_wiiuDeviceCert, 0, sizeof(g_wiiuDeviceCert)); - if (otpMem == nullptr) + if (!hasOtpMem) return; // cant generate certificate without OPT // set header based on otp security mode @@ -293,14 +292,6 @@ void iosuCrypto_generateDeviceCertificate() BN_CTX_free(context); } -void CertECC_generateHashForSignature(CertECC_t& cert, CHash256& hashOut) -{ - SHA256_CTX sha256; - SHA256_Init(&sha256); - SHA256_Update(&sha256, cert.certificateSubject, 0x100); - SHA256_Final(hashOut.b, &sha256); -} - bool iosuCrypto_hasAllDataForLogin() { if (hasOtpMem == false) diff --git a/src/Cafe/OS/libs/nn_idbe/nn_idbe.cpp b/src/Cafe/OS/libs/nn_idbe/nn_idbe.cpp index 55f064ac..72ea5231 100644 --- a/src/Cafe/OS/libs/nn_idbe/nn_idbe.cpp +++ b/src/Cafe/OS/libs/nn_idbe/nn_idbe.cpp @@ -100,13 +100,13 @@ namespace nn // decrypt data uint8 iv[16]; memcpy(iv, idbeAesIv, sizeof(iv)); - uint8 decryptedSHA256[32]; + uint8 decryptedSHA256[SHA256_DIGEST_LENGTH]; AES128_CBC_decrypt_updateIV(decryptedSHA256, iconInput->hashSHA256, sizeof(decryptedSHA256), idbeAesKeys + 16 * idbeHeader->keyIndex, iv); AES128_CBC_decrypt((uint8*)iconOutput, (uint8*)&iconInput->iconData, sizeof(iconInput->iconData), idbeAesKeys + 16 * idbeHeader->keyIndex, iv); // calculate and compare sha256 - uint8 calculatedSHA256[32]; - SHA256((const unsigned char*)iconOutput, sizeof(nnIdbeIconDataV0_t), (unsigned char*)&calculatedSHA256); - if (memcmp(calculatedSHA256, decryptedSHA256, 32) != 0) + uint8 calculatedSHA256[SHA256_DIGEST_LENGTH]; + SHA256((const unsigned char*)iconOutput, sizeof(nnIdbeIconDataV0_t), calculatedSHA256); + if (memcmp(calculatedSHA256, decryptedSHA256, SHA256_DIGEST_LENGTH) != 0) { forceLogDebug_printf("Idbe icon has incorrect sha256 hash"); return false; diff --git a/src/Cemu/Tools/DownloadManager/DownloadManager.cpp b/src/Cemu/Tools/DownloadManager/DownloadManager.cpp index edaa2e00..45b66eed 100644 --- a/src/Cemu/Tools/DownloadManager/DownloadManager.cpp +++ b/src/Cemu/Tools/DownloadManager/DownloadManager.cpp @@ -581,7 +581,7 @@ void DownloadManager::searchForIncompleteDownloads() uint64 titleId; uint32 version; std::string name = p.path().filename().generic_string(); - if( sscanf(name.c_str(), "cemu_% " PRIx64 "_v%u", &titleId, &version) != 2) + if( sscanf(name.c_str(), "cemu_%" PRIx64 "_v%u", &titleId, &version) != 2) continue; std::unique_lock _l(m_mutex); for (auto& itr : m_ticketCache) diff --git a/src/Cemu/napi/napi_idbe.cpp b/src/Cemu/napi/napi_idbe.cpp index 034b94db..90c9c2f2 100644 --- a/src/Cemu/napi/napi_idbe.cpp +++ b/src/Cemu/napi/napi_idbe.cpp @@ -124,12 +124,9 @@ namespace NAPI // decrypt icon data and hash _decryptIDBEAndHash(&iconDataV0, hash, keyIndex); // verify hash of decrypted data - uint8 calcHash[32]; - SHA256_CTX shaCtx; - SHA256_Init(&shaCtx); - SHA256_Update(&shaCtx, &iconDataV0, sizeof(IDBEIconDataV0)); - SHA256_Final(calcHash, &shaCtx); - if (std::memcmp(calcHash, hash, 32) != 0) + uint8 calcHash[SHA256_DIGEST_LENGTH]; + SHA256((const unsigned char*) &iconDataV0, sizeof(IDBEIconDataV0), calcHash); + if (std::memcmp(calcHash, hash, SHA256_DIGEST_LENGTH) != 0) { cemuLog_log(LogType::Force, "IDBE_Request: Hash mismatch"); return std::nullopt; diff --git a/src/Cemu/ncrypto/ncrypto.cpp b/src/Cemu/ncrypto/ncrypto.cpp index 7181ab66..557c5228 100644 --- a/src/Cemu/ncrypto/ncrypto.cpp +++ b/src/Cemu/ncrypto/ncrypto.cpp @@ -153,20 +153,14 @@ namespace NCrypto /* Hashing */ - void GenerateHashSHA256(void* data, size_t len, CHash256& hashOut) + void GenerateHashSHA1(const void* data, size_t len, CHash160& hashOut) { - SHA256_CTX sha256; - SHA256_Init(&sha256); - SHA256_Update(&sha256, data, len); - SHA256_Final(hashOut.b, &sha256); + SHA1((const unsigned char*) data, len, hashOut.b); } - void GenerateHashSHA1(void* data, size_t len, CHash160& hashOut) + void GenerateHashSHA256(const void* data, size_t len, CHash256& hashOut) { - SHA_CTX shaCtx; - SHA1_Init(&shaCtx); - SHA1_Update(&shaCtx, data, len); - SHA1_Final(hashOut.b, &shaCtx); + SHA256((const unsigned char*) data, len, hashOut.b); } /* Ticket */ @@ -373,7 +367,7 @@ namespace NCrypto EC_POINT_free(ec_publicKey); NCrypto::CHash160 sharedKeySHA1; - GenerateHashSHA1(sharedKey, sharedKeyLen, sharedKeySHA1); + NCrypto::GenerateHashSHA1(sharedKey, sharedKeyLen, sharedKeySHA1); uint8 aesSharedKey[16]{}; std::memcpy(aesSharedKey, sharedKeySHA1.b, 16); @@ -621,11 +615,8 @@ namespace NCrypto bool CertECC::verifySignatureViaPubKey(ECCPubKey& signerPubKey) { - uint8 hash[32]; - SHA256_CTX sha256; - SHA256_Init(&sha256); - SHA256_Update(&sha256, this->issuer, 0x100); - SHA256_Final(hash, &sha256); + uint8 hash[SHA256_DIGEST_LENGTH]; + SHA256((const unsigned char *) this->issuer, 0x100, hash); EC_KEY* ecPubKey = signerPubKey.getPublicKey(); ECDSA_SIG* ecSig = this->signature.getSignature(); @@ -640,11 +631,8 @@ namespace NCrypto void CertECC::sign(ECCPrivKey& signerPrivKey) { - uint8 hash[32]; - SHA256_CTX sha256; - SHA256_Init(&sha256); - SHA256_Update(&sha256, this->issuer, 0x100); - SHA256_Final(hash, &sha256); + uint8 hash[SHA256_DIGEST_LENGTH]; + SHA256((const unsigned char *) this->issuer, 0x100, hash); // generate signature EC_KEY* ec_privKey = signerPrivKey.getPrivateKey(); diff --git a/src/Cemu/ncrypto/ncrypto.h b/src/Cemu/ncrypto/ncrypto.h index e44f7678..51f3d9cb 100644 --- a/src/Cemu/ncrypto/ncrypto.h +++ b/src/Cemu/ncrypto/ncrypto.h @@ -197,7 +197,7 @@ namespace NCrypto DEFINE_ENUM_FLAG_OPERATORS(TMDParser::TMDContentFlags); - void GenerateHashSHA256(void* data, size_t len, CHash256& hashOut); + void GenerateHashSHA256(const void* data, size_t len, CHash256& hashOut); ECCSig signHash(uint32 signerTitleIdHigh, uint32 signerTitleIdLow, uint8* hash, sint32 hashLen, CertECC& certChainOut); uint32 GetDeviceId(); diff --git a/src/gui/ChecksumTool.cpp b/src/gui/ChecksumTool.cpp index f13e8fa7..1c38e2fd 100644 --- a/src/gui/ChecksumTool.cpp +++ b/src/gui/ChecksumTool.cpp @@ -13,7 +13,8 @@ #include #include -#include +#include /* EVP_Digest */ +#include /* SHA256_DIGEST_LENGTH */ #include #include #include @@ -694,8 +695,8 @@ void ChecksumTool::DoWork() const auto wud_size = wud_getWUDSize(wud); std::vector buffer(1024 * 1024 * 8); - SHA256_CTX sha256; - SHA256_Init(&sha256); + EVP_MD_CTX *sha256 = EVP_MD_CTX_new(); + EVP_DigestInit(sha256, EVP_sha256()); uint32 read = 0; size_t offset = 0; @@ -712,7 +713,7 @@ void ChecksumTool::DoWork() offset += read; size -= read; - SHA256_Update(&sha256, buffer.data(), read); + EVP_DigestUpdate(sha256, buffer.data(), read); wxQueueEvent(this, new wxSetGaugeValue((int)((offset * 90) / wud_size), m_progress, m_status, wxStringFormat2(_("Reading game image: {}/{}kb"), offset / 1024, wud_size / 1024))); } while (read != 0 && size > 0); @@ -723,7 +724,8 @@ void ChecksumTool::DoWork() if (!m_running.load(std::memory_order_relaxed)) return; - SHA256_Final(checksum.data(), &sha256); + EVP_DigestFinal_ex(sha256, checksum.data(), NULL); + EVP_MD_CTX_free(sha256); std::stringstream str; for (const auto& b : checksum) @@ -757,10 +759,7 @@ void ChecksumTool::DoWork() continue; } - SHA256_CTX sha256; - SHA256_Init(&sha256); - SHA256_Update(&sha256, fileData->data(), fileData->size()); - SHA256_Final(checksum.data(), &sha256); + SHA256(fileData->data(), fileData->size(), checksum.data()); std::stringstream str; for (const auto& b : checksum)