diff --git a/libctru/include/3ds/services/fs.h b/libctru/include/3ds/services/fs.h index f1f1189..8db6c15 100644 --- a/libctru/include/3ds/services/fs.h +++ b/libctru/include/3ds/services/fs.h @@ -747,6 +747,14 @@ Result FSUSER_FormatSaveData(FS_ArchiveID archiveId, FS_Path path, u32 blocks, u */ Result FSUSER_GetLegacySubBannerData(u32 bannerSize, FS_MediaType mediaType, u64 programId, u8* banner); +/** + * @brief Hashes the given data and outputs a SHA256 hash. + * @param data Pointer to the data to be hashed. + * @param inputSize The size of the data. + * @param hash Hash output pointer. + */ +Result FSUSER_UpdateSha256Context(const void* data, u32 inputSize, u8* hash); + /** * @brief Reads from a special file. * @param bytesRead Pointer to output the number of bytes read to. diff --git a/libctru/source/services/fs.c b/libctru/source/services/fs.c index 8894cf8..35f3606 100644 --- a/libctru/source/services/fs.c +++ b/libctru/source/services/fs.c @@ -1201,6 +1201,27 @@ Result FSUSER_GetLegacySubBannerData(u32 bannerSize, FS_MediaType mediaType, u64 return cmdbuf[1]; } +Result FSUSER_UpdateSha256Context(const void* data, u32 inputSize, u8* hash) +{ + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = IPC_MakeHeader(0x84E, 13, 2); // 0x84E0342 + cmdbuf[9] = inputSize; + cmdbuf[10] = 0; + cmdbuf[11] = 0; + cmdbuf[12] = 0; + cmdbuf[13] = 1; + cmdbuf[14] = IPC_Desc_Buffer(inputSize, IPC_BUFFER_R); + cmdbuf[15] = (u32)data; + + Result ret = 0; + if(R_FAILED(ret = svcSendSyncRequest(fsSession()))) return ret; + + if(hash) memcpy(hash, &cmdbuf[2], 0x20); + + return cmdbuf[1]; +} + Result FSUSER_ReadSpecialFile(u32* bytesRead, u64 fileOffset, u32 size, u8* data) { u32 *cmdbuf = getThreadCommandBuffer();