From ecff4d03ee7544ab0ced82778affd5082570cd68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 23 Apr 2025 16:41:28 +0200 Subject: [PATCH] Update the naming of functions called by SavedataParam::EncryptData. Thanks Linblow, and Nemo for the reminder --- Core/Dialog/SavedataParam.cpp | 34 +++++++++++++++++----------------- Core/HLE/sceChnnlsv.cpp | 26 +++++++++++++------------- Core/HLE/sceChnnlsv.h | 12 ++++++------ 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index 0cb3e639c7..2781be96ba 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -941,28 +941,28 @@ int SavedataParam::EncryptData(unsigned int mode, memset(data, 0, 0x10); /* Build the 0x10-byte IV and setup encryption */ - if (sceSdCreateList_(ctx2, mode, 1, data, cryptkey) < 0) + if (sceSdCipherInit(ctx2, mode, 1, data, cryptkey) < 0) return -1; - if (sceSdSetIndex_(ctx1, mode) < 0) + if (sceSdMacInit(ctx1, mode) < 0) return -2; - if (sceSdRemoveValue_(ctx1, data, 0x10) < 0) + if (sceSdMacUpdate(ctx1, data, 0x10) < 0) return -3; - if (sceSdSetMember_(ctx2, data + 0x10, *alignedLen) < 0) + if (sceSdCipherUpdate(ctx2, data + 0x10, *alignedLen) < 0) return -4; /* Clear any extra bytes left from the previous steps */ memset(data + 0x10 + *dataLen, 0, *alignedLen - *dataLen); /* Encrypt the data */ - if (sceSdRemoveValue_(ctx1, data + 0x10, *alignedLen) < 0) + if (sceSdMacUpdate(ctx1, data + 0x10, *alignedLen) < 0) return -5; /* Verify encryption */ - if (sceSdCleanList_(ctx2) < 0) + if (sceSdCipherFinal(ctx2) < 0) return -6; /* Build the file hash from this PSP */ - if (sceSdGetLastIndex_(ctx1, hash, cryptkey) < 0) + if (sceSdMacFinal(ctx1, hash, cryptkey) < 0) return -7; /* Adjust sizes to account for IV */ @@ -985,24 +985,24 @@ int SavedataParam::DecryptData(unsigned int mode, unsigned char *data, int *data *alignedLen -= 0x10; /* Perform the magic */ - if (sceSdSetIndex_(ctx1, mode) < 0) + if (sceSdMacInit(ctx1, mode) < 0) return -2; - if (sceSdCreateList_(ctx2, mode, 2, data, cryptkey) < 0) + if (sceSdCipherInit(ctx2, mode, 2, data, cryptkey) < 0) return -3; - if (sceSdRemoveValue_(ctx1, data, 0x10) < 0) + if (sceSdMacUpdate(ctx1, data, 0x10) < 0) return -4; - if (sceSdRemoveValue_(ctx1, data + 0x10, *alignedLen) < 0) + if (sceSdMacUpdate(ctx1, data + 0x10, *alignedLen) < 0) return -5; - if (sceSdSetMember_(ctx2, data + 0x10, *alignedLen) < 0) + if (sceSdCipherUpdate(ctx2, data + 0x10, *alignedLen) < 0) return -6; /* Verify that it decrypted correctly */ - if (sceSdCleanList_(ctx2) < 0) + if (sceSdCipherFinal(ctx2) < 0) return -7; if (expectedHash) { u8 hash[16]; - if (sceSdGetLastIndex_(ctx1, hash, cryptkey) < 0) + if (sceSdMacFinal(ctx1, hash, cryptkey) < 0) return -7; if (memcmp(hash, expectedHash, sizeof(hash)) != 0) return -8; @@ -1077,11 +1077,11 @@ int SavedataParam::BuildHash(uint8_t *output, memset(output, 0, 0x10); /* Perform the magic */ - if (sceSdSetIndex_(ctx1, mode & 0xFF) < 0) + if (sceSdMacInit(ctx1, mode & 0xFF) < 0) return -1; - if (sceSdRemoveValue_(ctx1, data, alignedLen) < 0) + if (sceSdMacUpdate(ctx1, data, alignedLen) < 0) return -2; - if (sceSdGetLastIndex_(ctx1, output, cryptkey) < 0) + if (sceSdMacFinal(ctx1, output, cryptkey) < 0) { // Got here since Kirk CMD5 missing, return random value; memset(output,0x1,0x10); diff --git a/Core/HLE/sceChnnlsv.cpp b/Core/HLE/sceChnnlsv.cpp index b8aea6eee8..f88941f377 100644 --- a/Core/HLE/sceChnnlsv.cpp +++ b/Core/HLE/sceChnnlsv.cpp @@ -219,10 +219,10 @@ static int sceSdGetLastIndex(u32 addressCtx, u32 addressHash, u32 addressKey) { u8 *hash = Memory::GetPointerWrite(addressHash); if (!ctx.IsValid() || !hash) return hleLogError(Log::sceMisc, 0, "Invalid pointer"); - return hleLogDebug(Log::sceMisc, sceSdGetLastIndex_(*ctx, hash, Memory::GetPointerWrite(addressKey))); + return hleLogDebug(Log::sceMisc, sceSdMacFinal(*ctx, hash, Memory::GetPointerWrite(addressKey))); } -int sceSdGetLastIndex_(pspChnnlsvContext1& ctx, u8* in_hash, const u8* in_key) +int sceSdMacFinal(pspChnnlsvContext1& ctx, u8* in_hash, const u8* in_key) { if(ctx.keyLength >= 17) return -1026; @@ -319,7 +319,7 @@ int sceSdGetLastIndex_(pspChnnlsvContext1& ctx, u8* in_hash, const u8* in_key) memcpy(data2, dataBuf2, 16); } memcpy(in_hash, data2, 16); - sceSdSetIndex_(ctx, 0); + sceSdMacInit(ctx, 0); return 0; } @@ -328,10 +328,10 @@ static int sceSdSetIndex(u32 addressCtx, int value) { auto ctx = PSPPointer::Create(addressCtx); if (!ctx.IsValid()) return hleLogError(Log::sceMisc, 0, "Invalid pointer"); - return hleLogDebug(Log::sceMisc, sceSdSetIndex_(*ctx, value)); + return hleLogDebug(Log::sceMisc, sceSdMacInit(*ctx, value)); } -int sceSdSetIndex_(pspChnnlsvContext1& ctx, int value) +int sceSdMacInit(pspChnnlsvContext1& ctx, int value) { ctx.mode = value; memset(ctx.result, 0, 16); @@ -345,10 +345,10 @@ static int sceSdRemoveValue(u32 addressCtx, u32 addressData, int length) { auto ctx = PSPPointer::Create(addressCtx); if (!ctx.IsValid() || !Memory::IsValidAddress(addressData)) return hleLogError(Log::sceMisc, 0, "Invalid pointer"); - return hleLogDebug(Log::sceMisc, sceSdRemoveValue_(*ctx, Memory::GetPointerWrite(addressData), length)); + return hleLogDebug(Log::sceMisc, sceSdMacUpdate(*ctx, Memory::GetPointerWrite(addressData), length)); } -int sceSdRemoveValue_(pspChnnlsvContext1& ctx, const u8* data, int length) +int sceSdMacUpdate(pspChnnlsvContext1& ctx, const u8* data, int length) { if(ctx.keyLength >= 17) return -1026; @@ -397,10 +397,10 @@ static int sceSdCreateList(u32 ctx2Addr, int mode, int unkwn, u32 dataAddr, u32 if (!ctx2.IsValid() || !data) return hleLogError(Log::sceMisc, 0, "Invalid pointer"); - return hleLogDebug(Log::sceMisc, sceSdCreateList_(*ctx2, mode, unkwn, data, cryptkey)); + return hleLogDebug(Log::sceMisc, sceSdCipherInit(*ctx2, mode, unkwn, data, cryptkey)); } -int sceSdCreateList_(pspChnnlsvContext2& ctx2, int mode, int uknw, u8* data, const u8* cryptkey) +int sceSdCipherInit(pspChnnlsvContext2& ctx2, int mode, int uknw, u8* data, const u8* cryptkey) { ctx2.mode = mode; ctx2.unkn = 1; @@ -460,10 +460,10 @@ static int sceSdSetMember(u32 ctxAddr, u32 dataAddr, int alignedLen) { if (!ctx.IsValid() || !data) return hleLogError(Log::sceMisc, 0, "Invalid pointer"); - return hleLogDebug(Log::sceMisc, sceSdSetMember_(*ctx, data, alignedLen)); + return hleLogDebug(Log::sceMisc, sceSdCipherUpdate(*ctx, data, alignedLen)); } -int sceSdSetMember_(pspChnnlsvContext2& ctx, u8* data, int alignedLen) +int sceSdCipherUpdate(pspChnnlsvContext2& ctx, u8* data, int alignedLen) { if (alignedLen == 0) { @@ -501,10 +501,10 @@ static int sceSdCleanList(u32 ctxAddr) { auto ctx = PSPPointer::Create(ctxAddr); if (!ctx.IsValid()) return hleLogError(Log::sceMisc, 0, "Invalid pointer"); - return hleLogDebug(Log::sceMisc, sceSdCleanList_(*ctx)); + return hleLogDebug(Log::sceMisc, sceSdCipherFinal(*ctx)); } -int sceSdCleanList_(pspChnnlsvContext2& ctx) +int sceSdCipherFinal(pspChnnlsvContext2& ctx) { memset(ctx.cryptedData, 0, 16); ctx.unkn = 0; diff --git a/Core/HLE/sceChnnlsv.h b/Core/HLE/sceChnnlsv.h index d8a030932c..d38d574365 100644 --- a/Core/HLE/sceChnnlsv.h +++ b/Core/HLE/sceChnnlsv.h @@ -34,11 +34,11 @@ typedef struct _pspChnnlsvContext2 { u8 cryptedData[0x92]; } pspChnnlsvContext2; -int sceSdSetIndex_(pspChnnlsvContext1& ctx, int value); -int sceSdRemoveValue_(pspChnnlsvContext1& ctx, const u8* data, int length); -int sceSdCreateList_(pspChnnlsvContext2& ctx2, int mode, int uknw, u8* data, const u8* cryptkey); -int sceSdSetMember_(pspChnnlsvContext2& ctx, u8* data, int alignedLen); -int sceSdCleanList_(pspChnnlsvContext2& ctx); -int sceSdGetLastIndex_(pspChnnlsvContext1& ctx, u8* in_hash, const u8* in_key); +int sceSdMacInit(pspChnnlsvContext1& ctx, int value); +int sceSdMacUpdate(pspChnnlsvContext1& ctx, const u8* data, int length); +int sceSdCipherInit(pspChnnlsvContext2& ctx2, int mode, int uknw, u8* data, const u8* cryptkey); +int sceSdCipherUpdate(pspChnnlsvContext2& ctx, u8* data, int alignedLen); +int sceSdCipherFinal(pspChnnlsvContext2& ctx); +int sceSdMacFinal(pspChnnlsvContext1& ctx, u8* in_hash, const u8* in_key); void Register_sceChnnlsv();