2014-12-04 14:44:41 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
2014-12-07 18:25:45 +00:00
|
|
|
#include "Common/Crypto/sha256.h"
|
|
|
|
#include "Common/Log.h"
|
2014-12-04 14:44:41 +00:00
|
|
|
#include "Core/HLE/HLE.h"
|
|
|
|
#include "Core/HLE/FunctionWrappers.h"
|
|
|
|
#include "Core/HLE/sceSha256.h"
|
|
|
|
|
2014-12-08 17:31:57 +00:00
|
|
|
static int sceSha256Digest(u32 data, int dataLen, u32 digestPtr) {
|
2014-12-07 18:25:45 +00:00
|
|
|
if (!Memory::IsValidAddress(data) || !Memory::IsValidAddress(digestPtr) || !Memory::IsValidAddress(data + dataLen)) {
|
|
|
|
ERROR_LOG(HLE, "sceSha256Digest(data=%08x, len=%d, digest=%08x) - bad address(es)", data, dataLen, digestPtr);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
INFO_LOG(HLE, "sceSha256Digest(data=%08x, len=%d, digest=%08x)", data, dataLen, digestPtr);
|
|
|
|
|
|
|
|
// Already checked above...
|
2022-07-20 10:40:22 +00:00
|
|
|
u8 *digest = Memory::GetPointerWriteUnchecked(digestPtr);
|
2014-12-07 18:25:45 +00:00
|
|
|
sha256_context ctx;
|
|
|
|
sha256_starts(&ctx);
|
2022-07-20 10:40:22 +00:00
|
|
|
sha256_update(&ctx, Memory::GetPointerWriteUnchecked(data), dataLen);
|
2014-12-07 18:25:45 +00:00
|
|
|
sha256_finish(&ctx, digest);
|
|
|
|
|
2014-12-04 14:44:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const HLEFunction sceSha256[] =
|
|
|
|
{
|
2015-03-22 23:57:56 +00:00
|
|
|
{0X318A350C, &WrapI_UIU<sceSha256Digest>, "sceSha256Digest", 'i', "xix"},
|
2014-12-04 14:44:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void Register_sceSha256()
|
|
|
|
{
|
|
|
|
RegisterModule("sceSha256", ARRAY_SIZE(sceSha256), sceSha256);
|
|
|
|
}
|