Update the naming of functions called by SavedataParam::EncryptData. Thanks Linblow, and Nemo for the reminder

This commit is contained in:
Henrik Rydgård committed 2025-04-23 16:49:04 +02:00
1 parent 3f583ff5ab
commit ecff4d03ee
3 files changed
+36 -36

No files matched your search

+17 -17
View File
@@ -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);
+13 -13
View File
@@ -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<pspChnnlsvContext1>::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<pspChnnlsvContext1>::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<pspChnnlsvContext2>::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;
+6 -6
View File
@@ -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();