mirror of
https://github.com/RPCSX/rpcsx.git
synced 2025-12-06 07:12:14 +01:00
format all source code with clang-format
This commit is contained in:
parent
6bbaf18e71
commit
42cb5d7977
|
|
@ -65,8 +65,8 @@ struct ProcessOps {
|
||||||
uint64_t arg3);
|
uint64_t arg3);
|
||||||
SysResult (*dynlib_unload_prx)(Thread *thread, ModuleHandle handle);
|
SysResult (*dynlib_unload_prx)(Thread *thread, ModuleHandle handle);
|
||||||
|
|
||||||
SysResult (*thr_create)(Thread *thread, ptr<UContext> ctxt,
|
SysResult (*thr_create)(Thread *thread, ptr<UContext> ctxt, ptr<slong> arg,
|
||||||
ptr<slong> arg, sint flags);
|
sint flags);
|
||||||
SysResult (*thr_new)(Thread *thread, ptr<thr_param> param, sint param_size);
|
SysResult (*thr_new)(Thread *thread, ptr<thr_param> param, sint param_size);
|
||||||
SysResult (*thr_exit)(Thread *thread, ptr<slong> state);
|
SysResult (*thr_exit)(Thread *thread, ptr<slong> state);
|
||||||
SysResult (*thr_kill)(Thread *thread, slong id, sint sig);
|
SysResult (*thr_kill)(Thread *thread, slong id, sint sig);
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,6 @@ struct UContext {
|
||||||
|
|
||||||
static_assert(sizeof(UContext) == 0x500);
|
static_assert(sizeof(UContext) == 0x500);
|
||||||
|
|
||||||
|
|
||||||
enum Signal {
|
enum Signal {
|
||||||
kSigHup = 1,
|
kSigHup = 1,
|
||||||
kSigInt = 2,
|
kSigInt = 2,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "orbis-config.hpp"
|
|
||||||
#include "error/ErrorCode.hpp"
|
#include "error/ErrorCode.hpp"
|
||||||
|
#include "orbis-config.hpp"
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
@ -49,8 +49,7 @@ struct Uio {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template <typename T> ErrorCode write(const T &object) {
|
||||||
ErrorCode write(const T &object) {
|
|
||||||
return write(&object, sizeof(T));
|
return write(&object, sizeof(T));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,6 @@ inline constexpr auto kUmtxOpNwakePrivate = 21;
|
||||||
inline constexpr auto kUmtxOpMutexWake2 = 22;
|
inline constexpr auto kUmtxOpMutexWake2 = 22;
|
||||||
inline constexpr auto kUmtxOpMutexWake3 = 23;
|
inline constexpr auto kUmtxOpMutexWake3 = 23;
|
||||||
|
|
||||||
|
|
||||||
inline constexpr auto kSemNamed = 2;
|
inline constexpr auto kSemNamed = 2;
|
||||||
|
|
||||||
struct umtx {
|
struct umtx {
|
||||||
|
|
|
||||||
|
|
@ -203,7 +203,8 @@ static orbis::SysResult doRelocation(orbis::Process *process,
|
||||||
|
|
||||||
auto &defModule = module->importedModules.at(symbol.moduleIndex);
|
auto &defModule = module->importedModules.at(symbol.moduleIndex);
|
||||||
if (!defModule) {
|
if (!defModule) {
|
||||||
// std::printf("'%s' ('%s') uses undefined symbol '%llx' in unloaded module "
|
// std::printf("'%s' ('%s') uses undefined symbol '%llx' in unloaded
|
||||||
|
// module "
|
||||||
// "'%s', rel %u\n",
|
// "'%s', rel %u\n",
|
||||||
// module->moduleName, module->soName,
|
// module->moduleName, module->soName,
|
||||||
// (unsigned long long)symbol.id,
|
// (unsigned long long)symbol.id,
|
||||||
|
|
@ -295,7 +296,8 @@ static orbis::SysResult doRelocation(orbis::Process *process,
|
||||||
if (defObj == nullptr) {
|
if (defObj == nullptr) {
|
||||||
return orbis::ErrorCode::INVAL;
|
return orbis::ErrorCode::INVAL;
|
||||||
}
|
}
|
||||||
*where32 = S ? reinterpret_cast<std::uintptr_t>(defObj->base) + S + A - P : 0;
|
*where32 =
|
||||||
|
S ? reinterpret_cast<std::uintptr_t>(defObj->base) + S + A - P : 0;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
// case kRelCopy:
|
// case kRelCopy:
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ static orbis::ErrorCode pipe_read(orbis::File *file, orbis::Uio *uio,
|
||||||
while (true) {
|
while (true) {
|
||||||
if (pipe->data.empty()) {
|
if (pipe->data.empty()) {
|
||||||
// pipe->cv.wait(file->mtx);
|
// pipe->cv.wait(file->mtx);
|
||||||
// ORBIS_LOG_ERROR(__FUNCTION__, "wakeup", thread->name, thread->tid, file);
|
// ORBIS_LOG_ERROR(__FUNCTION__, "wakeup", thread->name, thread->tid,
|
||||||
// continue;
|
// file); continue;
|
||||||
return orbis::ErrorCode::WOULDBLOCK;
|
return orbis::ErrorCode::WOULDBLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -32,7 +32,8 @@ static orbis::ErrorCode pipe_read(orbis::File *file, orbis::Uio *uio,
|
||||||
uio->offset += size;
|
uio->offset += size;
|
||||||
std::memcpy(vec.base, pipe->data.data(), size);
|
std::memcpy(vec.base, pipe->data.data(), size);
|
||||||
|
|
||||||
ORBIS_LOG_ERROR(__FUNCTION__, thread->name, thread->tid, file, size, pipe->data.size(), uio->offset, file->nextOff);
|
ORBIS_LOG_ERROR(__FUNCTION__, thread->name, thread->tid, file, size,
|
||||||
|
pipe->data.size(), uio->offset, file->nextOff);
|
||||||
|
|
||||||
if (pipe->data.size() == size) {
|
if (pipe->data.size() == size) {
|
||||||
pipe->data.clear();
|
pipe->data.clear();
|
||||||
|
|
@ -69,9 +70,10 @@ static orbis::ErrorCode pipe_write(orbis::File *file, orbis::Uio *uio,
|
||||||
uio->resid -= cnt;
|
uio->resid -= cnt;
|
||||||
uio->offset += cnt;
|
uio->offset += cnt;
|
||||||
|
|
||||||
ORBIS_LOG_ERROR(__FUNCTION__, thread->name, thread->tid, file, uio->resid, uio->offset, file->nextOff, cnt);
|
ORBIS_LOG_ERROR(__FUNCTION__, thread->name, thread->tid, file, uio->resid,
|
||||||
|
uio->offset, file->nextOff, cnt);
|
||||||
thread->where();
|
thread->where();
|
||||||
return{};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static orbis::FileOps pipe_ops = {
|
static orbis::FileOps pipe_ops = {
|
||||||
|
|
@ -79,7 +81,8 @@ static orbis::FileOps pipe_ops = {
|
||||||
.write = pipe_write,
|
.write = pipe_write,
|
||||||
};
|
};
|
||||||
|
|
||||||
std::pair<orbis::Ref<orbis::Pipe>, orbis::Ref<orbis::Pipe>> orbis::createPipe() {
|
std::pair<orbis::Ref<orbis::Pipe>, orbis::Ref<orbis::Pipe>>
|
||||||
|
orbis::createPipe() {
|
||||||
auto a = knew<Pipe>();
|
auto a = knew<Pipe>();
|
||||||
auto b = knew<Pipe>();
|
auto b = knew<Pipe>();
|
||||||
a->event = knew<EventEmitter>();
|
a->event = knew<EventEmitter>();
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,12 @@
|
||||||
#include "sys/sysproto.hpp"
|
#include "sys/sysproto.hpp"
|
||||||
|
|
||||||
orbis::SysResult orbis::sys_getcontext(Thread *thread,
|
orbis::SysResult orbis::sys_getcontext(Thread *thread, ptr<UContext> ucp) {
|
||||||
ptr<UContext> ucp) {
|
return ErrorCode::NOSYS;
|
||||||
return ErrorCode::NOSYS;
|
}
|
||||||
}
|
orbis::SysResult orbis::sys_setcontext(Thread *thread, ptr<UContext> ucp) {
|
||||||
orbis::SysResult orbis::sys_setcontext(Thread *thread,
|
return ErrorCode::NOSYS;
|
||||||
ptr<UContext> ucp) {
|
}
|
||||||
return ErrorCode::NOSYS;
|
orbis::SysResult orbis::sys_swapcontext(Thread *thread, ptr<UContext> oucp,
|
||||||
}
|
|
||||||
orbis::SysResult orbis::sys_swapcontext(Thread *thread,
|
|
||||||
ptr<UContext> oucp,
|
|
||||||
ptr<UContext> ucp) {
|
ptr<UContext> ucp) {
|
||||||
return ErrorCode::NOSYS;
|
return ErrorCode::NOSYS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,8 @@ orbis::SysResult orbis::sys_cpuset_setaffinity(Thread *thread, cpulevel_t level,
|
||||||
auto threadHandle = whichThread->getNativeHandle();
|
auto threadHandle = whichThread->getNativeHandle();
|
||||||
auto hostCpuSet = toHostCpuSet(whichThread->affinity);
|
auto hostCpuSet = toHostCpuSet(whichThread->affinity);
|
||||||
ORBIS_LOG_ERROR(__FUNCTION__, threadHandle, thread->tid, id);
|
ORBIS_LOG_ERROR(__FUNCTION__, threadHandle, thread->tid, id);
|
||||||
if (pthread_setaffinity_np(threadHandle, sizeof(hostCpuSet), &hostCpuSet)) {
|
if (pthread_setaffinity_np(threadHandle, sizeof(hostCpuSet),
|
||||||
|
&hostCpuSet)) {
|
||||||
ORBIS_LOG_ERROR(__FUNCTION__,
|
ORBIS_LOG_ERROR(__FUNCTION__,
|
||||||
"failed to set affinity mask for host thread",
|
"failed to set affinity mask for host thread",
|
||||||
whichThread->hostTid, whichThread->affinity.bits);
|
whichThread->hostTid, whichThread->affinity.bits);
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
#include "orbis/utils/Logs.hpp"
|
#include "orbis/utils/Logs.hpp"
|
||||||
#include "stat.hpp"
|
#include "stat.hpp"
|
||||||
#include "sys/sysproto.hpp"
|
#include "sys/sysproto.hpp"
|
||||||
#include "thread/Thread.hpp"
|
|
||||||
#include "thread/Process.hpp"
|
#include "thread/Process.hpp"
|
||||||
|
#include "thread/Thread.hpp"
|
||||||
|
|
||||||
orbis::SysResult orbis::sys_getdtablesize(Thread *thread) {
|
orbis::SysResult orbis::sys_getdtablesize(Thread *thread) {
|
||||||
return ErrorCode::NOSYS;
|
return ErrorCode::NOSYS;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#include "sys/sysproto.hpp"
|
#include "sys/sysproto.hpp"
|
||||||
#include "thread/Thread.hpp"
|
|
||||||
#include "thread/Process.hpp"
|
#include "thread/Process.hpp"
|
||||||
#include "thread/ProcessOps.hpp"
|
#include "thread/ProcessOps.hpp"
|
||||||
|
#include "thread/Thread.hpp"
|
||||||
|
|
||||||
orbis::SysResult orbis::sys_execve(Thread *thread, ptr<char> fname,
|
orbis::SysResult orbis::sys_execve(Thread *thread, ptr<char> fname,
|
||||||
ptr<ptr<char>> argv, ptr<ptr<char>> envv) {
|
ptr<ptr<char>> argv, ptr<ptr<char>> envv) {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
#include "KernelContext.hpp"
|
#include "KernelContext.hpp"
|
||||||
#include "sys/sysproto.hpp"
|
#include "sys/sysproto.hpp"
|
||||||
|
#include "thread/Process.hpp"
|
||||||
#include "thread/ProcessOps.hpp"
|
#include "thread/ProcessOps.hpp"
|
||||||
#include "utils/Logs.hpp"
|
#include "utils/Logs.hpp"
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "thread/Process.hpp"
|
|
||||||
|
|
||||||
orbis::SysResult orbis::sys_exit(Thread *thread, sint status) {
|
orbis::SysResult orbis::sys_exit(Thread *thread, sint status) {
|
||||||
if (auto exit = thread->tproc->ops->exit) {
|
if (auto exit = thread->tproc->ops->exit) {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
#include "file.hpp"
|
#include "file.hpp"
|
||||||
#include "orbis/utils/Logs.hpp"
|
#include "orbis/utils/Logs.hpp"
|
||||||
#include "sys/sysproto.hpp"
|
#include "sys/sysproto.hpp"
|
||||||
#include "thread/Thread.hpp"
|
|
||||||
#include "thread/Process.hpp"
|
#include "thread/Process.hpp"
|
||||||
|
#include "thread/Thread.hpp"
|
||||||
#include "uio.hpp"
|
#include "uio.hpp"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include "sys/sysproto.hpp"
|
#include "sys/sysproto.hpp"
|
||||||
#include "thread/Thread.hpp"
|
|
||||||
#include "thread/Process.hpp"
|
#include "thread/Process.hpp"
|
||||||
|
#include "thread/Thread.hpp"
|
||||||
#include "utils/Logs.hpp"
|
#include "utils/Logs.hpp"
|
||||||
#include <pipe.hpp>
|
#include <pipe.hpp>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,11 +59,11 @@ orbis::SysResult orbis::sys_rtprio_thread(Thread *thread, sint function,
|
||||||
hostPolicy = SCHED_IDLE;
|
hostPolicy = SCHED_IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pthread_setschedparam(targetThread->getNativeHandle(),
|
if (pthread_setschedparam(targetThread->getNativeHandle(), hostPolicy,
|
||||||
hostPolicy, &hostParam)) {
|
&hostParam)) {
|
||||||
ORBIS_LOG_ERROR(__FUNCTION__, "failed to set host priority",
|
ORBIS_LOG_ERROR(
|
||||||
hostPriority, targetThread->prio.prio,
|
__FUNCTION__, "failed to set host priority", hostPriority,
|
||||||
targetThread->prio.type, errno,
|
targetThread->prio.prio, targetThread->prio.type, errno,
|
||||||
targetThread->getNativeHandle(), prioMin, prioMax, errno);
|
targetThread->getNativeHandle(), prioMin, prioMax, errno);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1165,8 +1165,7 @@ orbis::sys_dynlib_get_info_ex(Thread *thread, SceKernelModule handle,
|
||||||
result.ehFrame = module->ehFrame;
|
result.ehFrame = module->ehFrame;
|
||||||
result.ehFrameHdrSize = module->ehFrameHdrSize;
|
result.ehFrameHdrSize = module->ehFrameHdrSize;
|
||||||
result.ehFrameSize = module->ehFrameSize;
|
result.ehFrameSize = module->ehFrameSize;
|
||||||
std::memcpy(result.segments, module->segments,
|
std::memcpy(result.segments, module->segments, sizeof(ModuleSegment) * 2);
|
||||||
sizeof(ModuleSegment) * 2);
|
|
||||||
result.segmentCount = 2;
|
result.segmentCount = 2;
|
||||||
result.refCount = 1;
|
result.refCount = 1;
|
||||||
ORBIS_LOG_WARNING(__FUNCTION__, result.id, result.name, result.tlsIndex,
|
ORBIS_LOG_WARNING(__FUNCTION__, result.id, result.name, result.tlsIndex,
|
||||||
|
|
|
||||||
|
|
@ -140,14 +140,15 @@ orbis::SysResult orbis::sys_sigreturn(Thread *thread, ptr<UContext> sigcntxp) {
|
||||||
ORBIS_LOG_WARNING(__FUNCTION__, sigcntxp);
|
ORBIS_LOG_WARNING(__FUNCTION__, sigcntxp);
|
||||||
|
|
||||||
// auto sigRet = thread->sigReturns.front();
|
// auto sigRet = thread->sigReturns.front();
|
||||||
// thread->sigReturns.erase(thread->sigReturns.begin(), thread->sigReturns.begin() + 1);
|
// thread->sigReturns.erase(thread->sigReturns.begin(),
|
||||||
// writeRegister(thread->context, RegisterId::rip, sigRet.rip);
|
// thread->sigReturns.begin() + 1); writeRegister(thread->context,
|
||||||
// writeRegister(thread->context, RegisterId::rsp, sigRet.rsp);
|
// RegisterId::rip, sigRet.rip); writeRegister(thread->context,
|
||||||
// ORBIS_LOG_ERROR(__FUNCTION__, sigRet.rip, sigRet.rsp);
|
// RegisterId::rsp, sigRet.rsp); ORBIS_LOG_ERROR(__FUNCTION__, sigRet.rip,
|
||||||
|
// sigRet.rsp);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
orbis::SysResult orbis::nosys(Thread *thread) {
|
orbis::SysResult orbis::nosys(Thread *thread) {
|
||||||
thread->sendSignal(kSigSys);
|
thread->sendSignal(kSigSys);
|
||||||
return{};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
#include "sys/sysproto.hpp"
|
#include "sys/sysproto.hpp"
|
||||||
|
#include "thread/Process.hpp"
|
||||||
#include "thread/ProcessOps.hpp"
|
#include "thread/ProcessOps.hpp"
|
||||||
#include "thread/Thread.hpp"
|
#include "thread/Thread.hpp"
|
||||||
#include "thread/Process.hpp"
|
|
||||||
#include "ucontext.hpp"
|
#include "ucontext.hpp"
|
||||||
|
|
||||||
orbis::SysResult orbis::sys_thr_create(Thread *thread,
|
orbis::SysResult orbis::sys_thr_create(Thread *thread, ptr<UContext> ctxt,
|
||||||
ptr<UContext> ctxt,
|
|
||||||
ptr<slong> arg, sint flags) {
|
ptr<slong> arg, sint flags) {
|
||||||
if (auto thr_create = thread->tproc->ops->thr_create) {
|
if (auto thr_create = thread->tproc->ops->thr_create) {
|
||||||
return thr_create(thread, ctxt, arg, flags);
|
return thr_create(thread, ctxt, arg, flags);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
#include "file.hpp"
|
#include "file.hpp"
|
||||||
#include "sys/sysproto.hpp"
|
#include "sys/sysproto.hpp"
|
||||||
|
#include "thread/Process.hpp"
|
||||||
#include "thread/ProcessOps.hpp"
|
#include "thread/ProcessOps.hpp"
|
||||||
#include "thread/Thread.hpp"
|
#include "thread/Thread.hpp"
|
||||||
#include "thread/Process.hpp"
|
|
||||||
#include "uio.hpp"
|
#include "uio.hpp"
|
||||||
#include "utils/Logs.hpp"
|
#include "utils/Logs.hpp"
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
@ -128,7 +128,8 @@ orbis::SysResult orbis::sys_recvfrom(Thread *thread, sint s, caddr_t buf,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto recvfrom = file->ops->recvfrom) {
|
if (auto recvfrom = file->ops->recvfrom) {
|
||||||
return SysResult::notAnError(recvfrom(file.get(), buf, len, flags, from, fromlenaddr, thread));
|
return SysResult::notAnError(
|
||||||
|
recvfrom(file.get(), buf, len, flags, from, fromlenaddr, thread));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ErrorCode::NOTSUP;
|
return ErrorCode::NOTSUP;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
#include "file.hpp"
|
#include "file.hpp"
|
||||||
#include "orbis-config.hpp"
|
#include "orbis-config.hpp"
|
||||||
#include "sys/sysproto.hpp"
|
#include "sys/sysproto.hpp"
|
||||||
|
#include "thread/Process.hpp"
|
||||||
#include "thread/ProcessOps.hpp"
|
#include "thread/ProcessOps.hpp"
|
||||||
#include "thread/Thread.hpp"
|
#include "thread/Thread.hpp"
|
||||||
#include "thread/Process.hpp"
|
|
||||||
|
|
||||||
orbis::SysResult orbis::sys_shm_open(Thread *thread, ptr<const char> path,
|
orbis::SysResult orbis::sys_shm_open(Thread *thread, ptr<const char> path,
|
||||||
sint flags, mode_t mode) {
|
sint flags, mode_t mode) {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
#include "stat.hpp"
|
#include "stat.hpp"
|
||||||
#include "sys/sysproto.hpp"
|
#include "sys/sysproto.hpp"
|
||||||
|
#include "thread/Process.hpp"
|
||||||
#include "thread/ProcessOps.hpp"
|
#include "thread/ProcessOps.hpp"
|
||||||
#include "thread/Thread.hpp"
|
#include "thread/Thread.hpp"
|
||||||
#include "thread/Process.hpp"
|
|
||||||
#include "utils/Logs.hpp"
|
#include "utils/Logs.hpp"
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <span>
|
#include <span>
|
||||||
|
|
@ -71,8 +71,8 @@ orbis::SysResult orbis::sys_chroot(Thread *thread, ptr<char> path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// volatile bool debuggerPresent = false;
|
// volatile bool debuggerPresent = false;
|
||||||
orbis::SysResult orbis::sys_open(Thread *thread, ptr<const char> path, sint flags,
|
orbis::SysResult orbis::sys_open(Thread *thread, ptr<const char> path,
|
||||||
sint mode) {
|
sint flags, sint mode) {
|
||||||
if (auto open = thread->tproc->ops->open) {
|
if (auto open = thread->tproc->ops->open) {
|
||||||
Ref<File> file;
|
Ref<File> file;
|
||||||
auto result = open(thread, path, flags, mode, &file);
|
auto result = open(thread, path, flags, mode, &file);
|
||||||
|
|
@ -82,7 +82,9 @@ orbis::SysResult orbis::sys_open(Thread *thread, ptr<const char> path, sint flag
|
||||||
|
|
||||||
auto fd = thread->tproc->fileDescriptors.insert(file);
|
auto fd = thread->tproc->fileDescriptors.insert(file);
|
||||||
thread->retval[0] = fd;
|
thread->retval[0] = fd;
|
||||||
// if (path == std::string_view{"/app0/psm/Application/resource/Sce.Vsh.ShellUI.SystemMessage.rco"}) {
|
// if (path ==
|
||||||
|
// std::string_view{"/app0/psm/Application/resource/Sce.Vsh.ShellUI.SystemMessage.rco"})
|
||||||
|
// {
|
||||||
ORBIS_LOG_SUCCESS(__FUNCTION__, thread->tid, path, flags, mode, fd);
|
ORBIS_LOG_SUCCESS(__FUNCTION__, thread->tid, path, flags, mode, fd);
|
||||||
if (path == std::string_view{"/app0/wave/wave1.fbxd"}) {
|
if (path == std::string_view{"/app0/wave/wave1.fbxd"}) {
|
||||||
thread->where();
|
thread->where();
|
||||||
|
|
@ -288,13 +290,14 @@ orbis::SysResult orbis::sys_readlink(Thread *thread, ptr<char> path,
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<File> file;
|
Ref<File> file;
|
||||||
if (auto error = thread->tproc->ops->open(thread, path, 0, 0, &file); error.value()) {
|
if (auto error = thread->tproc->ops->open(thread, path, 0, 0, &file);
|
||||||
|
error.value()) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
ORBIS_RET_ON_ERROR(uwriteRaw(buf, _path, pathLen));
|
ORBIS_RET_ON_ERROR(uwriteRaw(buf, _path, pathLen));
|
||||||
thread->retval[0] = pathLen;
|
thread->retval[0] = pathLen;
|
||||||
return{};
|
return {};
|
||||||
}
|
}
|
||||||
orbis::SysResult orbis::sys_readlinkat(Thread *thread, sint fd, ptr<char> path,
|
orbis::SysResult orbis::sys_readlinkat(Thread *thread, sint fd, ptr<char> path,
|
||||||
ptr<char> buf, size_t bufsize) {
|
ptr<char> buf, size_t bufsize) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include "sys/sysproto.hpp"
|
#include "sys/sysproto.hpp"
|
||||||
#include "thread/Thread.hpp"
|
|
||||||
#include "thread/Process.hpp"
|
#include "thread/Process.hpp"
|
||||||
|
#include "thread/Thread.hpp"
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
@ -19,5 +19,5 @@ orbis::SysResult orbis::sys___getcwd(Thread *thread, ptr<char> buf,
|
||||||
}
|
}
|
||||||
|
|
||||||
ORBIS_RET_ON_ERROR(uwriteRaw(buf, cwd.data(), cwd.size() + 1));
|
ORBIS_RET_ON_ERROR(uwriteRaw(buf, cwd.data(), cwd.size() + 1));
|
||||||
return{};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#include "sys/sysproto.hpp"
|
#include "sys/sysproto.hpp"
|
||||||
|
#include "thread/Process.hpp"
|
||||||
#include "thread/ProcessOps.hpp"
|
#include "thread/ProcessOps.hpp"
|
||||||
#include "thread/Thread.hpp"
|
#include "thread/Thread.hpp"
|
||||||
#include "thread/Process.hpp"
|
|
||||||
|
|
||||||
orbis::SysResult orbis::sys_mount(Thread *thread, ptr<char> type,
|
orbis::SysResult orbis::sys_mount(Thread *thread, ptr<char> type,
|
||||||
ptr<char> path, sint flags, caddr_t data) {
|
ptr<char> path, sint flags, caddr_t data) {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
#include "error.hpp"
|
#include "error.hpp"
|
||||||
#include "sys/sysproto.hpp"
|
#include "sys/sysproto.hpp"
|
||||||
|
#include "thread/Process.hpp"
|
||||||
#include "thread/ProcessOps.hpp"
|
#include "thread/ProcessOps.hpp"
|
||||||
#include "thread/Thread.hpp"
|
#include "thread/Thread.hpp"
|
||||||
#include "thread/Process.hpp"
|
|
||||||
|
|
||||||
orbis::SysResult orbis::sys_sbrk(Thread *, sint) {
|
orbis::SysResult orbis::sys_sbrk(Thread *, sint) {
|
||||||
return ErrorCode::OPNOTSUPP;
|
return ErrorCode::OPNOTSUPP;
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,8 @@ void shared_mutex::impl_lock_shared(unsigned val) {
|
||||||
if ((old % c_sig) + c_one >= c_sig)
|
if ((old % c_sig) + c_one >= c_sig)
|
||||||
std::abort(); // "shared_mutex overflow"
|
std::abort(); // "shared_mutex overflow"
|
||||||
|
|
||||||
while (impl_wait() != std::errc{}) {}
|
while (impl_wait() != std::errc{}) {
|
||||||
|
}
|
||||||
lock_downgrade();
|
lock_downgrade();
|
||||||
}
|
}
|
||||||
void shared_mutex::impl_unlock_shared(unsigned old) {
|
void shared_mutex::impl_unlock_shared(unsigned old) {
|
||||||
|
|
@ -80,7 +81,7 @@ std::errc shared_mutex::impl_wait() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return{};
|
return {};
|
||||||
}
|
}
|
||||||
void shared_mutex::impl_signal() {
|
void shared_mutex::impl_signal() {
|
||||||
m_value += c_sig;
|
m_value += c_sig;
|
||||||
|
|
@ -120,7 +121,8 @@ void shared_mutex::impl_lock(unsigned val) {
|
||||||
|
|
||||||
if ((old % c_sig) + c_one >= c_sig)
|
if ((old % c_sig) + c_one >= c_sig)
|
||||||
std::abort(); // "shared_mutex overflow"
|
std::abort(); // "shared_mutex overflow"
|
||||||
while (impl_wait() != std::errc{}) {}
|
while (impl_wait() != std::errc{}) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void shared_mutex::impl_unlock(unsigned old) {
|
void shared_mutex::impl_unlock(unsigned old) {
|
||||||
if (old - c_one >= c_err)
|
if (old - c_one >= c_err)
|
||||||
|
|
@ -152,7 +154,8 @@ void shared_mutex::impl_lock_upgrade() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (impl_wait() != std::errc{}) {}
|
while (impl_wait() != std::errc{}) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
bool shared_mutex::lock_forced(int count) {
|
bool shared_mutex::lock_forced(int count) {
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
|
|
|
||||||
6
rpcs3/3rdparty/CMakeLists.txt
vendored
6
rpcs3/3rdparty/CMakeLists.txt
vendored
|
|
@ -102,7 +102,7 @@ add_subdirectory(yaml-cpp)
|
||||||
|
|
||||||
# OpenGL
|
# OpenGL
|
||||||
|
|
||||||
if (NOT ANDROID)
|
if (NOT ANDROID AND NOT WITHOUT_OPENGL)
|
||||||
find_package(OpenGL REQUIRED OPTIONAL_COMPONENTS EGL)
|
find_package(OpenGL REQUIRED OPTIONAL_COMPONENTS EGL)
|
||||||
|
|
||||||
add_library(3rdparty_opengl INTERFACE)
|
add_library(3rdparty_opengl INTERFACE)
|
||||||
|
|
@ -212,7 +212,7 @@ endif()
|
||||||
add_subdirectory(asmjit EXCLUDE_FROM_ALL)
|
add_subdirectory(asmjit EXCLUDE_FROM_ALL)
|
||||||
|
|
||||||
# OpenAL
|
# OpenAL
|
||||||
if (NOT ANDROID)
|
if (NOT ANDROID AND NOT WITHOUT_OPENAL)
|
||||||
add_subdirectory(OpenAL EXCLUDE_FROM_ALL)
|
add_subdirectory(OpenAL EXCLUDE_FROM_ALL)
|
||||||
else()
|
else()
|
||||||
add_library(3rdparty_openal INTERFACE)
|
add_library(3rdparty_openal INTERFACE)
|
||||||
|
|
@ -303,7 +303,7 @@ endif()
|
||||||
|
|
||||||
# GLEW
|
# GLEW
|
||||||
add_library(3rdparty_glew INTERFACE)
|
add_library(3rdparty_glew INTERFACE)
|
||||||
if(NOT MSVC AND NOT ANDROID)
|
if(NOT MSVC AND NOT ANDROID AND NOT WITHOUT_OPENGLEW)
|
||||||
find_package(GLEW REQUIRED)
|
find_package(GLEW REQUIRED)
|
||||||
target_link_libraries(3rdparty_glew INTERFACE GLEW::GLEW)
|
target_link_libraries(3rdparty_glew INTERFACE GLEW::GLEW)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
||||||
1
rpcs3/3rdparty/zstd/CMakeLists.txt
vendored
1
rpcs3/3rdparty/zstd/CMakeLists.txt
vendored
|
|
@ -2,6 +2,7 @@ option(ZSTD_BUILD_PROGRAMS "BUILD PROGRAMS" OFF)
|
||||||
option(ZSTD_BUILD_SHARED "BUILD SHARED LIBRARIES" OFF)
|
option(ZSTD_BUILD_SHARED "BUILD SHARED LIBRARIES" OFF)
|
||||||
option(ZSTD_BUILD_STATIC "BUILD STATIC LIBRARIES" ON)
|
option(ZSTD_BUILD_STATIC "BUILD STATIC LIBRARIES" ON)
|
||||||
option(ZSTD_BUILD_TESTS "BUILD TESTS" OFF)
|
option(ZSTD_BUILD_TESTS "BUILD TESTS" OFF)
|
||||||
|
option(ZSTD_USE_STATIC_RUNTIME "LINK TO STATIC RUN-TIME LIBRARIES" ON)
|
||||||
|
|
||||||
add_subdirectory(zstd/build/cmake EXLUDE_FROM_ALL)
|
add_subdirectory(zstd/build/cmake EXLUDE_FROM_ALL)
|
||||||
add_library(3rdparty_zstd INTERFACE)
|
add_library(3rdparty_zstd INTERFACE)
|
||||||
|
|
|
||||||
|
|
@ -101,8 +101,8 @@ if(MSVC)
|
||||||
add_compile_options(/MP)
|
add_compile_options(/MP)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
|
if(CMAKE_SIZEOF_VOID_P AND NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||||
message( FATAL_ERROR "RPCS3 can only be compiled on 64-bit platforms." )
|
message( FATAL_ERROR "RPCS3 can only be compiled on 64-bit platforms. ${CMAKE_SIZEOF_VOID_P}" )
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_program(CCACHE_FOUND ccache)
|
find_program(CCACHE_FOUND ccache)
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,8 @@ struct bf_base
|
||||||
using compact_type = std::conditional_t<can_be_packed, std::conditional_t<std::is_unsigned_v<vtype>, uint, int>, vtype>;
|
using compact_type = std::conditional_t<can_be_packed, std::conditional_t<std::is_unsigned_v<vtype>, uint, int>, vtype>;
|
||||||
|
|
||||||
// Datatype bitsize
|
// Datatype bitsize
|
||||||
static constexpr uint bitmax = sizeof(T) * 8; static_assert(N - 1 < bitmax, "bf_base<> error: N out of bounds");
|
static constexpr uint bitmax = sizeof(T) * 8;
|
||||||
|
static_assert(N - 1 < bitmax, "bf_base<> error: N out of bounds");
|
||||||
|
|
||||||
// Field bitsize
|
// Field bitsize
|
||||||
static constexpr uint bitsize = N;
|
static constexpr uint bitsize = N;
|
||||||
|
|
@ -44,7 +45,8 @@ struct bf_t : bf_base<T, N>
|
||||||
using compact_type = typename bf_t::compact_type;
|
using compact_type = typename bf_t::compact_type;
|
||||||
|
|
||||||
// Field offset
|
// Field offset
|
||||||
static constexpr uint bitpos = I; static_assert(bitpos + N <= bf_t::bitmax, "bf_t<> error: I out of bounds");
|
static constexpr uint bitpos = I;
|
||||||
|
static_assert(bitpos + N <= bf_t::bitmax, "bf_t<> error: I out of bounds");
|
||||||
|
|
||||||
// Get bitmask of size N, at I pos
|
// Get bitmask of size N, at I pos
|
||||||
static constexpr utype data_mask()
|
static constexpr utype data_mask()
|
||||||
|
|
@ -92,64 +94,64 @@ struct bf_t : bf_base<T, N>
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store bitfield value
|
// Store bitfield value
|
||||||
bf_t& operator =(compact_type value) noexcept
|
bf_t& operator=(compact_type value) noexcept
|
||||||
{
|
{
|
||||||
this->m_data = static_cast<vtype>((this->m_data & ~data_mask()) | insert(value));
|
this->m_data = static_cast<vtype>((this->m_data & ~data_mask()) | insert(value));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
compact_type operator ++(int)
|
compact_type operator++(int)
|
||||||
{
|
{
|
||||||
compact_type result = *this;
|
compact_type result = *this;
|
||||||
*this = static_cast<compact_type>(result + 1u);
|
*this = static_cast<compact_type>(result + 1u);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bf_t& operator ++()
|
bf_t& operator++()
|
||||||
{
|
{
|
||||||
return *this = static_cast<compact_type>(*this + 1u);
|
return *this = static_cast<compact_type>(*this + 1u);
|
||||||
}
|
}
|
||||||
|
|
||||||
compact_type operator --(int)
|
compact_type operator--(int)
|
||||||
{
|
{
|
||||||
compact_type result = *this;
|
compact_type result = *this;
|
||||||
*this = static_cast<compact_type>(result - 1u);
|
*this = static_cast<compact_type>(result - 1u);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bf_t& operator --()
|
bf_t& operator--()
|
||||||
{
|
{
|
||||||
return *this = static_cast<compact_type>(*this - 1u);
|
return *this = static_cast<compact_type>(*this - 1u);
|
||||||
}
|
}
|
||||||
|
|
||||||
bf_t& operator +=(compact_type right)
|
bf_t& operator+=(compact_type right)
|
||||||
{
|
{
|
||||||
return *this = static_cast<compact_type>(*this + right);
|
return *this = static_cast<compact_type>(*this + right);
|
||||||
}
|
}
|
||||||
|
|
||||||
bf_t& operator -=(compact_type right)
|
bf_t& operator-=(compact_type right)
|
||||||
{
|
{
|
||||||
return *this = static_cast<compact_type>(*this - right);
|
return *this = static_cast<compact_type>(*this - right);
|
||||||
}
|
}
|
||||||
|
|
||||||
bf_t& operator *=(compact_type right)
|
bf_t& operator*=(compact_type right)
|
||||||
{
|
{
|
||||||
return *this = static_cast<compact_type>(*this * right);
|
return *this = static_cast<compact_type>(*this * right);
|
||||||
}
|
}
|
||||||
|
|
||||||
bf_t& operator &=(compact_type right)
|
bf_t& operator&=(compact_type right)
|
||||||
{
|
{
|
||||||
this->m_data &= static_cast<vtype>(((static_cast<utype>(right + 0u) & bf_t::vmask) << bitpos) | ~(bf_t::vmask << bitpos));
|
this->m_data &= static_cast<vtype>(((static_cast<utype>(right + 0u) & bf_t::vmask) << bitpos) | ~(bf_t::vmask << bitpos));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bf_t& operator |=(compact_type right)
|
bf_t& operator|=(compact_type right)
|
||||||
{
|
{
|
||||||
this->m_data |= static_cast<vtype>((static_cast<utype>(right + 0u) & bf_t::vmask) << bitpos);
|
this->m_data |= static_cast<vtype>((static_cast<utype>(right + 0u) & bf_t::vmask) << bitpos);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bf_t& operator ^=(compact_type right)
|
bf_t& operator^=(compact_type right)
|
||||||
{
|
{
|
||||||
this->m_data ^= static_cast<vtype>((static_cast<utype>(right + 0u) & bf_t::vmask) << bitpos);
|
this->m_data ^= static_cast<vtype>((static_cast<utype>(right + 0u) & bf_t::vmask) << bitpos);
|
||||||
return *this;
|
return *this;
|
||||||
|
|
@ -157,13 +159,19 @@ struct bf_t : bf_base<T, N>
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, uint I, uint N>
|
template <typename T, uint I, uint N>
|
||||||
struct std::common_type<bf_t<T, I, N>, bf_t<T, I, N>> : std::common_type<T> {};
|
struct std::common_type<bf_t<T, I, N>, bf_t<T, I, N>> : std::common_type<T>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
template <typename T, uint I, uint N, typename T2>
|
template <typename T, uint I, uint N, typename T2>
|
||||||
struct std::common_type<bf_t<T, I, N>, T2> : std::common_type<T2, std::common_type_t<T>> {};
|
struct std::common_type<bf_t<T, I, N>, T2> : std::common_type<T2, std::common_type_t<T>>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
template <typename T, uint I, uint N, typename T2>
|
template <typename T, uint I, uint N, typename T2>
|
||||||
struct std::common_type<T2, bf_t<T, I, N>> : std::common_type<std::common_type_t<T>, T2> {};
|
struct std::common_type<T2, bf_t<T, I, N>> : std::common_type<std::common_type_t<T>, T2>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
// Field pack (concatenated from left to right)
|
// Field pack (concatenated from left to right)
|
||||||
template <typename F = void, typename... Fields>
|
template <typename F = void, typename... Fields>
|
||||||
|
|
@ -199,7 +207,7 @@ struct cf_t : bf_base<typename F::type, F::bitsize + cf_t<Fields...>::bitsize>
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store value
|
// Store value
|
||||||
cf_t& operator =(compact_type value) noexcept
|
cf_t& operator=(compact_type value) noexcept
|
||||||
{
|
{
|
||||||
this->m_data = (this->m_data & ~data_mask()) | insert(value);
|
this->m_data = (this->m_data & ~data_mask()) | insert(value);
|
||||||
return *this;
|
return *this;
|
||||||
|
|
|
||||||
|
|
@ -74,61 +74,61 @@ may be faster on processor architectures which support single-instruction intege
|
||||||
#include <utility> // Includes ::std::move
|
#include <utility> // Includes ::std::move
|
||||||
|
|
||||||
#ifndef crcpp_uint8
|
#ifndef crcpp_uint8
|
||||||
# ifdef CRCPP_USE_CPP11
|
#ifdef CRCPP_USE_CPP11
|
||||||
/// @brief Unsigned 8-bit integer definition, used primarily for parameter definitions.
|
/// @brief Unsigned 8-bit integer definition, used primarily for parameter definitions.
|
||||||
# define crcpp_uint8 ::std::uint8_t
|
#define crcpp_uint8 ::std::uint8_t
|
||||||
# else
|
#else
|
||||||
/// @brief Unsigned 8-bit integer definition, used primarily for parameter definitions.
|
/// @brief Unsigned 8-bit integer definition, used primarily for parameter definitions.
|
||||||
# define crcpp_uint8 uint8_t
|
#define crcpp_uint8 uint8_t
|
||||||
# endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef crcpp_uint16
|
#ifndef crcpp_uint16
|
||||||
# ifdef CRCPP_USE_CPP11
|
#ifdef CRCPP_USE_CPP11
|
||||||
/// @brief Unsigned 16-bit integer definition, used primarily for parameter definitions.
|
/// @brief Unsigned 16-bit integer definition, used primarily for parameter definitions.
|
||||||
# define crcpp_uint16 ::std::uint16_t
|
#define crcpp_uint16 ::std::uint16_t
|
||||||
# else
|
#else
|
||||||
/// @brief Unsigned 16-bit integer definition, used primarily for parameter definitions.
|
/// @brief Unsigned 16-bit integer definition, used primarily for parameter definitions.
|
||||||
# define crcpp_uint16 uint16_t
|
#define crcpp_uint16 uint16_t
|
||||||
# endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef crcpp_uint32
|
#ifndef crcpp_uint32
|
||||||
# ifdef CRCPP_USE_CPP11
|
#ifdef CRCPP_USE_CPP11
|
||||||
/// @brief Unsigned 32-bit integer definition, used primarily for parameter definitions.
|
/// @brief Unsigned 32-bit integer definition, used primarily for parameter definitions.
|
||||||
# define crcpp_uint32 ::std::uint32_t
|
#define crcpp_uint32 ::std::uint32_t
|
||||||
# else
|
#else
|
||||||
/// @brief Unsigned 32-bit integer definition, used primarily for parameter definitions.
|
/// @brief Unsigned 32-bit integer definition, used primarily for parameter definitions.
|
||||||
# define crcpp_uint32 uint32_t
|
#define crcpp_uint32 uint32_t
|
||||||
# endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef crcpp_uint64
|
#ifndef crcpp_uint64
|
||||||
# ifdef CRCPP_USE_CPP11
|
#ifdef CRCPP_USE_CPP11
|
||||||
/// @brief Unsigned 64-bit integer definition, used primarily for parameter definitions.
|
/// @brief Unsigned 64-bit integer definition, used primarily for parameter definitions.
|
||||||
# define crcpp_uint64 ::std::uint64_t
|
#define crcpp_uint64 ::std::uint64_t
|
||||||
# else
|
#else
|
||||||
/// @brief Unsigned 64-bit integer definition, used primarily for parameter definitions.
|
/// @brief Unsigned 64-bit integer definition, used primarily for parameter definitions.
|
||||||
# define crcpp_uint64 uint64_t
|
#define crcpp_uint64 uint64_t
|
||||||
# endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef crcpp_size
|
#ifndef crcpp_size
|
||||||
# ifdef CRCPP_USE_CPP11
|
#ifdef CRCPP_USE_CPP11
|
||||||
/// @brief Unsigned size definition, used for specifying data sizes.
|
/// @brief Unsigned size definition, used for specifying data sizes.
|
||||||
# define crcpp_size ::std::size_t
|
#define crcpp_size ::std::size_t
|
||||||
# else
|
#else
|
||||||
/// @brief Unsigned size definition, used for specifying data sizes.
|
/// @brief Unsigned size definition, used for specifying data sizes.
|
||||||
# define crcpp_size size_t
|
#define crcpp_size size_t
|
||||||
# endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CRCPP_USE_CPP11
|
#ifdef CRCPP_USE_CPP11
|
||||||
/// @brief Compile-time expression definition.
|
/// @brief Compile-time expression definition.
|
||||||
# define crcpp_constexpr constexpr
|
#define crcpp_constexpr constexpr
|
||||||
#else
|
#else
|
||||||
/// @brief Compile-time expression definition.
|
/// @brief Compile-time expression definition.
|
||||||
# define crcpp_constexpr const
|
#define crcpp_constexpr const
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CRCPP_USE_NAMESPACE
|
#ifdef CRCPP_USE_NAMESPACE
|
||||||
|
|
@ -173,15 +173,15 @@ namespace CRCPP
|
||||||
struct Table
|
struct Table
|
||||||
{
|
{
|
||||||
// Constructors are intentionally NOT marked explicit.
|
// Constructors are intentionally NOT marked explicit.
|
||||||
Table(const Parameters<CRCType, CRCWidth> & parameters);
|
Table(const Parameters<CRCType, CRCWidth>& parameters);
|
||||||
|
|
||||||
#ifdef CRCPP_USE_CPP11
|
#ifdef CRCPP_USE_CPP11
|
||||||
Table(Parameters<CRCType, CRCWidth> && parameters);
|
Table(Parameters<CRCType, CRCWidth>&& parameters);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const Parameters<CRCType, CRCWidth> & GetParameters() const;
|
const Parameters<CRCType, CRCWidth>& GetParameters() const;
|
||||||
|
|
||||||
const CRCType * GetTable() const;
|
const CRCType* GetTable() const;
|
||||||
|
|
||||||
CRCType operator[](unsigned char index) const;
|
CRCType operator[](unsigned char index) const;
|
||||||
|
|
||||||
|
|
@ -195,97 +195,97 @@ namespace CRCPP
|
||||||
// The number of bits in CRCType must be at least as large as CRCWidth.
|
// The number of bits in CRCType must be at least as large as CRCWidth.
|
||||||
// CRCType must be an unsigned integer type or a custom type with operator overloads.
|
// CRCType must be an unsigned integer type or a custom type with operator overloads.
|
||||||
template <typename CRCType, crcpp_uint16 CRCWidth>
|
template <typename CRCType, crcpp_uint16 CRCWidth>
|
||||||
static CRCType Calculate(const void * data, crcpp_size size, const Parameters<CRCType, CRCWidth> & parameters);
|
static CRCType Calculate(const void* data, crcpp_size size, const Parameters<CRCType, CRCWidth>& parameters);
|
||||||
|
|
||||||
template <typename CRCType, crcpp_uint16 CRCWidth>
|
template <typename CRCType, crcpp_uint16 CRCWidth>
|
||||||
static CRCType Calculate(const void * data, crcpp_size size, const Parameters<CRCType, CRCWidth> & parameters, CRCType crc);
|
static CRCType Calculate(const void* data, crcpp_size size, const Parameters<CRCType, CRCWidth>& parameters, CRCType crc);
|
||||||
|
|
||||||
template <typename CRCType, crcpp_uint16 CRCWidth>
|
template <typename CRCType, crcpp_uint16 CRCWidth>
|
||||||
static CRCType Calculate(const void * data, crcpp_size size, const Table<CRCType, CRCWidth> & lookupTable);
|
static CRCType Calculate(const void* data, crcpp_size size, const Table<CRCType, CRCWidth>& lookupTable);
|
||||||
|
|
||||||
template <typename CRCType, crcpp_uint16 CRCWidth>
|
template <typename CRCType, crcpp_uint16 CRCWidth>
|
||||||
static CRCType Calculate(const void * data, crcpp_size size, const Table<CRCType, CRCWidth> & lookupTable, CRCType crc);
|
static CRCType Calculate(const void* data, crcpp_size size, const Table<CRCType, CRCWidth>& lookupTable, CRCType crc);
|
||||||
|
|
||||||
// Common CRCs up to 64 bits.
|
// Common CRCs up to 64 bits.
|
||||||
// Note: Check values are the computed CRCs when given an ASCII input of "123456789" (without null terminator)
|
// Note: Check values are the computed CRCs when given an ASCII input of "123456789" (without null terminator)
|
||||||
#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
||||||
static const Parameters< crcpp_uint8, 4> & CRC_4_ITU();
|
static const Parameters<crcpp_uint8, 4>& CRC_4_ITU();
|
||||||
static const Parameters< crcpp_uint8, 5> & CRC_5_EPC();
|
static const Parameters<crcpp_uint8, 5>& CRC_5_EPC();
|
||||||
static const Parameters< crcpp_uint8, 5> & CRC_5_ITU();
|
static const Parameters<crcpp_uint8, 5>& CRC_5_ITU();
|
||||||
static const Parameters< crcpp_uint8, 5> & CRC_5_USB();
|
static const Parameters<crcpp_uint8, 5>& CRC_5_USB();
|
||||||
static const Parameters< crcpp_uint8, 6> & CRC_6_CDMA2000A();
|
static const Parameters<crcpp_uint8, 6>& CRC_6_CDMA2000A();
|
||||||
static const Parameters< crcpp_uint8, 6> & CRC_6_CDMA2000B();
|
static const Parameters<crcpp_uint8, 6>& CRC_6_CDMA2000B();
|
||||||
static const Parameters< crcpp_uint8, 6> & CRC_6_ITU();
|
static const Parameters<crcpp_uint8, 6>& CRC_6_ITU();
|
||||||
static const Parameters< crcpp_uint8, 7> & CRC_7();
|
static const Parameters<crcpp_uint8, 7>& CRC_7();
|
||||||
#endif
|
#endif
|
||||||
static const Parameters< crcpp_uint8, 8> & CRC_8();
|
static const Parameters<crcpp_uint8, 8>& CRC_8();
|
||||||
#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
||||||
static const Parameters< crcpp_uint8, 8> & CRC_8_EBU();
|
static const Parameters<crcpp_uint8, 8>& CRC_8_EBU();
|
||||||
static const Parameters< crcpp_uint8, 8> & CRC_8_MAXIM();
|
static const Parameters<crcpp_uint8, 8>& CRC_8_MAXIM();
|
||||||
static const Parameters< crcpp_uint8, 8> & CRC_8_WCDMA();
|
static const Parameters<crcpp_uint8, 8>& CRC_8_WCDMA();
|
||||||
static const Parameters<crcpp_uint16, 10> & CRC_10();
|
static const Parameters<crcpp_uint16, 10>& CRC_10();
|
||||||
static const Parameters<crcpp_uint16, 10> & CRC_10_CDMA2000();
|
static const Parameters<crcpp_uint16, 10>& CRC_10_CDMA2000();
|
||||||
static const Parameters<crcpp_uint16, 11> & CRC_11();
|
static const Parameters<crcpp_uint16, 11>& CRC_11();
|
||||||
static const Parameters<crcpp_uint16, 12> & CRC_12_CDMA2000();
|
static const Parameters<crcpp_uint16, 12>& CRC_12_CDMA2000();
|
||||||
static const Parameters<crcpp_uint16, 12> & CRC_12_DECT();
|
static const Parameters<crcpp_uint16, 12>& CRC_12_DECT();
|
||||||
static const Parameters<crcpp_uint16, 12> & CRC_12_UMTS();
|
static const Parameters<crcpp_uint16, 12>& CRC_12_UMTS();
|
||||||
static const Parameters<crcpp_uint16, 13> & CRC_13_BBC();
|
static const Parameters<crcpp_uint16, 13>& CRC_13_BBC();
|
||||||
static const Parameters<crcpp_uint16, 15> & CRC_15();
|
static const Parameters<crcpp_uint16, 15>& CRC_15();
|
||||||
static const Parameters<crcpp_uint16, 15> & CRC_15_MPT1327();
|
static const Parameters<crcpp_uint16, 15>& CRC_15_MPT1327();
|
||||||
#endif
|
#endif
|
||||||
static const Parameters<crcpp_uint16, 16> & CRC_16_ARC();
|
static const Parameters<crcpp_uint16, 16>& CRC_16_ARC();
|
||||||
static const Parameters<crcpp_uint16, 16> & CRC_16_BUYPASS();
|
static const Parameters<crcpp_uint16, 16>& CRC_16_BUYPASS();
|
||||||
static const Parameters<crcpp_uint16, 16> & CRC_16_CCITTFALSE();
|
static const Parameters<crcpp_uint16, 16>& CRC_16_CCITTFALSE();
|
||||||
#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
||||||
static const Parameters<crcpp_uint16, 16> & CRC_16_CDMA2000();
|
static const Parameters<crcpp_uint16, 16>& CRC_16_CDMA2000();
|
||||||
static const Parameters<crcpp_uint16, 16> & CRC_16_DECTR();
|
static const Parameters<crcpp_uint16, 16>& CRC_16_DECTR();
|
||||||
static const Parameters<crcpp_uint16, 16> & CRC_16_DECTX();
|
static const Parameters<crcpp_uint16, 16>& CRC_16_DECTX();
|
||||||
static const Parameters<crcpp_uint16, 16> & CRC_16_DNP();
|
static const Parameters<crcpp_uint16, 16>& CRC_16_DNP();
|
||||||
#endif
|
#endif
|
||||||
static const Parameters<crcpp_uint16, 16> & CRC_16_GENIBUS();
|
static const Parameters<crcpp_uint16, 16>& CRC_16_GENIBUS();
|
||||||
static const Parameters<crcpp_uint16, 16> & CRC_16_KERMIT();
|
static const Parameters<crcpp_uint16, 16>& CRC_16_KERMIT();
|
||||||
#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
||||||
static const Parameters<crcpp_uint16, 16> & CRC_16_MAXIM();
|
static const Parameters<crcpp_uint16, 16>& CRC_16_MAXIM();
|
||||||
static const Parameters<crcpp_uint16, 16> & CRC_16_MODBUS();
|
static const Parameters<crcpp_uint16, 16>& CRC_16_MODBUS();
|
||||||
static const Parameters<crcpp_uint16, 16> & CRC_16_T10DIF();
|
static const Parameters<crcpp_uint16, 16>& CRC_16_T10DIF();
|
||||||
static const Parameters<crcpp_uint16, 16> & CRC_16_USB();
|
static const Parameters<crcpp_uint16, 16>& CRC_16_USB();
|
||||||
#endif
|
#endif
|
||||||
static const Parameters<crcpp_uint16, 16> & CRC_16_X25();
|
static const Parameters<crcpp_uint16, 16>& CRC_16_X25();
|
||||||
static const Parameters<crcpp_uint16, 16> & CRC_16_XMODEM();
|
static const Parameters<crcpp_uint16, 16>& CRC_16_XMODEM();
|
||||||
#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
||||||
static const Parameters<crcpp_uint32, 17> & CRC_17_CAN();
|
static const Parameters<crcpp_uint32, 17>& CRC_17_CAN();
|
||||||
static const Parameters<crcpp_uint32, 21> & CRC_21_CAN();
|
static const Parameters<crcpp_uint32, 21>& CRC_21_CAN();
|
||||||
static const Parameters<crcpp_uint32, 24> & CRC_24();
|
static const Parameters<crcpp_uint32, 24>& CRC_24();
|
||||||
static const Parameters<crcpp_uint32, 24> & CRC_24_FLEXRAYA();
|
static const Parameters<crcpp_uint32, 24>& CRC_24_FLEXRAYA();
|
||||||
static const Parameters<crcpp_uint32, 24> & CRC_24_FLEXRAYB();
|
static const Parameters<crcpp_uint32, 24>& CRC_24_FLEXRAYB();
|
||||||
static const Parameters<crcpp_uint32, 30> & CRC_30();
|
static const Parameters<crcpp_uint32, 30>& CRC_30();
|
||||||
#endif
|
#endif
|
||||||
static const Parameters<crcpp_uint32, 32> & CRC_32();
|
static const Parameters<crcpp_uint32, 32>& CRC_32();
|
||||||
static const Parameters<crcpp_uint32, 32> & CRC_32_BZIP2();
|
static const Parameters<crcpp_uint32, 32>& CRC_32_BZIP2();
|
||||||
#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
||||||
static const Parameters<crcpp_uint32, 32> & CRC_32_C();
|
static const Parameters<crcpp_uint32, 32>& CRC_32_C();
|
||||||
#endif
|
#endif
|
||||||
static const Parameters<crcpp_uint32, 32> & CRC_32_MPEG2();
|
static const Parameters<crcpp_uint32, 32>& CRC_32_MPEG2();
|
||||||
static const Parameters<crcpp_uint32, 32> & CRC_32_POSIX();
|
static const Parameters<crcpp_uint32, 32>& CRC_32_POSIX();
|
||||||
#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
||||||
static const Parameters<crcpp_uint32, 32> & CRC_32_Q();
|
static const Parameters<crcpp_uint32, 32>& CRC_32_Q();
|
||||||
static const Parameters<crcpp_uint64, 40> & CRC_40_GSM();
|
static const Parameters<crcpp_uint64, 40>& CRC_40_GSM();
|
||||||
static const Parameters<crcpp_uint64, 64> & CRC_64();
|
static const Parameters<crcpp_uint64, 64>& CRC_64();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CRCPP_USE_CPP11
|
#ifdef CRCPP_USE_CPP11
|
||||||
CRC() = delete;
|
CRC() = delete;
|
||||||
CRC(const CRC & other) = delete;
|
CRC(const CRC& other) = delete;
|
||||||
CRC & operator=(const CRC & other) = delete;
|
CRC& operator=(const CRC& other) = delete;
|
||||||
CRC(CRC && other) = delete;
|
CRC(CRC&& other) = delete;
|
||||||
CRC & operator=(CRC && other) = delete;
|
CRC& operator=(CRC&& other) = delete;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifndef CRCPP_USE_CPP11
|
#ifndef CRCPP_USE_CPP11
|
||||||
CRC();
|
CRC();
|
||||||
CRC(const CRC & other);
|
CRC(const CRC& other);
|
||||||
CRC & operator=(const CRC & other);
|
CRC& operator=(const CRC& other);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <typename IntegerType>
|
template <typename IntegerType>
|
||||||
|
|
@ -298,10 +298,10 @@ namespace CRCPP
|
||||||
static CRCType UndoFinalize(CRCType crc, CRCType finalXOR, bool reflectOutput);
|
static CRCType UndoFinalize(CRCType crc, CRCType finalXOR, bool reflectOutput);
|
||||||
|
|
||||||
template <typename CRCType, crcpp_uint16 CRCWidth>
|
template <typename CRCType, crcpp_uint16 CRCWidth>
|
||||||
static CRCType CalculateRemainder(const void * data, crcpp_size size, const Parameters<CRCType, CRCWidth> & parameters, CRCType remainder);
|
static CRCType CalculateRemainder(const void* data, crcpp_size size, const Parameters<CRCType, CRCWidth>& parameters, CRCType remainder);
|
||||||
|
|
||||||
template <typename CRCType, crcpp_uint16 CRCWidth>
|
template <typename CRCType, crcpp_uint16 CRCWidth>
|
||||||
static CRCType CalculateRemainder(const void * data, crcpp_size size, const Table<CRCType, CRCWidth> & lookupTable, CRCType remainder);
|
static CRCType CalculateRemainder(const void* data, crcpp_size size, const Table<CRCType, CRCWidth>& lookupTable, CRCType remainder);
|
||||||
|
|
||||||
template <typename IntegerType>
|
template <typename IntegerType>
|
||||||
static crcpp_constexpr IntegerType BoundedConstexprValue(IntegerType x);
|
static crcpp_constexpr IntegerType BoundedConstexprValue(IntegerType x);
|
||||||
|
|
@ -329,8 +329,7 @@ namespace CRCPP
|
||||||
@tparam CRCWidth Number of bits in the CRC
|
@tparam CRCWidth Number of bits in the CRC
|
||||||
*/
|
*/
|
||||||
template <typename CRCType, crcpp_uint16 CRCWidth>
|
template <typename CRCType, crcpp_uint16 CRCWidth>
|
||||||
inline CRC::Table<CRCType, CRCWidth>::Table(const Parameters<CRCType, CRCWidth> & parameters) :
|
inline CRC::Table<CRCType, CRCWidth>::Table(const Parameters<CRCType, CRCWidth>& parameters) : parameters(parameters)
|
||||||
parameters(parameters)
|
|
||||||
{
|
{
|
||||||
InitTable();
|
InitTable();
|
||||||
}
|
}
|
||||||
|
|
@ -343,8 +342,7 @@ namespace CRCPP
|
||||||
@tparam CRCWidth Number of bits in the CRC
|
@tparam CRCWidth Number of bits in the CRC
|
||||||
*/
|
*/
|
||||||
template <typename CRCType, crcpp_uint16 CRCWidth>
|
template <typename CRCType, crcpp_uint16 CRCWidth>
|
||||||
inline CRC::Table<CRCType, CRCWidth>::Table(Parameters<CRCType, CRCWidth> && parameters) :
|
inline CRC::Table<CRCType, CRCWidth>::Table(Parameters<CRCType, CRCWidth>&& parameters) : parameters(::std::move(parameters))
|
||||||
parameters(::std::move(parameters))
|
|
||||||
{
|
{
|
||||||
InitTable();
|
InitTable();
|
||||||
}
|
}
|
||||||
|
|
@ -357,7 +355,7 @@ namespace CRCPP
|
||||||
@return CRC parameters
|
@return CRC parameters
|
||||||
*/
|
*/
|
||||||
template <typename CRCType, crcpp_uint16 CRCWidth>
|
template <typename CRCType, crcpp_uint16 CRCWidth>
|
||||||
inline const CRC::Parameters<CRCType, CRCWidth> & CRC::Table<CRCType, CRCWidth>::GetParameters() const
|
inline const CRC::Parameters<CRCType, CRCWidth>& CRC::Table<CRCType, CRCWidth>::GetParameters() const
|
||||||
{
|
{
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
@ -369,7 +367,7 @@ namespace CRCPP
|
||||||
@return CRC table
|
@return CRC table
|
||||||
*/
|
*/
|
||||||
template <typename CRCType, crcpp_uint16 CRCWidth>
|
template <typename CRCType, crcpp_uint16 CRCWidth>
|
||||||
inline const CRCType * CRC::Table<CRCType, CRCWidth>::GetTable() const
|
inline const CRCType* CRC::Table<CRCType, CRCWidth>::GetTable() const
|
||||||
{
|
{
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
@ -435,7 +433,7 @@ namespace CRCPP
|
||||||
@return CRC
|
@return CRC
|
||||||
*/
|
*/
|
||||||
template <typename CRCType, crcpp_uint16 CRCWidth>
|
template <typename CRCType, crcpp_uint16 CRCWidth>
|
||||||
inline CRCType CRC::Calculate(const void * data, crcpp_size size, const Parameters<CRCType, CRCWidth> & parameters)
|
inline CRCType CRC::Calculate(const void* data, crcpp_size size, const Parameters<CRCType, CRCWidth>& parameters)
|
||||||
{
|
{
|
||||||
CRCType remainder = CalculateRemainder(data, size, parameters, parameters.initialValue);
|
CRCType remainder = CalculateRemainder(data, size, parameters, parameters.initialValue);
|
||||||
|
|
||||||
|
|
@ -455,7 +453,7 @@ namespace CRCPP
|
||||||
@return CRC
|
@return CRC
|
||||||
*/
|
*/
|
||||||
template <typename CRCType, crcpp_uint16 CRCWidth>
|
template <typename CRCType, crcpp_uint16 CRCWidth>
|
||||||
inline CRCType CRC::Calculate(const void * data, crcpp_size size, const Parameters<CRCType, CRCWidth> & parameters, CRCType crc)
|
inline CRCType CRC::Calculate(const void* data, crcpp_size size, const Parameters<CRCType, CRCWidth>& parameters, CRCType crc)
|
||||||
{
|
{
|
||||||
CRCType remainder = UndoFinalize<CRCType, CRCWidth>(crc, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput);
|
CRCType remainder = UndoFinalize<CRCType, CRCWidth>(crc, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput);
|
||||||
|
|
||||||
|
|
@ -476,9 +474,9 @@ namespace CRCPP
|
||||||
@return CRC
|
@return CRC
|
||||||
*/
|
*/
|
||||||
template <typename CRCType, crcpp_uint16 CRCWidth>
|
template <typename CRCType, crcpp_uint16 CRCWidth>
|
||||||
inline CRCType CRC::Calculate(const void * data, crcpp_size size, const Table<CRCType, CRCWidth> & lookupTable)
|
inline CRCType CRC::Calculate(const void* data, crcpp_size size, const Table<CRCType, CRCWidth>& lookupTable)
|
||||||
{
|
{
|
||||||
const Parameters<CRCType, CRCWidth> & parameters = lookupTable.GetParameters();
|
const Parameters<CRCType, CRCWidth>& parameters = lookupTable.GetParameters();
|
||||||
|
|
||||||
CRCType remainder = CalculateRemainder(data, size, lookupTable, parameters.initialValue);
|
CRCType remainder = CalculateRemainder(data, size, lookupTable, parameters.initialValue);
|
||||||
|
|
||||||
|
|
@ -499,9 +497,9 @@ namespace CRCPP
|
||||||
@return CRC
|
@return CRC
|
||||||
*/
|
*/
|
||||||
template <typename CRCType, crcpp_uint16 CRCWidth>
|
template <typename CRCType, crcpp_uint16 CRCWidth>
|
||||||
inline CRCType CRC::Calculate(const void * data, crcpp_size size, const Table<CRCType, CRCWidth> & lookupTable, CRCType crc)
|
inline CRCType CRC::Calculate(const void* data, crcpp_size size, const Table<CRCType, CRCWidth>& lookupTable, CRCType crc)
|
||||||
{
|
{
|
||||||
const Parameters<CRCType, CRCWidth> & parameters = lookupTable.GetParameters();
|
const Parameters<CRCType, CRCWidth>& parameters = lookupTable.GetParameters();
|
||||||
|
|
||||||
CRCType remainder = UndoFinalize<CRCType, CRCWidth>(crc, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput);
|
CRCType remainder = UndoFinalize<CRCType, CRCWidth>(crc, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput);
|
||||||
|
|
||||||
|
|
@ -602,7 +600,7 @@ namespace CRCPP
|
||||||
@return CRC remainder
|
@return CRC remainder
|
||||||
*/
|
*/
|
||||||
template <typename CRCType, crcpp_uint16 CRCWidth>
|
template <typename CRCType, crcpp_uint16 CRCWidth>
|
||||||
inline CRCType CRC::CalculateRemainder(const void * data, crcpp_size size, const Parameters<CRCType, CRCWidth> & parameters, CRCType remainder)
|
inline CRCType CRC::CalculateRemainder(const void* data, crcpp_size size, const Parameters<CRCType, CRCWidth>& parameters, CRCType remainder)
|
||||||
{
|
{
|
||||||
#ifdef CRCPP_USE_CPP11
|
#ifdef CRCPP_USE_CPP11
|
||||||
// This static_assert is put here because this function will always be compiled in no matter what
|
// This static_assert is put here because this function will always be compiled in no matter what
|
||||||
|
|
@ -611,10 +609,13 @@ namespace CRCPP
|
||||||
#else
|
#else
|
||||||
// Catching this compile-time error is very important. Sadly, the compiler error will be very cryptic, but it's
|
// Catching this compile-time error is very important. Sadly, the compiler error will be very cryptic, but it's
|
||||||
// better than nothing.
|
// better than nothing.
|
||||||
enum { static_assert_failed_CRCType_is_too_small_to_contain_a_CRC_of_width_CRCWidth = 1 / (::std::numeric_limits<CRCType>::digits >= CRCWidth ? 1 : 0) };
|
enum
|
||||||
|
{
|
||||||
|
static_assert_failed_CRCType_is_too_small_to_contain_a_CRC_of_width_CRCWidth = 1 / (::std::numeric_limits<CRCType>::digits >= CRCWidth ? 1 : 0)
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const unsigned char * current = reinterpret_cast<const unsigned char *>(data);
|
const unsigned char* current = reinterpret_cast<const unsigned char*>(data);
|
||||||
|
|
||||||
// Slightly different implementations based on the parameters. The current implementations try to eliminate as much
|
// Slightly different implementations based on the parameters. The current implementations try to eliminate as much
|
||||||
// computation from the inner loop (looping over each bit) as possible.
|
// computation from the inner loop (looping over each bit) as possible.
|
||||||
|
|
@ -717,9 +718,9 @@ namespace CRCPP
|
||||||
@return CRC remainder
|
@return CRC remainder
|
||||||
*/
|
*/
|
||||||
template <typename CRCType, crcpp_uint16 CRCWidth>
|
template <typename CRCType, crcpp_uint16 CRCWidth>
|
||||||
inline CRCType CRC::CalculateRemainder(const void * data, crcpp_size size, const Table<CRCType, CRCWidth> & lookupTable, CRCType remainder)
|
inline CRCType CRC::CalculateRemainder(const void* data, crcpp_size size, const Table<CRCType, CRCWidth>& lookupTable, CRCType remainder)
|
||||||
{
|
{
|
||||||
const unsigned char * current = reinterpret_cast<const unsigned char *>(data);
|
const unsigned char* current = reinterpret_cast<const unsigned char*>(data);
|
||||||
|
|
||||||
if (lookupTable.GetParameters().reflectInput)
|
if (lookupTable.GetParameters().reflectInput)
|
||||||
{
|
{
|
||||||
|
|
@ -729,12 +730,12 @@ namespace CRCPP
|
||||||
// Disable warning about data loss when doing (remainder >> CHAR_BIT) when
|
// Disable warning about data loss when doing (remainder >> CHAR_BIT) when
|
||||||
// remainder is one byte long. The algorithm is still correct in this case,
|
// remainder is one byte long. The algorithm is still correct in this case,
|
||||||
// though it's possible that one additional machine instruction will be executed.
|
// though it's possible that one additional machine instruction will be executed.
|
||||||
# pragma warning (push)
|
#pragma warning(push)
|
||||||
# pragma warning (disable : 4333)
|
#pragma warning(disable : 4333)
|
||||||
#endif
|
#endif
|
||||||
remainder = (remainder >> CHAR_BIT) ^ lookupTable[static_cast<unsigned char>(remainder ^ *current++)];
|
remainder = (remainder >> CHAR_BIT) ^ lookupTable[static_cast<unsigned char>(remainder ^ *current++)];
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
# pragma warning (pop)
|
#pragma warning(pop)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -792,9 +793,9 @@ namespace CRCPP
|
||||||
- check value = 0x7
|
- check value = 0x7
|
||||||
@return CRC-4 ITU parameters
|
@return CRC-4 ITU parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint8, 4> & CRC::CRC_4_ITU()
|
inline const CRC::Parameters<crcpp_uint8, 4>& CRC::CRC_4_ITU()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint8, 4> parameters = { 0x3, 0x0, 0x0, true, true };
|
static const Parameters<crcpp_uint8, 4> parameters = {0x3, 0x0, 0x0, true, true};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -810,9 +811,9 @@ namespace CRCPP
|
||||||
- check value = 0x00
|
- check value = 0x00
|
||||||
@return CRC-5 EPC parameters
|
@return CRC-5 EPC parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint8, 5> & CRC::CRC_5_EPC()
|
inline const CRC::Parameters<crcpp_uint8, 5>& CRC::CRC_5_EPC()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint8, 5> parameters = { 0x09, 0x09, 0x00, false, false };
|
static const Parameters<crcpp_uint8, 5> parameters = {0x09, 0x09, 0x00, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -828,9 +829,9 @@ namespace CRCPP
|
||||||
- check value = 0x07
|
- check value = 0x07
|
||||||
@return CRC-5 ITU parameters
|
@return CRC-5 ITU parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint8, 5> & CRC::CRC_5_ITU()
|
inline const CRC::Parameters<crcpp_uint8, 5>& CRC::CRC_5_ITU()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint8, 5> parameters = { 0x15, 0x00, 0x00, true, true };
|
static const Parameters<crcpp_uint8, 5> parameters = {0x15, 0x00, 0x00, true, true};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -846,9 +847,9 @@ namespace CRCPP
|
||||||
- check value = 0x19
|
- check value = 0x19
|
||||||
@return CRC-5 USB parameters
|
@return CRC-5 USB parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint8, 5> & CRC::CRC_5_USB()
|
inline const CRC::Parameters<crcpp_uint8, 5>& CRC::CRC_5_USB()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint8, 5> parameters = { 0x05, 0x1F, 0x1F, true, true };
|
static const Parameters<crcpp_uint8, 5> parameters = {0x05, 0x1F, 0x1F, true, true};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -864,9 +865,9 @@ namespace CRCPP
|
||||||
- check value = 0x0D
|
- check value = 0x0D
|
||||||
@return CRC-6 CDMA2000-A parameters
|
@return CRC-6 CDMA2000-A parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint8, 6> & CRC::CRC_6_CDMA2000A()
|
inline const CRC::Parameters<crcpp_uint8, 6>& CRC::CRC_6_CDMA2000A()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint8, 6> parameters = { 0x27, 0x3F, 0x00, false, false };
|
static const Parameters<crcpp_uint8, 6> parameters = {0x27, 0x3F, 0x00, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -882,9 +883,9 @@ namespace CRCPP
|
||||||
- check value = 0x3B
|
- check value = 0x3B
|
||||||
@return CRC-6 CDMA2000-B parameters
|
@return CRC-6 CDMA2000-B parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint8, 6> & CRC::CRC_6_CDMA2000B()
|
inline const CRC::Parameters<crcpp_uint8, 6>& CRC::CRC_6_CDMA2000B()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint8, 6> parameters = { 0x07, 0x3F, 0x00, false, false };
|
static const Parameters<crcpp_uint8, 6> parameters = {0x07, 0x3F, 0x00, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -900,9 +901,9 @@ namespace CRCPP
|
||||||
- check value = 0x06
|
- check value = 0x06
|
||||||
@return CRC-6 ITU parameters
|
@return CRC-6 ITU parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint8, 6> & CRC::CRC_6_ITU()
|
inline const CRC::Parameters<crcpp_uint8, 6>& CRC::CRC_6_ITU()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint8, 6> parameters = { 0x03, 0x00, 0x00, true, true };
|
static const Parameters<crcpp_uint8, 6> parameters = {0x03, 0x00, 0x00, true, true};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -918,9 +919,9 @@ namespace CRCPP
|
||||||
- check value = 0x75
|
- check value = 0x75
|
||||||
@return CRC-7 JEDEC parameters
|
@return CRC-7 JEDEC parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint8, 7> & CRC::CRC_7()
|
inline const CRC::Parameters<crcpp_uint8, 7>& CRC::CRC_7()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint8, 7> parameters = { 0x09, 0x00, 0x00, false, false };
|
static const Parameters<crcpp_uint8, 7> parameters = {0x09, 0x00, 0x00, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
||||||
|
|
@ -937,9 +938,9 @@ namespace CRCPP
|
||||||
- check value = 0xF4
|
- check value = 0xF4
|
||||||
@return CRC-8 SMBus parameters
|
@return CRC-8 SMBus parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint8, 8> & CRC::CRC_8()
|
inline const CRC::Parameters<crcpp_uint8, 8>& CRC::CRC_8()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint8, 8> parameters = { 0x07, 0x00, 0x00, false, false };
|
static const Parameters<crcpp_uint8, 8> parameters = {0x07, 0x00, 0x00, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -956,9 +957,9 @@ namespace CRCPP
|
||||||
- check value = 0x97
|
- check value = 0x97
|
||||||
@return CRC-8 EBU parameters
|
@return CRC-8 EBU parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint8, 8> & CRC::CRC_8_EBU()
|
inline const CRC::Parameters<crcpp_uint8, 8>& CRC::CRC_8_EBU()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint8, 8> parameters = { 0x1D, 0xFF, 0x00, true, true };
|
static const Parameters<crcpp_uint8, 8> parameters = {0x1D, 0xFF, 0x00, true, true};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -974,9 +975,9 @@ namespace CRCPP
|
||||||
- check value = 0xA1
|
- check value = 0xA1
|
||||||
@return CRC-8 MAXIM parameters
|
@return CRC-8 MAXIM parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint8, 8> & CRC::CRC_8_MAXIM()
|
inline const CRC::Parameters<crcpp_uint8, 8>& CRC::CRC_8_MAXIM()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint8, 8> parameters = { 0x31, 0x00, 0x00, true, true };
|
static const Parameters<crcpp_uint8, 8> parameters = {0x31, 0x00, 0x00, true, true};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -992,9 +993,9 @@ namespace CRCPP
|
||||||
- check value = 0x25
|
- check value = 0x25
|
||||||
@return CRC-8 WCDMA parameters
|
@return CRC-8 WCDMA parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint8, 8> & CRC::CRC_8_WCDMA()
|
inline const CRC::Parameters<crcpp_uint8, 8>& CRC::CRC_8_WCDMA()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint8, 8> parameters = { 0x9B, 0x00, 0x00, true, true };
|
static const Parameters<crcpp_uint8, 8> parameters = {0x9B, 0x00, 0x00, true, true};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1010,9 +1011,9 @@ namespace CRCPP
|
||||||
- check value = 0x199
|
- check value = 0x199
|
||||||
@return CRC-10 ITU parameters
|
@return CRC-10 ITU parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 10> & CRC::CRC_10()
|
inline const CRC::Parameters<crcpp_uint16, 10>& CRC::CRC_10()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 10> parameters = { 0x233, 0x000, 0x000, false, false };
|
static const Parameters<crcpp_uint16, 10> parameters = {0x233, 0x000, 0x000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1028,9 +1029,9 @@ namespace CRCPP
|
||||||
- check value = 0x233
|
- check value = 0x233
|
||||||
@return CRC-10 CDMA2000 parameters
|
@return CRC-10 CDMA2000 parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 10> & CRC::CRC_10_CDMA2000()
|
inline const CRC::Parameters<crcpp_uint16, 10>& CRC::CRC_10_CDMA2000()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 10> parameters = { 0x3D9, 0x3FF, 0x000, false, false };
|
static const Parameters<crcpp_uint16, 10> parameters = {0x3D9, 0x3FF, 0x000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1046,9 +1047,9 @@ namespace CRCPP
|
||||||
- check value = 0x5A3
|
- check value = 0x5A3
|
||||||
@return CRC-11 FlexRay parameters
|
@return CRC-11 FlexRay parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 11> & CRC::CRC_11()
|
inline const CRC::Parameters<crcpp_uint16, 11>& CRC::CRC_11()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 11> parameters = { 0x385, 0x01A, 0x000, false, false };
|
static const Parameters<crcpp_uint16, 11> parameters = {0x385, 0x01A, 0x000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1064,9 +1065,9 @@ namespace CRCPP
|
||||||
- check value = 0xD4D
|
- check value = 0xD4D
|
||||||
@return CRC-12 CDMA2000 parameters
|
@return CRC-12 CDMA2000 parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 12> & CRC::CRC_12_CDMA2000()
|
inline const CRC::Parameters<crcpp_uint16, 12>& CRC::CRC_12_CDMA2000()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 12> parameters = { 0xF13, 0xFFF, 0x000, false, false };
|
static const Parameters<crcpp_uint16, 12> parameters = {0xF13, 0xFFF, 0x000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1082,9 +1083,9 @@ namespace CRCPP
|
||||||
- check value = 0xF5B
|
- check value = 0xF5B
|
||||||
@return CRC-12 DECT parameters
|
@return CRC-12 DECT parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 12> & CRC::CRC_12_DECT()
|
inline const CRC::Parameters<crcpp_uint16, 12>& CRC::CRC_12_DECT()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 12> parameters = { 0x80F, 0x000, 0x000, false, false };
|
static const Parameters<crcpp_uint16, 12> parameters = {0x80F, 0x000, 0x000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1100,9 +1101,9 @@ namespace CRCPP
|
||||||
- check value = 0xDAF
|
- check value = 0xDAF
|
||||||
@return CRC-12 UMTS parameters
|
@return CRC-12 UMTS parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 12> & CRC::CRC_12_UMTS()
|
inline const CRC::Parameters<crcpp_uint16, 12>& CRC::CRC_12_UMTS()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 12> parameters = { 0x80F, 0x000, 0x000, false, true };
|
static const Parameters<crcpp_uint16, 12> parameters = {0x80F, 0x000, 0x000, false, true};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1118,9 +1119,9 @@ namespace CRCPP
|
||||||
- check value = 0x04FA
|
- check value = 0x04FA
|
||||||
@return CRC-13 BBC parameters
|
@return CRC-13 BBC parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 13> & CRC::CRC_13_BBC()
|
inline const CRC::Parameters<crcpp_uint16, 13>& CRC::CRC_13_BBC()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 13> parameters = { 0x1CF5, 0x0000, 0x0000, false, false };
|
static const Parameters<crcpp_uint16, 13> parameters = {0x1CF5, 0x0000, 0x0000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1136,9 +1137,9 @@ namespace CRCPP
|
||||||
- check value = 0x059E
|
- check value = 0x059E
|
||||||
@return CRC-15 CAN parameters
|
@return CRC-15 CAN parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 15> & CRC::CRC_15()
|
inline const CRC::Parameters<crcpp_uint16, 15>& CRC::CRC_15()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 15> parameters = { 0x4599, 0x0000, 0x0000, false, false };
|
static const Parameters<crcpp_uint16, 15> parameters = {0x4599, 0x0000, 0x0000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1154,9 +1155,9 @@ namespace CRCPP
|
||||||
- check value = 0x2566
|
- check value = 0x2566
|
||||||
@return CRC-15 MPT1327 parameters
|
@return CRC-15 MPT1327 parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 15> & CRC::CRC_15_MPT1327()
|
inline const CRC::Parameters<crcpp_uint16, 15>& CRC::CRC_15_MPT1327()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 15> parameters = { 0x6815, 0x0000, 0x0001, false, false };
|
static const Parameters<crcpp_uint16, 15> parameters = {0x6815, 0x0000, 0x0001, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
||||||
|
|
@ -1173,9 +1174,9 @@ namespace CRCPP
|
||||||
- check value = 0xBB3D
|
- check value = 0xBB3D
|
||||||
@return CRC-16 ARC parameters
|
@return CRC-16 ARC parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_ARC()
|
inline const CRC::Parameters<crcpp_uint16, 16>& CRC::CRC_16_ARC()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 16> parameters = { 0x8005, 0x0000, 0x0000, true, true };
|
static const Parameters<crcpp_uint16, 16> parameters = {0x8005, 0x0000, 0x0000, true, true};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1191,9 +1192,9 @@ namespace CRCPP
|
||||||
- check value = 0xFEE8
|
- check value = 0xFEE8
|
||||||
@return CRC-16 BUYPASS parameters
|
@return CRC-16 BUYPASS parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_BUYPASS()
|
inline const CRC::Parameters<crcpp_uint16, 16>& CRC::CRC_16_BUYPASS()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 16> parameters = { 0x8005, 0x0000, 0x0000, false, false };
|
static const Parameters<crcpp_uint16, 16> parameters = {0x8005, 0x0000, 0x0000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1209,9 +1210,9 @@ namespace CRCPP
|
||||||
- check value = 0x29B1
|
- check value = 0x29B1
|
||||||
@return CRC-16 CCITT FALSE parameters
|
@return CRC-16 CCITT FALSE parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_CCITTFALSE()
|
inline const CRC::Parameters<crcpp_uint16, 16>& CRC::CRC_16_CCITTFALSE()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 16> parameters = { 0x1021, 0xFFFF, 0x0000, false, false };
|
static const Parameters<crcpp_uint16, 16> parameters = {0x1021, 0xFFFF, 0x0000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1228,9 +1229,9 @@ namespace CRCPP
|
||||||
- check value = 0x4C06
|
- check value = 0x4C06
|
||||||
@return CRC-16 CDMA2000 parameters
|
@return CRC-16 CDMA2000 parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_CDMA2000()
|
inline const CRC::Parameters<crcpp_uint16, 16>& CRC::CRC_16_CDMA2000()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 16> parameters = { 0xC867, 0xFFFF, 0x0000, false, false };
|
static const Parameters<crcpp_uint16, 16> parameters = {0xC867, 0xFFFF, 0x0000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1246,9 +1247,9 @@ namespace CRCPP
|
||||||
- check value = 0x007E
|
- check value = 0x007E
|
||||||
@return CRC-16 DECT-R parameters
|
@return CRC-16 DECT-R parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_DECTR()
|
inline const CRC::Parameters<crcpp_uint16, 16>& CRC::CRC_16_DECTR()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 16> parameters = { 0x0589, 0x0000, 0x0001, false, false };
|
static const Parameters<crcpp_uint16, 16> parameters = {0x0589, 0x0000, 0x0001, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1264,9 +1265,9 @@ namespace CRCPP
|
||||||
- check value = 0x007F
|
- check value = 0x007F
|
||||||
@return CRC-16 DECT-X parameters
|
@return CRC-16 DECT-X parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_DECTX()
|
inline const CRC::Parameters<crcpp_uint16, 16>& CRC::CRC_16_DECTX()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 16> parameters = { 0x0589, 0x0000, 0x0000, false, false };
|
static const Parameters<crcpp_uint16, 16> parameters = {0x0589, 0x0000, 0x0000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1282,9 +1283,9 @@ namespace CRCPP
|
||||||
- check value = 0xEA82
|
- check value = 0xEA82
|
||||||
@return CRC-16 DNP parameters
|
@return CRC-16 DNP parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_DNP()
|
inline const CRC::Parameters<crcpp_uint16, 16>& CRC::CRC_16_DNP()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 16> parameters = { 0x3D65, 0x0000, 0xFFFF, true, true };
|
static const Parameters<crcpp_uint16, 16> parameters = {0x3D65, 0x0000, 0xFFFF, true, true};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
||||||
|
|
@ -1301,9 +1302,9 @@ namespace CRCPP
|
||||||
- check value = 0xD64E
|
- check value = 0xD64E
|
||||||
@return CRC-16 GENIBUS parameters
|
@return CRC-16 GENIBUS parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_GENIBUS()
|
inline const CRC::Parameters<crcpp_uint16, 16>& CRC::CRC_16_GENIBUS()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 16> parameters = { 0x1021, 0xFFFF, 0xFFFF, false, false };
|
static const Parameters<crcpp_uint16, 16> parameters = {0x1021, 0xFFFF, 0xFFFF, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1319,9 +1320,9 @@ namespace CRCPP
|
||||||
- check value = 0x2189
|
- check value = 0x2189
|
||||||
@return CRC-16 KERMIT parameters
|
@return CRC-16 KERMIT parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_KERMIT()
|
inline const CRC::Parameters<crcpp_uint16, 16>& CRC::CRC_16_KERMIT()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 16> parameters = { 0x1021, 0x0000, 0x0000, true, true };
|
static const Parameters<crcpp_uint16, 16> parameters = {0x1021, 0x0000, 0x0000, true, true};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1338,9 +1339,9 @@ namespace CRCPP
|
||||||
- check value = 0x44C2
|
- check value = 0x44C2
|
||||||
@return CRC-16 MAXIM parameters
|
@return CRC-16 MAXIM parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_MAXIM()
|
inline const CRC::Parameters<crcpp_uint16, 16>& CRC::CRC_16_MAXIM()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 16> parameters = { 0x8005, 0x0000, 0xFFFF, true, true };
|
static const Parameters<crcpp_uint16, 16> parameters = {0x8005, 0x0000, 0xFFFF, true, true};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1356,9 +1357,9 @@ namespace CRCPP
|
||||||
- check value = 0x4B37
|
- check value = 0x4B37
|
||||||
@return CRC-16 MODBUS parameters
|
@return CRC-16 MODBUS parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_MODBUS()
|
inline const CRC::Parameters<crcpp_uint16, 16>& CRC::CRC_16_MODBUS()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 16> parameters = { 0x8005, 0xFFFF, 0x0000, true, true };
|
static const Parameters<crcpp_uint16, 16> parameters = {0x8005, 0xFFFF, 0x0000, true, true};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1374,9 +1375,9 @@ namespace CRCPP
|
||||||
- check value = 0xD0DB
|
- check value = 0xD0DB
|
||||||
@return CRC-16 T10-DIF parameters
|
@return CRC-16 T10-DIF parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_T10DIF()
|
inline const CRC::Parameters<crcpp_uint16, 16>& CRC::CRC_16_T10DIF()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 16> parameters = { 0x8BB7, 0x0000, 0x0000, false, false };
|
static const Parameters<crcpp_uint16, 16> parameters = {0x8BB7, 0x0000, 0x0000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1392,9 +1393,9 @@ namespace CRCPP
|
||||||
- check value = 0xB4C8
|
- check value = 0xB4C8
|
||||||
@return CRC-16 USB parameters
|
@return CRC-16 USB parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_USB()
|
inline const CRC::Parameters<crcpp_uint16, 16>& CRC::CRC_16_USB()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 16> parameters = { 0x8005, 0xFFFF, 0xFFFF, true, true };
|
static const Parameters<crcpp_uint16, 16> parameters = {0x8005, 0xFFFF, 0xFFFF, true, true};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
||||||
|
|
@ -1411,9 +1412,9 @@ namespace CRCPP
|
||||||
- check value = 0x906E
|
- check value = 0x906E
|
||||||
@return CRC-16 X-25 parameters
|
@return CRC-16 X-25 parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_X25()
|
inline const CRC::Parameters<crcpp_uint16, 16>& CRC::CRC_16_X25()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 16> parameters = { 0x1021, 0xFFFF, 0xFFFF, true, true };
|
static const Parameters<crcpp_uint16, 16> parameters = {0x1021, 0xFFFF, 0xFFFF, true, true};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1429,9 +1430,9 @@ namespace CRCPP
|
||||||
- check value = 0x31C3
|
- check value = 0x31C3
|
||||||
@return CRC-16 XMODEM parameters
|
@return CRC-16 XMODEM parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_XMODEM()
|
inline const CRC::Parameters<crcpp_uint16, 16>& CRC::CRC_16_XMODEM()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint16, 16> parameters = { 0x1021, 0x0000, 0x0000, false, false };
|
static const Parameters<crcpp_uint16, 16> parameters = {0x1021, 0x0000, 0x0000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1448,9 +1449,9 @@ namespace CRCPP
|
||||||
- check value = 0x04F03
|
- check value = 0x04F03
|
||||||
@return CRC-17 CAN parameters
|
@return CRC-17 CAN parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint32, 17> & CRC::CRC_17_CAN()
|
inline const CRC::Parameters<crcpp_uint32, 17>& CRC::CRC_17_CAN()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint32, 17> parameters = { 0x1685B, 0x00000, 0x00000, false, false };
|
static const Parameters<crcpp_uint32, 17> parameters = {0x1685B, 0x00000, 0x00000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1466,9 +1467,9 @@ namespace CRCPP
|
||||||
- check value = 0x0ED841
|
- check value = 0x0ED841
|
||||||
@return CRC-21 CAN parameters
|
@return CRC-21 CAN parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint32, 21> & CRC::CRC_21_CAN()
|
inline const CRC::Parameters<crcpp_uint32, 21>& CRC::CRC_21_CAN()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint32, 21> parameters = { 0x102899, 0x000000, 0x000000, false, false };
|
static const Parameters<crcpp_uint32, 21> parameters = {0x102899, 0x000000, 0x000000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1484,9 +1485,9 @@ namespace CRCPP
|
||||||
- check value = 0x21CF02
|
- check value = 0x21CF02
|
||||||
@return CRC-24 OPENPGP parameters
|
@return CRC-24 OPENPGP parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint32, 24> & CRC::CRC_24()
|
inline const CRC::Parameters<crcpp_uint32, 24>& CRC::CRC_24()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint32, 24> parameters = { 0x864CFB, 0xB704CE, 0x000000, false, false };
|
static const Parameters<crcpp_uint32, 24> parameters = {0x864CFB, 0xB704CE, 0x000000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1502,9 +1503,9 @@ namespace CRCPP
|
||||||
- check value = 0x7979BD
|
- check value = 0x7979BD
|
||||||
@return CRC-24 FlexRay-A parameters
|
@return CRC-24 FlexRay-A parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint32, 24> & CRC::CRC_24_FLEXRAYA()
|
inline const CRC::Parameters<crcpp_uint32, 24>& CRC::CRC_24_FLEXRAYA()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint32, 24> parameters = { 0x5D6DCB, 0xFEDCBA, 0x000000, false, false };
|
static const Parameters<crcpp_uint32, 24> parameters = {0x5D6DCB, 0xFEDCBA, 0x000000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1520,9 +1521,9 @@ namespace CRCPP
|
||||||
- check value = 0x1F23B8
|
- check value = 0x1F23B8
|
||||||
@return CRC-24 FlexRay-B parameters
|
@return CRC-24 FlexRay-B parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint32, 24> & CRC::CRC_24_FLEXRAYB()
|
inline const CRC::Parameters<crcpp_uint32, 24>& CRC::CRC_24_FLEXRAYB()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint32, 24> parameters = { 0x5D6DCB, 0xABCDEF, 0x000000, false, false };
|
static const Parameters<crcpp_uint32, 24> parameters = {0x5D6DCB, 0xABCDEF, 0x000000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1538,9 +1539,9 @@ namespace CRCPP
|
||||||
- check value = 0x3B3CB540
|
- check value = 0x3B3CB540
|
||||||
@return CRC-30 CDMA parameters
|
@return CRC-30 CDMA parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint32, 30> & CRC::CRC_30()
|
inline const CRC::Parameters<crcpp_uint32, 30>& CRC::CRC_30()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint32, 30> parameters = { 0x2030B9C7, 0x3FFFFFFF, 0x00000000, false, false };
|
static const Parameters<crcpp_uint32, 30> parameters = {0x2030B9C7, 0x3FFFFFFF, 0x00000000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
||||||
|
|
@ -1557,9 +1558,9 @@ namespace CRCPP
|
||||||
- check value = 0xCBF43926
|
- check value = 0xCBF43926
|
||||||
@return CRC-32 parameters
|
@return CRC-32 parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint32, 32> & CRC::CRC_32()
|
inline const CRC::Parameters<crcpp_uint32, 32>& CRC::CRC_32()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint32, 32> parameters = { 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, true, true };
|
static const Parameters<crcpp_uint32, 32> parameters = {0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, true, true};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1575,9 +1576,9 @@ namespace CRCPP
|
||||||
- check value = 0xFC891918
|
- check value = 0xFC891918
|
||||||
@return CRC-32 BZIP2 parameters
|
@return CRC-32 BZIP2 parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint32, 32> & CRC::CRC_32_BZIP2()
|
inline const CRC::Parameters<crcpp_uint32, 32>& CRC::CRC_32_BZIP2()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint32, 32> parameters = { 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, false, false };
|
static const Parameters<crcpp_uint32, 32> parameters = {0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1594,9 +1595,9 @@ namespace CRCPP
|
||||||
- check value = 0xE3069283
|
- check value = 0xE3069283
|
||||||
@return CRC-32 C parameters
|
@return CRC-32 C parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint32, 32> & CRC::CRC_32_C()
|
inline const CRC::Parameters<crcpp_uint32, 32>& CRC::CRC_32_C()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint32, 32> parameters = { 0x1EDC6F41, 0xFFFFFFFF, 0xFFFFFFFF, true, true };
|
static const Parameters<crcpp_uint32, 32> parameters = {0x1EDC6F41, 0xFFFFFFFF, 0xFFFFFFFF, true, true};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -1613,9 +1614,9 @@ namespace CRCPP
|
||||||
- check value = 0x0376E6E7
|
- check value = 0x0376E6E7
|
||||||
@return CRC-32 MPEG-2 parameters
|
@return CRC-32 MPEG-2 parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint32, 32> & CRC::CRC_32_MPEG2()
|
inline const CRC::Parameters<crcpp_uint32, 32>& CRC::CRC_32_MPEG2()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint32, 32> parameters = { 0x04C11DB7, 0xFFFFFFFF, 0x00000000, false, false };
|
static const Parameters<crcpp_uint32, 32> parameters = {0x04C11DB7, 0xFFFFFFFF, 0x00000000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1631,9 +1632,9 @@ namespace CRCPP
|
||||||
- check value = 0x765E7680
|
- check value = 0x765E7680
|
||||||
@return CRC-32 POSIX parameters
|
@return CRC-32 POSIX parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint32, 32> & CRC::CRC_32_POSIX()
|
inline const CRC::Parameters<crcpp_uint32, 32>& CRC::CRC_32_POSIX()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint32, 32> parameters = { 0x04C11DB7, 0x00000000, 0xFFFFFFFF, false, false };
|
static const Parameters<crcpp_uint32, 32> parameters = {0x04C11DB7, 0x00000000, 0xFFFFFFFF, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1650,9 +1651,9 @@ namespace CRCPP
|
||||||
- check value = 0x3010BF7F
|
- check value = 0x3010BF7F
|
||||||
@return CRC-32 Q parameters
|
@return CRC-32 Q parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint32, 32> & CRC::CRC_32_Q()
|
inline const CRC::Parameters<crcpp_uint32, 32>& CRC::CRC_32_Q()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint32, 32> parameters = { 0x814141AB, 0x00000000, 0x00000000, false, false };
|
static const Parameters<crcpp_uint32, 32> parameters = {0x814141AB, 0x00000000, 0x00000000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1668,9 +1669,9 @@ namespace CRCPP
|
||||||
- check value = 0xD4164FC646
|
- check value = 0xD4164FC646
|
||||||
@return CRC-40 GSM parameters
|
@return CRC-40 GSM parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint64, 40> & CRC::CRC_40_GSM()
|
inline const CRC::Parameters<crcpp_uint64, 40>& CRC::CRC_40_GSM()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint64, 40> parameters = { 0x0004820009, 0x0000000000, 0xFFFFFFFFFF, false, false };
|
static const Parameters<crcpp_uint64, 40> parameters = {0x0004820009, 0x0000000000, 0xFFFFFFFFFF, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1686,9 +1687,9 @@ namespace CRCPP
|
||||||
- check value = 0x6C40DF5F0B497347
|
- check value = 0x6C40DF5F0B497347
|
||||||
@return CRC-64 ECMA parameters
|
@return CRC-64 ECMA parameters
|
||||||
*/
|
*/
|
||||||
inline const CRC::Parameters<crcpp_uint64, 64> & CRC::CRC_64()
|
inline const CRC::Parameters<crcpp_uint64, 64>& CRC::CRC_64()
|
||||||
{
|
{
|
||||||
static const Parameters<crcpp_uint64, 64> parameters = { 0x42F0E1EBA9EA3693, 0x0000000000000000, 0x0000000000000000, false, false };
|
static const Parameters<crcpp_uint64, 64> parameters = {0x42F0E1EBA9EA3693, 0x0000000000000000, 0x0000000000000000, false, false};
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ namespace cfg
|
||||||
// Incrementally load config entries from YAML::Node.
|
// Incrementally load config entries from YAML::Node.
|
||||||
// The config value is preserved if the corresponding YAML node doesn't exist.
|
// The config value is preserved if the corresponding YAML node doesn't exist.
|
||||||
static void decode(const YAML::Node& data, class _base& rhs, bool dynamic = false);
|
static void decode(const YAML::Node& data, class _base& rhs, bool dynamic = false);
|
||||||
}
|
} // namespace cfg
|
||||||
|
|
||||||
std::vector<std::string> cfg::make_int_range(s64 min, s64 max)
|
std::vector<std::string> cfg::make_int_range(s64 min, s64 max)
|
||||||
{
|
{
|
||||||
|
|
@ -80,7 +80,8 @@ bool try_to_int64(s64* out, std::string_view value, s64 min, s64 max)
|
||||||
{
|
{
|
||||||
if (value.empty())
|
if (value.empty())
|
||||||
{
|
{
|
||||||
if (out) cfg_log.error("cfg::try_to_int64(): called with an empty string");
|
if (out)
|
||||||
|
cfg_log.error("cfg::try_to_int64(): called with an empty string");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,7 +108,8 @@ bool try_to_int64(s64* out, std::string_view value, s64 min, s64 max)
|
||||||
|
|
||||||
if (ret.ec != std::errc() || ret.ptr != end || (start[0] == '-' && sign < 0))
|
if (ret.ec != std::errc() || ret.ptr != end || (start[0] == '-' && sign < 0))
|
||||||
{
|
{
|
||||||
if (out) cfg_log.error("cfg::try_to_int64('%s'): invalid integer", value);
|
if (out)
|
||||||
|
cfg_log.error("cfg::try_to_int64('%s'): invalid integer", value);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,11 +117,13 @@ bool try_to_int64(s64* out, std::string_view value, s64 min, s64 max)
|
||||||
|
|
||||||
if (result < min || result > max)
|
if (result < min || result > max)
|
||||||
{
|
{
|
||||||
if (out) cfg_log.error("cfg::try_to_int64('%s'): out of bounds (val=%d, min=%d, max=%d)", value, result, min, max);
|
if (out)
|
||||||
|
cfg_log.error("cfg::try_to_int64('%s'): out of bounds (val=%d, min=%d, max=%d)", value, result, min, max);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out) *out = result;
|
if (out)
|
||||||
|
*out = result;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -132,7 +136,8 @@ bool try_to_uint64(u64* out, std::string_view value, u64 min, u64 max)
|
||||||
{
|
{
|
||||||
if (value.empty())
|
if (value.empty())
|
||||||
{
|
{
|
||||||
if (out) cfg_log.error("cfg::try_to_uint64(): called with an empty string");
|
if (out)
|
||||||
|
cfg_log.error("cfg::try_to_uint64(): called with an empty string");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -152,17 +157,20 @@ bool try_to_uint64(u64* out, std::string_view value, u64 min, u64 max)
|
||||||
|
|
||||||
if (ret.ec != std::errc() || ret.ptr != end)
|
if (ret.ec != std::errc() || ret.ptr != end)
|
||||||
{
|
{
|
||||||
if (out) cfg_log.error("cfg::try_to_uint64('%s'): invalid integer", value);
|
if (out)
|
||||||
|
cfg_log.error("cfg::try_to_uint64('%s'): invalid integer", value);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result < min || result > max)
|
if (result < min || result > max)
|
||||||
{
|
{
|
||||||
if (out) cfg_log.error("cfg::try_to_uint64('%s'): out of bounds (val=%u, min=%u, max=%u)", value, result, min, max);
|
if (out)
|
||||||
|
cfg_log.error("cfg::try_to_uint64('%s'): out of bounds (val=%u, min=%u, max=%u)", value, result, min, max);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out) *out = result;
|
if (out)
|
||||||
|
*out = result;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -175,7 +183,8 @@ bool try_to_float(f64* out, std::string_view value, f64 min, f64 max)
|
||||||
{
|
{
|
||||||
if (value.empty())
|
if (value.empty())
|
||||||
{
|
{
|
||||||
if (out) cfg_log.error("cfg::try_to_float(): called with an empty string");
|
if (out)
|
||||||
|
cfg_log.error("cfg::try_to_float(): called with an empty string");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -188,36 +197,42 @@ bool try_to_float(f64* out, std::string_view value, f64 min, f64 max)
|
||||||
|
|
||||||
if (end_check != str.data() + str.size())
|
if (end_check != str.data() + str.size())
|
||||||
{
|
{
|
||||||
if (out) cfg_log.error("cfg::try_to_float('%s'): invalid float", value);
|
if (out)
|
||||||
|
cfg_log.error("cfg::try_to_float('%s'): invalid float", value);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result < min || result > max)
|
if (result < min || result > max)
|
||||||
{
|
{
|
||||||
if (out) cfg_log.error("cfg::try_to_float('%s'): out of bounds (val=%f, min=%f, max=%f)", value, result, min, max);
|
if (out)
|
||||||
|
cfg_log.error("cfg::try_to_float('%s'): out of bounds (val=%f, min=%f, max=%f)", value, result, min, max);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out) *out = result;
|
if (out)
|
||||||
|
*out = result;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool try_to_string(std::string* out, const f64& value)
|
bool try_to_string(std::string* out, const f64& value)
|
||||||
{
|
{
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
if (out) *out = std::to_string(value);
|
if (out)
|
||||||
|
*out = std::to_string(value);
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
std::array<char, 32> str{};
|
std::array<char, 32> str{};
|
||||||
|
|
||||||
if (auto [ptr, ec] = std::to_chars(str.data(), str.data() + str.size(), value, std::chars_format::fixed); ec == std::errc())
|
if (auto [ptr, ec] = std::to_chars(str.data(), str.data() + str.size(), value, std::chars_format::fixed); ec == std::errc())
|
||||||
{
|
{
|
||||||
if (out) *out = std::string(str.data(), ptr);
|
if (out)
|
||||||
|
*out = std::string(str.data(), ptr);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (out) cfg_log.error("cfg::try_to_string(): could not convert value '%f' to string. error='%s'", value, std::make_error_code(ec).message());
|
if (out)
|
||||||
|
cfg_log.error("cfg::try_to_string(): could not convert value '%f' to string. error='%s'", value, std::make_error_code(ec).message());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -235,7 +250,8 @@ bool cfg::try_to_enum_value(u64* out, decltype(&fmt_class_string<int>::format) f
|
||||||
|
|
||||||
if (var == value)
|
if (var == value)
|
||||||
{
|
{
|
||||||
if (out) *out = i;
|
if (out)
|
||||||
|
*out = i;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -271,17 +287,20 @@ bool cfg::try_to_enum_value(u64* out, decltype(&fmt_class_string<int>::format) f
|
||||||
|
|
||||||
if (ret.ec != std::errc() || ret.ptr != end)
|
if (ret.ec != std::errc() || ret.ptr != end)
|
||||||
{
|
{
|
||||||
if (out) cfg_log.error("cfg::try_to_enum_value('%s'): invalid enum or integer", value);
|
if (out)
|
||||||
|
cfg_log.error("cfg::try_to_enum_value('%s'): invalid enum or integer", value);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result > max)
|
if (result > max)
|
||||||
{
|
{
|
||||||
if (out) cfg_log.error("cfg::try_to_enum_value('%s'): out of bounds(val=%u, min=0, max=%u)", value, result, max);
|
if (out)
|
||||||
|
cfg_log.error("cfg::try_to_enum_value('%s'): out of bounds(val=%u, min=0, max=%u)", value, result, max);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out) *out = result;
|
if (out)
|
||||||
|
*out = result;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -354,7 +373,7 @@ void cfg::encode(YAML::Emitter& out, const cfg::_base& rhs)
|
||||||
}
|
}
|
||||||
case type::node_map:
|
case type::node_map:
|
||||||
{
|
{
|
||||||
//out << YAML::Block; // Does nothing, output is in Flow mode still (TODO)
|
// out << YAML::Block; // Does nothing, output is in Flow mode still (TODO)
|
||||||
out << YAML::BeginMap;
|
out << YAML::BeginMap;
|
||||||
for (const auto& np : static_cast<const node_map_entry&>(rhs).get_map())
|
for (const auto& np : static_cast<const node_map_entry&>(rhs).get_map())
|
||||||
{
|
{
|
||||||
|
|
@ -369,7 +388,8 @@ void cfg::encode(YAML::Emitter& out, const cfg::_base& rhs)
|
||||||
out << YAML::BeginMap;
|
out << YAML::BeginMap;
|
||||||
for (const auto& np : static_cast<const log_entry&>(rhs).get_map())
|
for (const auto& np : static_cast<const log_entry&>(rhs).get_map())
|
||||||
{
|
{
|
||||||
if (np.second == logs::level::notice) continue;
|
if (np.second == logs::level::notice)
|
||||||
|
continue;
|
||||||
out << YAML::Key << np.first;
|
out << YAML::Key << np.first;
|
||||||
out << YAML::Value << fmt::format("%s", np.second);
|
out << YAML::Value << fmt::format("%s", np.second);
|
||||||
}
|
}
|
||||||
|
|
@ -418,7 +438,8 @@ void cfg::decode(const YAML::Node& data, cfg::_base& rhs, bool dynamic)
|
||||||
|
|
||||||
for (const auto& pair : data)
|
for (const auto& pair : data)
|
||||||
{
|
{
|
||||||
if (!pair.first.IsScalar()) continue;
|
if (!pair.first.IsScalar())
|
||||||
|
continue;
|
||||||
|
|
||||||
// Find the key among existing nodes
|
// Find the key among existing nodes
|
||||||
for (const auto& node : static_cast<node&>(rhs).get_nodes())
|
for (const auto& node : static_cast<node&>(rhs).get_nodes())
|
||||||
|
|
@ -455,7 +476,8 @@ void cfg::decode(const YAML::Node& data, cfg::_base& rhs, bool dynamic)
|
||||||
|
|
||||||
for (const auto& pair : data)
|
for (const auto& pair : data)
|
||||||
{
|
{
|
||||||
if (!pair.first.IsScalar() || !pair.second.IsScalar()) continue;
|
if (!pair.first.IsScalar() || !pair.second.IsScalar())
|
||||||
|
continue;
|
||||||
|
|
||||||
values.emplace(pair.first.Scalar(), pair.second.Scalar());
|
values.emplace(pair.first.Scalar(), pair.second.Scalar());
|
||||||
}
|
}
|
||||||
|
|
@ -474,7 +496,8 @@ void cfg::decode(const YAML::Node& data, cfg::_base& rhs, bool dynamic)
|
||||||
|
|
||||||
for (const auto& pair : data)
|
for (const auto& pair : data)
|
||||||
{
|
{
|
||||||
if (!pair.first.IsScalar() || !pair.second.IsScalar()) continue;
|
if (!pair.first.IsScalar() || !pair.second.IsScalar())
|
||||||
|
continue;
|
||||||
|
|
||||||
u64 value;
|
u64 value;
|
||||||
if (cfg::try_to_enum_value(&value, &fmt_class_string<logs::level>::format, pair.second.Scalar()))
|
if (cfg::try_to_enum_value(&value, &fmt_class_string<logs::level>::format, pair.second.Scalar()))
|
||||||
|
|
@ -497,13 +520,15 @@ void cfg::decode(const YAML::Node& data, cfg::_base& rhs, bool dynamic)
|
||||||
|
|
||||||
for (const auto& pair : data)
|
for (const auto& pair : data)
|
||||||
{
|
{
|
||||||
if (!pair.first.IsScalar() || !pair.second.IsMap()) continue;
|
if (!pair.first.IsScalar() || !pair.second.IsMap())
|
||||||
|
continue;
|
||||||
|
|
||||||
device_info info{};
|
device_info info{};
|
||||||
|
|
||||||
for (const auto& key_value : pair.second)
|
for (const auto& key_value : pair.second)
|
||||||
{
|
{
|
||||||
if (!key_value.first.IsScalar() || !key_value.second.IsScalar()) continue;
|
if (!key_value.first.IsScalar() || !key_value.second.IsScalar())
|
||||||
|
continue;
|
||||||
|
|
||||||
if (key_value.first.Scalar() == "Path")
|
if (key_value.first.Scalar() == "Path")
|
||||||
info.path = key_value.second.Scalar();
|
info.path = key_value.second.Scalar();
|
||||||
|
|
@ -558,14 +583,14 @@ nlohmann::ordered_json cfg::node::to_json() const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cfg::node::from_json(const nlohmann::json &json, bool dynamic)
|
bool cfg::node::from_json(const nlohmann::json& json, bool dynamic)
|
||||||
{
|
{
|
||||||
if (!json.is_object())
|
if (!json.is_object())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto find_node = [this](std::string_view name) -> _base *
|
auto find_node = [this](std::string_view name) -> _base*
|
||||||
{
|
{
|
||||||
for (const auto& node : get_nodes())
|
for (const auto& node : get_nodes())
|
||||||
{
|
{
|
||||||
|
|
@ -578,8 +603,7 @@ bool cfg::node::from_json(const nlohmann::json &json, bool dynamic)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
for (auto& [key, value] : json.get<nlohmann::json::object_t>())
|
||||||
for (auto &[key, value] : json.get<nlohmann::json::object_t>())
|
|
||||||
{
|
{
|
||||||
auto keyNode = find_node(key);
|
auto keyNode = find_node(key);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,19 +75,34 @@ namespace cfg
|
||||||
virtual ~_base() = default;
|
virtual ~_base() = default;
|
||||||
|
|
||||||
// Get unique ID
|
// Get unique ID
|
||||||
u32 get_id() const { return m_id; }
|
u32 get_id() const
|
||||||
|
{
|
||||||
|
return m_id;
|
||||||
|
}
|
||||||
|
|
||||||
// Get parent
|
// Get parent
|
||||||
_base* get_parent() const { return m_parent; }
|
_base* get_parent() const
|
||||||
|
{
|
||||||
|
return m_parent;
|
||||||
|
}
|
||||||
|
|
||||||
// Get type
|
// Get type
|
||||||
type get_type() const { return m_type; }
|
type get_type() const
|
||||||
|
{
|
||||||
|
return m_type;
|
||||||
|
}
|
||||||
|
|
||||||
// Get name
|
// Get name
|
||||||
const std::string& get_name() const { return m_name; }
|
const std::string& get_name() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
// Get dynamic property for reloading configs during games
|
// Get dynamic property for reloading configs during games
|
||||||
bool get_is_dynamic() const { return m_dynamic; }
|
bool get_is_dynamic() const
|
||||||
|
{
|
||||||
|
return m_dynamic;
|
||||||
|
}
|
||||||
|
|
||||||
// Reset defaults
|
// Reset defaults
|
||||||
virtual void from_default() = 0;
|
virtual void from_default() = 0;
|
||||||
|
|
@ -99,7 +114,7 @@ namespace cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual nlohmann::ordered_json to_json() const = 0;
|
virtual nlohmann::ordered_json to_json() const = 0;
|
||||||
virtual bool from_json(const nlohmann::json &, bool dynamic = false) = 0;
|
virtual bool from_json(const nlohmann::json&, bool dynamic = false) = 0;
|
||||||
|
|
||||||
// Convert default to string (optional)
|
// Convert default to string (optional)
|
||||||
virtual std::string def_to_string() const
|
virtual std::string def_to_string() const
|
||||||
|
|
@ -154,7 +169,7 @@ namespace cfg
|
||||||
|
|
||||||
// Deserialize node
|
// Deserialize node
|
||||||
bool from_string(std::string_view value, bool dynamic = false) override;
|
bool from_string(std::string_view value, bool dynamic = false) override;
|
||||||
bool from_json(const nlohmann::json &, bool dynamic = false) override;
|
bool from_json(const nlohmann::json&, bool dynamic = false) override;
|
||||||
|
|
||||||
// Set default values
|
// Set default values
|
||||||
void from_default() override;
|
void from_default() override;
|
||||||
|
|
@ -168,9 +183,7 @@ namespace cfg
|
||||||
bool def;
|
bool def;
|
||||||
|
|
||||||
_bool(node* owner, std::string name, bool def = false, bool dynamic = false)
|
_bool(node* owner, std::string name, bool def = false, bool dynamic = false)
|
||||||
: _base(type::_bool, owner, std::move(name), dynamic)
|
: _base(type::_bool, owner, std::move(name), dynamic), m_value(def), def(def)
|
||||||
, m_value(def)
|
|
||||||
, def(def)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -193,8 +206,7 @@ namespace cfg
|
||||||
|
|
||||||
nlohmann::ordered_json to_json() const override
|
nlohmann::ordered_json to_json() const override
|
||||||
{
|
{
|
||||||
return
|
return {
|
||||||
{
|
|
||||||
{"type", "bool"},
|
{"type", "bool"},
|
||||||
{"value", m_value.load()},
|
{"value", m_value.load()},
|
||||||
{"default", def},
|
{"default", def},
|
||||||
|
|
@ -226,7 +238,7 @@ namespace cfg
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool from_json(const nlohmann::json &json, bool) override
|
bool from_json(const nlohmann::json& json, bool) override
|
||||||
{
|
{
|
||||||
if (!json.is_boolean())
|
if (!json.is_boolean())
|
||||||
{
|
{
|
||||||
|
|
@ -253,9 +265,7 @@ namespace cfg
|
||||||
const T def;
|
const T def;
|
||||||
|
|
||||||
_enum(node* owner, const std::string& name, T value = {}, bool dynamic = false)
|
_enum(node* owner, const std::string& name, T value = {}, bool dynamic = false)
|
||||||
: _base(type::_enum, owner, name, dynamic)
|
: _base(type::_enum, owner, name, dynamic), m_value(value), def(value)
|
||||||
, m_value(value)
|
|
||||||
, def(value)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -293,8 +303,7 @@ namespace cfg
|
||||||
|
|
||||||
nlohmann::ordered_json to_json() const override
|
nlohmann::ordered_json to_json() const override
|
||||||
{
|
{
|
||||||
return
|
return {
|
||||||
{
|
|
||||||
{"type", "enum"},
|
{"type", "enum"},
|
||||||
{"value", to_string()},
|
{"value", to_string()},
|
||||||
{"default", def_to_string()},
|
{"default", def_to_string()},
|
||||||
|
|
@ -323,7 +332,7 @@ namespace cfg
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool from_json(const nlohmann::json &json, bool dynamic) override
|
bool from_json(const nlohmann::json& json, bool dynamic) override
|
||||||
{
|
{
|
||||||
if (!json.is_string())
|
if (!json.is_string())
|
||||||
{
|
{
|
||||||
|
|
@ -362,11 +371,7 @@ namespace cfg
|
||||||
_int(node* owner, const std::string& name, int_type def = std::min<int_type>(Max, std::max<int_type>(Min, 0)), bool dynamic = false,
|
_int(node* owner, const std::string& name, int_type def = std::min<int_type>(Max, std::max<int_type>(Min, 0)), bool dynamic = false,
|
||||||
std::function<s64()> min_fn = nullptr,
|
std::function<s64()> min_fn = nullptr,
|
||||||
std::function<s64()> max_fn = nullptr)
|
std::function<s64()> max_fn = nullptr)
|
||||||
: _base(type::_int, owner, name, dynamic)
|
: _base(type::_int, owner, name, dynamic), m_value(def), m_min_fn(std::move(min_fn)), m_max_fn(std::move(max_fn)), def(def)
|
||||||
, m_value(def)
|
|
||||||
, m_min_fn(std::move(min_fn))
|
|
||||||
, m_max_fn(std::move(max_fn))
|
|
||||||
, def(def)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -412,8 +417,7 @@ namespace cfg
|
||||||
|
|
||||||
nlohmann::ordered_json to_json() const override
|
nlohmann::ordered_json to_json() const override
|
||||||
{
|
{
|
||||||
return
|
return {
|
||||||
{
|
|
||||||
{"type", "int"},
|
{"type", "int"},
|
||||||
{"value", to_string()},
|
{"value", to_string()},
|
||||||
{"default", def_to_string()},
|
{"default", def_to_string()},
|
||||||
|
|
@ -439,7 +443,7 @@ namespace cfg
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool from_json(const nlohmann::json &json, bool) override
|
bool from_json(const nlohmann::json& json, bool) override
|
||||||
{
|
{
|
||||||
if (!json.is_number_integer())
|
if (!json.is_number_integer())
|
||||||
{
|
{
|
||||||
|
|
@ -485,9 +489,7 @@ namespace cfg
|
||||||
static constexpr float_type min = Min;
|
static constexpr float_type min = Min;
|
||||||
|
|
||||||
_float(node* owner, const std::string& name, float_type def = std::min<float_type>(Max, std::max<float_type>(Min, 0)), bool dynamic = false)
|
_float(node* owner, const std::string& name, float_type def = std::min<float_type>(Max, std::max<float_type>(Min, 0)), bool dynamic = false)
|
||||||
: _base(type::_int, owner, name, dynamic)
|
: _base(type::_int, owner, name, dynamic), m_value(def), def(def)
|
||||||
, m_value(def)
|
|
||||||
, def(def)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -519,8 +521,7 @@ namespace cfg
|
||||||
|
|
||||||
nlohmann::ordered_json to_json() const override
|
nlohmann::ordered_json to_json() const override
|
||||||
{
|
{
|
||||||
return
|
return {
|
||||||
{
|
|
||||||
{"type", "float"},
|
{"type", "float"},
|
||||||
{"value", to_string()},
|
{"value", to_string()},
|
||||||
{"default", def_to_string()},
|
{"default", def_to_string()},
|
||||||
|
|
@ -552,7 +553,7 @@ namespace cfg
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool from_json(const nlohmann::json &json, bool) override
|
bool from_json(const nlohmann::json& json, bool) override
|
||||||
{
|
{
|
||||||
if (!json.is_number_float())
|
if (!json.is_number_float())
|
||||||
{
|
{
|
||||||
|
|
@ -606,9 +607,7 @@ namespace cfg
|
||||||
static constexpr u64 min = Min;
|
static constexpr u64 min = Min;
|
||||||
|
|
||||||
uint(node* owner, const std::string& name, int_type def = std::max<int_type>(Min, 0), bool dynamic = false)
|
uint(node* owner, const std::string& name, int_type def = std::max<int_type>(Min, 0), bool dynamic = false)
|
||||||
: _base(type::uint, owner, name, dynamic)
|
: _base(type::uint, owner, name, dynamic), m_value(def), def(def)
|
||||||
, m_value(def)
|
|
||||||
, def(def)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -634,8 +633,7 @@ namespace cfg
|
||||||
|
|
||||||
nlohmann::ordered_json to_json() const override
|
nlohmann::ordered_json to_json() const override
|
||||||
{
|
{
|
||||||
return
|
return {
|
||||||
{
|
|
||||||
{"type", "uint"},
|
{"type", "uint"},
|
||||||
{"value", to_string()},
|
{"value", to_string()},
|
||||||
{"default", def_to_string()},
|
{"default", def_to_string()},
|
||||||
|
|
@ -661,7 +659,7 @@ namespace cfg
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool from_json(const nlohmann::json &json, bool) override
|
bool from_json(const nlohmann::json& json, bool) override
|
||||||
{
|
{
|
||||||
if (!json.is_number_unsigned())
|
if (!json.is_number_unsigned())
|
||||||
{
|
{
|
||||||
|
|
@ -705,9 +703,7 @@ namespace cfg
|
||||||
std::string def;
|
std::string def;
|
||||||
|
|
||||||
string(node* owner, std::string name, std::string def = {}, bool dynamic = false)
|
string(node* owner, std::string name, std::string def = {}, bool dynamic = false)
|
||||||
: _base(type::string, owner, std::move(name), dynamic)
|
: _base(type::string, owner, std::move(name), dynamic), m_value(def), def(std::move(def))
|
||||||
, m_value(def)
|
|
||||||
, def(std::move(def))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -725,8 +721,7 @@ namespace cfg
|
||||||
|
|
||||||
nlohmann::ordered_json to_json() const override
|
nlohmann::ordered_json to_json() const override
|
||||||
{
|
{
|
||||||
return
|
return {
|
||||||
{
|
|
||||||
{"type", "string"},
|
{"type", "string"},
|
||||||
{"value", to_string()},
|
{"value", to_string()},
|
||||||
{"default", def_to_string()},
|
{"default", def_to_string()},
|
||||||
|
|
@ -744,7 +739,7 @@ namespace cfg
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool from_json(const nlohmann::json &json, bool) override
|
bool from_json(const nlohmann::json& json, bool) override
|
||||||
{
|
{
|
||||||
if (!json.is_string())
|
if (!json.is_string())
|
||||||
{
|
{
|
||||||
|
|
@ -782,13 +777,12 @@ namespace cfg
|
||||||
|
|
||||||
std::vector<std::string> to_list() const override
|
std::vector<std::string> to_list() const override
|
||||||
{
|
{
|
||||||
return { m_set.begin(), m_set.end() };
|
return {m_set.begin(), m_set.end()};
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::ordered_json to_json() const override
|
nlohmann::ordered_json to_json() const override
|
||||||
{
|
{
|
||||||
return
|
return {
|
||||||
{
|
|
||||||
{"type", "set"},
|
{"type", "set"},
|
||||||
{"value", to_list()},
|
{"value", to_list()},
|
||||||
};
|
};
|
||||||
|
|
@ -796,12 +790,12 @@ namespace cfg
|
||||||
|
|
||||||
bool from_list(std::vector<std::string>&& list) override
|
bool from_list(std::vector<std::string>&& list) override
|
||||||
{
|
{
|
||||||
m_set = { std::make_move_iterator(list.begin()), std::make_move_iterator(list.end()) };
|
m_set = {std::make_move_iterator(list.begin()), std::make_move_iterator(list.end())};
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool from_json(const nlohmann::json &json, bool) override
|
bool from_json(const nlohmann::json& json, bool) override
|
||||||
{
|
{
|
||||||
if (!json.is_array())
|
if (!json.is_array())
|
||||||
{
|
{
|
||||||
|
|
@ -813,7 +807,7 @@ namespace cfg
|
||||||
std::vector<std::string> string_array;
|
std::vector<std::string> string_array;
|
||||||
string_array.reserve(array.size());
|
string_array.reserve(array.size());
|
||||||
|
|
||||||
for (auto &elem : array)
|
for (auto& elem : array)
|
||||||
{
|
{
|
||||||
if (!elem.is_string())
|
if (!elem.is_string())
|
||||||
{
|
{
|
||||||
|
|
@ -827,7 +821,7 @@ namespace cfg
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template <typename T>
|
||||||
using map_of_type = std::map<std::string, T, std::less<>>;
|
using map_of_type = std::map<std::string, T, std::less<>>;
|
||||||
|
|
||||||
class map_entry : public _base
|
class map_entry : public _base
|
||||||
|
|
@ -847,22 +841,20 @@ namespace cfg
|
||||||
|
|
||||||
nlohmann::ordered_json to_json() const override
|
nlohmann::ordered_json to_json() const override
|
||||||
{
|
{
|
||||||
return
|
return {
|
||||||
{
|
|
||||||
{"type", "map"},
|
{"type", "map"},
|
||||||
{"value", m_map},
|
{"value", m_map},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool from_json(const nlohmann::json& json, bool) override
|
||||||
bool from_json(const nlohmann::json &json, bool) override
|
|
||||||
{
|
{
|
||||||
if (!json.is_object())
|
if (!json.is_object())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &elem : json.get<nlohmann::json::object_t>())
|
for (auto& elem : json.get<nlohmann::json::object_t>())
|
||||||
{
|
{
|
||||||
set_value(elem.first, elem.second);
|
set_value(elem.first, elem.second);
|
||||||
}
|
}
|
||||||
|
|
@ -915,15 +907,14 @@ namespace cfg
|
||||||
values[key] = level_string;
|
values[key] = level_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return {
|
||||||
{
|
|
||||||
{"type", "log_map"},
|
{"type", "log_map"},
|
||||||
{"values", values},
|
{"values", values},
|
||||||
{"levels", levels},
|
{"levels", levels},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool from_json(const nlohmann::json &json, bool) override
|
bool from_json(const nlohmann::json& json, bool) override
|
||||||
{
|
{
|
||||||
if (!json.is_object())
|
if (!json.is_object())
|
||||||
{
|
{
|
||||||
|
|
@ -978,7 +969,7 @@ namespace cfg
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool from_json(const nlohmann::json &json)
|
bool from_json(const nlohmann::json& json)
|
||||||
{
|
{
|
||||||
if (json.contains("path"))
|
if (json.contains("path"))
|
||||||
{
|
{
|
||||||
|
|
@ -1031,8 +1022,7 @@ namespace cfg
|
||||||
|
|
||||||
public:
|
public:
|
||||||
device_entry(node* owner, const std::string& name, map_of_type<device_info> def = {})
|
device_entry(node* owner, const std::string& name, map_of_type<device_info> def = {})
|
||||||
: _base(type::device, owner, name, true)
|
: _base(type::device, owner, name, true), m_map(std::move(def))
|
||||||
, m_map(std::move(def))
|
|
||||||
{
|
{
|
||||||
m_default = m_map;
|
m_default = m_map;
|
||||||
}
|
}
|
||||||
|
|
@ -1042,7 +1032,7 @@ namespace cfg
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool from_json(const nlohmann::json &, bool) override
|
bool from_json(const nlohmann::json&, bool) override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -1061,4 +1051,4 @@ namespace cfg
|
||||||
|
|
||||||
void from_default() override;
|
void from_default() override;
|
||||||
};
|
};
|
||||||
}
|
} // namespace cfg
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ std::string g_android_cache_dir;
|
||||||
#include "Utilities/StrUtil.h"
|
#include "Utilities/StrUtil.h"
|
||||||
|
|
||||||
#include <cwchar>
|
#include <cwchar>
|
||||||
#include <Windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
static std::unique_ptr<wchar_t[]> to_wchar(std::string_view source)
|
static std::unique_ptr<wchar_t[]> to_wchar(std::string_view source)
|
||||||
{
|
{
|
||||||
|
|
@ -205,7 +205,7 @@ namespace fs
|
||||||
std::unordered_map<std::string, shared_ptr<device_base>> m_map{};
|
std::unordered_map<std::string, shared_ptr<device_base>> m_map{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
shared_ptr<device_base> get_device(const std::string& path, std::string_view *device_path = nullptr);
|
shared_ptr<device_base> get_device(const std::string& path, std::string_view* device_path = nullptr);
|
||||||
shared_ptr<device_base> set_device(const std::string& name, shared_ptr<device_base>);
|
shared_ptr<device_base> set_device(const std::string& name, shared_ptr<device_base>);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -402,8 +402,7 @@ namespace fs
|
||||||
|
|
||||||
public:
|
public:
|
||||||
windows_file(HANDLE handle)
|
windows_file(HANDLE handle)
|
||||||
: m_handle(handle)
|
: m_handle(handle), m_pos(0)
|
||||||
, m_pos(0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -577,7 +576,8 @@ namespace fs
|
||||||
const s64 new_pos =
|
const s64 new_pos =
|
||||||
whence == fs::seek_set ? offset :
|
whence == fs::seek_set ? offset :
|
||||||
whence == fs::seek_cur ? offset + m_pos :
|
whence == fs::seek_cur ? offset + m_pos :
|
||||||
whence == fs::seek_end ? offset + size() : -1;
|
whence == fs::seek_end ? offset + size() :
|
||||||
|
-1;
|
||||||
|
|
||||||
if (new_pos < 0)
|
if (new_pos < 0)
|
||||||
{
|
{
|
||||||
|
|
@ -766,7 +766,8 @@ namespace fs
|
||||||
|
|
||||||
const int mode =
|
const int mode =
|
||||||
whence == seek_set ? SEEK_SET :
|
whence == seek_set ? SEEK_SET :
|
||||||
whence == seek_cur ? SEEK_CUR : SEEK_END;
|
whence == seek_cur ? SEEK_CUR :
|
||||||
|
SEEK_END;
|
||||||
|
|
||||||
const auto result = ::lseek(m_fd, offset, mode);
|
const auto result = ::lseek(m_fd, offset, mode);
|
||||||
|
|
||||||
|
|
@ -833,9 +834,9 @@ namespace fs
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
}
|
} // namespace fs
|
||||||
|
|
||||||
shared_ptr<fs::device_base> fs::device_manager::get_device(const std::string& path, std::string_view *device_path)
|
shared_ptr<fs::device_base> fs::device_manager::get_device(const std::string& path, std::string_view* device_path)
|
||||||
{
|
{
|
||||||
auto prefix = path.substr(0, path.find_first_of("/\\", 1));
|
auto prefix = path.substr(0, path.find_first_of("/\\", 1));
|
||||||
|
|
||||||
|
|
@ -885,7 +886,7 @@ shared_ptr<fs::device_base> fs::device_manager::set_device(const std::string& na
|
||||||
return null_ptr;
|
return null_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr<fs::device_base> fs::get_virtual_device(const std::string& path, std::string_view *device_path)
|
shared_ptr<fs::device_base> fs::get_virtual_device(const std::string& path, std::string_view* device_path)
|
||||||
{
|
{
|
||||||
// Every virtual device path must have specific name at the beginning
|
// Every virtual device path must have specific name at the beginning
|
||||||
if ((path.starts_with("/vfsv0_") || path.starts_with("\\vfsv0_")) && path.size() >= 8 + 22 && path[29] == '_' && path.find_first_of("/\\", 1) > 29)
|
if ((path.starts_with("/vfsv0_") || path.starts_with("\\vfsv0_")) && path.size() >= 8 + 22 && path[29] == '_' && path.find_first_of("/\\", 1) > 29)
|
||||||
|
|
@ -1019,7 +1020,10 @@ bool fs::get_stat(const std::string& path, stat_t& info)
|
||||||
struct close_t
|
struct close_t
|
||||||
{
|
{
|
||||||
HANDLE handle;
|
HANDLE handle;
|
||||||
~close_t() { FindClose(handle); }
|
~close_t()
|
||||||
|
{
|
||||||
|
FindClose(handle);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (close_t find_manage{handle}; attrs.cFileName != wpath_view.substr(wpath_view.find_last_of(wdelim) + 1);)
|
for (close_t find_manage{handle}; attrs.cFileName != wpath_view.substr(wpath_view.find_last_of(wdelim) + 1);)
|
||||||
|
|
@ -1426,7 +1430,7 @@ bool fs::copy_file(const std::string& from, const std::string& to, bool overwrit
|
||||||
if (::fcopyfile(input, output, 0, COPYFILE_ALL))
|
if (::fcopyfile(input, output, 0, COPYFILE_ALL))
|
||||||
#elif defined(__linux__) || defined(__sun)
|
#elif defined(__linux__) || defined(__sun)
|
||||||
// sendfile will work with non-socket output (i.e. regular file) on Linux 2.6.33+
|
// sendfile will work with non-socket output (i.e. regular file) on Linux 2.6.33+
|
||||||
struct ::stat fileinfo = { 0 };
|
struct ::stat fileinfo = {0};
|
||||||
bool result = ::fstat(input, &fileinfo) != -1;
|
bool result = ::fstat(input, &fileinfo) != -1;
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
|
|
@ -1653,15 +1657,18 @@ fs::file::file(const std::string& path, bs_t<open_mode> mode)
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
DWORD access = 0;
|
DWORD access = 0;
|
||||||
if (mode & fs::read) access |= GENERIC_READ;
|
if (mode & fs::read)
|
||||||
if (mode & fs::write) access |= DELETE | (mode & fs::append ? FILE_APPEND_DATA : GENERIC_WRITE);
|
access |= GENERIC_READ;
|
||||||
|
if (mode & fs::write)
|
||||||
|
access |= DELETE | (mode & fs::append ? FILE_APPEND_DATA : GENERIC_WRITE);
|
||||||
|
|
||||||
DWORD disp = 0;
|
DWORD disp = 0;
|
||||||
if (mode & fs::create)
|
if (mode & fs::create)
|
||||||
{
|
{
|
||||||
disp =
|
disp =
|
||||||
mode & fs::excl ? CREATE_NEW :
|
mode & fs::excl ? CREATE_NEW :
|
||||||
mode & fs::trunc ? CREATE_ALWAYS : OPEN_ALWAYS;
|
mode & fs::trunc ? CREATE_ALWAYS :
|
||||||
|
OPEN_ALWAYS;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -1697,14 +1704,21 @@ fs::file::file(const std::string& path, bs_t<open_mode> mode)
|
||||||
#else
|
#else
|
||||||
int flags = O_CLOEXEC; // Ensures all files are closed on execl for auto updater
|
int flags = O_CLOEXEC; // Ensures all files are closed on execl for auto updater
|
||||||
|
|
||||||
if (mode & fs::read && mode & fs::write) flags |= O_RDWR;
|
if (mode & fs::read && mode & fs::write)
|
||||||
else if (mode & fs::read) flags |= O_RDONLY;
|
flags |= O_RDWR;
|
||||||
else if (mode & fs::write) flags |= O_WRONLY;
|
else if (mode & fs::read)
|
||||||
|
flags |= O_RDONLY;
|
||||||
|
else if (mode & fs::write)
|
||||||
|
flags |= O_WRONLY;
|
||||||
|
|
||||||
if (mode & fs::append) flags |= O_APPEND;
|
if (mode & fs::append)
|
||||||
if (mode & fs::create) flags |= O_CREAT;
|
flags |= O_APPEND;
|
||||||
if (mode & fs::trunc && !(mode & fs::lock)) flags |= O_TRUNC;
|
if (mode & fs::create)
|
||||||
if (mode & fs::excl) flags |= O_EXCL;
|
flags |= O_CREAT;
|
||||||
|
if (mode & fs::trunc && !(mode & fs::lock))
|
||||||
|
flags |= O_TRUNC;
|
||||||
|
if (mode & fs::excl)
|
||||||
|
flags |= O_EXCL;
|
||||||
|
|
||||||
int perm = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
|
int perm = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
|
||||||
|
|
||||||
|
|
@ -1753,8 +1767,6 @@ fs::file::file(const std::string& path, bs_t<open_mode> mode)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fs::file fs::file::from_native_handle(native_handle handle)
|
fs::file fs::file::from_native_handle(native_handle handle)
|
||||||
{
|
{
|
||||||
fs::file result;
|
fs::file result;
|
||||||
|
|
@ -1779,8 +1791,7 @@ fs::file::file(const void* ptr, usz size)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
memory_stream(const void* ptr, u64 size)
|
memory_stream(const void* ptr, u64 size)
|
||||||
: m_ptr(static_cast<const char*>(ptr))
|
: m_ptr(static_cast<const char*>(ptr)), m_size(size)
|
||||||
, m_size(size)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1834,7 +1845,8 @@ fs::file::file(const void* ptr, usz size)
|
||||||
const s64 new_pos =
|
const s64 new_pos =
|
||||||
whence == fs::seek_set ? offset :
|
whence == fs::seek_set ? offset :
|
||||||
whence == fs::seek_cur ? offset + m_pos :
|
whence == fs::seek_cur ? offset + m_pos :
|
||||||
whence == fs::seek_end ? offset + size() : -1;
|
whence == fs::seek_end ? offset + size() :
|
||||||
|
-1;
|
||||||
|
|
||||||
if (new_pos < 0)
|
if (new_pos < 0)
|
||||||
{
|
{
|
||||||
|
|
@ -2006,7 +2018,7 @@ bool fs::dir::open(const std::string& path)
|
||||||
|
|
||||||
if (::fstatat(::dirfd(m_dd), found->d_name, &file_info, 0) != 0)
|
if (::fstatat(::dirfd(m_dd), found->d_name, &file_info, 0) != 0)
|
||||||
{
|
{
|
||||||
//failed metadata (broken symlink?), ignore and skip to next file
|
// failed metadata (broken symlink?), ignore and skip to next file
|
||||||
return read(info);
|
return read(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2518,7 +2530,8 @@ fs::file fs::make_gather(std::vector<fs::file> files)
|
||||||
const s64 new_pos =
|
const s64 new_pos =
|
||||||
whence == fs::seek_set ? offset :
|
whence == fs::seek_set ? offset :
|
||||||
whence == fs::seek_cur ? offset + pos :
|
whence == fs::seek_cur ? offset + pos :
|
||||||
whence == fs::seek_end ? offset + end : -1;
|
whence == fs::seek_end ? offset + end :
|
||||||
|
-1;
|
||||||
|
|
||||||
if (new_pos < 0)
|
if (new_pos < 0)
|
||||||
{
|
{
|
||||||
|
|
@ -2581,8 +2594,7 @@ bool fs::pending_file::open(std::string_view path)
|
||||||
}
|
}
|
||||||
|
|
||||||
m_path.clear();
|
m_path.clear();
|
||||||
}
|
} while (fs::g_tls_error == fs::error::exist); // Only retry if failed due to existing file
|
||||||
while (fs::g_tls_error == fs::error::exist); // Only retry if failed due to existing file
|
|
||||||
|
|
||||||
return file.operator bool();
|
return file.operator bool();
|
||||||
}
|
}
|
||||||
|
|
@ -2626,8 +2638,7 @@ bool fs::pending_file::commit(bool overwrite)
|
||||||
|
|
||||||
const auto ws1 = to_wchar(m_path);
|
const auto ws1 = to_wchar(m_path);
|
||||||
|
|
||||||
const HANDLE file_handle = !overwrite ? INVALID_HANDLE_VALUE
|
const HANDLE file_handle = !overwrite ? INVALID_HANDLE_VALUE : CreateFileW(ws1.get(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr);
|
||||||
: CreateFileW(ws1.get(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr);
|
|
||||||
|
|
||||||
while (file_handle != INVALID_HANDLE_VALUE)
|
while (file_handle != INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
|
|
@ -2734,8 +2745,7 @@ bool fs::pending_file::commit(bool overwrite)
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} while (fs::g_tls_error == fs::error::exist); // Only retry if failed due to existing file
|
||||||
while (fs::g_tls_error == fs::error::exist); // Only retry if failed due to existing file
|
|
||||||
|
|
||||||
if (write_temp_path)
|
if (write_temp_path)
|
||||||
{
|
{
|
||||||
|
|
@ -2787,7 +2797,7 @@ stx::generator<fs::dir_entry&> fs::list_dir_recursively(const std::string& path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template <>
|
||||||
void fmt_class_string<fs::seek_mode>::format(std::string& out, u64 arg)
|
void fmt_class_string<fs::seek_mode>::format(std::string& out, u64 arg)
|
||||||
{
|
{
|
||||||
format_enum(out, arg, [](auto arg)
|
format_enum(out, arg, [](auto arg)
|
||||||
|
|
@ -2803,7 +2813,7 @@ void fmt_class_string<fs::seek_mode>::format(std::string& out, u64 arg)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template <>
|
||||||
void fmt_class_string<fs::error>::format(std::string& out, u64 arg)
|
void fmt_class_string<fs::error>::format(std::string& out, u64 arg)
|
||||||
{
|
{
|
||||||
if (arg == static_cast<u64>(fs::error::unknown))
|
if (arg == static_cast<u64>(fs::error::unknown))
|
||||||
|
|
@ -2840,7 +2850,7 @@ void fmt_class_string<fs::error>::format(std::string& out, u64 arg)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template <>
|
||||||
void fmt_class_string<fs::file_id>::format(std::string& out, u64 arg)
|
void fmt_class_string<fs::file_id>::format(std::string& out, u64 arg)
|
||||||
{
|
{
|
||||||
const fs::file_id& id = get_object(arg);
|
const fs::file_id& id = get_object(arg);
|
||||||
|
|
|
||||||
|
|
@ -182,10 +182,12 @@ namespace fs
|
||||||
[[noreturn]] void xfail(std::source_location);
|
[[noreturn]] void xfail(std::source_location);
|
||||||
[[noreturn]] void xovfl();
|
[[noreturn]] void xovfl();
|
||||||
|
|
||||||
constexpr struct pod_tag_t{} pod_tag;
|
constexpr struct pod_tag_t
|
||||||
|
{
|
||||||
|
} pod_tag;
|
||||||
|
|
||||||
// Get virtual device for specified path (nullptr for real path)
|
// Get virtual device for specified path (nullptr for real path)
|
||||||
shared_ptr<device_base> get_virtual_device(const std::string& path, std::string_view *device_path);
|
shared_ptr<device_base> get_virtual_device(const std::string& path, std::string_view* device_path);
|
||||||
|
|
||||||
// Set virtual device with specified name (nullptr for deletion)
|
// Set virtual device with specified name (nullptr for deletion)
|
||||||
shared_ptr<device_base> set_virtual_device(const std::string& name, shared_ptr<device_base> device);
|
shared_ptr<device_base> set_virtual_device(const std::string& name, shared_ptr<device_base> device);
|
||||||
|
|
@ -305,21 +307,24 @@ namespace fs
|
||||||
// Change file size (possibly appending zero bytes)
|
// Change file size (possibly appending zero bytes)
|
||||||
bool trunc(u64 length, std::source_location src_loc = std::source_location::current()) const
|
bool trunc(u64 length, std::source_location src_loc = std::source_location::current()) const
|
||||||
{
|
{
|
||||||
if (!m_file) xnull(src_loc);
|
if (!m_file)
|
||||||
|
xnull(src_loc);
|
||||||
return m_file->trunc(length);
|
return m_file->trunc(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get file information
|
// Get file information
|
||||||
stat_t get_stat(std::source_location src_loc = std::source_location::current()) const
|
stat_t get_stat(std::source_location src_loc = std::source_location::current()) const
|
||||||
{
|
{
|
||||||
if (!m_file) xnull(src_loc);
|
if (!m_file)
|
||||||
|
xnull(src_loc);
|
||||||
return m_file->get_stat();
|
return m_file->get_stat();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync file buffers
|
// Sync file buffers
|
||||||
void sync(std::source_location src_loc = std::source_location::current()) const
|
void sync(std::source_location src_loc = std::source_location::current()) const
|
||||||
{
|
{
|
||||||
if (!m_file) xnull(src_loc);
|
if (!m_file)
|
||||||
|
xnull(src_loc);
|
||||||
return m_file->sync();
|
return m_file->sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -329,80 +334,95 @@ namespace fs
|
||||||
// Read the data from the file and return the amount of data written in buffer
|
// Read the data from the file and return the amount of data written in buffer
|
||||||
u64 read(void* buffer, u64 count, std::source_location src_loc = std::source_location::current()) const
|
u64 read(void* buffer, u64 count, std::source_location src_loc = std::source_location::current()) const
|
||||||
{
|
{
|
||||||
if (!m_file) xnull(src_loc);
|
if (!m_file)
|
||||||
|
xnull(src_loc);
|
||||||
return m_file->read(buffer, count);
|
return m_file->read(buffer, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the data from the file at specified offset in thread-safe manner
|
// Read the data from the file at specified offset in thread-safe manner
|
||||||
u64 read_at(u64 offset, void* buffer, u64 count, std::source_location src_loc = std::source_location::current()) const
|
u64 read_at(u64 offset, void* buffer, u64 count, std::source_location src_loc = std::source_location::current()) const
|
||||||
{
|
{
|
||||||
if (!m_file) xnull(src_loc);
|
if (!m_file)
|
||||||
|
xnull(src_loc);
|
||||||
return m_file->read_at(offset, buffer, count);
|
return m_file->read_at(offset, buffer, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the data to the file and return the amount of data actually written
|
// Write the data to the file and return the amount of data actually written
|
||||||
u64 write(const void* buffer, u64 count, std::source_location src_loc = std::source_location::current()) const
|
u64 write(const void* buffer, u64 count, std::source_location src_loc = std::source_location::current()) const
|
||||||
{
|
{
|
||||||
if (!m_file) xnull(src_loc);
|
if (!m_file)
|
||||||
|
xnull(src_loc);
|
||||||
return m_file->write(buffer, count);
|
return m_file->write(buffer, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 write_at(u64 offset, const void* buffer, u64 count, std::source_location src_loc = std::source_location::current()) const
|
u64 write_at(u64 offset, const void* buffer, u64 count, std::source_location src_loc = std::source_location::current()) const
|
||||||
{
|
{
|
||||||
if (!m_file) xnull(src_loc);
|
if (!m_file)
|
||||||
|
xnull(src_loc);
|
||||||
return m_file->write_at(offset, buffer, count);
|
return m_file->write_at(offset, buffer, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change current position, returns resulting position
|
// Change current position, returns resulting position
|
||||||
u64 seek(s64 offset, seek_mode whence = seek_set, std::source_location src_loc = std::source_location::current()) const
|
u64 seek(s64 offset, seek_mode whence = seek_set, std::source_location src_loc = std::source_location::current()) const
|
||||||
{
|
{
|
||||||
if (!m_file) xnull(src_loc);
|
if (!m_file)
|
||||||
|
xnull(src_loc);
|
||||||
return m_file->seek(offset, whence);
|
return m_file->seek(offset, whence);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get file size
|
// Get file size
|
||||||
u64 size(std::source_location src_loc = std::source_location::current()) const
|
u64 size(std::source_location src_loc = std::source_location::current()) const
|
||||||
{
|
{
|
||||||
if (!m_file) xnull(src_loc);
|
if (!m_file)
|
||||||
|
xnull(src_loc);
|
||||||
return m_file->size();
|
return m_file->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get current position
|
// Get current position
|
||||||
u64 pos(std::source_location src_loc = std::source_location::current()) const
|
u64 pos(std::source_location src_loc = std::source_location::current()) const
|
||||||
{
|
{
|
||||||
if (!m_file) xnull(src_loc);
|
if (!m_file)
|
||||||
|
xnull(src_loc);
|
||||||
return m_file->seek(0, seek_cur);
|
return m_file->seek(0, seek_cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write std::basic_string unconditionally
|
// Write std::basic_string unconditionally
|
||||||
template <typename T> requires (std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
|
template <typename T>
|
||||||
|
requires(std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
|
||||||
const file& write(const std::basic_string<T>& str, std::source_location src_loc = std::source_location::current()) const
|
const file& write(const std::basic_string<T>& str, std::source_location src_loc = std::source_location::current()) const
|
||||||
{
|
{
|
||||||
if (write(str.data(), str.size() * sizeof(T), src_loc) != str.size() * sizeof(T)) xfail(src_loc);
|
if (write(str.data(), str.size() * sizeof(T), src_loc) != str.size() * sizeof(T))
|
||||||
|
xfail(src_loc);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write POD unconditionally
|
// Write POD unconditionally
|
||||||
template <typename T> requires (std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
|
template <typename T>
|
||||||
|
requires(std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
|
||||||
const file& write(const T& data, std::source_location src_loc = std::source_location::current()) const
|
const file& write(const T& data, std::source_location src_loc = std::source_location::current()) const
|
||||||
{
|
{
|
||||||
if (write(std::addressof(data), sizeof(T), src_loc) != sizeof(T)) xfail(src_loc);
|
if (write(std::addressof(data), sizeof(T), src_loc) != sizeof(T))
|
||||||
|
xfail(src_loc);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write POD std::vector unconditionally
|
// Write POD std::vector unconditionally
|
||||||
template <typename T> requires (std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
|
template <typename T>
|
||||||
|
requires(std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
|
||||||
const file& write(const std::vector<T>& vec, std::source_location src_loc = std::source_location::current()) const
|
const file& write(const std::vector<T>& vec, std::source_location src_loc = std::source_location::current()) const
|
||||||
{
|
{
|
||||||
if (write(vec.data(), vec.size() * sizeof(T), src_loc) != vec.size() * sizeof(T)) xfail(src_loc);
|
if (write(vec.data(), vec.size() * sizeof(T), src_loc) != vec.size() * sizeof(T))
|
||||||
|
xfail(src_loc);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read std::basic_string
|
// Read std::basic_string
|
||||||
template <typename T> requires (std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
|
template <typename T>
|
||||||
|
requires(std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
|
||||||
bool read(std::basic_string<T>& str, usz _size = umax, std::source_location src_loc = std::source_location::current()) const
|
bool read(std::basic_string<T>& str, usz _size = umax, std::source_location src_loc = std::source_location::current()) const
|
||||||
{
|
{
|
||||||
if (!m_file) xnull(src_loc);
|
if (!m_file)
|
||||||
|
xnull(src_loc);
|
||||||
|
|
||||||
if (_size != umax)
|
if (_size != umax)
|
||||||
{
|
{
|
||||||
|
|
@ -419,7 +439,8 @@ namespace fs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read POD, sizeof(T) is used
|
// Read POD, sizeof(T) is used
|
||||||
template <typename T> requires (std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
|
template <typename T>
|
||||||
|
requires(std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
|
||||||
bool read(T& data,
|
bool read(T& data,
|
||||||
pod_tag_t = pod_tag, std::source_location src_loc = std::source_location::current()) const
|
pod_tag_t = pod_tag, std::source_location src_loc = std::source_location::current()) const
|
||||||
{
|
{
|
||||||
|
|
@ -427,10 +448,12 @@ namespace fs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read POD std::vector
|
// Read POD std::vector
|
||||||
template <typename T> requires (std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
|
template <typename T>
|
||||||
|
requires(std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
|
||||||
bool read(std::vector<T>& vec, usz _size = umax, bool use_offs = false, usz offset = umax, std::source_location src_loc = std::source_location::current()) const
|
bool read(std::vector<T>& vec, usz _size = umax, bool use_offs = false, usz offset = umax, std::source_location src_loc = std::source_location::current()) const
|
||||||
{
|
{
|
||||||
if (!m_file) xnull(src_loc);
|
if (!m_file)
|
||||||
|
xnull(src_loc);
|
||||||
|
|
||||||
if (_size != umax)
|
if (_size != umax)
|
||||||
{
|
{
|
||||||
|
|
@ -452,11 +475,13 @@ namespace fs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read POD (experimental)
|
// Read POD (experimental)
|
||||||
template <typename T> requires (std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
|
template <typename T>
|
||||||
|
requires(std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
|
||||||
T read(pod_tag_t = pod_tag, std::source_location src_loc = std::source_location::current()) const
|
T read(pod_tag_t = pod_tag, std::source_location src_loc = std::source_location::current()) const
|
||||||
{
|
{
|
||||||
T result;
|
T result;
|
||||||
if (!read(result, pod_tag, src_loc)) xfail(src_loc);
|
if (!read(result, pod_tag, src_loc))
|
||||||
|
xfail(src_loc);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -467,17 +492,20 @@ namespace fs
|
||||||
std::basic_string<T> result;
|
std::basic_string<T> result;
|
||||||
result.resize(size() / sizeof(T));
|
result.resize(size() / sizeof(T));
|
||||||
seek(0);
|
seek(0);
|
||||||
if (!read(result, result.size(), src_loc)) xfail(src_loc);
|
if (!read(result, result.size(), src_loc))
|
||||||
|
xfail(src_loc);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read full file to std::vector
|
// Read full file to std::vector
|
||||||
template<typename T> requires (std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
|
template <typename T>
|
||||||
|
requires(std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
|
||||||
std::vector<T> to_vector(std::source_location src_loc = std::source_location::current()) const
|
std::vector<T> to_vector(std::source_location src_loc = std::source_location::current()) const
|
||||||
{
|
{
|
||||||
std::vector<T> result;
|
std::vector<T> result;
|
||||||
result.resize(size() / sizeof(T));
|
result.resize(size() / sizeof(T));
|
||||||
if (!read(result, result.size(), true, 0, src_loc)) xfail(src_loc);
|
if (!read(result, result.size(), true, 0, src_loc))
|
||||||
|
xfail(src_loc);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -490,7 +518,8 @@ namespace fs
|
||||||
// Gathered write
|
// Gathered write
|
||||||
u64 write_gather(const iovec_clone* buffers, u64 buf_count, std::source_location src_loc = std::source_location::current()) const
|
u64 write_gather(const iovec_clone* buffers, u64 buf_count, std::source_location src_loc = std::source_location::current()) const
|
||||||
{
|
{
|
||||||
if (!m_file) xnull(src_loc);
|
if (!m_file)
|
||||||
|
xnull(src_loc);
|
||||||
return m_file->write_gather(buffers, buf_count);
|
return m_file->write_gather(buffers, buf_count);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -536,14 +565,16 @@ namespace fs
|
||||||
// Get next directory entry
|
// Get next directory entry
|
||||||
bool read(dir_entry& out, std::source_location src_loc = std::source_location::current()) const
|
bool read(dir_entry& out, std::source_location src_loc = std::source_location::current()) const
|
||||||
{
|
{
|
||||||
if (!m_dir) xnull(src_loc);
|
if (!m_dir)
|
||||||
|
xnull(src_loc);
|
||||||
return m_dir->read(out);
|
return m_dir->read(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset to the beginning
|
// Reset to the beginning
|
||||||
void rewind(std::source_location src_loc = std::source_location::current()) const
|
void rewind(std::source_location src_loc = std::source_location::current()) const
|
||||||
{
|
{
|
||||||
if (!m_dir) xnull(src_loc);
|
if (!m_dir)
|
||||||
|
xnull(src_loc);
|
||||||
return m_dir->rewind();
|
return m_dir->rewind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -586,7 +617,7 @@ namespace fs
|
||||||
|
|
||||||
iterator& operator=(iterator&&) = default;
|
iterator& operator=(iterator&&) = default;
|
||||||
|
|
||||||
dir_entry& operator *()
|
dir_entry& operator*()
|
||||||
{
|
{
|
||||||
return m_entry;
|
return m_entry;
|
||||||
}
|
}
|
||||||
|
|
@ -604,7 +635,7 @@ namespace fs
|
||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator !=(const iterator& rhs) const
|
bool operator!=(const iterator& rhs) const
|
||||||
{
|
{
|
||||||
return m_parent != rhs.m_parent;
|
return m_parent != rhs.m_parent;
|
||||||
}
|
}
|
||||||
|
|
@ -630,7 +661,7 @@ namespace fs
|
||||||
virtual_dir(std::vector<fs::dir_entry> entries)
|
virtual_dir(std::vector<fs::dir_entry> entries)
|
||||||
: m_entries(std::move(entries)) {}
|
: m_entries(std::move(entries)) {}
|
||||||
|
|
||||||
bool read(fs::dir_entry &entry) override
|
bool read(fs::dir_entry& entry) override
|
||||||
{
|
{
|
||||||
if (m_offset < m_entries.size())
|
if (m_offset < m_entries.size())
|
||||||
{
|
{
|
||||||
|
|
@ -641,7 +672,10 @@ namespace fs
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rewind() override { m_offset = 0; }
|
void rewind() override
|
||||||
|
{
|
||||||
|
m_offset = 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get executable path
|
// Get executable path
|
||||||
|
|
@ -730,9 +764,7 @@ namespace fs
|
||||||
u64 pos;
|
u64 pos;
|
||||||
|
|
||||||
container_stream(T&& obj, const stat_t& init_stat = {})
|
container_stream(T&& obj, const stat_t& init_stat = {})
|
||||||
: obj(std::forward<T>(obj))
|
: obj(std::forward<T>(obj)), pos(0), m_stat(init_stat)
|
||||||
, pos(0)
|
|
||||||
, m_stat(init_stat)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -812,7 +844,8 @@ namespace fs
|
||||||
obj.insert(obj.end(), src + overlap, src + size);
|
obj.insert(obj.end(), src + overlap, src + size);
|
||||||
pos += size;
|
pos += size;
|
||||||
|
|
||||||
if (size) update_time(true);
|
if (size)
|
||||||
|
update_time(true);
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -821,7 +854,8 @@ namespace fs
|
||||||
const s64 new_pos =
|
const s64 new_pos =
|
||||||
whence == fs::seek_set ? offset :
|
whence == fs::seek_set ? offset :
|
||||||
whence == fs::seek_cur ? offset + pos :
|
whence == fs::seek_cur ? offset + pos :
|
||||||
whence == fs::seek_end ? offset + size() : -1;
|
whence == fs::seek_end ? offset + size() :
|
||||||
|
-1;
|
||||||
|
|
||||||
if (new_pos < 0)
|
if (new_pos < 0)
|
||||||
{
|
{
|
||||||
|
|
@ -899,4 +933,4 @@ namespace fs
|
||||||
file make_gather(std::vector<file>);
|
file make_gather(std::vector<file>);
|
||||||
|
|
||||||
stx::generator<dir_entry&> list_dir_recursively(const std::string& path);
|
stx::generator<dir_entry&> list_dir_recursively(const std::string& path);
|
||||||
}
|
} // namespace fs
|
||||||
|
|
|
||||||
|
|
@ -432,7 +432,7 @@ namespace asmjit
|
||||||
c.bind(next);
|
c.bind(next);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
} // namespace asmjit
|
||||||
|
|
||||||
// Build runtime function with asmjit::X86Assembler
|
// Build runtime function with asmjit::X86Assembler
|
||||||
template <typename FT, typename Asm = native_asm, typename F>
|
template <typename FT, typename Asm = native_asm, typename F>
|
||||||
|
|
@ -501,7 +501,7 @@ namespace llvm
|
||||||
class ExecutionEngine;
|
class ExecutionEngine;
|
||||||
class Module;
|
class Module;
|
||||||
class StringRef;
|
class StringRef;
|
||||||
}
|
} // namespace llvm
|
||||||
|
|
||||||
enum class thread_state : u32;
|
enum class thread_state : u32;
|
||||||
|
|
||||||
|
|
@ -569,6 +569,6 @@ public:
|
||||||
bool add_sub_disk_space(ssz space);
|
bool add_sub_disk_space(ssz space);
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *fallback_cpu_detection();
|
const char* fallback_cpu_detection();
|
||||||
|
|
||||||
#endif // LLVM_AVAILABLE
|
#endif // LLVM_AVAILABLE
|
||||||
|
|
|
||||||
|
|
@ -389,8 +389,7 @@ jit_runtime_base& asmjit::get_global_runtime()
|
||||||
}
|
}
|
||||||
|
|
||||||
asmjit::inline_runtime::inline_runtime(uchar* data, usz size)
|
asmjit::inline_runtime::inline_runtime(uchar* data, usz size)
|
||||||
: m_data(data)
|
: m_data(data), m_size(size)
|
||||||
, m_size(size)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -312,7 +312,7 @@ struct MemoryManager1 : llvm::RTDyldMemoryManager
|
||||||
if (is_ro)
|
if (is_ro)
|
||||||
{
|
{
|
||||||
// Disabled
|
// Disabled
|
||||||
//return allocate(data_ro_ptr, m_data_ro_mems, size, align, utils::protection::rw);
|
// return allocate(data_ro_ptr, m_data_ro_mems, size, align, utils::protection::rw);
|
||||||
}
|
}
|
||||||
|
|
||||||
return allocate(data_rw_ptr, m_data_rw_mems, size, align, utils::protection::rw);
|
return allocate(data_rw_ptr, m_data_rw_mems, size, align, utils::protection::rw);
|
||||||
|
|
@ -402,8 +402,7 @@ class ObjectCache final : public llvm::ObjectCache
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ObjectCache(const std::string& path, jit_compiler* compiler = nullptr)
|
ObjectCache(const std::string& path, jit_compiler* compiler = nullptr)
|
||||||
: m_path(path)
|
: m_path(path), m_compiler(compiler)
|
||||||
, m_compiler(compiler)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -414,7 +413,7 @@ public:
|
||||||
std::string name = m_path;
|
std::string name = m_path;
|
||||||
|
|
||||||
name.append(_module->getName());
|
name.append(_module->getName());
|
||||||
//fs::file(name, fs::rewrite).write(obj.getBufferStart(), obj.getBufferSize());
|
// fs::file(name, fs::rewrite).write(obj.getBufferStart(), obj.getBufferSize());
|
||||||
name.append(".gz");
|
name.append(".gz");
|
||||||
|
|
||||||
if (!obj.getBufferSize())
|
if (!obj.getBufferSize())
|
||||||
|
|
@ -636,12 +635,12 @@ bool jit_compiler::add_sub_disk_space(ssz space)
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}).second;
|
})
|
||||||
|
.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
jit_compiler::jit_compiler(const std::unordered_map<std::string, u64>& _link, const std::string& _cpu, u32 flags, std::function<u64(const std::string&)> symbols_cement) noexcept
|
jit_compiler::jit_compiler(const std::unordered_map<std::string, u64>& _link, const std::string& _cpu, u32 flags, std::function<u64(const std::string&)> symbols_cement) noexcept
|
||||||
: m_context(new llvm::LLVMContext)
|
: m_context(new llvm::LLVMContext), m_cpu(cpu(_cpu))
|
||||||
, m_cpu(cpu(_cpu))
|
|
||||||
{
|
{
|
||||||
[[maybe_unused]] static const bool s_install_llvm_error_handler = []()
|
[[maybe_unused]] static const bool s_install_llvm_error_handler = []()
|
||||||
{
|
{
|
||||||
|
|
@ -650,14 +649,15 @@ jit_compiler::jit_compiler(const std::unordered_map<std::string, u64>& _link, co
|
||||||
{
|
{
|
||||||
const std::string_view out = msg ? msg : "";
|
const std::string_view out = msg ? msg : "";
|
||||||
fmt::throw_exception("LLVM Emergency Exit Invoked: '%s'", out);
|
fmt::throw_exception("LLVM Emergency Exit Invoked: '%s'", out);
|
||||||
}, nullptr);
|
},
|
||||||
|
nullptr);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|
||||||
auto null_mod = std::make_unique<llvm::Module> ("null_", *m_context);
|
auto null_mod = std::make_unique<llvm::Module>("null_", *m_context);
|
||||||
null_mod->setTargetTriple(jit_compiler::triple1());
|
null_mod->setTargetTriple(jit_compiler::triple1());
|
||||||
|
|
||||||
std::unique_ptr<llvm::RTDyldMemoryManager> mem;
|
std::unique_ptr<llvm::RTDyldMemoryManager> mem;
|
||||||
|
|
@ -824,7 +824,7 @@ u64 jit_compiler::get(const std::string& name)
|
||||||
return m_engine->getGlobalValueAddress(name);
|
return m_engine->getGlobalValueAddress(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * fallback_cpu_detection()
|
const char* fallback_cpu_detection()
|
||||||
{
|
{
|
||||||
#if defined(ARCH_X64)
|
#if defined(ARCH_X64)
|
||||||
// If we got here we either have a very old and outdated CPU or a new CPU that has not been seen by LLVM yet.
|
// If we got here we either have a very old and outdated CPU or a new CPU that has not been seen by LLVM yet.
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
// check if the scheme name is valid
|
// check if the scheme name is valid
|
||||||
static bool IsSchemeValid( const std::string& SchemeName )
|
static bool IsSchemeValid(const std::string& SchemeName)
|
||||||
{
|
{
|
||||||
return std::all_of(SchemeName.cbegin(), SchemeName.cend(), [](const auto& c)
|
return std::all_of(SchemeName.cbegin(), SchemeName.cend(), [](const auto& c)
|
||||||
{
|
{
|
||||||
|
|
@ -40,21 +40,30 @@ static bool IsSchemeValid( const std::string& SchemeName )
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LUrlParser::clParseURL::GetPort( int* OutPort ) const
|
bool LUrlParser::clParseURL::GetPort(int* OutPort) const
|
||||||
{
|
{
|
||||||
if ( !IsValid() ) { return false; }
|
if (!IsValid())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const int Port = atoi( m_Port.c_str() );
|
const int Port = atoi(m_Port.c_str());
|
||||||
|
|
||||||
if ( Port <= 0 || Port > 65535 ) { return false; }
|
if (Port <= 0 || Port > 65535)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ( OutPort ) { *OutPort = Port; }
|
if (OutPort)
|
||||||
|
{
|
||||||
|
*OutPort = Port;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// based on RFC 1738 and RFC 3986
|
// based on RFC 1738 and RFC 3986
|
||||||
LUrlParser::clParseURL LUrlParser::clParseURL::ParseURL( const std::string& URL )
|
LUrlParser::clParseURL LUrlParser::clParseURL::ParseURL(const std::string& URL)
|
||||||
{
|
{
|
||||||
LUrlParser::clParseURL Result;
|
LUrlParser::clParseURL Result;
|
||||||
|
|
||||||
|
|
@ -68,26 +77,26 @@ LUrlParser::clParseURL LUrlParser::clParseURL::ParseURL( const std::string& URL
|
||||||
|
|
||||||
// try to read scheme
|
// try to read scheme
|
||||||
{
|
{
|
||||||
const char* LocalString = strchr( CurrentString, ':' );
|
const char* LocalString = strchr(CurrentString, ':');
|
||||||
|
|
||||||
if ( !LocalString )
|
if (!LocalString)
|
||||||
{
|
{
|
||||||
return clParseURL( LUrlParserError_NoUrlCharacter );
|
return clParseURL(LUrlParserError_NoUrlCharacter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// save the scheme name
|
// save the scheme name
|
||||||
Result.m_Scheme = std::string( CurrentString, LocalString - CurrentString );
|
Result.m_Scheme = std::string(CurrentString, LocalString - CurrentString);
|
||||||
|
|
||||||
if ( !IsSchemeValid( Result.m_Scheme ) )
|
if (!IsSchemeValid(Result.m_Scheme))
|
||||||
{
|
{
|
||||||
return clParseURL( LUrlParserError_InvalidSchemeName );
|
return clParseURL(LUrlParserError_InvalidSchemeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// scheme should be lowercase
|
// scheme should be lowercase
|
||||||
std::transform( Result.m_Scheme.begin(), Result.m_Scheme.end(), Result.m_Scheme.begin(), ::tolower );
|
std::transform(Result.m_Scheme.begin(), Result.m_Scheme.end(), Result.m_Scheme.begin(), ::tolower);
|
||||||
|
|
||||||
// skip ':'
|
// skip ':'
|
||||||
CurrentString = LocalString+1;
|
CurrentString = LocalString + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -96,23 +105,25 @@ LUrlParser::clParseURL LUrlParser::clParseURL::ParseURL( const std::string& URL
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// skip "//"
|
// skip "//"
|
||||||
if ( *CurrentString++ != '/' ) return clParseURL( LUrlParserError_NoDoubleSlash );
|
if (*CurrentString++ != '/')
|
||||||
if ( *CurrentString++ != '/' ) return clParseURL( LUrlParserError_NoDoubleSlash );
|
return clParseURL(LUrlParserError_NoDoubleSlash);
|
||||||
|
if (*CurrentString++ != '/')
|
||||||
|
return clParseURL(LUrlParserError_NoDoubleSlash);
|
||||||
|
|
||||||
// check if the user name and password are specified
|
// check if the user name and password are specified
|
||||||
bool bHasUserName = false;
|
bool bHasUserName = false;
|
||||||
|
|
||||||
const char* LocalString = CurrentString;
|
const char* LocalString = CurrentString;
|
||||||
|
|
||||||
while ( *LocalString )
|
while (*LocalString)
|
||||||
{
|
{
|
||||||
if ( *LocalString == '@' )
|
if (*LocalString == '@')
|
||||||
{
|
{
|
||||||
// user name and password are specified
|
// user name and password are specified
|
||||||
bHasUserName = true;
|
bHasUserName = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if ( *LocalString == '/' )
|
else if (*LocalString == '/')
|
||||||
{
|
{
|
||||||
// end of <host>:<port> specification
|
// end of <host>:<port> specification
|
||||||
bHasUserName = false;
|
bHasUserName = false;
|
||||||
|
|
@ -125,17 +136,18 @@ LUrlParser::clParseURL LUrlParser::clParseURL::ParseURL( const std::string& URL
|
||||||
// user name and password
|
// user name and password
|
||||||
LocalString = CurrentString;
|
LocalString = CurrentString;
|
||||||
|
|
||||||
if ( bHasUserName )
|
if (bHasUserName)
|
||||||
{
|
{
|
||||||
// read user name
|
// read user name
|
||||||
while ( *LocalString && *LocalString != ':' && *LocalString != '@' ) LocalString++;
|
while (*LocalString && *LocalString != ':' && *LocalString != '@')
|
||||||
|
LocalString++;
|
||||||
|
|
||||||
Result.m_UserName = std::string( CurrentString, LocalString - CurrentString );
|
Result.m_UserName = std::string(CurrentString, LocalString - CurrentString);
|
||||||
|
|
||||||
// proceed with the current pointer
|
// proceed with the current pointer
|
||||||
CurrentString = LocalString;
|
CurrentString = LocalString;
|
||||||
|
|
||||||
if ( *CurrentString == ':' )
|
if (*CurrentString == ':')
|
||||||
{
|
{
|
||||||
// skip ':'
|
// skip ':'
|
||||||
CurrentString++;
|
CurrentString++;
|
||||||
|
|
@ -143,36 +155,37 @@ LUrlParser::clParseURL LUrlParser::clParseURL::ParseURL( const std::string& URL
|
||||||
// read password
|
// read password
|
||||||
LocalString = CurrentString;
|
LocalString = CurrentString;
|
||||||
|
|
||||||
while ( *LocalString && *LocalString != '@' ) LocalString++;
|
while (*LocalString && *LocalString != '@')
|
||||||
|
LocalString++;
|
||||||
|
|
||||||
Result.m_Password = std::string( CurrentString, LocalString - CurrentString );
|
Result.m_Password = std::string(CurrentString, LocalString - CurrentString);
|
||||||
|
|
||||||
CurrentString = LocalString;
|
CurrentString = LocalString;
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip '@'
|
// skip '@'
|
||||||
if ( *CurrentString != '@' )
|
if (*CurrentString != '@')
|
||||||
{
|
{
|
||||||
return clParseURL( LUrlParserError_NoAtSign );
|
return clParseURL(LUrlParserError_NoAtSign);
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentString++;
|
CurrentString++;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bHasBracket = ( *CurrentString == '[' );
|
bool bHasBracket = (*CurrentString == '[');
|
||||||
|
|
||||||
// go ahead, read the host name
|
// go ahead, read the host name
|
||||||
LocalString = CurrentString;
|
LocalString = CurrentString;
|
||||||
|
|
||||||
while ( *LocalString )
|
while (*LocalString)
|
||||||
{
|
{
|
||||||
if ( bHasBracket && *LocalString == ']' )
|
if (bHasBracket && *LocalString == ']')
|
||||||
{
|
{
|
||||||
// end of IPv6 address
|
// end of IPv6 address
|
||||||
LocalString++;
|
LocalString++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if ( !bHasBracket && ( *LocalString == ':' || *LocalString == '/' ) )
|
else if (!bHasBracket && (*LocalString == ':' || *LocalString == '/'))
|
||||||
{
|
{
|
||||||
// port number is specified
|
// port number is specified
|
||||||
break;
|
break;
|
||||||
|
|
@ -181,27 +194,28 @@ LUrlParser::clParseURL LUrlParser::clParseURL::ParseURL( const std::string& URL
|
||||||
LocalString++;
|
LocalString++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result.m_Host = std::string( CurrentString, LocalString - CurrentString );
|
Result.m_Host = std::string(CurrentString, LocalString - CurrentString);
|
||||||
|
|
||||||
CurrentString = LocalString;
|
CurrentString = LocalString;
|
||||||
|
|
||||||
// is port number specified?
|
// is port number specified?
|
||||||
if ( *CurrentString == ':' )
|
if (*CurrentString == ':')
|
||||||
{
|
{
|
||||||
CurrentString++;
|
CurrentString++;
|
||||||
|
|
||||||
// read port number
|
// read port number
|
||||||
LocalString = CurrentString;
|
LocalString = CurrentString;
|
||||||
|
|
||||||
while ( *LocalString && *LocalString != '/' ) LocalString++;
|
while (*LocalString && *LocalString != '/')
|
||||||
|
LocalString++;
|
||||||
|
|
||||||
Result.m_Port = std::string( CurrentString, LocalString - CurrentString );
|
Result.m_Port = std::string(CurrentString, LocalString - CurrentString);
|
||||||
|
|
||||||
CurrentString = LocalString;
|
CurrentString = LocalString;
|
||||||
}
|
}
|
||||||
|
|
||||||
// end of string
|
// end of string
|
||||||
if ( !*CurrentString )
|
if (!*CurrentString)
|
||||||
{
|
{
|
||||||
Result.m_ErrorCode = LUrlParserError_Ok;
|
Result.m_ErrorCode = LUrlParserError_Ok;
|
||||||
|
|
||||||
|
|
@ -209,9 +223,9 @@ LUrlParser::clParseURL LUrlParser::clParseURL::ParseURL( const std::string& URL
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip '/'
|
// skip '/'
|
||||||
if ( *CurrentString != '/' )
|
if (*CurrentString != '/')
|
||||||
{
|
{
|
||||||
return clParseURL( LUrlParserError_NoSlash );
|
return clParseURL(LUrlParserError_NoSlash);
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentString++;
|
CurrentString++;
|
||||||
|
|
@ -219,14 +233,15 @@ LUrlParser::clParseURL LUrlParser::clParseURL::ParseURL( const std::string& URL
|
||||||
// parse the path
|
// parse the path
|
||||||
LocalString = CurrentString;
|
LocalString = CurrentString;
|
||||||
|
|
||||||
while ( *LocalString && *LocalString != '#' && *LocalString != '?' ) LocalString++;
|
while (*LocalString && *LocalString != '#' && *LocalString != '?')
|
||||||
|
LocalString++;
|
||||||
|
|
||||||
Result.m_Path = std::string( CurrentString, LocalString - CurrentString );
|
Result.m_Path = std::string(CurrentString, LocalString - CurrentString);
|
||||||
|
|
||||||
CurrentString = LocalString;
|
CurrentString = LocalString;
|
||||||
|
|
||||||
// check for query
|
// check for query
|
||||||
if ( *CurrentString == '?' )
|
if (*CurrentString == '?')
|
||||||
{
|
{
|
||||||
// skip '?'
|
// skip '?'
|
||||||
CurrentString++;
|
CurrentString++;
|
||||||
|
|
@ -234,15 +249,16 @@ LUrlParser::clParseURL LUrlParser::clParseURL::ParseURL( const std::string& URL
|
||||||
// read query
|
// read query
|
||||||
LocalString = CurrentString;
|
LocalString = CurrentString;
|
||||||
|
|
||||||
while ( *LocalString && *LocalString != '#' ) LocalString++;
|
while (*LocalString && *LocalString != '#')
|
||||||
|
LocalString++;
|
||||||
|
|
||||||
Result.m_Query = std::string( CurrentString, LocalString - CurrentString );
|
Result.m_Query = std::string(CurrentString, LocalString - CurrentString);
|
||||||
|
|
||||||
CurrentString = LocalString;
|
CurrentString = LocalString;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for fragment
|
// check for fragment
|
||||||
if ( *CurrentString == '#' )
|
if (*CurrentString == '#')
|
||||||
{
|
{
|
||||||
// skip '#'
|
// skip '#'
|
||||||
CurrentString++;
|
CurrentString++;
|
||||||
|
|
@ -250,9 +266,10 @@ LUrlParser::clParseURL LUrlParser::clParseURL::ParseURL( const std::string& URL
|
||||||
// read fragment
|
// read fragment
|
||||||
LocalString = CurrentString;
|
LocalString = CurrentString;
|
||||||
|
|
||||||
while ( *LocalString ) LocalString++;
|
while (*LocalString)
|
||||||
|
LocalString++;
|
||||||
|
|
||||||
Result.m_Fragment = std::string( CurrentString, LocalString - CurrentString );
|
Result.m_Fragment = std::string(CurrentString, LocalString - CurrentString);
|
||||||
|
|
||||||
CurrentString = LocalString;
|
CurrentString = LocalString;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,22 +57,27 @@ namespace LUrlParser
|
||||||
std::string m_Password{};
|
std::string m_Password{};
|
||||||
|
|
||||||
clParseURL()
|
clParseURL()
|
||||||
: m_ErrorCode( LUrlParserError_Uninitialized )
|
: m_ErrorCode(LUrlParserError_Uninitialized)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// return 'true' if the parsing was successful
|
/// return 'true' if the parsing was successful
|
||||||
bool IsValid() const { return m_ErrorCode == LUrlParserError_Ok; }
|
bool IsValid() const
|
||||||
|
{
|
||||||
|
return m_ErrorCode == LUrlParserError_Ok;
|
||||||
|
}
|
||||||
|
|
||||||
/// helper to convert the port number to int, return 'true' if the port is valid (within the 0..65535 range)
|
/// helper to convert the port number to int, return 'true' if the port is valid (within the 0..65535 range)
|
||||||
bool GetPort( int* OutPort ) const;
|
bool GetPort(int* OutPort) const;
|
||||||
|
|
||||||
/// parse the URL
|
/// parse the URL
|
||||||
static clParseURL ParseURL( const std::string& URL );
|
static clParseURL ParseURL(const std::string& URL);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit clParseURL( LUrlParserError ErrorCode )
|
explicit clParseURL(LUrlParserError ErrorCode)
|
||||||
: m_ErrorCode( ErrorCode )
|
: m_ErrorCode(ErrorCode)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace LUrlParser
|
} // namespace LUrlParser
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,11 @@
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
#include <string>
|
||||||
#include "Thread.h"
|
#include "Thread.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <Windows.h>
|
#include <windows.h>
|
||||||
#else
|
#else
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -568,8 +569,7 @@ void fmt_class_string<std::source_location>::format(std::string& out, u64 arg)
|
||||||
if (std::string_view full_func{loc.function_name() ? loc.function_name() : ""}; !full_func.empty())
|
if (std::string_view full_func{loc.function_name() ? loc.function_name() : ""}; !full_func.empty())
|
||||||
{
|
{
|
||||||
// Remove useless disambiguators
|
// Remove useless disambiguators
|
||||||
std::string func = fmt::replace_all(std::string(full_func), {
|
std::string func = fmt::replace_all(std::string(full_func), {{"struct ", ""},
|
||||||
{"struct ", ""},
|
|
||||||
{"class ", ""},
|
{"class ", ""},
|
||||||
{"enum ", ""},
|
{"enum ", ""},
|
||||||
{"typename ", ""},
|
{"typename ", ""},
|
||||||
|
|
@ -670,7 +670,7 @@ namespace fmt
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cfmt_src;
|
struct cfmt_src;
|
||||||
}
|
} // namespace fmt
|
||||||
|
|
||||||
// Temporary implementation
|
// Temporary implementation
|
||||||
struct fmt::cfmt_src
|
struct fmt::cfmt_src
|
||||||
|
|
@ -714,13 +714,15 @@ struct fmt::cfmt_src
|
||||||
{
|
{
|
||||||
// Hack: use known function pointers to determine type
|
// Hack: use known function pointers to determine type
|
||||||
#define TYPE(type) \
|
#define TYPE(type) \
|
||||||
if (sup[extra].fmt_string == &fmt_class_string<type>::format) return sizeof(type);
|
if (sup[extra].fmt_string == &fmt_class_string<type>::format) \
|
||||||
|
return sizeof(type);
|
||||||
|
|
||||||
TYPE(int);
|
TYPE(int);
|
||||||
TYPE(llong);
|
TYPE(llong);
|
||||||
TYPE(schar);
|
TYPE(schar);
|
||||||
TYPE(short);
|
TYPE(short);
|
||||||
if constexpr (std::is_signed_v<char>) TYPE(char);
|
if constexpr (std::is_signed_v<char>)
|
||||||
|
TYPE(char);
|
||||||
TYPE(long);
|
TYPE(long);
|
||||||
TYPE(s128);
|
TYPE(s128);
|
||||||
|
|
||||||
|
|
@ -806,7 +808,7 @@ std::vector<std::string> fmt::split(std::string_view source, std::initializer_li
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.emplace_back(std::string(piece));
|
result.emplace_back(piece);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.empty() && !is_skip_empty)
|
if (result.empty() && !is_skip_empty)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
namespace fmt
|
namespace fmt
|
||||||
{
|
{
|
||||||
template <typename CharT, usz N, typename... Args>
|
template <typename CharT, usz N, typename... Args>
|
||||||
static std::string format(const CharT(&)[N], const Args&...);
|
static std::string format(const CharT (&)[N], const Args&...);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
struct win_error
|
struct win_error
|
||||||
|
|
@ -20,7 +20,7 @@ namespace fmt
|
||||||
std::string win_error_to_string(unsigned long error, void* module_handle = nullptr);
|
std::string win_error_to_string(unsigned long error, void* module_handle = nullptr);
|
||||||
std::string win_error_to_string(const win_error& error);
|
std::string win_error_to_string(const win_error& error);
|
||||||
#endif
|
#endif
|
||||||
}
|
} // namespace fmt
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct fmt_unveil
|
struct fmt_unveil
|
||||||
|
|
@ -146,7 +146,7 @@ struct fmt_class_string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enum -> string function type
|
// Enum -> string function type
|
||||||
using convert_t = const char*(*)(T value);
|
using convert_t = const char* (*)(T value);
|
||||||
|
|
||||||
// Helper function (safely converts arg to enum value)
|
// Helper function (safely converts arg to enum value)
|
||||||
static FORCE_INLINE SAFE_BUFFERS(void) format_enum(std::string& out, u64 arg, convert_t convert)
|
static FORCE_INLINE SAFE_BUFFERS(void) format_enum(std::string& out, u64 arg, convert_t convert)
|
||||||
|
|
@ -250,11 +250,10 @@ struct fmt_class_string<wchar_t*> : fmt_class_string<const wchar_t*>
|
||||||
namespace fmt
|
namespace fmt
|
||||||
{
|
{
|
||||||
template <typename T>
|
template <typename T>
|
||||||
concept StringConvertible = requires (T & t)
|
concept StringConvertible = requires(T& t) {
|
||||||
{
|
|
||||||
{ t.to_string() } -> std::convertible_to<std::string>;
|
{ t.to_string() } -> std::convertible_to<std::string>;
|
||||||
};
|
};
|
||||||
}
|
} // namespace fmt
|
||||||
|
|
||||||
template <fmt::StringConvertible T>
|
template <fmt::StringConvertible T>
|
||||||
struct fmt_class_string<T>
|
struct fmt_class_string<T>
|
||||||
|
|
@ -274,8 +273,8 @@ namespace fmt
|
||||||
{
|
{
|
||||||
// Both uchar and std::byte are allowed
|
// Both uchar and std::byte are allowed
|
||||||
template <typename T>
|
template <typename T>
|
||||||
concept ByteArray = requires (T& t) { const_cast<std::conditional_t<std::is_same_v<decltype(std::as_const(t[0])), const std::byte&>, std::byte, uchar>&>(std::data(t)[0]); };
|
concept ByteArray = requires(T& t) { const_cast<std::conditional_t<std::is_same_v<decltype(std::as_const(t[0])), const std::byte&>, std::byte, uchar>&>(std::data(t)[0]); };
|
||||||
}
|
} // namespace fmt
|
||||||
|
|
||||||
template <fmt::ByteArray T>
|
template <fmt::ByteArray T>
|
||||||
struct fmt_class_string<T>
|
struct fmt_class_string<T>
|
||||||
|
|
@ -301,8 +300,7 @@ struct fmt_type_info
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static constexpr fmt_type_info make()
|
static constexpr fmt_type_info make()
|
||||||
{
|
{
|
||||||
return fmt_type_info
|
return fmt_type_info{
|
||||||
{
|
|
||||||
&fmt_class_string<T>::format,
|
&fmt_class_string<T>::format,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -310,7 +308,7 @@ struct fmt_type_info
|
||||||
|
|
||||||
// Argument array type (each element generated via fmt_unveil<>)
|
// Argument array type (each element generated via fmt_unveil<>)
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
using fmt_args_t = const u64(&&)[sizeof...(Args) + 1];
|
using fmt_args_t = const u64 (&&)[sizeof...(Args) + 1];
|
||||||
|
|
||||||
template <typename Arg>
|
template <typename Arg>
|
||||||
using fmt_unveil_t = typename fmt_unveil<Arg>::type;
|
using fmt_unveil_t = typename fmt_unveil<Arg>::type;
|
||||||
|
|
@ -327,14 +325,12 @@ namespace fmt
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
base57(const T& arg) noexcept
|
base57(const T& arg) noexcept
|
||||||
: data(reinterpret_cast<const uchar*>(std::addressof(arg)))
|
: data(reinterpret_cast<const uchar*>(std::addressof(arg))), size(sizeof(T))
|
||||||
, size(sizeof(T))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
base57(const uchar* data, usz size) noexcept
|
base57(const uchar* data, usz size) noexcept
|
||||||
: data(data)
|
: data(data), size(size)
|
||||||
, size(size)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -348,8 +344,7 @@ namespace fmt
|
||||||
base57_result& operator=(base57_result&&) = default;
|
base57_result& operator=(base57_result&&) = default;
|
||||||
|
|
||||||
explicit base57_result(usz size) noexcept
|
explicit base57_result(usz size) noexcept
|
||||||
: base57(size ? new uchar[size] : nullptr, size)
|
: base57(size ? new uchar[size] : nullptr, size), memory(const_cast<uchar*>(this->data))
|
||||||
, memory(const_cast<uchar*>(this->data))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -364,14 +359,14 @@ namespace fmt
|
||||||
|
|
||||||
// Formatting function
|
// Formatting function
|
||||||
template <typename CharT, usz N, typename... Args>
|
template <typename CharT, usz N, typename... Args>
|
||||||
FORCE_INLINE SAFE_BUFFERS(void) append(std::string& out, const CharT(&fmt)[N], const Args&... args)
|
FORCE_INLINE SAFE_BUFFERS(void) append(std::string& out, const CharT (&fmt)[N], const Args&... args)
|
||||||
{
|
{
|
||||||
raw_append(out, reinterpret_cast<const char*>(fmt), type_info_v<Args...>, fmt_args_t<Args...>{fmt_unveil<Args>::get(args)...});
|
raw_append(out, reinterpret_cast<const char*>(fmt), type_info_v<Args...>, fmt_args_t<Args...>{fmt_unveil<Args>::get(args)...});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Formatting function
|
// Formatting function
|
||||||
template <typename CharT, usz N, typename... Args>
|
template <typename CharT, usz N, typename... Args>
|
||||||
FORCE_INLINE SAFE_BUFFERS(std::string) format(const CharT(&fmt)[N], const Args&... args)
|
FORCE_INLINE SAFE_BUFFERS(std::string) format(const CharT (&fmt)[N], const Args&... args)
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
append(result, fmt, args...);
|
append(result, fmt, args...);
|
||||||
|
|
@ -385,9 +380,11 @@ namespace fmt
|
||||||
template <typename CharT, usz N, typename... Args>
|
template <typename CharT, usz N, typename... Args>
|
||||||
struct throw_exception
|
struct throw_exception
|
||||||
{
|
{
|
||||||
struct args_break_t {};
|
struct args_break_t
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
[[noreturn]] FORCE_INLINE SAFE_BUFFERS() throw_exception(const CharT(&fmt)[N], const Args&... args,
|
[[noreturn]] FORCE_INLINE SAFE_BUFFERS() throw_exception(const CharT (&fmt)[N], const Args&... args,
|
||||||
args_break_t = args_break_t{}, std::source_location src_loc = std::source_location::current())
|
args_break_t = args_break_t{}, std::source_location src_loc = std::source_location::current())
|
||||||
{
|
{
|
||||||
raw_throw_exception(src_loc, reinterpret_cast<const char*>(fmt), type_info_v<Args...>, fmt_args_t<Args...>{fmt_unveil<Args>::get(args)...});
|
raw_throw_exception(src_loc, reinterpret_cast<const char*>(fmt), type_info_v<Args...>, fmt_args_t<Args...>{fmt_unveil<Args>::get(args)...});
|
||||||
|
|
@ -399,7 +396,7 @@ namespace fmt
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename CharT, usz N, typename... Args>
|
template <typename CharT, usz N, typename... Args>
|
||||||
throw_exception(const CharT(&)[N], const Args&...) -> throw_exception<CharT, N, Args...>;
|
throw_exception(const CharT (&)[N], const Args&...) -> throw_exception<CharT, N, Args...>;
|
||||||
|
|
||||||
// Helper template: pack format variables
|
// Helper template: pack format variables
|
||||||
template <typename Arg = void, typename... Args>
|
template <typename Arg = void, typename... Args>
|
||||||
|
|
@ -412,8 +409,7 @@ namespace fmt
|
||||||
|
|
||||||
// Store only references, unveil op is postponed
|
// Store only references, unveil op is postponed
|
||||||
tie(Arg&& arg, Args&&... args) noexcept
|
tie(Arg&& arg, Args&&... args) noexcept
|
||||||
: arg(std::forward<Arg>(arg))
|
: arg(std::forward<Arg>(arg)), next(std::forward<Args>(args)...)
|
||||||
, next(std::forward<Args>(args)...)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -445,7 +441,7 @@ namespace fmt
|
||||||
|
|
||||||
// Ensure with formatting
|
// Ensure with formatting
|
||||||
template <typename T, typename CharT, usz N, typename... Args>
|
template <typename T, typename CharT, usz N, typename... Args>
|
||||||
decltype(auto) ensure(T&& arg, const CharT(&fmt)[N], tie<Args...> args, std::source_location src_loc = std::source_location::current()) noexcept
|
decltype(auto) ensure(T&& arg, const CharT (&fmt)[N], tie<Args...> args, std::source_location src_loc = std::source_location::current()) noexcept
|
||||||
{
|
{
|
||||||
if (std::forward<T>(arg)) [[likely]]
|
if (std::forward<T>(arg)) [[likely]]
|
||||||
{
|
{
|
||||||
|
|
@ -458,4 +454,4 @@ namespace fmt
|
||||||
|
|
||||||
raw_throw_exception(src_loc, reinterpret_cast<const char*>(fmt), type_info_v<std::remove_cvref_t<Args>...>, +data);
|
raw_throw_exception(src_loc, reinterpret_cast<const char*>(fmt), type_info_v<std::remove_cvref_t<Args>...>, +data);
|
||||||
}
|
}
|
||||||
}
|
} // namespace fmt
|
||||||
|
|
|
||||||
|
|
@ -96,8 +96,7 @@ namespace fmt
|
||||||
return src;
|
return src;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline
|
static inline std::string replace_all(std::string src, const std::vector<std::pair<std::string, std::string>>& list)
|
||||||
std::string replace_all(std::string src, const std::vector<std::pair<std::string, std::string>>& list)
|
|
||||||
{
|
{
|
||||||
for (usz pos = 0; pos < src.length(); ++pos)
|
for (usz pos = 0; pos < src.length(); ++pos)
|
||||||
{
|
{
|
||||||
|
|
@ -211,4 +210,4 @@ namespace fmt
|
||||||
return hash_type{}(str);
|
return hash_type{}(str);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace fmt
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <Windows.h>
|
#include <windows.h>
|
||||||
#include <Psapi.h>
|
#include <Psapi.h>
|
||||||
#include <process.h>
|
#include <process.h>
|
||||||
#include <sysinfoapi.h>
|
#include <sysinfoapi.h>
|
||||||
|
|
@ -56,34 +56,34 @@ DYNAMIC_IMPORT_RENAME("Kernel32.dll", SetThreadDescriptionImport, "SetThreadDesc
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
|
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
|
||||||
# include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
# include <unistd.h>
|
#include <unistd.h>
|
||||||
# if defined(__DragonFly__) || defined(__FreeBSD__)
|
#if defined(__DragonFly__) || defined(__FreeBSD__)
|
||||||
# include <sys/user.h>
|
#include <sys/user.h>
|
||||||
# endif
|
#endif
|
||||||
# if defined(__OpenBSD__)
|
#if defined(__OpenBSD__)
|
||||||
# include <sys/param.h>
|
#include <sys/param.h>
|
||||||
# include <sys/proc.h>
|
#include <sys/proc.h>
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
# if defined(__NetBSD__)
|
#if defined(__NetBSD__)
|
||||||
# undef KERN_PROC
|
#undef KERN_PROC
|
||||||
# define KERN_PROC KERN_PROC2
|
#define KERN_PROC KERN_PROC2
|
||||||
# define kinfo_proc kinfo_proc2
|
#define kinfo_proc kinfo_proc2
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
# if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
# define KP_FLAGS kp_proc.p_flag
|
#define KP_FLAGS kp_proc.p_flag
|
||||||
# elif defined(__DragonFly__)
|
#elif defined(__DragonFly__)
|
||||||
# define KP_FLAGS kp_flags
|
#define KP_FLAGS kp_flags
|
||||||
# elif defined(__FreeBSD__)
|
#elif defined(__FreeBSD__)
|
||||||
# define KP_FLAGS ki_flag
|
#define KP_FLAGS ki_flag
|
||||||
# elif defined(__NetBSD__)
|
#elif defined(__NetBSD__)
|
||||||
# define KP_FLAGS p_flag
|
#define KP_FLAGS p_flag
|
||||||
# elif defined(__OpenBSD__)
|
#elif defined(__OpenBSD__)
|
||||||
# define KP_FLAGS p_psflags
|
#define KP_FLAGS p_psflags
|
||||||
# define P_TRACED PS_TRACED
|
#define P_TRACED PS_TRACED
|
||||||
# endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "util/vm.hpp"
|
#include "util/vm.hpp"
|
||||||
|
|
@ -104,14 +104,16 @@ thread_local u64 g_tls_fault_spu = 0;
|
||||||
thread_local u64 g_tls_wait_time = 0;
|
thread_local u64 g_tls_wait_time = 0;
|
||||||
thread_local u64 g_tls_wait_fail = 0;
|
thread_local u64 g_tls_wait_fail = 0;
|
||||||
thread_local bool g_tls_access_violation_recovered = false;
|
thread_local bool g_tls_access_violation_recovered = false;
|
||||||
extern thread_local std::string(*g_tls_log_prefix)();
|
extern thread_local std::string (*g_tls_log_prefix)();
|
||||||
|
|
||||||
// Report error and call std::abort(), defined in main.cpp
|
// Report error and call std::abort(), defined in main.cpp
|
||||||
[[noreturn]] void report_fatal_error(std::string_view text, bool is_html = false, bool include_help_text = true);
|
[[noreturn]] void report_fatal_error(std::string_view text, bool is_html = false, bool include_help_text = true);
|
||||||
|
|
||||||
enum cpu_threads_emulation_info_dump_t : u32 {};
|
enum cpu_threads_emulation_info_dump_t : u32
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
template<>
|
template <>
|
||||||
void fmt_class_string<thread_class>::format(std::string& out, u64 arg)
|
void fmt_class_string<thread_class>::format(std::string& out, u64 arg)
|
||||||
{
|
{
|
||||||
format_enum(out, arg, [](thread_class value)
|
format_enum(out, arg, [](thread_class value)
|
||||||
|
|
@ -148,10 +150,10 @@ bool IsDebuggerPresent()
|
||||||
KERN_PROC,
|
KERN_PROC,
|
||||||
KERN_PROC_PID,
|
KERN_PROC_PID,
|
||||||
getpid(),
|
getpid(),
|
||||||
# if defined(__NetBSD__) || defined(__OpenBSD__)
|
#if defined(__NetBSD__) || defined(__OpenBSD__)
|
||||||
sizeof(struct kinfo_proc),
|
sizeof(struct kinfo_proc),
|
||||||
1,
|
1,
|
||||||
# endif
|
#endif
|
||||||
};
|
};
|
||||||
u_int miblen = std::size(mib);
|
u_int miblen = std::size(mib);
|
||||||
struct kinfo_proc info;
|
struct kinfo_proc info;
|
||||||
|
|
@ -590,7 +592,7 @@ void decode_x64_reg_op(const u8* code, x64_op_t& out_op, x64_reg_t& out_reg, usz
|
||||||
{
|
{
|
||||||
switch (get_modRM_reg(code, 0))
|
switch (get_modRM_reg(code, 0))
|
||||||
{
|
{
|
||||||
//case 0: out_op = X64OP_ADD; break; // TODO: strange info in instruction manual
|
// case 0: out_op = X64OP_ADD; break; // TODO: strange info in instruction manual
|
||||||
case 1: out_op = X64OP_OR; break;
|
case 1: out_op = X64OP_OR; break;
|
||||||
case 2: out_op = X64OP_ADC; break;
|
case 2: out_op = X64OP_ADC; break;
|
||||||
case 3: out_op = X64OP_SBB; break;
|
case 3: out_op = X64OP_SBB; break;
|
||||||
|
|
@ -773,7 +775,8 @@ void decode_x64_reg_op(const u8* code, x64_op_t& out_op, x64_reg_t& out_reg, usz
|
||||||
|
|
||||||
s_tls_reg3 = x64_reg_t{vreg};
|
s_tls_reg3 = x64_reg_t{vreg};
|
||||||
|
|
||||||
if (vopm == 0x1) switch (vop1) // Implied leading byte 0x0F
|
if (vopm == 0x1)
|
||||||
|
switch (vop1) // Implied leading byte 0x0F
|
||||||
{
|
{
|
||||||
case 0x11:
|
case 0x11:
|
||||||
case 0x29:
|
case 0x29:
|
||||||
|
|
@ -802,7 +805,8 @@ void decode_x64_reg_op(const u8* code, x64_op_t& out_op, x64_reg_t& out_reg, usz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vopm == 0x2) switch (vop1) // Implied leading bytes 0x0F 0x38
|
if (vopm == 0x2)
|
||||||
|
switch (vop1) // Implied leading bytes 0x0F 0x38
|
||||||
{
|
{
|
||||||
case 0xf7:
|
case 0xf7:
|
||||||
{
|
{
|
||||||
|
|
@ -900,10 +904,10 @@ typedef ucontext_t x64_context;
|
||||||
#define XMMREG(context, reg) (reinterpret_cast<v128*>(&(context)->uc_mcontext->__fs.__fpu_xmm0.__xmm_reg[reg]))
|
#define XMMREG(context, reg) (reinterpret_cast<v128*>(&(context)->uc_mcontext->__fs.__fpu_xmm0.__xmm_reg[reg]))
|
||||||
#define EFLAGS(context) ((context)->uc_mcontext->__ss.__rflags)
|
#define EFLAGS(context) ((context)->uc_mcontext->__ss.__rflags)
|
||||||
|
|
||||||
u64* darwin_x64reg(x64_context *context, int reg)
|
u64* darwin_x64reg(x64_context* context, int reg)
|
||||||
{
|
{
|
||||||
auto *state = &context->uc_mcontext->__ss;
|
auto* state = &context->uc_mcontext->__ss;
|
||||||
switch(reg)
|
switch (reg)
|
||||||
{
|
{
|
||||||
case 0: return &state->__rax;
|
case 0: return &state->__rax;
|
||||||
case 1: return &state->__rcx;
|
case 1: return &state->__rcx;
|
||||||
|
|
@ -932,16 +936,16 @@ u64* darwin_x64reg(x64_context *context, int reg)
|
||||||
|
|
||||||
#define X64REG(context, reg) (freebsd_x64reg(context, reg))
|
#define X64REG(context, reg) (freebsd_x64reg(context, reg))
|
||||||
#ifdef __DragonFly__
|
#ifdef __DragonFly__
|
||||||
# define XMMREG(context, reg) (reinterpret_cast<v128*>((reinterpret_cast<union savefpu*>(context)->uc_mcontext.mc_fpregs)->sv_xmm.sv_xmm[reg]))
|
#define XMMREG(context, reg) (reinterpret_cast<v128*>((reinterpret_cast<union savefpu*>(context)->uc_mcontext.mc_fpregs)->sv_xmm.sv_xmm[reg]))
|
||||||
#else
|
#else
|
||||||
# define XMMREG(context, reg) (reinterpret_cast<v128*>((reinterpret_cast<struct savefpu*>(context)->uc_mcontext.mc_fpstate)->sv_xmm[reg]))
|
#define XMMREG(context, reg) (reinterpret_cast<v128*>((reinterpret_cast<struct savefpu*>(context)->uc_mcontext.mc_fpstate)->sv_xmm[reg]))
|
||||||
#endif
|
#endif
|
||||||
#define EFLAGS(context) ((context)->uc_mcontext.mc_rflags)
|
#define EFLAGS(context) ((context)->uc_mcontext.mc_rflags)
|
||||||
|
|
||||||
register_t* freebsd_x64reg(x64_context *context, int reg)
|
register_t* freebsd_x64reg(x64_context* context, int reg)
|
||||||
{
|
{
|
||||||
auto *state = &context->uc_mcontext;
|
auto* state = &context->uc_mcontext;
|
||||||
switch(reg)
|
switch (reg)
|
||||||
{
|
{
|
||||||
case 0: return &state->mc_rax;
|
case 0: return &state->mc_rax;
|
||||||
case 1: return &state->mc_rcx;
|
case 1: return &state->mc_rcx;
|
||||||
|
|
@ -972,10 +976,10 @@ register_t* freebsd_x64reg(x64_context *context, int reg)
|
||||||
#define XMMREG(context, reg) (reinterpret_cast<v128*>((context)->sc_fpstate->fx_xmm[reg]))
|
#define XMMREG(context, reg) (reinterpret_cast<v128*>((context)->sc_fpstate->fx_xmm[reg]))
|
||||||
#define EFLAGS(context) ((context)->sc_rflags)
|
#define EFLAGS(context) ((context)->sc_rflags)
|
||||||
|
|
||||||
long* openbsd_x64reg(x64_context *context, int reg)
|
long* openbsd_x64reg(x64_context* context, int reg)
|
||||||
{
|
{
|
||||||
auto *state = &context;
|
auto* state = &context;
|
||||||
switch(reg)
|
switch (reg)
|
||||||
{
|
{
|
||||||
case 0: return &state->sc_rax;
|
case 0: return &state->sc_rax;
|
||||||
case 1: return &state->sc_rcx;
|
case 1: return &state->sc_rcx;
|
||||||
|
|
@ -1003,10 +1007,9 @@ long* openbsd_x64reg(x64_context *context, int reg)
|
||||||
#elif defined(__NetBSD__)
|
#elif defined(__NetBSD__)
|
||||||
|
|
||||||
static const decltype(_REG_RAX) reg_table[] =
|
static const decltype(_REG_RAX) reg_table[] =
|
||||||
{
|
{
|
||||||
_REG_RAX, _REG_RCX, _REG_RDX, _REG_RBX, _REG_RSP, _REG_RBP, _REG_RSI, _REG_RDI,
|
_REG_RAX, _REG_RCX, _REG_RDX, _REG_RBX, _REG_RSP, _REG_RBP, _REG_RSI, _REG_RDI,
|
||||||
_REG_R8, _REG_R9, _REG_R10, _REG_R11, _REG_R12, _REG_R13, _REG_R14, _REG_R15, _REG_RIP
|
_REG_R8, _REG_R9, _REG_R10, _REG_R11, _REG_R12, _REG_R13, _REG_R14, _REG_R15, _REG_RIP};
|
||||||
};
|
|
||||||
|
|
||||||
#define X64REG(context, reg) (&(context)->uc_mcontext.__gregs[reg_table[reg]])
|
#define X64REG(context, reg) (&(context)->uc_mcontext.__gregs[reg_table[reg]])
|
||||||
#define XMM_sig(context, reg) (reinterpret_cast<v128*>(((struct fxsave64*)(context)->uc_mcontext.__fpregs)->fx_xmm[reg]))
|
#define XMM_sig(context, reg) (reinterpret_cast<v128*>(((struct fxsave64*)(context)->uc_mcontext.__fpregs)->fx_xmm[reg]))
|
||||||
|
|
@ -1015,10 +1018,9 @@ static const decltype(_REG_RAX) reg_table[] =
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static const int reg_table[] =
|
static const int reg_table[] =
|
||||||
{
|
{
|
||||||
REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI,
|
REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI,
|
||||||
REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP
|
REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP};
|
||||||
};
|
|
||||||
|
|
||||||
#define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]])
|
#define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]])
|
||||||
#ifdef __sun
|
#ifdef __sun
|
||||||
|
|
@ -1374,7 +1376,8 @@ bool handle_access_violation(u32 addr, bool is_writing, ucontext_t* context) noe
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if address is RawSPU MMIO register
|
// check if address is RawSPU MMIO register
|
||||||
do if (addr - RAW_SPU_BASE_ADDR < (6 * RAW_SPU_OFFSET) && (addr % RAW_SPU_OFFSET) >= RAW_SPU_PROB_OFFSET)
|
do
|
||||||
|
if (addr - RAW_SPU_BASE_ADDR < (6 * RAW_SPU_OFFSET) && (addr % RAW_SPU_OFFSET) >= RAW_SPU_PROB_OFFSET)
|
||||||
{
|
{
|
||||||
auto thread = idm::get_unlocked<named_thread<spu_thread>>(spu_thread::find_raw_spu((addr - RAW_SPU_BASE_ADDR) / RAW_SPU_OFFSET));
|
auto thread = idm::get_unlocked<named_thread<spu_thread>>(spu_thread::find_raw_spu((addr - RAW_SPU_BASE_ADDR) / RAW_SPU_OFFSET));
|
||||||
|
|
||||||
|
|
@ -1505,7 +1508,8 @@ bool handle_access_violation(u32 addr, bool is_writing, ucontext_t* context) noe
|
||||||
RIP(context) += i_size;
|
RIP(context) += i_size;
|
||||||
g_tls_fault_spu++;
|
g_tls_fault_spu++;
|
||||||
return true;
|
return true;
|
||||||
} while (0);
|
}
|
||||||
|
while (0);
|
||||||
#else
|
#else
|
||||||
static_cast<void>(context);
|
static_cast<void>(context);
|
||||||
#endif /* ARCH_ */
|
#endif /* ARCH_ */
|
||||||
|
|
@ -1602,7 +1606,6 @@ bool handle_access_violation(u32 addr, bool is_writing, ucontext_t* context) noe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Now, place the page fault event onto table so that other functions [sys_mmapper_free_address and pagefault recovery funcs etc]
|
// Now, place the page fault event onto table so that other functions [sys_mmapper_free_address and pagefault recovery funcs etc]
|
||||||
// know that this thread is page faulted and where.
|
// know that this thread is page faulted and where.
|
||||||
|
|
||||||
|
|
@ -1843,7 +1846,7 @@ static LONG exception_handler(PEXCEPTION_POINTERS pExp) noexcept
|
||||||
case EXCEPTION_INT_DIVIDE_BY_ZERO:
|
case EXCEPTION_INT_DIVIDE_BY_ZERO:
|
||||||
case EXCEPTION_NONCONTINUABLE_EXCEPTION:
|
case EXCEPTION_NONCONTINUABLE_EXCEPTION:
|
||||||
case EXCEPTION_PRIV_INSTRUCTION:
|
case EXCEPTION_PRIV_INSTRUCTION:
|
||||||
//case EXCEPTION_STACK_OVERFLOW:
|
// case EXCEPTION_STACK_OVERFLOW:
|
||||||
{
|
{
|
||||||
sys_log.notice("\n%s", dump_useful_thread_info());
|
sys_log.notice("\n%s", dump_useful_thread_info());
|
||||||
logs::listener::sync_all();
|
logs::listener::sync_all();
|
||||||
|
|
@ -1866,7 +1869,8 @@ static LONG exception_filter(PEXCEPTION_POINTERS pExp) noexcept
|
||||||
{
|
{
|
||||||
const auto cause =
|
const auto cause =
|
||||||
pExp->ExceptionRecord->ExceptionInformation[0] == 8 ? "executing" :
|
pExp->ExceptionRecord->ExceptionInformation[0] == 8 ? "executing" :
|
||||||
pExp->ExceptionRecord->ExceptionInformation[0] == 1 ? "writing" : "reading";
|
pExp->ExceptionRecord->ExceptionInformation[0] == 1 ? "writing" :
|
||||||
|
"reading";
|
||||||
|
|
||||||
fmt::append(msg, "Segfault %s location %p at %p.\n", cause, pExp->ExceptionRecord->ExceptionInformation[1], pExp->ExceptionRecord->ExceptionAddress);
|
fmt::append(msg, "Segfault %s location %p at %p.\n", cause, pExp->ExceptionRecord->ExceptionInformation[1], pExp->ExceptionRecord->ExceptionAddress);
|
||||||
|
|
||||||
|
|
@ -1916,7 +1920,7 @@ static LONG exception_filter(PEXCEPTION_POINTERS pExp) noexcept
|
||||||
fmt::append(msg, "Function address: %p (base+0x%x).\n", func_addr, rtf->BeginAddress);
|
fmt::append(msg, "Function address: %p (base+0x%x).\n", func_addr, rtf->BeginAddress);
|
||||||
|
|
||||||
// Access UNWIND_INFO structure
|
// Access UNWIND_INFO structure
|
||||||
//const auto uw = (u8*)(unwind_base + rtf->UnwindData);
|
// const auto uw = (u8*)(unwind_base + rtf->UnwindData);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (HMODULE _module : modules)
|
for (HMODULE _module : modules)
|
||||||
|
|
@ -2034,7 +2038,8 @@ static void signal_handler(int /*sig*/, siginfo_t* info, void* uct) noexcept
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const u64 exec64 = (reinterpret_cast<u64>(info->si_addr) - reinterpret_cast<u64>(vm::g_exec_addr)) / 2;
|
const u64 exec64 = (reinterpret_cast<u64>(info->si_addr) - reinterpret_cast<u64>(vm::g_exec_addr)) / 2;
|
||||||
const auto cause = is_executing ? "executing" : is_writing ? "writing" : "reading";
|
const auto cause = is_executing ? "executing" : is_writing ? "writing" :
|
||||||
|
"reading";
|
||||||
|
|
||||||
if (auto [addr, ok] = vm::try_get_addr(info->si_addr); ok && !is_executing)
|
if (auto [addr, ok] = vm::try_get_addr(info->si_addr); ok && !is_executing)
|
||||||
{
|
{
|
||||||
|
|
@ -2161,7 +2166,7 @@ thread_local DECLARE(thread_ctrl::g_tls_this_thread) = nullptr;
|
||||||
|
|
||||||
thread_local DECLARE(thread_ctrl::g_tls_error_callback) = nullptr;
|
thread_local DECLARE(thread_ctrl::g_tls_error_callback) = nullptr;
|
||||||
|
|
||||||
DECLARE(thread_ctrl::g_native_core_layout) { native_core_arrangement::undefined };
|
DECLARE(thread_ctrl::g_native_core_layout){native_core_arrangement::undefined};
|
||||||
|
|
||||||
void thread_base::start()
|
void thread_base::start()
|
||||||
{
|
{
|
||||||
|
|
@ -2241,7 +2246,8 @@ void thread_base::set_name(std::string name)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Set thread name for VS debugger
|
// Set thread name for VS debugger
|
||||||
if (IsDebuggerPresent()) [&]() NEVER_INLINE
|
if (IsDebuggerPresent())
|
||||||
|
[&]() NEVER_INLINE
|
||||||
{
|
{
|
||||||
THREADNAME_INFO info;
|
THREADNAME_INFO info;
|
||||||
info.dwType = 0x1000;
|
info.dwType = 0x1000;
|
||||||
|
|
@ -2361,7 +2367,10 @@ thread_base::native_entry thread_base::finalize(u64 _self) noexcept
|
||||||
g_tls_wait_fail = 0;
|
g_tls_wait_fail = 0;
|
||||||
g_tls_access_violation_recovered = false;
|
g_tls_access_violation_recovered = false;
|
||||||
|
|
||||||
g_tls_log_prefix = []() -> std::string { return {}; };
|
g_tls_log_prefix = []() -> std::string
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
};
|
||||||
|
|
||||||
if (_self == umax)
|
if (_self == umax)
|
||||||
{
|
{
|
||||||
|
|
@ -2378,7 +2387,7 @@ thread_base::native_entry thread_base::finalize(u64 _self) noexcept
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_base::native_entry thread_base::make_trampoline(u64(*entry)(thread_base* _base))
|
thread_base::native_entry thread_base::make_trampoline(u64 (*entry)(thread_base* _base))
|
||||||
{
|
{
|
||||||
return build_function_asm<native_entry>("", [&](native_asm& c, auto& args)
|
return build_function_asm<native_entry>("", [&](native_asm& c, auto& args)
|
||||||
{
|
{
|
||||||
|
|
@ -2394,7 +2403,7 @@ thread_base::native_entry thread_base::make_trampoline(u64(*entry)(thread_base*
|
||||||
|
|
||||||
// Call finalize, return if zero
|
// Call finalize, return if zero
|
||||||
c.mov(args[0], x86::rax);
|
c.mov(args[0], x86::rax);
|
||||||
c.call(static_cast<native_entry(*)(u64)>(&finalize));
|
c.call(static_cast<native_entry (*)(u64)>(&finalize));
|
||||||
c.test(x86::rax, x86::rax);
|
c.test(x86::rax, x86::rax);
|
||||||
c.jz(_ret);
|
c.jz(_ret);
|
||||||
|
|
||||||
|
|
@ -2516,7 +2525,6 @@ void thread_ctrl::wait_for(u64 usec, [[maybe_unused]] bool alert /* true */)
|
||||||
list.wait(atomic_wait_timeout{usec <= 0xffff'ffff'ffff'ffff / 1000 ? usec * 1000 : 0xffff'ffff'ffff'ffff});
|
list.wait(atomic_wait_timeout{usec <= 0xffff'ffff'ffff'ffff / 1000 ? usec * 1000 : 0xffff'ffff'ffff'ffff});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void thread_ctrl::wait_until(u64* wait_time, u64 add_time, u64 min_wait, bool update_to_current_time)
|
void thread_ctrl::wait_until(u64* wait_time, u64 add_time, u64 min_wait, bool update_to_current_time)
|
||||||
{
|
{
|
||||||
*wait_time = utils::add_saturate<u64>(*wait_time, add_time);
|
*wait_time = utils::add_saturate<u64>(*wait_time, add_time);
|
||||||
|
|
@ -2621,8 +2629,7 @@ std::string thread_ctrl::get_name_cached()
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_base::thread_base(native_entry entry, std::string name) noexcept
|
thread_base::thread_base(native_entry entry, std::string name) noexcept
|
||||||
: entry_point(entry)
|
: entry_point(entry), m_tname(make_single_value(std::move(name)))
|
||||||
, m_tname(make_single_value(std::move(name)))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2851,7 +2858,8 @@ void thread_base::exec()
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}).second)
|
})
|
||||||
|
.second)
|
||||||
{
|
{
|
||||||
utils::trap();
|
utils::trap();
|
||||||
}
|
}
|
||||||
|
|
@ -2913,7 +2921,7 @@ void thread_ctrl::detect_cpu_layout()
|
||||||
std::vector<u8> buffer(buffer_size);
|
std::vector<u8> buffer(buffer_size);
|
||||||
|
|
||||||
if (!GetLogicalProcessorInformationEx(relationship,
|
if (!GetLogicalProcessorInformationEx(relationship,
|
||||||
reinterpret_cast<SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *>(buffer.data()), &buffer_size))
|
reinterpret_cast<SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*>(buffer.data()), &buffer_size))
|
||||||
{
|
{
|
||||||
sig_log.error("GetLogicalProcessorInformationEx failed (size=%u, error=%s)", buffer_size, fmt::win_error{GetLastError(), nullptr});
|
sig_log.error("GetLogicalProcessorInformationEx failed (size=%u, error=%s)", buffer_size, fmt::win_error{GetLastError(), nullptr});
|
||||||
}
|
}
|
||||||
|
|
@ -2925,7 +2933,7 @@ void thread_ctrl::detect_cpu_layout()
|
||||||
|
|
||||||
while (ptr < end)
|
while (ptr < end)
|
||||||
{
|
{
|
||||||
auto info = reinterpret_cast<SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *>(ptr);
|
auto info = reinterpret_cast<SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*>(ptr);
|
||||||
if (info->Relationship == relationship && info->Processor.Flags == LTP_PC_SMT)
|
if (info->Relationship == relationship && info->Processor.Flags == LTP_PC_SMT)
|
||||||
{
|
{
|
||||||
g_native_core_layout.store(native_core_arrangement::intel_ht);
|
g_native_core_layout.store(native_core_arrangement::intel_ht);
|
||||||
|
|
@ -2953,8 +2961,7 @@ u64 thread_ctrl::get_affinity_mask(thread_class group)
|
||||||
g_cfg.core.affinity.cpu4.get(),
|
g_cfg.core.affinity.cpu4.get(),
|
||||||
g_cfg.core.affinity.cpu5.get(),
|
g_cfg.core.affinity.cpu5.get(),
|
||||||
g_cfg.core.affinity.cpu6.get(),
|
g_cfg.core.affinity.cpu6.get(),
|
||||||
g_cfg.core.affinity.cpu7.get()
|
g_cfg.core.affinity.cpu7.get()};
|
||||||
};
|
|
||||||
|
|
||||||
for (std::size_t i = 0; i < std::min<std::size_t>(std::thread::hardware_concurrency(), std::size(affinities)); ++i)
|
for (std::size_t i = 0; i < std::min<std::size_t>(std::thread::hardware_concurrency(), std::size(affinities)); ++i)
|
||||||
{
|
{
|
||||||
|
|
@ -3248,7 +3255,7 @@ void thread_ctrl::set_thread_affinity_mask(u64 mask)
|
||||||
}
|
}
|
||||||
#elif __APPLE__
|
#elif __APPLE__
|
||||||
// Supports only one core
|
// Supports only one core
|
||||||
thread_affinity_policy_data_t policy = { static_cast<integer_t>(std::countr_zero(mask)) };
|
thread_affinity_policy_data_t policy = {static_cast<integer_t>(std::countr_zero(mask))};
|
||||||
thread_port_t mach_thread = pthread_mach_thread_np(pthread_self());
|
thread_port_t mach_thread = pthread_mach_thread_np(pthread_self());
|
||||||
thread_policy_set(mach_thread, THREAD_AFFINITY_POLICY, reinterpret_cast<thread_policy_t>(&policy), !mask ? 0 : 1);
|
thread_policy_set(mach_thread, THREAD_AFFINITY_POLICY, reinterpret_cast<thread_policy_t>(&policy), !mask ? 0 : 1);
|
||||||
#elif (defined(__linux__) || defined(__DragonFly__) || defined(__FreeBSD__))
|
#elif (defined(__linux__) || defined(__DragonFly__) || defined(__FreeBSD__))
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,8 @@ struct result_storage
|
||||||
using type = void;
|
using type = void;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Ctx, typename... Args> requires (!std::is_void_v<std::invoke_result_t<Ctx, Args&&...>>)
|
template <typename Ctx, typename... Args>
|
||||||
|
requires(!std::is_void_v<std::invoke_result_t<Ctx, Args && ...>>)
|
||||||
struct result_storage<Ctx, Args...>
|
struct result_storage<Ctx, Args...>
|
||||||
{
|
{
|
||||||
using T = std::invoke_result_t<Ctx, Args&&...>;
|
using T = std::invoke_result_t<Ctx, Args&&...>;
|
||||||
|
|
@ -81,8 +82,7 @@ struct result_storage<Ctx, Args...>
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
concept NamedThreadName = requires (const T&)
|
concept NamedThreadName = requires(const T&) {
|
||||||
{
|
|
||||||
std::string(T::thread_name);
|
std::string(T::thread_name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -96,7 +96,7 @@ class thread_future
|
||||||
thread_future* prev{};
|
thread_future* prev{};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
atomic_t<void(*)(thread_base*, thread_future*)> exec{};
|
atomic_t<void (*)(thread_base*, thread_future*)> exec{};
|
||||||
|
|
||||||
atomic_t<u32> done{0};
|
atomic_t<u32> done{0};
|
||||||
|
|
||||||
|
|
@ -122,7 +122,7 @@ public:
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
using native_entry = uint(__stdcall*)(void* arg);
|
using native_entry = uint(__stdcall*)(void* arg);
|
||||||
#else
|
#else
|
||||||
using native_entry = void*(*)(void* arg);
|
using native_entry = void* (*)(void* arg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const native_entry entry_point;
|
const native_entry entry_point;
|
||||||
|
|
@ -161,7 +161,7 @@ private:
|
||||||
static native_entry finalize(u64 _self) noexcept;
|
static native_entry finalize(u64 _self) noexcept;
|
||||||
|
|
||||||
// Make entry point
|
// Make entry point
|
||||||
static native_entry make_trampoline(u64(*entry)(thread_base* _base));
|
static native_entry make_trampoline(u64 (*entry)(thread_base* _base));
|
||||||
|
|
||||||
friend class thread_ctrl;
|
friend class thread_ctrl;
|
||||||
|
|
||||||
|
|
@ -201,7 +201,7 @@ class thread_ctrl final
|
||||||
static thread_local thread_base* g_tls_this_thread;
|
static thread_local thread_base* g_tls_this_thread;
|
||||||
|
|
||||||
// Error handling details
|
// Error handling details
|
||||||
static thread_local void(*g_tls_error_callback)();
|
static thread_local void (*g_tls_error_callback)();
|
||||||
|
|
||||||
// Target cpu core layout
|
// Target cpu core layout
|
||||||
static atomic_t<native_core_arrangement> g_native_core_layout;
|
static atomic_t<native_core_arrangement> g_native_core_layout;
|
||||||
|
|
@ -306,13 +306,20 @@ public:
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
static inline void wait_on(T& wait, U old, u64 usec = -1)
|
static inline void wait_on(T& wait, U old, u64 usec = -1)
|
||||||
{
|
{
|
||||||
wait_on_custom<1>([&](atomic_wait::list<3>& list) { list.template set<0>(wait, old); }, usec);
|
wait_on_custom<1>([&](atomic_wait::list<3>& list)
|
||||||
|
{
|
||||||
|
list.template set<0>(wait, old);
|
||||||
|
},
|
||||||
|
usec);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static inline void wait_on(T& wait)
|
static inline void wait_on(T& wait)
|
||||||
{
|
{
|
||||||
wait_on_custom<1>([&](atomic_wait::list<3>& list) { list.template set<0>(wait); });
|
wait_on_custom<1>([&](atomic_wait::list<3>& list)
|
||||||
|
{
|
||||||
|
list.template set<0>(wait);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exit.
|
// Exit.
|
||||||
|
|
@ -386,8 +393,7 @@ class thread_future_t : public thread_future, result_storage<Ctx, std::condition
|
||||||
|
|
||||||
public:
|
public:
|
||||||
thread_future_t(Ctx&& func, Args&&... args) noexcept
|
thread_future_t(Ctx&& func, Args&&... args) noexcept
|
||||||
: m_args(std::forward<Args>(args)...)
|
: m_args(std::forward<Args>(args)...), m_func(std::forward<Ctx>(func))
|
||||||
, m_func(std::forward<Ctx>(func))
|
|
||||||
{
|
{
|
||||||
thread_future::exec.raw() = +[](thread_base* tb, thread_future* tf)
|
thread_future::exec.raw() = +[](thread_base* tb, thread_future* tf)
|
||||||
{
|
{
|
||||||
|
|
@ -527,37 +533,37 @@ class named_thread final : public Context, result_storage<Context>, thread_base
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Forwarding constructor with default name (also potentially the default constructor)
|
// Forwarding constructor with default name (also potentially the default constructor)
|
||||||
template <typename... Args> requires (std::is_constructible_v<Context, Args&&...>) && (!(std::is_same_v<std::remove_cvref_t<Args>, stx::launch_retainer> || ...)) && (NamedThreadName<Context>)
|
template <typename... Args>
|
||||||
|
requires(std::is_constructible_v<Context, Args && ...>) && (!(std::is_same_v<std::remove_cvref_t<Args>, stx::launch_retainer> || ...)) && (NamedThreadName<Context>)
|
||||||
named_thread(Args&&... args) noexcept
|
named_thread(Args&&... args) noexcept
|
||||||
: Context(std::forward<Args>(args)...)
|
: Context(std::forward<Args>(args)...), thread(trampoline, std::string(Context::thread_name))
|
||||||
, thread(trampoline, std::string(Context::thread_name))
|
|
||||||
{
|
{
|
||||||
thread::start();
|
thread::start();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Forwarding constructor with default name, does not automatically run the thread
|
// Forwarding constructor with default name, does not automatically run the thread
|
||||||
template <typename... Args> requires (std::is_constructible_v<Context, Args&&...>) && (NamedThreadName<Context>)
|
template <typename... Args>
|
||||||
|
requires(std::is_constructible_v<Context, Args && ...>) && (NamedThreadName<Context>)
|
||||||
named_thread(const stx::launch_retainer&, Args&&... args) noexcept
|
named_thread(const stx::launch_retainer&, Args&&... args) noexcept
|
||||||
: Context(std::forward<Args>(args)...)
|
: Context(std::forward<Args>(args)...), thread(trampoline, std::string(Context::thread_name))
|
||||||
, thread(trampoline, std::string(Context::thread_name))
|
|
||||||
{
|
{
|
||||||
// Create a stand-by thread context
|
// Create a stand-by thread context
|
||||||
m_sync |= static_cast<u32>(thread_state::finished);
|
m_sync |= static_cast<u32>(thread_state::finished);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normal forwarding constructor
|
// Normal forwarding constructor
|
||||||
template <typename... Args> requires (std::is_constructible_v<Context, Args&&...>) && (!NamedThreadName<Context>)
|
template <typename... Args>
|
||||||
|
requires(std::is_constructible_v<Context, Args && ...>) && (!NamedThreadName<Context>)
|
||||||
named_thread(std::string name, Args&&... args) noexcept
|
named_thread(std::string name, Args&&... args) noexcept
|
||||||
: Context(std::forward<Args>(args)...)
|
: Context(std::forward<Args>(args)...), thread(trampoline, std::move(name))
|
||||||
, thread(trampoline, std::move(name))
|
|
||||||
{
|
{
|
||||||
thread::start();
|
thread::start();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lambda constructor, also the implicit deduction guide candidate
|
// Lambda constructor, also the implicit deduction guide candidate
|
||||||
named_thread(std::string_view name, Context&& f) noexcept requires (!NamedThreadName<Context>)
|
named_thread(std::string_view name, Context&& f) noexcept
|
||||||
: Context(std::forward<Context>(f))
|
requires(!NamedThreadName<Context>)
|
||||||
, thread(trampoline, std::string(name))
|
: Context(std::forward<Context>(f)), thread(trampoline, std::string(name))
|
||||||
{
|
{
|
||||||
thread::start();
|
thread::start();
|
||||||
}
|
}
|
||||||
|
|
@ -683,7 +689,11 @@ public:
|
||||||
|
|
||||||
// Try to abort by assigning thread_state::aborting/finished
|
// Try to abort by assigning thread_state::aborting/finished
|
||||||
// Join thread by thread_state::finished
|
// Join thread by thread_state::finished
|
||||||
if (s >= thread_state::aborting && thread::m_sync.fetch_op([](u32& v) { return !(v & 3) && (v |= 1); }).second)
|
if (s >= thread_state::aborting && thread::m_sync.fetch_op([](u32& v)
|
||||||
|
{
|
||||||
|
return !(v & 3) && (v |= 1);
|
||||||
|
})
|
||||||
|
.second)
|
||||||
{
|
{
|
||||||
notify_sync = true;
|
notify_sync = true;
|
||||||
}
|
}
|
||||||
|
|
@ -747,8 +757,7 @@ class named_thread_group final
|
||||||
public:
|
public:
|
||||||
// Lambda constructor, also the implicit deduction guide candidate
|
// Lambda constructor, also the implicit deduction guide candidate
|
||||||
named_thread_group(std::string_view name, u32 count, Context&& f) noexcept
|
named_thread_group(std::string_view name, u32 count, Context&& f) noexcept
|
||||||
: m_count(count)
|
: m_count(count), m_threads(nullptr)
|
||||||
, m_threads(nullptr)
|
|
||||||
{
|
{
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -771,8 +780,7 @@ public:
|
||||||
// Constructor with a function performed before adding more threads
|
// Constructor with a function performed before adding more threads
|
||||||
template <typename CheckAndPrepare>
|
template <typename CheckAndPrepare>
|
||||||
named_thread_group(std::string_view name, u32 count, Context&& f, CheckAndPrepare&& check) noexcept
|
named_thread_group(std::string_view name, u32 count, Context&& f, CheckAndPrepare&& check) noexcept
|
||||||
: m_count(count)
|
: m_count(count), m_threads(nullptr)
|
||||||
, m_threads(nullptr)
|
|
||||||
{
|
{
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -812,8 +820,7 @@ public:
|
||||||
|
|
||||||
// Default constructor
|
// Default constructor
|
||||||
named_thread_group(std::string_view name, u32 count) noexcept
|
named_thread_group(std::string_view name, u32 count) noexcept
|
||||||
: m_count(count)
|
: m_count(count), m_threads(nullptr)
|
||||||
, m_threads(nullptr)
|
|
||||||
{
|
{
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -840,7 +847,7 @@ public:
|
||||||
|
|
||||||
for (u32 i = 0; i < m_count; i++)
|
for (u32 i = 0; i < m_count; i++)
|
||||||
{
|
{
|
||||||
std::as_const(*std::launder(m_threads + i))();
|
std::as_const (*std::launder(m_threads + i))();
|
||||||
|
|
||||||
if (std::as_const(*std::launder(m_threads + i)) != thread_state::finished)
|
if (std::as_const(*std::launder(m_threads + i)) != thread_state::finished)
|
||||||
result = false;
|
result = false;
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@ namespace utils
|
||||||
return (val & (get_page_size() - 1)) == 0;
|
return (val & (get_page_size() - 1)) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Address Range utility class
|
* Address Range utility class
|
||||||
*/
|
*/
|
||||||
|
|
@ -105,7 +104,7 @@ namespace utils
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overlapping checks
|
// Overlapping checks
|
||||||
bool overlaps(const address_range &other) const
|
bool overlaps(const address_range& other) const
|
||||||
{
|
{
|
||||||
AUDIT(valid() && other.valid());
|
AUDIT(valid() && other.valid());
|
||||||
return range_overlaps(start, end, other.start, other.end);
|
return range_overlaps(start, end, other.start, other.end);
|
||||||
|
|
@ -117,16 +116,16 @@ namespace utils
|
||||||
return address_overlaps(addr, start, end);
|
return address_overlaps(addr, start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool inside(const address_range &other) const
|
bool inside(const address_range& other) const
|
||||||
{
|
{
|
||||||
AUDIT(valid() && other.valid());
|
AUDIT(valid() && other.valid());
|
||||||
return range_inside_range(start, end, other.start, other.end);
|
return range_inside_range(start, end, other.start, other.end);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool inside(const address_range_vector &vec) const;
|
inline bool inside(const address_range_vector& vec) const;
|
||||||
inline bool overlaps(const address_range_vector &vec) const;
|
inline bool overlaps(const address_range_vector& vec) const;
|
||||||
|
|
||||||
bool touches(const address_range &other) const
|
bool touches(const address_range& other) const
|
||||||
{
|
{
|
||||||
AUDIT(valid() && other.valid());
|
AUDIT(valid() && other.valid());
|
||||||
// returns true if there is overlap, or if sections are side-by-side
|
// returns true if there is overlap, or if sections are side-by-side
|
||||||
|
|
@ -134,7 +133,7 @@ namespace utils
|
||||||
}
|
}
|
||||||
|
|
||||||
// Utilities
|
// Utilities
|
||||||
s32 signed_distance(const address_range &other) const
|
s32 signed_distance(const address_range& other) const
|
||||||
{
|
{
|
||||||
if (touches(other))
|
if (touches(other))
|
||||||
{
|
{
|
||||||
|
|
@ -152,7 +151,7 @@ namespace utils
|
||||||
return -static_cast<s32>(start - other.end - 1);
|
return -static_cast<s32>(start - other.end - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 distance(const address_range &other) const
|
u32 distance(const address_range& other) const
|
||||||
{
|
{
|
||||||
if (touches(other))
|
if (touches(other))
|
||||||
{
|
{
|
||||||
|
|
@ -170,15 +169,14 @@ namespace utils
|
||||||
return (start - other.end - 1);
|
return (start - other.end - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
address_range get_min_max(const address_range &other) const
|
address_range get_min_max(const address_range& other) const
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
std::min(valid() ? start : umax, other.valid() ? other.start : umax),
|
std::min(valid() ? start : umax, other.valid() ? other.start : umax),
|
||||||
std::max(valid() ? end : 0, other.valid() ? other.end : 0)
|
std::max(valid() ? end : 0, other.valid() ? other.end : 0)};
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_min_max(const address_range &other)
|
void set_min_max(const address_range& other)
|
||||||
{
|
{
|
||||||
*this = get_min_max(other);
|
*this = get_min_max(other);
|
||||||
}
|
}
|
||||||
|
|
@ -191,7 +189,7 @@ namespace utils
|
||||||
address_range to_page_range() const
|
address_range to_page_range() const
|
||||||
{
|
{
|
||||||
AUDIT(valid());
|
AUDIT(valid());
|
||||||
return { page_start(start), page_end(end) };
|
return {page_start(start), page_end(end)};
|
||||||
}
|
}
|
||||||
|
|
||||||
void page_align()
|
void page_align()
|
||||||
|
|
@ -202,17 +200,17 @@ namespace utils
|
||||||
AUDIT(is_page_range());
|
AUDIT(is_page_range());
|
||||||
}
|
}
|
||||||
|
|
||||||
address_range get_intersect(const address_range &clamp) const
|
address_range get_intersect(const address_range& clamp) const
|
||||||
{
|
{
|
||||||
if (!valid() || !clamp.valid())
|
if (!valid() || !clamp.valid())
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return { std::max(start, clamp.start), std::min(end, clamp.end) };
|
return {std::max(start, clamp.start), std::min(end, clamp.end)};
|
||||||
}
|
}
|
||||||
|
|
||||||
void intersect(const address_range &clamp)
|
void intersect(const address_range& clamp)
|
||||||
{
|
{
|
||||||
if (!clamp.valid())
|
if (!clamp.valid())
|
||||||
{
|
{
|
||||||
|
|
@ -238,7 +236,7 @@ namespace utils
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comparison Operators
|
// Comparison Operators
|
||||||
bool operator ==(const address_range& other) const
|
bool operator==(const address_range& other) const
|
||||||
{
|
{
|
||||||
return (start == other.start && end == other.end);
|
return (start == other.start && end == other.end);
|
||||||
}
|
}
|
||||||
|
|
@ -257,7 +255,6 @@ namespace utils
|
||||||
return address_range::start_end(page_start(addr), page_end(addr));
|
return address_range::start_end(page_start(addr), page_end(addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Address Range Vector utility class
|
* Address Range Vector utility class
|
||||||
*
|
*
|
||||||
|
|
@ -276,20 +273,50 @@ namespace utils
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Wrapped functions
|
// Wrapped functions
|
||||||
inline void reserve(usz nr) { data.reserve(nr); }
|
inline void reserve(usz nr)
|
||||||
inline void clear() { data.clear(); }
|
{
|
||||||
inline size_type size() const { return data.size(); }
|
data.reserve(nr);
|
||||||
inline bool empty() const { return data.empty(); }
|
}
|
||||||
inline address_range& operator[](size_type n) { return data[n]; }
|
inline void clear()
|
||||||
inline const address_range& operator[](size_type n) const { return data[n]; }
|
{
|
||||||
inline iterator begin() { return data.begin(); }
|
data.clear();
|
||||||
inline const_iterator begin() const { return data.begin(); }
|
}
|
||||||
inline iterator end() { return data.end(); }
|
inline size_type size() const
|
||||||
inline const_iterator end() const { return data.end(); }
|
{
|
||||||
|
return data.size();
|
||||||
|
}
|
||||||
|
inline bool empty() const
|
||||||
|
{
|
||||||
|
return data.empty();
|
||||||
|
}
|
||||||
|
inline address_range& operator[](size_type n)
|
||||||
|
{
|
||||||
|
return data[n];
|
||||||
|
}
|
||||||
|
inline const address_range& operator[](size_type n) const
|
||||||
|
{
|
||||||
|
return data[n];
|
||||||
|
}
|
||||||
|
inline iterator begin()
|
||||||
|
{
|
||||||
|
return data.begin();
|
||||||
|
}
|
||||||
|
inline const_iterator begin() const
|
||||||
|
{
|
||||||
|
return data.begin();
|
||||||
|
}
|
||||||
|
inline iterator end()
|
||||||
|
{
|
||||||
|
return data.end();
|
||||||
|
}
|
||||||
|
inline const_iterator end() const
|
||||||
|
{
|
||||||
|
return data.end();
|
||||||
|
}
|
||||||
|
|
||||||
// Search for ranges that touch new_range. If found, merge instead of adding new_range.
|
// Search for ranges that touch new_range. If found, merge instead of adding new_range.
|
||||||
// When adding a new range, re-use invalid ranges whenever possible
|
// When adding a new range, re-use invalid ranges whenever possible
|
||||||
void merge(const address_range &new_range)
|
void merge(const address_range& new_range)
|
||||||
{
|
{
|
||||||
// Note the case where we have
|
// Note the case where we have
|
||||||
// AAAA BBBB
|
// AAAA BBBB
|
||||||
|
|
@ -301,10 +328,10 @@ namespace utils
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
address_range *found = nullptr;
|
address_range* found = nullptr;
|
||||||
address_range *invalid = nullptr;
|
address_range* invalid = nullptr;
|
||||||
|
|
||||||
for (auto &existing : data)
|
for (auto& existing : data)
|
||||||
{
|
{
|
||||||
if (!existing.valid())
|
if (!existing.valid())
|
||||||
{
|
{
|
||||||
|
|
@ -347,16 +374,16 @@ namespace utils
|
||||||
AUDIT(check_consistency());
|
AUDIT(check_consistency());
|
||||||
}
|
}
|
||||||
|
|
||||||
void merge(const address_range_vector &other)
|
void merge(const address_range_vector& other)
|
||||||
{
|
{
|
||||||
for (const address_range &new_range : other)
|
for (const address_range& new_range : other)
|
||||||
{
|
{
|
||||||
merge(new_range);
|
merge(new_range);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exclude a given range from data
|
// Exclude a given range from data
|
||||||
void exclude(const address_range &exclusion)
|
void exclude(const address_range& exclusion)
|
||||||
{
|
{
|
||||||
// Note the case where we have
|
// Note the case where we have
|
||||||
// AAAAAAA
|
// AAAAAAA
|
||||||
|
|
@ -371,13 +398,13 @@ namespace utils
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
address_range *invalid = nullptr; // try to re-use an invalid range instead of calling push_back
|
address_range* invalid = nullptr; // try to re-use an invalid range instead of calling push_back
|
||||||
|
|
||||||
// We use index access because we might have to push_back within the loop, which could invalidate the iterators
|
// We use index access because we might have to push_back within the loop, which could invalidate the iterators
|
||||||
size_type _size = data.size();
|
size_type _size = data.size();
|
||||||
for (size_type n = 0; n < _size; ++n)
|
for (size_type n = 0; n < _size; ++n)
|
||||||
{
|
{
|
||||||
address_range &existing = data[n];
|
address_range& existing = data[n];
|
||||||
|
|
||||||
if (!existing.valid())
|
if (!existing.valid())
|
||||||
{
|
{
|
||||||
|
|
@ -438,9 +465,9 @@ namespace utils
|
||||||
AUDIT(!overlaps(exclusion));
|
AUDIT(!overlaps(exclusion));
|
||||||
}
|
}
|
||||||
|
|
||||||
void exclude(const address_range_vector &other)
|
void exclude(const address_range_vector& other)
|
||||||
{
|
{
|
||||||
for (const address_range &exclusion : other)
|
for (const address_range& exclusion : other)
|
||||||
{
|
{
|
||||||
exclude(exclusion);
|
exclude(exclusion);
|
||||||
}
|
}
|
||||||
|
|
@ -454,7 +481,7 @@ namespace utils
|
||||||
|
|
||||||
for (usz i = 0; i < _size; ++i)
|
for (usz i = 0; i < _size; ++i)
|
||||||
{
|
{
|
||||||
const auto &r1 = data[i];
|
const auto& r1 = data[i];
|
||||||
if (!r1.valid())
|
if (!r1.valid())
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -462,7 +489,7 @@ namespace utils
|
||||||
|
|
||||||
for (usz j = i + 1; j < _size; ++j)
|
for (usz j = i + 1; j < _size; ++j)
|
||||||
{
|
{
|
||||||
const auto &r2 = data[j];
|
const auto& r2 = data[j];
|
||||||
if (!r2.valid())
|
if (!r2.valid())
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -478,7 +505,7 @@ namespace utils
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test for overlap with a given range
|
// Test for overlap with a given range
|
||||||
bool overlaps(const address_range &range) const
|
bool overlaps(const address_range& range) const
|
||||||
{
|
{
|
||||||
return std::any_of(data.cbegin(), data.cend(), [&range](const address_range& cur)
|
return std::any_of(data.cbegin(), data.cend(), [&range](const address_range& cur)
|
||||||
{
|
{
|
||||||
|
|
@ -487,16 +514,16 @@ namespace utils
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test for overlap with a given address_range vector
|
// Test for overlap with a given address_range vector
|
||||||
bool overlaps(const address_range_vector &other) const
|
bool overlaps(const address_range_vector& other) const
|
||||||
{
|
{
|
||||||
for (const address_range &rng1 : data)
|
for (const address_range& rng1 : data)
|
||||||
{
|
{
|
||||||
if (!rng1.valid())
|
if (!rng1.valid())
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const address_range &rng2 : other.data)
|
for (const address_range& rng2 : other.data)
|
||||||
{
|
{
|
||||||
if (!rng2.valid())
|
if (!rng2.valid())
|
||||||
{
|
{
|
||||||
|
|
@ -513,7 +540,7 @@ namespace utils
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test if a given range is fully contained inside this vector
|
// Test if a given range is fully contained inside this vector
|
||||||
bool contains(const address_range &range) const
|
bool contains(const address_range& range) const
|
||||||
{
|
{
|
||||||
return std::any_of(this->begin(), this->end(), [&range](const address_range& cur)
|
return std::any_of(this->begin(), this->end(), [&range](const address_range& cur)
|
||||||
{
|
{
|
||||||
|
|
@ -522,7 +549,7 @@ namespace utils
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test if all ranges in this vector are full contained inside a specific range
|
// Test if all ranges in this vector are full contained inside a specific range
|
||||||
bool inside(const address_range &range) const
|
bool inside(const address_range& range) const
|
||||||
{
|
{
|
||||||
return std::all_of(this->begin(), this->end(), [&range](const address_range& cur)
|
return std::all_of(this->begin(), this->end(), [&range](const address_range& cur)
|
||||||
{
|
{
|
||||||
|
|
@ -531,21 +558,19 @@ namespace utils
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// These declarations must be done after address_range_vector has been defined
|
// These declarations must be done after address_range_vector has been defined
|
||||||
bool address_range::inside(const address_range_vector &vec) const
|
bool address_range::inside(const address_range_vector& vec) const
|
||||||
{
|
{
|
||||||
return vec.contains(*this);
|
return vec.contains(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool address_range::overlaps(const address_range_vector &vec) const
|
bool address_range::overlaps(const address_range_vector& vec) const
|
||||||
{
|
{
|
||||||
return vec.overlaps(*this);
|
return vec.overlaps(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace utils
|
} // namespace utils
|
||||||
|
|
||||||
|
|
||||||
namespace std
|
namespace std
|
||||||
{
|
{
|
||||||
static_assert(sizeof(usz) >= 2 * sizeof(u32), "usz must be at least twice the size of u32");
|
static_assert(sizeof(usz) >= 2 * sizeof(u32), "usz must be at least twice the size of u32");
|
||||||
|
|
@ -556,7 +581,7 @@ namespace std
|
||||||
usz operator()(const utils::address_range& k) const
|
usz operator()(const utils::address_range& k) const
|
||||||
{
|
{
|
||||||
// we can guarantee a unique hash since our type is 64 bits and usz as well
|
// we can guarantee a unique hash since our type is 64 bits and usz as well
|
||||||
return (usz{ k.start } << 32) | usz{ k.end };
|
return (usz{k.start} << 32) | usz{k.end};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace std
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,10 @@ void patch_engine::patch_config_value::set_and_check_value(f64 new_value, std::s
|
||||||
case patch_configurable_type::double_enum:
|
case patch_configurable_type::double_enum:
|
||||||
case patch_configurable_type::long_enum:
|
case patch_configurable_type::long_enum:
|
||||||
{
|
{
|
||||||
if (std::none_of(allowed_values.begin(), allowed_values.end(), [&new_value](const patch_allowed_value& allowed_value){ return allowed_value.value == new_value; }))
|
if (std::none_of(allowed_values.begin(), allowed_values.end(), [&new_value](const patch_allowed_value& allowed_value)
|
||||||
|
{
|
||||||
|
return allowed_value.value == new_value;
|
||||||
|
}))
|
||||||
{
|
{
|
||||||
patch_log.error("Can't set configurable enumerated value '%s' to %f. Using default value %f", name, new_value, value);
|
patch_log.error("Can't set configurable enumerated value '%s' to %f. Using default value %f", name, new_value, value);
|
||||||
return;
|
return;
|
||||||
|
|
@ -268,7 +271,7 @@ bool patch_engine::load(patch_map& patches_map, const std::string& path, std::st
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct patch_info info {};
|
struct patch_info info{};
|
||||||
info.description = description;
|
info.description = description;
|
||||||
info.hash = main_key;
|
info.hash = main_key;
|
||||||
info.version = version;
|
info.version = version;
|
||||||
|
|
@ -329,7 +332,10 @@ bool patch_engine::load(patch_map& patches_map, const std::string& path, std::st
|
||||||
is_valid = false;
|
is_valid = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (serial.size() != 9 || !std::all_of(serial.begin(), serial.end(), [](char c) { return std::isalnum(c); }))
|
else if (serial.size() != 9 || !std::all_of(serial.begin(), serial.end(), [](char c)
|
||||||
|
{
|
||||||
|
return std::isalnum(c);
|
||||||
|
}))
|
||||||
{
|
{
|
||||||
append_log_message(log_messages, fmt::format("Error: Serial '%s' invalid (patch: %s, key: %s, location: %s, file: %s)", serial, description, main_key, get_yaml_node_location(serial_node), path), &patch_log.error);
|
append_log_message(log_messages, fmt::format("Error: Serial '%s' invalid (patch: %s, key: %s, location: %s, file: %s)", serial, description, main_key, get_yaml_node_location(serial_node), path), &patch_log.error);
|
||||||
is_valid = false;
|
is_valid = false;
|
||||||
|
|
@ -457,7 +463,7 @@ bool patch_engine::load(patch_map& patches_map, const std::string& path, std::st
|
||||||
const std::string& str_type = config_value_type_node.Scalar();
|
const std::string& str_type = config_value_type_node.Scalar();
|
||||||
bool is_valid_type = false;
|
bool is_valid_type = false;
|
||||||
|
|
||||||
for (patch_configurable_type type : { patch_configurable_type::double_range, patch_configurable_type::double_enum, patch_configurable_type::long_range, patch_configurable_type::long_enum })
|
for (patch_configurable_type type : {patch_configurable_type::double_range, patch_configurable_type::double_enum, patch_configurable_type::long_range, patch_configurable_type::long_enum})
|
||||||
{
|
{
|
||||||
if (str_type == fmt::format("%s", type))
|
if (str_type == fmt::format("%s", type))
|
||||||
{
|
{
|
||||||
|
|
@ -558,7 +564,10 @@ bool patch_engine::load(patch_map& patches_map, const std::string& path, std::st
|
||||||
new_allowed_value.label = allowed_value.first.Scalar();
|
new_allowed_value.label = allowed_value.first.Scalar();
|
||||||
new_allowed_value.value = get_and_check_config_value(allowed_value.second);
|
new_allowed_value.value = get_and_check_config_value(allowed_value.second);
|
||||||
|
|
||||||
if (std::any_of(config_value.allowed_values.begin(), config_value.allowed_values.end(), [&new_allowed_value](const patch_allowed_value& other){ return new_allowed_value.value == other.value || new_allowed_value.label == other.label; }))
|
if (std::any_of(config_value.allowed_values.begin(), config_value.allowed_values.end(), [&new_allowed_value](const patch_allowed_value& other)
|
||||||
|
{
|
||||||
|
return new_allowed_value.value == other.value || new_allowed_value.label == other.label;
|
||||||
|
}))
|
||||||
{
|
{
|
||||||
append_log_message(log_messages, fmt::format("Error: Skipping configurable allowed value. Another entry with the same label or value already exists. (patch: %s, key: %s, location: %s, file: %s)", description, main_key, get_yaml_node_location(allowed_value), path), &patch_log.error);
|
append_log_message(log_messages, fmt::format("Error: Skipping configurable allowed value. Another entry with the same label or value already exists. (patch: %s, key: %s, location: %s, file: %s)", description, main_key, get_yaml_node_location(allowed_value), path), &patch_log.error);
|
||||||
is_valid = false;
|
is_valid = false;
|
||||||
|
|
@ -581,7 +590,10 @@ bool patch_engine::load(patch_map& patches_map, const std::string& path, std::st
|
||||||
is_valid = false;
|
is_valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (std::none_of(config_value.allowed_values.begin(), config_value.allowed_values.end(), [&config_value](const patch_allowed_value& other){ return other.value == config_value.value; }))
|
if (std::none_of(config_value.allowed_values.begin(), config_value.allowed_values.end(), [&config_value](const patch_allowed_value& other)
|
||||||
|
{
|
||||||
|
return other.value == config_value.value;
|
||||||
|
}))
|
||||||
{
|
{
|
||||||
append_log_message(log_messages, fmt::format("Error: Configurable value was not found in allowed values (key: %s, location: %s, file: %s)", main_key, get_yaml_node_location(config_value_allowed_values_node), path), &patch_log.error);
|
append_log_message(log_messages, fmt::format("Error: Configurable value was not found in allowed values (key: %s, location: %s, file: %s)", main_key, get_yaml_node_location(config_value_allowed_values_node), path), &patch_log.error);
|
||||||
is_valid = false;
|
is_valid = false;
|
||||||
|
|
@ -954,7 +966,8 @@ static usz apply_modification(std::vector<u32>& applied, patch_engine::patch_inf
|
||||||
|
|
||||||
for (const patch_engine::patch_data& p : patch.data_list)
|
for (const patch_engine::patch_data& p : patch.data_list)
|
||||||
{
|
{
|
||||||
if (p.type != patch_type::alloc) continue;
|
if (p.type != patch_type::alloc)
|
||||||
|
continue;
|
||||||
|
|
||||||
// Do not allow null address or if resultant ptr is not a VM ptr
|
// Do not allow null address or if resultant ptr is not a VM ptr
|
||||||
if (const u32 alloc_at = (p.offset & -4096); alloc_at >> 16)
|
if (const u32 alloc_at = (p.offset & -4096); alloc_at >> 16)
|
||||||
|
|
@ -1572,8 +1585,7 @@ void patch_engine::apply(std::vector<u32>& applied_total, const std::string& nam
|
||||||
&patches_for_all_serials_and_all_versions,
|
&patches_for_all_serials_and_all_versions,
|
||||||
&patches_for_all_serials_and_this_version,
|
&patches_for_all_serials_and_this_version,
|
||||||
&patches_for_this_serial_and_all_versions,
|
&patches_for_this_serial_and_all_versions,
|
||||||
&patches_for_this_serial_and_this_version
|
&patches_for_this_serial_and_this_version};
|
||||||
};
|
|
||||||
|
|
||||||
// Filter by patch group (reverse so specific patches will be prioritized over globals)
|
// Filter by patch group (reverse so specific patches will be prioritized over globals)
|
||||||
for (auto it = std::rbegin(patch_super_list); it != std::rend(patch_super_list); it++)
|
for (auto it = std::rbegin(patch_super_list); it != std::rend(patch_super_list); it++)
|
||||||
|
|
@ -1790,11 +1802,16 @@ static void append_patches(patch_engine::patch_map& existing_patches, const patc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!new_info.patch_version.empty()) info.patch_version = new_info.patch_version;
|
if (!new_info.patch_version.empty())
|
||||||
if (!new_info.author.empty()) info.author = new_info.author;
|
info.patch_version = new_info.patch_version;
|
||||||
if (!new_info.notes.empty()) info.notes = new_info.notes;
|
if (!new_info.author.empty())
|
||||||
if (!new_info.data_list.empty()) info.data_list = new_info.data_list;
|
info.author = new_info.author;
|
||||||
if (!new_info.source_path.empty()) info.source_path = new_info.source_path;
|
if (!new_info.notes.empty())
|
||||||
|
info.notes = new_info.notes;
|
||||||
|
if (!new_info.data_list.empty())
|
||||||
|
info.data_list = new_info.data_list;
|
||||||
|
if (!new_info.source_path.empty())
|
||||||
|
info.source_path = new_info.source_path;
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
@ -1850,10 +1867,14 @@ bool patch_engine::save_patches(const patch_map& patches, const std::string& pat
|
||||||
|
|
||||||
out << YAML::EndMap;
|
out << YAML::EndMap;
|
||||||
|
|
||||||
if (!info.author.empty()) out << patch_key::author << info.author;
|
if (!info.author.empty())
|
||||||
if (!info.patch_version.empty()) out << patch_key::patch_version << info.patch_version;
|
out << patch_key::author << info.author;
|
||||||
if (!info.patch_group.empty()) out << patch_key::group << info.patch_group;
|
if (!info.patch_version.empty())
|
||||||
if (!info.notes.empty()) out << patch_key::notes << info.notes;
|
out << patch_key::patch_version << info.patch_version;
|
||||||
|
if (!info.patch_group.empty())
|
||||||
|
out << patch_key::group << info.patch_group;
|
||||||
|
if (!info.notes.empty())
|
||||||
|
out << patch_key::notes << info.notes;
|
||||||
|
|
||||||
if (!info.default_config_values.empty())
|
if (!info.default_config_values.empty())
|
||||||
{
|
{
|
||||||
|
|
@ -1964,7 +1985,7 @@ patch_engine::patch_map patch_engine::load_config()
|
||||||
const std::string path = get_patch_config_path();
|
const std::string path = get_patch_config_path();
|
||||||
patch_log.notice("Loading patch config file %s", path);
|
patch_log.notice("Loading patch config file %s", path);
|
||||||
|
|
||||||
if (fs::file f{ path })
|
if (fs::file f{path})
|
||||||
{
|
{
|
||||||
auto [root, error] = yaml_load(f.to_string());
|
auto [root, error] = yaml_load(f.to_string());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ namespace patch_key
|
||||||
static const std::string min = "Min";
|
static const std::string min = "Min";
|
||||||
static const std::string max = "Max";
|
static const std::string max = "Max";
|
||||||
static const std::string allowed_values = "Allowed Values";
|
static const std::string allowed_values = "Allowed Values";
|
||||||
}
|
} // namespace patch_key
|
||||||
|
|
||||||
inline static const std::string patch_engine_version = "1.2";
|
inline static const std::string patch_engine_version = "1.2";
|
||||||
|
|
||||||
|
|
@ -35,7 +35,7 @@ enum class patch_type
|
||||||
invalid,
|
invalid,
|
||||||
load,
|
load,
|
||||||
alloc, // Allocate memory at address (zeroized executable memory)
|
alloc, // Allocate memory at address (zeroized executable memory)
|
||||||
code_alloc,// Allocate memory somewhere, saves branch to memory at specfied address (filled with PPU NOP and branch for returning)
|
code_alloc, // Allocate memory somewhere, saves branch to memory at specfied address (filled with PPU NOP and branch for returning)
|
||||||
jump, // Install special 32-bit jump instruction (PPU only atm)
|
jump, // Install special 32-bit jump instruction (PPU only atm)
|
||||||
jump_link, // jump + set link (PPU only atm)
|
jump_link, // jump + set link (PPU only atm)
|
||||||
jump_func, // jump to exported function (PPU only, forever)
|
jump_func, // jump to exported function (PPU only, forever)
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,7 @@ Intersection (&) and symmetric difference (^) is also available.
|
||||||
#include "Utilities/StrFmt.h"
|
#include "Utilities/StrFmt.h"
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
concept BitSetEnum = std::is_enum_v<T> && requires(T x)
|
concept BitSetEnum = std::is_enum_v<T> && requires(T x) {
|
||||||
{
|
|
||||||
T::__bitset_enum_max;
|
T::__bitset_enum_max;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -91,56 +90,56 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy
|
// Copy
|
||||||
constexpr bs_t operator +() const
|
constexpr bs_t operator+() const
|
||||||
{
|
{
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bs_t& operator +=(bs_t rhs)
|
constexpr bs_t& operator+=(bs_t rhs)
|
||||||
{
|
{
|
||||||
m_data |= static_cast<under>(rhs);
|
m_data |= static_cast<under>(rhs);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bs_t& operator -=(bs_t rhs)
|
constexpr bs_t& operator-=(bs_t rhs)
|
||||||
{
|
{
|
||||||
m_data &= ~static_cast<under>(rhs);
|
m_data &= ~static_cast<under>(rhs);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bs_t& operator &=(bs_t rhs)
|
constexpr bs_t& operator&=(bs_t rhs)
|
||||||
{
|
{
|
||||||
m_data &= static_cast<under>(rhs);
|
m_data &= static_cast<under>(rhs);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bs_t& operator ^=(bs_t rhs)
|
constexpr bs_t& operator^=(bs_t rhs)
|
||||||
{
|
{
|
||||||
m_data ^= static_cast<under>(rhs);
|
m_data ^= static_cast<under>(rhs);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
friend constexpr bs_t operator +(bs_t lhs, bs_t rhs)
|
friend constexpr bs_t operator+(bs_t lhs, bs_t rhs)
|
||||||
{
|
{
|
||||||
return bs_t(0, lhs.m_data | rhs.m_data);
|
return bs_t(0, lhs.m_data | rhs.m_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
friend constexpr bs_t operator -(bs_t lhs, bs_t rhs)
|
friend constexpr bs_t operator-(bs_t lhs, bs_t rhs)
|
||||||
{
|
{
|
||||||
return bs_t(0, lhs.m_data & ~rhs.m_data);
|
return bs_t(0, lhs.m_data & ~rhs.m_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
friend constexpr bs_t operator &(bs_t lhs, bs_t rhs)
|
friend constexpr bs_t operator&(bs_t lhs, bs_t rhs)
|
||||||
{
|
{
|
||||||
return bs_t(0, lhs.m_data & rhs.m_data);
|
return bs_t(0, lhs.m_data & rhs.m_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
friend constexpr bs_t operator ^(bs_t lhs, bs_t rhs)
|
friend constexpr bs_t operator^(bs_t lhs, bs_t rhs)
|
||||||
{
|
{
|
||||||
return bs_t(0, lhs.m_data ^ rhs.m_data);
|
return bs_t(0, lhs.m_data ^ rhs.m_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool operator ==(bs_t rhs) const noexcept
|
constexpr bool operator==(bs_t rhs) const noexcept
|
||||||
{
|
{
|
||||||
return m_data == rhs.m_data;
|
return m_data == rhs.m_data;
|
||||||
}
|
}
|
||||||
|
|
@ -179,63 +178,71 @@ public:
|
||||||
|
|
||||||
// Unary '+' operator: promote plain enum value to bitset value
|
// Unary '+' operator: promote plain enum value to bitset value
|
||||||
template <BitSetEnum T>
|
template <BitSetEnum T>
|
||||||
constexpr bs_t<T> operator +(T bit)
|
constexpr bs_t<T> operator+(T bit)
|
||||||
{
|
{
|
||||||
return bs_t<T>(bit);
|
return bs_t<T>(bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Binary '+' operator: bitset union
|
// Binary '+' operator: bitset union
|
||||||
template <BitSetEnum T, typename U> requires (std::is_constructible_v<bs_t<T>, U>)
|
template <BitSetEnum T, typename U>
|
||||||
constexpr bs_t<T> operator +(T lhs, const U& rhs)
|
requires(std::is_constructible_v<bs_t<T>, U>)
|
||||||
|
constexpr bs_t<T> operator+(T lhs, const U& rhs)
|
||||||
{
|
{
|
||||||
return bs_t<T>(lhs) + bs_t<T>(rhs);
|
return bs_t<T>(lhs) + bs_t<T>(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Binary '+' operator: bitset union
|
// Binary '+' operator: bitset union
|
||||||
template <typename U, BitSetEnum T> requires (std::is_constructible_v<bs_t<T>, U> && !std::is_enum_v<U>)
|
template <typename U, BitSetEnum T>
|
||||||
constexpr bs_t<T> operator +(const U& lhs, T rhs)
|
requires(std::is_constructible_v<bs_t<T>, U> && !std::is_enum_v<U>)
|
||||||
|
constexpr bs_t<T> operator+(const U& lhs, T rhs)
|
||||||
{
|
{
|
||||||
return bs_t<T>(lhs) + bs_t<T>(rhs);
|
return bs_t<T>(lhs) + bs_t<T>(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Binary '-' operator: bitset difference
|
// Binary '-' operator: bitset difference
|
||||||
template <BitSetEnum T, typename U> requires (std::is_constructible_v<bs_t<T>, U>)
|
template <BitSetEnum T, typename U>
|
||||||
constexpr bs_t<T> operator -(T lhs, const U& rhs)
|
requires(std::is_constructible_v<bs_t<T>, U>)
|
||||||
|
constexpr bs_t<T> operator-(T lhs, const U& rhs)
|
||||||
{
|
{
|
||||||
return bs_t<T>(lhs) - bs_t<T>(rhs);
|
return bs_t<T>(lhs) - bs_t<T>(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Binary '-' operator: bitset difference
|
// Binary '-' operator: bitset difference
|
||||||
template <typename U, BitSetEnum T> requires (std::is_constructible_v<bs_t<T>, U> && !std::is_enum_v<U>)
|
template <typename U, BitSetEnum T>
|
||||||
constexpr bs_t<T> operator -(const U& lhs, T rhs)
|
requires(std::is_constructible_v<bs_t<T>, U> && !std::is_enum_v<U>)
|
||||||
|
constexpr bs_t<T> operator-(const U& lhs, T rhs)
|
||||||
{
|
{
|
||||||
return bs_t<T>(lhs) - bs_t<T>(rhs);
|
return bs_t<T>(lhs) - bs_t<T>(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Binary '&' operator: bitset intersection
|
// Binary '&' operator: bitset intersection
|
||||||
template <BitSetEnum T, typename U> requires (std::is_constructible_v<bs_t<T>, U>)
|
template <BitSetEnum T, typename U>
|
||||||
constexpr bs_t<T> operator &(T lhs, const U& rhs)
|
requires(std::is_constructible_v<bs_t<T>, U>)
|
||||||
|
constexpr bs_t<T> operator&(T lhs, const U& rhs)
|
||||||
{
|
{
|
||||||
return bs_t<T>(lhs) & bs_t<T>(rhs);
|
return bs_t<T>(lhs) & bs_t<T>(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Binary '&' operator: bitset intersection
|
// Binary '&' operator: bitset intersection
|
||||||
template <typename U, BitSetEnum T> requires (std::is_constructible_v<bs_t<T>, U> && !std::is_enum_v<U>)
|
template <typename U, BitSetEnum T>
|
||||||
constexpr bs_t<T> operator &(const U& lhs, T rhs)
|
requires(std::is_constructible_v<bs_t<T>, U> && !std::is_enum_v<U>)
|
||||||
|
constexpr bs_t<T> operator&(const U& lhs, T rhs)
|
||||||
{
|
{
|
||||||
return bs_t<T>(lhs) & bs_t<T>(rhs);
|
return bs_t<T>(lhs) & bs_t<T>(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Binary '^' operator: bitset symmetric difference
|
// Binary '^' operator: bitset symmetric difference
|
||||||
template <BitSetEnum T, typename U> requires (std::is_constructible_v<bs_t<T>, U>)
|
template <BitSetEnum T, typename U>
|
||||||
constexpr bs_t<T> operator ^(T lhs, const U& rhs)
|
requires(std::is_constructible_v<bs_t<T>, U>)
|
||||||
|
constexpr bs_t<T> operator^(T lhs, const U& rhs)
|
||||||
{
|
{
|
||||||
return bs_t<T>(lhs) ^ bs_t<T>(rhs);
|
return bs_t<T>(lhs) ^ bs_t<T>(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Binary '^' operator: bitset symmetric difference
|
// Binary '^' operator: bitset symmetric difference
|
||||||
template <typename U, BitSetEnum T> requires (std::is_constructible_v<bs_t<T>, U> && !std::is_enum_v<U>)
|
template <typename U, BitSetEnum T>
|
||||||
constexpr bs_t<T> operator ^(const U& lhs, T rhs)
|
requires(std::is_constructible_v<bs_t<T>, U> && !std::is_enum_v<U>)
|
||||||
|
constexpr bs_t<T> operator^(const U& lhs, T rhs)
|
||||||
{
|
{
|
||||||
return bs_t<T>(lhs) ^ bs_t<T>(rhs);
|
return bs_t<T>(lhs) ^ bs_t<T>(rhs);
|
||||||
}
|
}
|
||||||
|
|
@ -261,7 +268,7 @@ public:
|
||||||
|
|
||||||
atomic_bs_t(const atomic_bs_t&) = delete;
|
atomic_bs_t(const atomic_bs_t&) = delete;
|
||||||
|
|
||||||
atomic_bs_t& operator =(const atomic_bs_t&) = delete;
|
atomic_bs_t& operator=(const atomic_bs_t&) = delete;
|
||||||
|
|
||||||
explicit constexpr atomic_bs_t(bs_t value)
|
explicit constexpr atomic_bs_t(bs_t value)
|
||||||
: base(value)
|
: base(value)
|
||||||
|
|
@ -285,7 +292,7 @@ public:
|
||||||
return static_cast<under>(base::load());
|
return static_cast<under>(base::load());
|
||||||
}
|
}
|
||||||
|
|
||||||
bs_t operator +() const
|
bs_t operator+() const
|
||||||
{
|
{
|
||||||
return base::load();
|
return base::load();
|
||||||
}
|
}
|
||||||
|
|
@ -300,7 +307,7 @@ public:
|
||||||
return bs_t(0, atomic_storage<under>::or_fetch(m_data.m_data, rhs.m_data));
|
return bs_t(0, atomic_storage<under>::or_fetch(m_data.m_data, rhs.m_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
bs_t operator +=(const bs_t& rhs)
|
bs_t operator+=(const bs_t& rhs)
|
||||||
{
|
{
|
||||||
return add_fetch(rhs);
|
return add_fetch(rhs);
|
||||||
}
|
}
|
||||||
|
|
@ -315,7 +322,7 @@ public:
|
||||||
return bs_t(0, atomic_storage<under>::and_fetch(m_data.m_data, ~rhs.m_data));
|
return bs_t(0, atomic_storage<under>::and_fetch(m_data.m_data, ~rhs.m_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
bs_t operator -=(const bs_t& rhs)
|
bs_t operator-=(const bs_t& rhs)
|
||||||
{
|
{
|
||||||
return sub_fetch(rhs);
|
return sub_fetch(rhs);
|
||||||
}
|
}
|
||||||
|
|
@ -330,7 +337,7 @@ public:
|
||||||
return bs_t(0, atomic_storage<under>::and_fetch(m_data.m_data, rhs.m_data));
|
return bs_t(0, atomic_storage<under>::and_fetch(m_data.m_data, rhs.m_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
bs_t operator &=(const bs_t& rhs)
|
bs_t operator&=(const bs_t& rhs)
|
||||||
{
|
{
|
||||||
return and_fetch(rhs);
|
return and_fetch(rhs);
|
||||||
}
|
}
|
||||||
|
|
@ -345,14 +352,14 @@ public:
|
||||||
return bs_t(0, atomic_storage<under>::xor_fetch(m_data.m_data, rhs.m_data));
|
return bs_t(0, atomic_storage<under>::xor_fetch(m_data.m_data, rhs.m_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
bs_t operator ^=(const bs_t& rhs)
|
bs_t operator^=(const bs_t& rhs)
|
||||||
{
|
{
|
||||||
return xor_fetch(rhs);
|
return xor_fetch(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto fetch_or(const bs_t&) = delete;
|
auto fetch_or(const bs_t&) = delete;
|
||||||
auto or_fetch(const bs_t&) = delete;
|
auto or_fetch(const bs_t&) = delete;
|
||||||
auto operator |=(const bs_t&) = delete;
|
auto operator|=(const bs_t&) = delete;
|
||||||
|
|
||||||
bool test_and_set(T rhs)
|
bool test_and_set(T rhs)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ C-style format parser. Appends formatted string to `out`, returns number of char
|
||||||
`fmt`: null-terminated string of `Char` type (char or constructible from char)
|
`fmt`: null-terminated string of `Char` type (char or constructible from char)
|
||||||
`src`: rvalue reference to argument provider.
|
`src`: rvalue reference to argument provider.
|
||||||
*/
|
*/
|
||||||
template<typename Dst, typename Char, typename Src>
|
template <typename Dst, typename Char, typename Src>
|
||||||
usz cfmt_append(Dst& out, const Char* fmt, Src&& src)
|
usz cfmt_append(Dst& out, const Char* fmt, Src&& src)
|
||||||
{
|
{
|
||||||
ensure(fmt);
|
ensure(fmt);
|
||||||
|
|
@ -114,8 +114,7 @@ usz cfmt_append(Dst& out, const Char* fmt, Src&& src)
|
||||||
out.push_back(value % 10 + '0');
|
out.push_back(value % 10 + '0');
|
||||||
value /= 10;
|
value /= 10;
|
||||||
}
|
}
|
||||||
}
|
} while (0 < --min_size || value);
|
||||||
while (0 < --min_size || value);
|
|
||||||
|
|
||||||
// Revert written characters
|
// Revert written characters
|
||||||
for (usz i = start, j = out.size() - 1; i < j; i++, j--)
|
for (usz i = start, j = out.size() - 1; i < j; i++, j--)
|
||||||
|
|
@ -125,7 +124,8 @@ usz cfmt_append(Dst& out, const Char* fmt, Src&& src)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Single pass over fmt string (null-terminated), TODO: check correct order
|
// Single pass over fmt string (null-terminated), TODO: check correct order
|
||||||
while (const Char ch = *fmt++) if (ctx.size == 0)
|
while (const Char ch = *fmt++)
|
||||||
|
if (ctx.size == 0)
|
||||||
{
|
{
|
||||||
if (ch == '%')
|
if (ch == '%')
|
||||||
{
|
{
|
||||||
|
|
@ -145,7 +145,8 @@ usz cfmt_append(Dst& out, const Char* fmt, Src&& src)
|
||||||
{
|
{
|
||||||
out.push_back(ch);
|
out.push_back(ch);
|
||||||
}
|
}
|
||||||
else switch (ctx.size++, ch)
|
else
|
||||||
|
switch (ctx.size++, ch)
|
||||||
{
|
{
|
||||||
case '-': ctx.left = true; break;
|
case '-': ctx.left = true; break;
|
||||||
case '+': ctx.sign = true; break;
|
case '+': ctx.sign = true; break;
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ namespace date_time
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<char separator = 0>
|
template <char separator = 0>
|
||||||
static inline std::string current_time_narrow()
|
static inline std::string current_time_narrow()
|
||||||
{
|
{
|
||||||
char str[80];
|
char str[80];
|
||||||
|
|
@ -47,7 +47,7 @@ namespace date_time
|
||||||
|
|
||||||
std::string parse_buf;
|
std::string parse_buf;
|
||||||
|
|
||||||
if constexpr(separator != 0)
|
if constexpr (separator != 0)
|
||||||
parse_buf = std::string("%Y") + separator + "%m" + separator + "%d" + separator + "%H" + separator + "%M" + separator + "%S";
|
parse_buf = std::string("%Y") + separator + "%m" + separator + "%d" + separator + "%H" + separator + "%M" + separator + "%S";
|
||||||
else
|
else
|
||||||
parse_buf = "%Y%m%d%H%M%S";
|
parse_buf = "%Y%m%d%H%M%S";
|
||||||
|
|
@ -55,4 +55,4 @@ namespace date_time
|
||||||
strftime(str, sizeof(str), parse_buf.c_str(), &now);
|
strftime(str, sizeof(str), parse_buf.c_str(), &now);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
}
|
} // namespace date_time
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -30,7 +30,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
T& operator [](usz index)
|
T& operator[](usz index)
|
||||||
{
|
{
|
||||||
lf_array* _this = this;
|
lf_array* _this = this;
|
||||||
|
|
||||||
|
|
@ -73,7 +73,8 @@ public:
|
||||||
return *result;
|
return *result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename F> requires (std::is_invocable_v<F, T&>)
|
template <typename F>
|
||||||
|
requires(std::is_invocable_v<F, T&>)
|
||||||
auto for_each(F&& func, bool is_finite = true)
|
auto for_each(F&& func, bool is_finite = true)
|
||||||
{
|
{
|
||||||
lf_array* _this = this;
|
lf_array* _this = this;
|
||||||
|
|
@ -143,7 +144,7 @@ public:
|
||||||
|
|
||||||
// Simple lock-free FIFO queue base. Based on lf_array<T, N> itself. Currently uses 32-bit counters.
|
// Simple lock-free FIFO queue base. Based on lf_array<T, N> itself. Currently uses 32-bit counters.
|
||||||
// There is no "push_end" or "pop_begin" provided, the queue element must signal its state on its own.
|
// There is no "push_end" or "pop_begin" provided, the queue element must signal its state on its own.
|
||||||
template<typename T, usz N = std::max<usz>(256 / sizeof(T), 1)>
|
template <typename T, usz N = std::max<usz>(256 / sizeof(T), 1)>
|
||||||
class lf_fifo : public lf_array<T, N>
|
class lf_fifo : public lf_array<T, N>
|
||||||
{
|
{
|
||||||
// LSB 32-bit: push, MSB 32-bit: pop
|
// LSB 32-bit: push, MSB 32-bit: pop
|
||||||
|
|
@ -214,8 +215,7 @@ class lf_queue_item final
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
constexpr lf_queue_item(lf_queue_item* link, Args&&... args)
|
constexpr lf_queue_item(lf_queue_item* link, Args&&... args)
|
||||||
: m_link(link)
|
: m_link(link), m_data(std::forward<Args>(args)...)
|
||||||
, m_data(std::forward<Args>(args)...)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -248,28 +248,28 @@ class lf_queue_iterator
|
||||||
public:
|
public:
|
||||||
constexpr lf_queue_iterator() = default;
|
constexpr lf_queue_iterator() = default;
|
||||||
|
|
||||||
bool operator ==(const lf_queue_iterator& rhs) const
|
bool operator==(const lf_queue_iterator& rhs) const
|
||||||
{
|
{
|
||||||
return m_ptr == rhs.m_ptr;
|
return m_ptr == rhs.m_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
T& operator *() const
|
T& operator*() const
|
||||||
{
|
{
|
||||||
return m_ptr->m_data;
|
return m_ptr->m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
T* operator ->() const
|
T* operator->() const
|
||||||
{
|
{
|
||||||
return &m_ptr->m_data;
|
return &m_ptr->m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
lf_queue_iterator& operator ++()
|
lf_queue_iterator& operator++()
|
||||||
{
|
{
|
||||||
m_ptr = m_ptr->m_link;
|
m_ptr = m_ptr->m_link;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
lf_queue_iterator operator ++(int)
|
lf_queue_iterator operator++(int)
|
||||||
{
|
{
|
||||||
lf_queue_iterator result;
|
lf_queue_iterator result;
|
||||||
result.m_ptr = m_ptr;
|
result.m_ptr = m_ptr;
|
||||||
|
|
@ -298,9 +298,9 @@ public:
|
||||||
r.m_head = nullptr;
|
r.m_head = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
lf_queue_slice& operator =(const lf_queue_slice&) = delete;
|
lf_queue_slice& operator=(const lf_queue_slice&) = delete;
|
||||||
|
|
||||||
lf_queue_slice& operator =(lf_queue_slice&& r) noexcept
|
lf_queue_slice& operator=(lf_queue_slice&& r) noexcept
|
||||||
{
|
{
|
||||||
if (this != &r)
|
if (this != &r)
|
||||||
{
|
{
|
||||||
|
|
@ -317,12 +317,12 @@ public:
|
||||||
delete m_head;
|
delete m_head;
|
||||||
}
|
}
|
||||||
|
|
||||||
T& operator *() const
|
T& operator*() const
|
||||||
{
|
{
|
||||||
return m_head->m_data;
|
return m_head->m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
T* operator ->() const
|
T* operator->() const
|
||||||
{
|
{
|
||||||
return &m_head->m_data;
|
return &m_head->m_data;
|
||||||
}
|
}
|
||||||
|
|
@ -405,8 +405,7 @@ class lf_queue final
|
||||||
auto* pprev = prev->m_link;
|
auto* pprev = prev->m_link;
|
||||||
prev->m_link = head;
|
prev->m_link = head;
|
||||||
head = std::exchange(prev, pprev);
|
head = std::exchange(prev, pprev);
|
||||||
}
|
} while (prev);
|
||||||
while (prev);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return head;
|
return head;
|
||||||
|
|
@ -573,8 +572,7 @@ public:
|
||||||
|
|
||||||
// Set to not check already checked items
|
// Set to not check already checked items
|
||||||
_chk = _old;
|
_chk = _old;
|
||||||
}
|
} while (!m_head.compare_exchange(_old, item));
|
||||||
while (!m_head.compare_exchange(_old, item));
|
|
||||||
|
|
||||||
return &item->m_data;
|
return &item->m_data;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ struct rXmlDocument
|
||||||
{
|
{
|
||||||
rXmlDocument();
|
rXmlDocument();
|
||||||
rXmlDocument(const rXmlDocument& other) = delete;
|
rXmlDocument(const rXmlDocument& other) = delete;
|
||||||
rXmlDocument &operator=(const rXmlDocument& other) = delete;
|
rXmlDocument& operator=(const rXmlDocument& other) = delete;
|
||||||
pugi::xml_parse_result Read(std::string_view data);
|
pugi::xml_parse_result Read(std::string_view data);
|
||||||
virtual std::shared_ptr<rXmlNode> GetRoot();
|
virtual std::shared_ptr<rXmlNode> GetRoot();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,8 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}).second;
|
})
|
||||||
|
.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void post(u32 _max)
|
void post(u32 _max)
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,8 @@ simple_ringbuf::simple_ringbuf(const simple_ringbuf& other)
|
||||||
|
|
||||||
simple_ringbuf& simple_ringbuf::operator=(const simple_ringbuf& other)
|
simple_ringbuf& simple_ringbuf::operator=(const simple_ringbuf& other)
|
||||||
{
|
{
|
||||||
if (this == &other) return *this;
|
if (this == &other)
|
||||||
|
return *this;
|
||||||
|
|
||||||
ctr_state old = other.rw_ptr.load();
|
ctr_state old = other.rw_ptr.load();
|
||||||
|
|
||||||
|
|
@ -61,7 +62,8 @@ simple_ringbuf::simple_ringbuf(simple_ringbuf&& other)
|
||||||
|
|
||||||
simple_ringbuf& simple_ringbuf::operator=(simple_ringbuf&& other)
|
simple_ringbuf& simple_ringbuf::operator=(simple_ringbuf&& other)
|
||||||
{
|
{
|
||||||
if (this == &other) return *this;
|
if (this == &other)
|
||||||
|
return *this;
|
||||||
|
|
||||||
const ctr_state other_rw_ptr = other.rw_ptr.load();
|
const ctr_state other_rw_ptr = other.rw_ptr.load();
|
||||||
buf = std::move(other.buf);
|
buf = std::move(other.buf);
|
||||||
|
|
@ -119,7 +121,8 @@ void simple_ringbuf::writer_flush(u64 cnt)
|
||||||
rw_ptr.atomic_op([&](ctr_state& val)
|
rw_ptr.atomic_op([&](ctr_state& val)
|
||||||
{
|
{
|
||||||
const u64 used = get_used_size(val);
|
const u64 used = get_used_size(val);
|
||||||
if (used == 0) return;
|
if (used == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
val.write_ptr += buf.size() - std::min<u64>(used, cnt);
|
val.write_ptr += buf.size() - std::min<u64>(used, cnt);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@
|
||||||
class simple_ringbuf
|
class simple_ringbuf
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
simple_ringbuf(u64 size = 0);
|
simple_ringbuf(u64 size = 0);
|
||||||
virtual ~simple_ringbuf();
|
virtual ~simple_ringbuf();
|
||||||
|
|
||||||
|
|
@ -34,7 +33,6 @@ public:
|
||||||
void reader_flush(u64 cnt = umax);
|
void reader_flush(u64 cnt = umax);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
struct ctr_state
|
struct ctr_state
|
||||||
{
|
{
|
||||||
alignas(sizeof(u64) * 2)
|
alignas(sizeof(u64) * 2)
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <Windows.h>
|
#include <windows.h>
|
||||||
#define DBGHELP_TRANSLATE_TCHAR
|
#define DBGHELP_TRANSLATE_TCHAR
|
||||||
#include <DbgHelp.h>
|
#include <DbgHelp.h>
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
|
|
@ -150,4 +150,4 @@ namespace utils
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
} // namespace utils
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,7 @@ namespace utils
|
||||||
// Printing utilities
|
// Printing utilities
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
concept Logger = requires (T& t, const std::string& msg)
|
concept Logger = requires(T& t, const std::string& msg) {
|
||||||
{
|
|
||||||
{ t.print(msg) };
|
{ t.print(msg) };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -21,14 +20,15 @@ namespace utils
|
||||||
public:
|
public:
|
||||||
print_to_log(logs::channel& chan)
|
print_to_log(logs::channel& chan)
|
||||||
: log(chan)
|
: log(chan)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void print(const std::string& s)
|
void print(const std::string& s)
|
||||||
{
|
{
|
||||||
log.error("%s", s);
|
log.error("%s", s);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace stack_trace
|
||||||
|
|
||||||
std::vector<void*> get_backtrace(int max_depth = 255);
|
std::vector<void*> get_backtrace(int max_depth = 255);
|
||||||
std::vector<std::string> get_backtrace_symbols(const std::vector<void*>& stack);
|
std::vector<std::string> get_backtrace_symbols(const std::vector<void*>& stack);
|
||||||
|
|
@ -43,4 +43,4 @@ namespace utils
|
||||||
logger.print(line);
|
logger.print(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} // namespace utils
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
#ifndef NOMINMAX
|
#ifndef NOMINMAX
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
#endif
|
#endif
|
||||||
#include <Windows.h>
|
#include <windows.h>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
|
|
@ -20,12 +20,18 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
#if !defined(NTSTATUS)
|
||||||
|
typedef _Return_type_success_(return >= 0) LONG NTSTATUS;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __GNUC__
|
||||||
DYNAMIC_IMPORT("ntdll.dll", NtWaitForKeyedEvent, NTSTATUS(HANDLE, PVOID Key, BOOLEAN Alertable, PLARGE_INTEGER Timeout));
|
DYNAMIC_IMPORT("ntdll.dll", NtWaitForKeyedEvent, NTSTATUS(HANDLE, PVOID Key, BOOLEAN Alertable, PLARGE_INTEGER Timeout));
|
||||||
DYNAMIC_IMPORT("ntdll.dll", NtReleaseKeyedEvent, NTSTATUS(HANDLE, PVOID Key, BOOLEAN Alertable, PLARGE_INTEGER Timeout));
|
DYNAMIC_IMPORT("ntdll.dll", NtReleaseKeyedEvent, NTSTATUS(HANDLE, PVOID Key, BOOLEAN Alertable, PLARGE_INTEGER Timeout));
|
||||||
DYNAMIC_IMPORT("ntdll.dll", NtWaitForSingleObject, NTSTATUS(HANDLE Handle, BOOLEAN Alertable, PLARGE_INTEGER Timeout));
|
DYNAMIC_IMPORT("ntdll.dll", NtWaitForSingleObject, NTSTATUS(HANDLE Handle, BOOLEAN Alertable, PLARGE_INTEGER Timeout));
|
||||||
DYNAMIC_IMPORT("ntdll.dll", NtDelayExecution, NTSTATUS(BOOLEAN Alertable, PLARGE_INTEGER DelayInterval));
|
DYNAMIC_IMPORT("ntdll.dll", NtDelayExecution, NTSTATUS(BOOLEAN Alertable, PLARGE_INTEGER DelayInterval));
|
||||||
DYNAMIC_IMPORT("ntdll.dll", NtWaitForAlertByThreadId, NTSTATUS(PVOID Address, PLARGE_INTEGER Timeout));
|
DYNAMIC_IMPORT("ntdll.dll", NtWaitForAlertByThreadId, NTSTATUS(PVOID Address, PLARGE_INTEGER Timeout));
|
||||||
DYNAMIC_IMPORT("ntdll.dll", NtAlertThreadByThreadId, NTSTATUS(DWORD_PTR ThreadId));
|
DYNAMIC_IMPORT("ntdll.dll", NtAlertThreadByThreadId, NTSTATUS(DWORD_PTR ThreadId));
|
||||||
|
#endif
|
||||||
|
|
||||||
constexpr NTSTATUS NTSTATUS_SUCCESS = 0;
|
constexpr NTSTATUS NTSTATUS_SUCCESS = 0;
|
||||||
constexpr NTSTATUS NTSTATUS_ALERTED = 0x101;
|
constexpr NTSTATUS NTSTATUS_ALERTED = 0x101;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@
|
||||||
class universal_pool
|
class universal_pool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
universal_pool(u32 gc_interval = 10000) : gc_interval(gc_interval)
|
universal_pool(u32 gc_interval = 10000) : gc_interval(gc_interval)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -27,7 +26,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
requires (std::invocable<F&> && std::is_same_v<std::invoke_result_t<F&>, std::shared_ptr<void>>)
|
requires(std::invocable<F&> && std::is_same_v<std::invoke_result_t<F&>, std::shared_ptr<void>>)
|
||||||
void add_op(F func)
|
void add_op(F func)
|
||||||
{
|
{
|
||||||
std::lock_guard lock(mutex);
|
std::lock_guard lock(mutex);
|
||||||
|
|
@ -45,7 +44,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void delete_unused()
|
void delete_unused()
|
||||||
{
|
{
|
||||||
const u32 gc_int = gc_interval.observe();
|
const u32 gc_int = gc_interval.observe();
|
||||||
|
|
@ -53,11 +51,12 @@ private:
|
||||||
if (u64 crnt_time = get_system_time(); gc_int == 0 || crnt_time > gc_last_time + gc_int)
|
if (u64 crnt_time = get_system_time(); gc_int == 0 || crnt_time > gc_last_time + gc_int)
|
||||||
{
|
{
|
||||||
gc_last_time = crnt_time;
|
gc_last_time = crnt_time;
|
||||||
storage.erase
|
storage.erase(
|
||||||
(
|
std::remove_if(storage.begin(), storage.end(), [](auto& obj)
|
||||||
std::remove_if(storage.begin(), storage.end(), [](auto& obj) { return obj.use_count() <= 1; }),
|
{
|
||||||
storage.end()
|
return obj.use_count() <= 1;
|
||||||
);
|
}),
|
||||||
|
storage.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,11 +66,10 @@ private:
|
||||||
atomic_t<u32> gc_interval = 0;
|
atomic_t<u32> gc_interval = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template <typename T>
|
||||||
class transactional_storage
|
class transactional_storage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
transactional_storage(std::shared_ptr<universal_pool> pool, std::shared_ptr<T> obj = std::make_shared<T>())
|
transactional_storage(std::shared_ptr<universal_pool> pool, std::shared_ptr<T> obj = std::make_shared<T>())
|
||||||
{
|
{
|
||||||
ensure(pool && obj);
|
ensure(pool && obj);
|
||||||
|
|
@ -98,7 +96,8 @@ public:
|
||||||
|
|
||||||
transactional_storage& operator=(transactional_storage&& other)
|
transactional_storage& operator=(transactional_storage&& other)
|
||||||
{
|
{
|
||||||
if (this == &other) return *this;
|
if (this == &other)
|
||||||
|
return *this;
|
||||||
|
|
||||||
pool = std::move(other.pool);
|
pool = std::move(other.pool);
|
||||||
|
|
||||||
|
|
@ -137,7 +136,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
requires (std::invocable<F&> && std::is_same_v<std::invoke_result_t<F&>, std::shared_ptr<T>>)
|
requires(std::invocable<F&> && std::is_same_v<std::invoke_result_t<F&>, std::shared_ptr<T>>)
|
||||||
void add_op(F func)
|
void add_op(F func)
|
||||||
{
|
{
|
||||||
pool->add_op([&]() -> std::shared_ptr<void>
|
pool->add_op([&]() -> std::shared_ptr<void>
|
||||||
|
|
@ -153,7 +152,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
shared_mutex current_mutex{};
|
shared_mutex current_mutex{};
|
||||||
std::shared_ptr<T> current{};
|
std::shared_ptr<T> current{};
|
||||||
std::shared_ptr<universal_pool> pool{};
|
std::shared_ptr<universal_pool> pool{};
|
||||||
|
|
|
||||||
|
|
@ -99,4 +99,4 @@ namespace utils
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
} // namespace utils
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,7 @@ namespace utils
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr version(uint hi, uint mid, uint lo, version_type type, uint type_index, const char* postfix)
|
constexpr version(uint hi, uint mid, uint lo, version_type type, uint type_index, const char* postfix)
|
||||||
: m_hi(hi)
|
: m_hi(hi), m_mid(mid), m_lo(lo), m_type(type), m_type_index(type_index), m_postfix(postfix)
|
||||||
, m_mid(mid)
|
|
||||||
, m_lo(lo)
|
|
||||||
, m_type(type)
|
|
||||||
, m_type_index(type_index)
|
|
||||||
, m_postfix(postfix)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,4 +67,4 @@ namespace utils
|
||||||
|
|
||||||
// Generic version comparison (e.g. 0.0.5 vs 1.3)
|
// Generic version comparison (e.g. 0.0.5 vs 1.3)
|
||||||
int compare_versions(const std::string& v1, const std::string& v2, bool& ok);
|
int compare_versions(const std::string& v1, const std::string& v2, bool& ok);
|
||||||
}
|
} // namespace utils
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,11 @@
|
||||||
std::string to_hex(std::uint64_t value, bool prfx = true)
|
std::string to_hex(std::uint64_t value, bool prfx = true)
|
||||||
{
|
{
|
||||||
char buf[20]{}, *ptr = buf + 19;
|
char buf[20]{}, *ptr = buf + 19;
|
||||||
do *--ptr = "0123456789abcdef"[value % 16], value /= 16; while (value);
|
do
|
||||||
if (!prfx) return ptr;
|
*--ptr = "0123456789abcdef"[value % 16], value /= 16;
|
||||||
|
while (value);
|
||||||
|
if (!prfx)
|
||||||
|
return ptr;
|
||||||
*--ptr = 'x';
|
*--ptr = 'x';
|
||||||
*--ptr = '0';
|
*--ptr = '0';
|
||||||
return ptr;
|
return ptr;
|
||||||
|
|
@ -200,7 +203,9 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
while ((dup2(fds[1], STDOUT_FILENO) == -1) && (errno == EINTR)) {}
|
while ((dup2(fds[1], STDOUT_FILENO) == -1) && (errno == EINTR))
|
||||||
|
{
|
||||||
|
}
|
||||||
close(fds[1]);
|
close(fds[1]);
|
||||||
close(fds[0]);
|
close(fds[0]);
|
||||||
// Fallthrough
|
// Fallthrough
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -50,16 +50,16 @@ typedef UINT32 uint32_t;
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int nr; /*!< number of rounds */
|
int nr; /*!< number of rounds */
|
||||||
uint32_t *rk; /*!< AES round keys */
|
uint32_t* rk; /*!< AES round keys */
|
||||||
uint32_t buf[68]; /*!< unaligned data */
|
uint32_t buf[68]; /*!< unaligned data */
|
||||||
}
|
} aes_context;
|
||||||
aes_context;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief AES key schedule (encryption)
|
* \brief AES key schedule (encryption)
|
||||||
*
|
*
|
||||||
* \param ctx AES context to be initialized
|
* \param ctx AES context to be initialized
|
||||||
|
|
@ -68,9 +68,9 @@ extern "C" {
|
||||||
*
|
*
|
||||||
* \return 0 if successful, or POLARSSL_ERR_AES_INVALID_KEY_LENGTH
|
* \return 0 if successful, or POLARSSL_ERR_AES_INVALID_KEY_LENGTH
|
||||||
*/
|
*/
|
||||||
int aes_setkey_enc( aes_context *ctx, const unsigned char *key, unsigned int keysize );
|
int aes_setkey_enc(aes_context* ctx, const unsigned char* key, unsigned int keysize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief AES key schedule (decryption)
|
* \brief AES key schedule (decryption)
|
||||||
*
|
*
|
||||||
* \param ctx AES context to be initialized
|
* \param ctx AES context to be initialized
|
||||||
|
|
@ -79,9 +79,9 @@ int aes_setkey_enc( aes_context *ctx, const unsigned char *key, unsigned int key
|
||||||
*
|
*
|
||||||
* \return 0 if successful, or POLARSSL_ERR_AES_INVALID_KEY_LENGTH
|
* \return 0 if successful, or POLARSSL_ERR_AES_INVALID_KEY_LENGTH
|
||||||
*/
|
*/
|
||||||
int aes_setkey_dec( aes_context *ctx, const unsigned char *key, unsigned int keysize );
|
int aes_setkey_dec(aes_context* ctx, const unsigned char* key, unsigned int keysize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief AES-ECB block encryption/decryption
|
* \brief AES-ECB block encryption/decryption
|
||||||
*
|
*
|
||||||
* \param ctx AES context
|
* \param ctx AES context
|
||||||
|
|
@ -91,12 +91,12 @@ int aes_setkey_dec( aes_context *ctx, const unsigned char *key, unsigned int key
|
||||||
*
|
*
|
||||||
* \return 0 if successful
|
* \return 0 if successful
|
||||||
*/
|
*/
|
||||||
int aes_crypt_ecb( aes_context *ctx,
|
int aes_crypt_ecb(aes_context* ctx,
|
||||||
int mode,
|
int mode,
|
||||||
const unsigned char input[16],
|
const unsigned char input[16],
|
||||||
unsigned char output[16] );
|
unsigned char output[16]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief AES-CBC buffer encryption/decryption
|
* \brief AES-CBC buffer encryption/decryption
|
||||||
* Length should be a multiple of the block
|
* Length should be a multiple of the block
|
||||||
* size (16 bytes)
|
* size (16 bytes)
|
||||||
|
|
@ -110,14 +110,14 @@ int aes_crypt_ecb( aes_context *ctx,
|
||||||
*
|
*
|
||||||
* \return 0 if successful, or POLARSSL_ERR_AES_INVALID_INPUT_LENGTH
|
* \return 0 if successful, or POLARSSL_ERR_AES_INVALID_INPUT_LENGTH
|
||||||
*/
|
*/
|
||||||
int aes_crypt_cbc( aes_context *ctx,
|
int aes_crypt_cbc(aes_context* ctx,
|
||||||
int mode,
|
int mode,
|
||||||
size_t length,
|
size_t length,
|
||||||
unsigned char iv[16],
|
unsigned char iv[16],
|
||||||
const unsigned char *input,
|
const unsigned char* input,
|
||||||
unsigned char *output );
|
unsigned char* output);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief AES-CFB128 buffer encryption/decryption.
|
* \brief AES-CFB128 buffer encryption/decryption.
|
||||||
*
|
*
|
||||||
* Note: Due to the nature of CFB you should use the same key schedule for
|
* Note: Due to the nature of CFB you should use the same key schedule for
|
||||||
|
|
@ -135,15 +135,15 @@ int aes_crypt_cbc( aes_context *ctx,
|
||||||
*
|
*
|
||||||
* \return 0 if successful
|
* \return 0 if successful
|
||||||
*/
|
*/
|
||||||
int aes_crypt_cfb128( aes_context *ctx,
|
int aes_crypt_cfb128(aes_context* ctx,
|
||||||
int mode,
|
int mode,
|
||||||
size_t length,
|
size_t length,
|
||||||
size_t *iv_off,
|
size_t* iv_off,
|
||||||
unsigned char iv[16],
|
unsigned char iv[16],
|
||||||
const unsigned char *input,
|
const unsigned char* input,
|
||||||
unsigned char *output );
|
unsigned char* output);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief AES-CTR buffer encryption/decryption
|
* \brief AES-CTR buffer encryption/decryption
|
||||||
*
|
*
|
||||||
* Warning: You have to keep the maximum use of your counter in mind!
|
* Warning: You have to keep the maximum use of your counter in mind!
|
||||||
|
|
@ -164,15 +164,15 @@ int aes_crypt_cfb128( aes_context *ctx,
|
||||||
*
|
*
|
||||||
* \return 0 if successful
|
* \return 0 if successful
|
||||||
*/
|
*/
|
||||||
int aes_crypt_ctr( aes_context *ctx,
|
int aes_crypt_ctr(aes_context* ctx,
|
||||||
size_t length,
|
size_t length,
|
||||||
size_t *nc_off,
|
size_t* nc_off,
|
||||||
unsigned char nonce_counter[16],
|
unsigned char nonce_counter[16],
|
||||||
unsigned char stream_block[16],
|
unsigned char stream_block[16],
|
||||||
const unsigned char *input,
|
const unsigned char* input,
|
||||||
unsigned char *output );
|
unsigned char* output);
|
||||||
|
|
||||||
void aes_cmac(aes_context *ctx, size_t length, unsigned char *input, unsigned char *output);
|
void aes_cmac(aes_context* ctx, size_t length, unsigned char* input, unsigned char* output);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,61 +40,61 @@
|
||||||
/*
|
/*
|
||||||
* AES-NI support detection routine
|
* AES-NI support detection routine
|
||||||
*/
|
*/
|
||||||
int aesni_supports( unsigned int what )
|
int aesni_supports(unsigned int what)
|
||||||
{
|
{
|
||||||
static int done = 0;
|
static int done = 0;
|
||||||
static unsigned int c = 0;
|
static unsigned int c = 0;
|
||||||
|
|
||||||
if( ! done )
|
if (!done)
|
||||||
{
|
{
|
||||||
#if defined(POLARSSL_HAVE_MSVC_X64_INTRINSICS)
|
#if defined(POLARSSL_HAVE_MSVC_X64_INTRINSICS)
|
||||||
int regs[4]; // eax, ebx, ecx, edx
|
int regs[4]; // eax, ebx, ecx, edx
|
||||||
__cpuid( regs, 1 );
|
__cpuid(regs, 1);
|
||||||
c = regs[2];
|
c = regs[2];
|
||||||
#else
|
#else
|
||||||
asm( "movl $1, %%eax \n"
|
asm("movl $1, %%eax \n"
|
||||||
"cpuid \n"
|
"cpuid \n"
|
||||||
: "=c" (c)
|
: "=c"(c)
|
||||||
:
|
:
|
||||||
: "eax", "ebx", "edx" );
|
: "eax", "ebx", "edx");
|
||||||
#endif /* POLARSSL_HAVE_MSVC_X64_INTRINSICS */
|
#endif /* POLARSSL_HAVE_MSVC_X64_INTRINSICS */
|
||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return( ( c & what ) != 0 );
|
return ((c & what) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* AES-NI AES-ECB block en(de)cryption
|
* AES-NI AES-ECB block en(de)cryption
|
||||||
*/
|
*/
|
||||||
int aesni_crypt_ecb( aes_context *ctx,
|
int aesni_crypt_ecb(aes_context* ctx,
|
||||||
int mode,
|
int mode,
|
||||||
const unsigned char input[16],
|
const unsigned char input[16],
|
||||||
unsigned char output[16] )
|
unsigned char output[16])
|
||||||
{
|
{
|
||||||
#if defined(POLARSSL_HAVE_MSVC_X64_INTRINSICS)
|
#if defined(POLARSSL_HAVE_MSVC_X64_INTRINSICS)
|
||||||
__m128i* rk, a;
|
__m128i *rk, a;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
rk = (__m128i*)ctx->rk;
|
rk = (__m128i*)ctx->rk;
|
||||||
a = _mm_xor_si128( _mm_loadu_si128( (__m128i*)input ), _mm_loadu_si128( rk++ ) );
|
a = _mm_xor_si128(_mm_loadu_si128((__m128i*)input), _mm_loadu_si128(rk++));
|
||||||
|
|
||||||
if (mode == AES_ENCRYPT)
|
if (mode == AES_ENCRYPT)
|
||||||
{
|
{
|
||||||
for (i = ctx->nr - 1; i; --i)
|
for (i = ctx->nr - 1; i; --i)
|
||||||
a = _mm_aesenc_si128( a, _mm_loadu_si128( rk++ ) );
|
a = _mm_aesenc_si128(a, _mm_loadu_si128(rk++));
|
||||||
a = _mm_aesenclast_si128( a, _mm_loadu_si128( rk ) );
|
a = _mm_aesenclast_si128(a, _mm_loadu_si128(rk));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (i = ctx->nr - 1; i; --i)
|
for (i = ctx->nr - 1; i; --i)
|
||||||
a = _mm_aesdec_si128( a, _mm_loadu_si128( rk++ ) );
|
a = _mm_aesdec_si128(a, _mm_loadu_si128(rk++));
|
||||||
a = _mm_aesdeclast_si128( a, _mm_loadu_si128( rk ) );
|
a = _mm_aesdeclast_si128(a, _mm_loadu_si128(rk));
|
||||||
}
|
}
|
||||||
|
|
||||||
_mm_storeu_si128( (__m128i*)output, a );
|
_mm_storeu_si128((__m128i*)output, a);
|
||||||
#else
|
#else
|
||||||
asm( "movdqu (%3), %%xmm0 \n" // load input
|
asm("movdqu (%3), %%xmm0 \n" // load input
|
||||||
"movdqu (%1), %%xmm1 \n" // load round key 0
|
"movdqu (%1), %%xmm1 \n" // load round key 0
|
||||||
"pxor %%xmm1, %%xmm0 \n" // round 0
|
"pxor %%xmm1, %%xmm0 \n" // round 0
|
||||||
"addq $16, %1 \n" // point to next round key
|
"addq $16, %1 \n" // point to next round key
|
||||||
|
|
@ -124,67 +124,67 @@ int aesni_crypt_ecb( aes_context *ctx,
|
||||||
"3: \n"
|
"3: \n"
|
||||||
"movdqu %%xmm0, (%4) \n" // export output
|
"movdqu %%xmm0, (%4) \n" // export output
|
||||||
:
|
:
|
||||||
: "r" (ctx->nr), "r" (ctx->rk), "r" (mode), "r" (input), "r" (output)
|
: "r"(ctx->nr), "r"(ctx->rk), "r"(mode), "r"(input), "r"(output)
|
||||||
: "memory", "cc", "xmm0", "xmm1" );
|
: "memory", "cc", "xmm0", "xmm1");
|
||||||
#endif /* POLARSSL_HAVE_MSVC_X64_INTRINSICS */
|
#endif /* POLARSSL_HAVE_MSVC_X64_INTRINSICS */
|
||||||
|
|
||||||
return( 0 );
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(POLARSSL_HAVE_MSVC_X64_INTRINSICS)
|
#if defined(POLARSSL_HAVE_MSVC_X64_INTRINSICS)
|
||||||
static inline void clmul256( __m128i a, __m128i b, __m128i* r0, __m128i* r1 )
|
static inline void clmul256(__m128i a, __m128i b, __m128i* r0, __m128i* r1)
|
||||||
{
|
{
|
||||||
__m128i c, d, e, f, ef;
|
__m128i c, d, e, f, ef;
|
||||||
c = _mm_clmulepi64_si128( a, b, 0x00 );
|
c = _mm_clmulepi64_si128(a, b, 0x00);
|
||||||
d = _mm_clmulepi64_si128( a, b, 0x11 );
|
d = _mm_clmulepi64_si128(a, b, 0x11);
|
||||||
e = _mm_clmulepi64_si128( a, b, 0x10 );
|
e = _mm_clmulepi64_si128(a, b, 0x10);
|
||||||
f = _mm_clmulepi64_si128( a, b, 0x01 );
|
f = _mm_clmulepi64_si128(a, b, 0x01);
|
||||||
|
|
||||||
// r0 = f0^e0^c1:c0 = c1:c0 ^ f0^e0:0
|
// r0 = f0^e0^c1:c0 = c1:c0 ^ f0^e0:0
|
||||||
// r1 = d1:f1^e1^d0 = d1:d0 ^ 0:f1^e1
|
// r1 = d1:f1^e1^d0 = d1:d0 ^ 0:f1^e1
|
||||||
|
|
||||||
ef = _mm_xor_si128( e, f );
|
ef = _mm_xor_si128(e, f);
|
||||||
*r0 = _mm_xor_si128( c, _mm_slli_si128( ef, 8 ) );
|
*r0 = _mm_xor_si128(c, _mm_slli_si128(ef, 8));
|
||||||
*r1 = _mm_xor_si128( d, _mm_srli_si128( ef, 8 ) );
|
*r1 = _mm_xor_si128(d, _mm_srli_si128(ef, 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void sll256( __m128i a0, __m128i a1, __m128i* s0, __m128i* s1 )
|
static inline void sll256(__m128i a0, __m128i a1, __m128i* s0, __m128i* s1)
|
||||||
{
|
{
|
||||||
__m128i l0, l1, r0, r1;
|
__m128i l0, l1, r0, r1;
|
||||||
|
|
||||||
l0 = _mm_slli_epi64( a0, 1 );
|
l0 = _mm_slli_epi64(a0, 1);
|
||||||
l1 = _mm_slli_epi64( a1, 1 );
|
l1 = _mm_slli_epi64(a1, 1);
|
||||||
|
|
||||||
r0 = _mm_srli_epi64( a0, 63 );
|
r0 = _mm_srli_epi64(a0, 63);
|
||||||
r1 = _mm_srli_epi64( a1, 63 );
|
r1 = _mm_srli_epi64(a1, 63);
|
||||||
|
|
||||||
*s0 = _mm_or_si128( l0, _mm_slli_si128( r0, 8 ) );
|
*s0 = _mm_or_si128(l0, _mm_slli_si128(r0, 8));
|
||||||
*s1 = _mm_or_si128( _mm_or_si128( l1, _mm_srli_si128( r0, 8 ) ), _mm_slli_si128( r1, 8 ) );
|
*s1 = _mm_or_si128(_mm_or_si128(l1, _mm_srli_si128(r0, 8)), _mm_slli_si128(r1, 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline __m128i reducemod128( __m128i x10, __m128i x32 )
|
static inline __m128i reducemod128(__m128i x10, __m128i x32)
|
||||||
{
|
{
|
||||||
__m128i a, b, c, dx0, e, f, g, h;
|
__m128i a, b, c, dx0, e, f, g, h;
|
||||||
|
|
||||||
// (1) left shift x0 by 63, 62 and 57
|
// (1) left shift x0 by 63, 62 and 57
|
||||||
a = _mm_slli_epi64( x10, 63 );
|
a = _mm_slli_epi64(x10, 63);
|
||||||
b = _mm_slli_epi64( x10, 62 );
|
b = _mm_slli_epi64(x10, 62);
|
||||||
c = _mm_slli_epi64( x10, 57 );
|
c = _mm_slli_epi64(x10, 57);
|
||||||
|
|
||||||
// (2) compute D xor'ing a, b, c and x1
|
// (2) compute D xor'ing a, b, c and x1
|
||||||
// d:x0 = x1:x0 ^ [a^b^c:0]
|
// d:x0 = x1:x0 ^ [a^b^c:0]
|
||||||
dx0 = _mm_xor_si128( x10, _mm_slli_si128( _mm_xor_si128( _mm_xor_si128( a, b ), c ), 8 ) );
|
dx0 = _mm_xor_si128(x10, _mm_slli_si128(_mm_xor_si128(_mm_xor_si128(a, b), c), 8));
|
||||||
|
|
||||||
// (3) right shift [d:x0] by 1, 2, 7
|
// (3) right shift [d:x0] by 1, 2, 7
|
||||||
e = _mm_or_si128( _mm_srli_epi64( dx0, 1 ), _mm_srli_si128( _mm_slli_epi64( dx0, 63 ), 8 ) );
|
e = _mm_or_si128(_mm_srli_epi64(dx0, 1), _mm_srli_si128(_mm_slli_epi64(dx0, 63), 8));
|
||||||
f = _mm_or_si128( _mm_srli_epi64( dx0, 2 ), _mm_srli_si128( _mm_slli_epi64( dx0, 62 ), 8 ) );
|
f = _mm_or_si128(_mm_srli_epi64(dx0, 2), _mm_srli_si128(_mm_slli_epi64(dx0, 62), 8));
|
||||||
g = _mm_or_si128( _mm_srli_epi64( dx0, 7 ), _mm_srli_si128( _mm_slli_epi64( dx0, 57 ), 8 ) );
|
g = _mm_or_si128(_mm_srli_epi64(dx0, 7), _mm_srli_si128(_mm_slli_epi64(dx0, 57), 8));
|
||||||
|
|
||||||
// (4) compute h = d^e1^f1^g1 : x0^e0^f0^g0
|
// (4) compute h = d^e1^f1^g1 : x0^e0^f0^g0
|
||||||
h = _mm_xor_si128( dx0, _mm_xor_si128( e, _mm_xor_si128( f, g ) ) );
|
h = _mm_xor_si128(dx0, _mm_xor_si128(e, _mm_xor_si128(f, g)));
|
||||||
|
|
||||||
// result is x3^h1:x2^h0
|
// result is x3^h1:x2^h0
|
||||||
return _mm_xor_si128( x32, h );
|
return _mm_xor_si128(x32, h);
|
||||||
}
|
}
|
||||||
#endif /* POLARSSL_HAVE_MSVC_X64_INTRINSICS */
|
#endif /* POLARSSL_HAVE_MSVC_X64_INTRINSICS */
|
||||||
|
|
||||||
|
|
@ -192,36 +192,36 @@ static inline __m128i reducemod128( __m128i x10, __m128i x32 )
|
||||||
* GCM multiplication: c = a times b in GF(2^128)
|
* GCM multiplication: c = a times b in GF(2^128)
|
||||||
* Based on [CLMUL-WP] algorithms 1 (with equation 27) and 5.
|
* Based on [CLMUL-WP] algorithms 1 (with equation 27) and 5.
|
||||||
*/
|
*/
|
||||||
void aesni_gcm_mult( unsigned char c[16],
|
void aesni_gcm_mult(unsigned char c[16],
|
||||||
const unsigned char a[16],
|
const unsigned char a[16],
|
||||||
const unsigned char b[16] )
|
const unsigned char b[16])
|
||||||
{
|
{
|
||||||
#if defined(POLARSSL_HAVE_MSVC_X64_INTRINSICS)
|
#if defined(POLARSSL_HAVE_MSVC_X64_INTRINSICS)
|
||||||
__m128i xa, xb, m0, m1, x10, x32, r;
|
__m128i xa, xb, m0, m1, x10, x32, r;
|
||||||
|
|
||||||
xa.m128i_u64[1] = _byteswap_uint64( *((unsigned __int64*)a + 0) );
|
xa.m128i_u64[1] = _byteswap_uint64(*((unsigned __int64*)a + 0));
|
||||||
xa.m128i_u64[0] = _byteswap_uint64( *((unsigned __int64*)a + 1) );
|
xa.m128i_u64[0] = _byteswap_uint64(*((unsigned __int64*)a + 1));
|
||||||
xb.m128i_u64[1] = _byteswap_uint64( *((unsigned __int64*)b + 0) );
|
xb.m128i_u64[1] = _byteswap_uint64(*((unsigned __int64*)b + 0));
|
||||||
xb.m128i_u64[0] = _byteswap_uint64( *((unsigned __int64*)b + 1) );
|
xb.m128i_u64[0] = _byteswap_uint64(*((unsigned __int64*)b + 1));
|
||||||
|
|
||||||
clmul256( xa, xb, &m0, &m1 );
|
clmul256(xa, xb, &m0, &m1);
|
||||||
sll256( m0, m1, &x10, &x32 );
|
sll256(m0, m1, &x10, &x32);
|
||||||
r = reducemod128( x10, x32 );
|
r = reducemod128(x10, x32);
|
||||||
|
|
||||||
*((unsigned __int64*)c + 0) = _byteswap_uint64( r.m128i_u64[1] );
|
*((unsigned __int64*)c + 0) = _byteswap_uint64(r.m128i_u64[1]);
|
||||||
*((unsigned __int64*)c + 1) = _byteswap_uint64( r.m128i_u64[0] );
|
*((unsigned __int64*)c + 1) = _byteswap_uint64(r.m128i_u64[0]);
|
||||||
#else
|
#else
|
||||||
unsigned char aa[16], bb[16], cc[16];
|
unsigned char aa[16], bb[16], cc[16];
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
/* The inputs are in big-endian order, so byte-reverse them */
|
/* The inputs are in big-endian order, so byte-reverse them */
|
||||||
for( i = 0; i < 16; i++ )
|
for (i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
aa[i] = a[15 - i];
|
aa[i] = a[15 - i];
|
||||||
bb[i] = b[15 - i];
|
bb[i] = b[15 - i];
|
||||||
}
|
}
|
||||||
|
|
||||||
asm( "movdqu (%0), %%xmm0 \n" // a1:a0
|
asm("movdqu (%0), %%xmm0 \n" // a1:a0
|
||||||
"movdqu (%1), %%xmm1 \n" // b1:b0
|
"movdqu (%1), %%xmm1 \n" // b1:b0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -305,11 +305,11 @@ void aesni_gcm_mult( unsigned char c[16],
|
||||||
|
|
||||||
"movdqu %%xmm0, (%2) \n" // done
|
"movdqu %%xmm0, (%2) \n" // done
|
||||||
:
|
:
|
||||||
: "r" (aa), "r" (bb), "r" (cc)
|
: "r"(aa), "r"(bb), "r"(cc)
|
||||||
: "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" );
|
: "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5");
|
||||||
|
|
||||||
/* Now byte-reverse the outputs */
|
/* Now byte-reverse the outputs */
|
||||||
for( i = 0; i < 16; i++ )
|
for (i = 0; i < 16; i++)
|
||||||
c[i] = cc[15 - i];
|
c[i] = cc[15 - i];
|
||||||
#endif /* POLARSSL_HAVE_MSVC_X64_INTRINSICS */
|
#endif /* POLARSSL_HAVE_MSVC_X64_INTRINSICS */
|
||||||
|
|
||||||
|
|
@ -319,118 +319,118 @@ void aesni_gcm_mult( unsigned char c[16],
|
||||||
/*
|
/*
|
||||||
* Compute decryption round keys from encryption round keys
|
* Compute decryption round keys from encryption round keys
|
||||||
*/
|
*/
|
||||||
void aesni_inverse_key( unsigned char *invkey,
|
void aesni_inverse_key(unsigned char* invkey,
|
||||||
const unsigned char *fwdkey, int nr )
|
const unsigned char* fwdkey, int nr)
|
||||||
{
|
{
|
||||||
unsigned char *ik = invkey;
|
unsigned char* ik = invkey;
|
||||||
const unsigned char *fk = fwdkey + 16 * nr;
|
const unsigned char* fk = fwdkey + 16 * nr;
|
||||||
|
|
||||||
memcpy( ik, fk, 16 );
|
memcpy(ik, fk, 16);
|
||||||
|
|
||||||
for( fk -= 16, ik += 16; fk > fwdkey; fk -= 16, ik += 16 )
|
for (fk -= 16, ik += 16; fk > fwdkey; fk -= 16, ik += 16)
|
||||||
#if defined(POLARSSL_HAVE_MSVC_X64_INTRINSICS)
|
#if defined(POLARSSL_HAVE_MSVC_X64_INTRINSICS)
|
||||||
_mm_storeu_si128( (__m128i*)ik, _mm_aesimc_si128( _mm_loadu_si128( (__m128i*)fk) ) );
|
_mm_storeu_si128((__m128i*)ik, _mm_aesimc_si128(_mm_loadu_si128((__m128i*)fk)));
|
||||||
#else
|
#else
|
||||||
asm( "movdqu (%0), %%xmm0 \n"
|
asm("movdqu (%0), %%xmm0 \n"
|
||||||
"aesimc %%xmm0, %%xmm0 \n"
|
"aesimc %%xmm0, %%xmm0 \n"
|
||||||
"movdqu %%xmm0, (%1) \n"
|
"movdqu %%xmm0, (%1) \n"
|
||||||
:
|
:
|
||||||
: "r" (fk), "r" (ik)
|
: "r"(fk), "r"(ik)
|
||||||
: "memory", "xmm0" );
|
: "memory", "xmm0");
|
||||||
#endif /* POLARSSL_HAVE_MSVC_X64_INTRINSICS */
|
#endif /* POLARSSL_HAVE_MSVC_X64_INTRINSICS */
|
||||||
|
|
||||||
memcpy( ik, fk, 16 );
|
memcpy(ik, fk, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(POLARSSL_HAVE_MSVC_X64_INTRINSICS)
|
#if defined(POLARSSL_HAVE_MSVC_X64_INTRINSICS)
|
||||||
inline static __m128i aes_key_128_assist( __m128i key, __m128i kg )
|
inline static __m128i aes_key_128_assist(__m128i key, __m128i kg)
|
||||||
{
|
{
|
||||||
key = _mm_xor_si128( key, _mm_slli_si128( key, 4 ) );
|
key = _mm_xor_si128(key, _mm_slli_si128(key, 4));
|
||||||
key = _mm_xor_si128( key, _mm_slli_si128( key, 4 ) );
|
key = _mm_xor_si128(key, _mm_slli_si128(key, 4));
|
||||||
key = _mm_xor_si128( key, _mm_slli_si128( key, 4 ) );
|
key = _mm_xor_si128(key, _mm_slli_si128(key, 4));
|
||||||
kg = _mm_shuffle_epi32( kg, _MM_SHUFFLE( 3, 3, 3, 3 ) );
|
kg = _mm_shuffle_epi32(kg, _MM_SHUFFLE(3, 3, 3, 3));
|
||||||
return _mm_xor_si128( key, kg );
|
return _mm_xor_si128(key, kg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [AES-WP] Part of Fig. 25 page 32
|
// [AES-WP] Part of Fig. 25 page 32
|
||||||
inline static void aes_key_192_assist( __m128i* temp1, __m128i * temp3, __m128i kg )
|
inline static void aes_key_192_assist(__m128i* temp1, __m128i* temp3, __m128i kg)
|
||||||
{
|
{
|
||||||
__m128i temp4;
|
__m128i temp4;
|
||||||
kg = _mm_shuffle_epi32( kg, 0x55 );
|
kg = _mm_shuffle_epi32(kg, 0x55);
|
||||||
temp4 = _mm_slli_si128( *temp1, 0x4 );
|
temp4 = _mm_slli_si128(*temp1, 0x4);
|
||||||
*temp1 = _mm_xor_si128( *temp1, temp4 );
|
*temp1 = _mm_xor_si128(*temp1, temp4);
|
||||||
temp4 = _mm_slli_si128( temp4, 0x4 );
|
temp4 = _mm_slli_si128(temp4, 0x4);
|
||||||
*temp1 = _mm_xor_si128( *temp1, temp4 );
|
*temp1 = _mm_xor_si128(*temp1, temp4);
|
||||||
temp4 = _mm_slli_si128( temp4, 0x4 );
|
temp4 = _mm_slli_si128(temp4, 0x4);
|
||||||
*temp1 = _mm_xor_si128( *temp1, temp4 );
|
*temp1 = _mm_xor_si128(*temp1, temp4);
|
||||||
*temp1 = _mm_xor_si128( *temp1, kg );
|
*temp1 = _mm_xor_si128(*temp1, kg);
|
||||||
kg = _mm_shuffle_epi32( *temp1, 0xff );
|
kg = _mm_shuffle_epi32(*temp1, 0xff);
|
||||||
temp4 = _mm_slli_si128( *temp3, 0x4 );
|
temp4 = _mm_slli_si128(*temp3, 0x4);
|
||||||
*temp3 = _mm_xor_si128( *temp3, temp4 );
|
*temp3 = _mm_xor_si128(*temp3, temp4);
|
||||||
*temp3 = _mm_xor_si128( *temp3, kg );
|
*temp3 = _mm_xor_si128(*temp3, kg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [AES-WP] Part of Fig. 26 page 34
|
// [AES-WP] Part of Fig. 26 page 34
|
||||||
inline static void aes_key_256_assist_1( __m128i* temp1, __m128i kg )
|
inline static void aes_key_256_assist_1(__m128i* temp1, __m128i kg)
|
||||||
{
|
{
|
||||||
__m128i temp4;
|
__m128i temp4;
|
||||||
kg = _mm_shuffle_epi32( kg, 0xff );
|
kg = _mm_shuffle_epi32(kg, 0xff);
|
||||||
temp4 = _mm_slli_si128( *temp1, 0x4 );
|
temp4 = _mm_slli_si128(*temp1, 0x4);
|
||||||
*temp1 = _mm_xor_si128( *temp1, temp4 );
|
*temp1 = _mm_xor_si128(*temp1, temp4);
|
||||||
temp4 = _mm_slli_si128( temp4, 0x4 );
|
temp4 = _mm_slli_si128(temp4, 0x4);
|
||||||
*temp1 = _mm_xor_si128( *temp1, temp4 );
|
*temp1 = _mm_xor_si128(*temp1, temp4);
|
||||||
temp4 = _mm_slli_si128( temp4, 0x4 );
|
temp4 = _mm_slli_si128(temp4, 0x4);
|
||||||
*temp1 = _mm_xor_si128( *temp1, temp4 );
|
*temp1 = _mm_xor_si128(*temp1, temp4);
|
||||||
*temp1 = _mm_xor_si128( *temp1, kg );
|
*temp1 = _mm_xor_si128(*temp1, kg);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static void aes_key_256_assist_2( __m128i* temp1, __m128i* temp3 )
|
inline static void aes_key_256_assist_2(__m128i* temp1, __m128i* temp3)
|
||||||
{
|
{
|
||||||
__m128i temp2, temp4;
|
__m128i temp2, temp4;
|
||||||
temp4 = _mm_aeskeygenassist_si128( *temp1, 0x0 );
|
temp4 = _mm_aeskeygenassist_si128(*temp1, 0x0);
|
||||||
temp2 = _mm_shuffle_epi32( temp4, 0xaa );
|
temp2 = _mm_shuffle_epi32(temp4, 0xaa);
|
||||||
temp4 = _mm_slli_si128( *temp3, 0x4 );
|
temp4 = _mm_slli_si128(*temp3, 0x4);
|
||||||
*temp3 = _mm_xor_si128( *temp3, temp4 );
|
*temp3 = _mm_xor_si128(*temp3, temp4);
|
||||||
temp4 = _mm_slli_si128( temp4, 0x4 );
|
temp4 = _mm_slli_si128(temp4, 0x4);
|
||||||
*temp3 = _mm_xor_si128( *temp3, temp4 );
|
*temp3 = _mm_xor_si128(*temp3, temp4);
|
||||||
temp4 = _mm_slli_si128( temp4, 0x4 );
|
temp4 = _mm_slli_si128(temp4, 0x4);
|
||||||
*temp3 = _mm_xor_si128( *temp3, temp4 );
|
*temp3 = _mm_xor_si128(*temp3, temp4);
|
||||||
*temp3 = _mm_xor_si128( *temp3, temp2 );
|
*temp3 = _mm_xor_si128(*temp3, temp2);
|
||||||
}
|
}
|
||||||
#endif /* POLARSSL_HAVE_MSVC_X64_INTRINSICS */
|
#endif /* POLARSSL_HAVE_MSVC_X64_INTRINSICS */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Key expansion, 128-bit case
|
* Key expansion, 128-bit case
|
||||||
*/
|
*/
|
||||||
static void aesni_setkey_enc_128( unsigned char *rk,
|
static void aesni_setkey_enc_128(unsigned char* rk,
|
||||||
const unsigned char *key )
|
const unsigned char* key)
|
||||||
{
|
{
|
||||||
#if defined(POLARSSL_HAVE_MSVC_X64_INTRINSICS)
|
#if defined(POLARSSL_HAVE_MSVC_X64_INTRINSICS)
|
||||||
__m128i* xrk, k;
|
__m128i *xrk, k;
|
||||||
|
|
||||||
xrk = (__m128i*)rk;
|
xrk = (__m128i*)rk;
|
||||||
|
|
||||||
#define EXPAND_ROUND(k, rcon) \
|
#define EXPAND_ROUND(k, rcon) \
|
||||||
_mm_storeu_si128( xrk++, k ); \
|
_mm_storeu_si128(xrk++, k); \
|
||||||
k = aes_key_128_assist( k, _mm_aeskeygenassist_si128( k, rcon ) )
|
k = aes_key_128_assist(k, _mm_aeskeygenassist_si128(k, rcon))
|
||||||
|
|
||||||
k = _mm_loadu_si128( (__m128i*)key );
|
k = _mm_loadu_si128((__m128i*)key);
|
||||||
EXPAND_ROUND( k, 0x01 );
|
EXPAND_ROUND(k, 0x01);
|
||||||
EXPAND_ROUND( k, 0x02 );
|
EXPAND_ROUND(k, 0x02);
|
||||||
EXPAND_ROUND( k, 0x04 );
|
EXPAND_ROUND(k, 0x04);
|
||||||
EXPAND_ROUND( k, 0x08 );
|
EXPAND_ROUND(k, 0x08);
|
||||||
EXPAND_ROUND( k, 0x10 );
|
EXPAND_ROUND(k, 0x10);
|
||||||
EXPAND_ROUND( k, 0x20 );
|
EXPAND_ROUND(k, 0x20);
|
||||||
EXPAND_ROUND( k, 0x40 );
|
EXPAND_ROUND(k, 0x40);
|
||||||
EXPAND_ROUND( k, 0x80 );
|
EXPAND_ROUND(k, 0x80);
|
||||||
EXPAND_ROUND( k, 0x1b );
|
EXPAND_ROUND(k, 0x1b);
|
||||||
EXPAND_ROUND( k, 0x36 );
|
EXPAND_ROUND(k, 0x36);
|
||||||
_mm_storeu_si128( xrk, k );
|
_mm_storeu_si128(xrk, k);
|
||||||
|
|
||||||
#undef EXPAND_ROUND
|
#undef EXPAND_ROUND
|
||||||
|
|
||||||
#else
|
#else
|
||||||
asm( "movdqu (%1), %%xmm0 \n" // copy the original key
|
asm("movdqu (%1), %%xmm0 \n" // copy the original key
|
||||||
"movdqu %%xmm0, (%0) \n" // as round key 0
|
"movdqu %%xmm0, (%0) \n" // as round key 0
|
||||||
"jmp 2f \n" // skip auxiliary routine
|
"jmp 2f \n" // skip auxiliary routine
|
||||||
|
|
||||||
|
|
@ -470,49 +470,49 @@ static void aesni_setkey_enc_128( unsigned char *rk,
|
||||||
"aeskeygenassist $0x1B, %%xmm0, %%xmm1 \ncall 1b \n"
|
"aeskeygenassist $0x1B, %%xmm0, %%xmm1 \ncall 1b \n"
|
||||||
"aeskeygenassist $0x36, %%xmm0, %%xmm1 \ncall 1b \n"
|
"aeskeygenassist $0x36, %%xmm0, %%xmm1 \ncall 1b \n"
|
||||||
:
|
:
|
||||||
: "r" (rk), "r" (key)
|
: "r"(rk), "r"(key)
|
||||||
: "memory", "cc", "0" );
|
: "memory", "cc", "0");
|
||||||
#endif /* POLARSSL_HAVE_MSVC_X64_INTRINSICS */
|
#endif /* POLARSSL_HAVE_MSVC_X64_INTRINSICS */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Key expansion, 192-bit case
|
* Key expansion, 192-bit case
|
||||||
*/
|
*/
|
||||||
static void aesni_setkey_enc_192( unsigned char *rk,
|
static void aesni_setkey_enc_192(unsigned char* rk,
|
||||||
const unsigned char *key )
|
const unsigned char* key)
|
||||||
{
|
{
|
||||||
#if defined(POLARSSL_HAVE_MSVC_X64_INTRINSICS)
|
#if defined(POLARSSL_HAVE_MSVC_X64_INTRINSICS)
|
||||||
__m128i temp1, temp3;
|
__m128i temp1, temp3;
|
||||||
__m128i *key_schedule = (__m128i*)rk;
|
__m128i* key_schedule = (__m128i*)rk;
|
||||||
temp1 = _mm_loadu_si128( (__m128i*)key );
|
temp1 = _mm_loadu_si128((__m128i*)key);
|
||||||
temp3 = _mm_loadu_si128( (__m128i*)(key + 16) );
|
temp3 = _mm_loadu_si128((__m128i*)(key + 16));
|
||||||
key_schedule[0] = temp1;
|
key_schedule[0] = temp1;
|
||||||
key_schedule[1] = temp3;
|
key_schedule[1] = temp3;
|
||||||
aes_key_192_assist( &temp1, &temp3, _mm_aeskeygenassist_si128(temp3, 0x1) );
|
aes_key_192_assist(&temp1, &temp3, _mm_aeskeygenassist_si128(temp3, 0x1));
|
||||||
key_schedule[1] = _mm_castpd_si128( _mm_shuffle_pd( _mm_castsi128_pd( key_schedule[1] ), _mm_castsi128_pd( temp1 ), 0 ) );
|
key_schedule[1] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_schedule[1]), _mm_castsi128_pd(temp1), 0));
|
||||||
key_schedule[2] = _mm_castpd_si128( _mm_shuffle_pd( _mm_castsi128_pd( temp1 ), _mm_castsi128_pd( temp3 ), 1 ) );
|
key_schedule[2] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(temp1), _mm_castsi128_pd(temp3), 1));
|
||||||
aes_key_192_assist( &temp1, &temp3, _mm_aeskeygenassist_si128( temp3, 0x2 ) );
|
aes_key_192_assist(&temp1, &temp3, _mm_aeskeygenassist_si128(temp3, 0x2));
|
||||||
key_schedule[3] = temp1;
|
key_schedule[3] = temp1;
|
||||||
key_schedule[4] = temp3;
|
key_schedule[4] = temp3;
|
||||||
aes_key_192_assist( &temp1, &temp3, _mm_aeskeygenassist_si128( temp3, 0x4 ) );
|
aes_key_192_assist(&temp1, &temp3, _mm_aeskeygenassist_si128(temp3, 0x4));
|
||||||
key_schedule[4] = _mm_castpd_si128( _mm_shuffle_pd( _mm_castsi128_pd( key_schedule[4] ), _mm_castsi128_pd( temp1 ), 0 ) );
|
key_schedule[4] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_schedule[4]), _mm_castsi128_pd(temp1), 0));
|
||||||
key_schedule[5] = _mm_castpd_si128( _mm_shuffle_pd( _mm_castsi128_pd( temp1 ), _mm_castsi128_pd( temp3 ), 1 ) );
|
key_schedule[5] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(temp1), _mm_castsi128_pd(temp3), 1));
|
||||||
aes_key_192_assist( &temp1, &temp3, _mm_aeskeygenassist_si128( temp3, 0x8 ) );
|
aes_key_192_assist(&temp1, &temp3, _mm_aeskeygenassist_si128(temp3, 0x8));
|
||||||
key_schedule[6] = temp1;
|
key_schedule[6] = temp1;
|
||||||
key_schedule[7] = temp3;
|
key_schedule[7] = temp3;
|
||||||
aes_key_192_assist( &temp1, &temp3, _mm_aeskeygenassist_si128( temp3, 0x10 ) );
|
aes_key_192_assist(&temp1, &temp3, _mm_aeskeygenassist_si128(temp3, 0x10));
|
||||||
key_schedule[7] = _mm_castpd_si128( _mm_shuffle_pd( _mm_castsi128_pd( key_schedule[7] ), _mm_castsi128_pd( temp1 ), 0 ) );
|
key_schedule[7] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_schedule[7]), _mm_castsi128_pd(temp1), 0));
|
||||||
key_schedule[8] = _mm_castpd_si128( _mm_shuffle_pd( _mm_castsi128_pd( temp1 ), _mm_castsi128_pd( temp3 ), 1 ) );
|
key_schedule[8] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(temp1), _mm_castsi128_pd(temp3), 1));
|
||||||
aes_key_192_assist( &temp1, &temp3, _mm_aeskeygenassist_si128( temp3, 0x20 ) );
|
aes_key_192_assist(&temp1, &temp3, _mm_aeskeygenassist_si128(temp3, 0x20));
|
||||||
key_schedule[9] = temp1;
|
key_schedule[9] = temp1;
|
||||||
key_schedule[10] = temp3;
|
key_schedule[10] = temp3;
|
||||||
aes_key_192_assist( &temp1, &temp3, _mm_aeskeygenassist_si128( temp3, 0x40 ) );
|
aes_key_192_assist(&temp1, &temp3, _mm_aeskeygenassist_si128(temp3, 0x40));
|
||||||
key_schedule[10] = _mm_castpd_si128( _mm_shuffle_pd( _mm_castsi128_pd( key_schedule[10] ), _mm_castsi128_pd( temp1 ), 0 ) );
|
key_schedule[10] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_schedule[10]), _mm_castsi128_pd(temp1), 0));
|
||||||
key_schedule[11] = _mm_castpd_si128( _mm_shuffle_pd( _mm_castsi128_pd( temp1 ), _mm_castsi128_pd( temp3 ), 1 ) );
|
key_schedule[11] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(temp1), _mm_castsi128_pd(temp3), 1));
|
||||||
aes_key_192_assist( &temp1, &temp3, _mm_aeskeygenassist_si128( temp3, 0x80 ) );
|
aes_key_192_assist(&temp1, &temp3, _mm_aeskeygenassist_si128(temp3, 0x80));
|
||||||
key_schedule[12] = temp1;
|
key_schedule[12] = temp1;
|
||||||
#else
|
#else
|
||||||
asm( "movdqu (%1), %%xmm0 \n" // copy original round key
|
asm("movdqu (%1), %%xmm0 \n" // copy original round key
|
||||||
"movdqu %%xmm0, (%0) \n"
|
"movdqu %%xmm0, (%0) \n"
|
||||||
"add $16, %0 \n"
|
"add $16, %0 \n"
|
||||||
"movq 16(%1), %%xmm1 \n"
|
"movq 16(%1), %%xmm1 \n"
|
||||||
|
|
@ -559,52 +559,52 @@ static void aesni_setkey_enc_192( unsigned char *rk,
|
||||||
"aeskeygenassist $0x80, %%xmm1, %%xmm2 \ncall 1b \n"
|
"aeskeygenassist $0x80, %%xmm1, %%xmm2 \ncall 1b \n"
|
||||||
|
|
||||||
:
|
:
|
||||||
: "r" (rk), "r" (key)
|
: "r"(rk), "r"(key)
|
||||||
: "memory", "cc", "0" );
|
: "memory", "cc", "0");
|
||||||
#endif /* POLARSSL_HAVE_MSVC_X64_INTRINSICS */
|
#endif /* POLARSSL_HAVE_MSVC_X64_INTRINSICS */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Key expansion, 256-bit case
|
* Key expansion, 256-bit case
|
||||||
*/
|
*/
|
||||||
static void aesni_setkey_enc_256( unsigned char *rk,
|
static void aesni_setkey_enc_256(unsigned char* rk,
|
||||||
const unsigned char *key )
|
const unsigned char* key)
|
||||||
{
|
{
|
||||||
#if defined(POLARSSL_HAVE_MSVC_X64_INTRINSICS)
|
#if defined(POLARSSL_HAVE_MSVC_X64_INTRINSICS)
|
||||||
__m128i temp1, temp3;
|
__m128i temp1, temp3;
|
||||||
__m128i *key_schedule = (__m128i*)rk;
|
__m128i* key_schedule = (__m128i*)rk;
|
||||||
temp1 = _mm_loadu_si128( (__m128i*)key );
|
temp1 = _mm_loadu_si128((__m128i*)key);
|
||||||
temp3 = _mm_loadu_si128( (__m128i*)(key + 16) );
|
temp3 = _mm_loadu_si128((__m128i*)(key + 16));
|
||||||
key_schedule[0] = temp1;
|
key_schedule[0] = temp1;
|
||||||
key_schedule[1] = temp3;
|
key_schedule[1] = temp3;
|
||||||
aes_key_256_assist_1( &temp1, _mm_aeskeygenassist_si128( temp3, 0x01 ) );
|
aes_key_256_assist_1(&temp1, _mm_aeskeygenassist_si128(temp3, 0x01));
|
||||||
key_schedule[2] = temp1;
|
key_schedule[2] = temp1;
|
||||||
aes_key_256_assist_2( &temp1, &temp3 );
|
aes_key_256_assist_2(&temp1, &temp3);
|
||||||
key_schedule[3] = temp3;
|
key_schedule[3] = temp3;
|
||||||
aes_key_256_assist_1( &temp1, _mm_aeskeygenassist_si128( temp3, 0x02 ) );
|
aes_key_256_assist_1(&temp1, _mm_aeskeygenassist_si128(temp3, 0x02));
|
||||||
key_schedule[4] = temp1;
|
key_schedule[4] = temp1;
|
||||||
aes_key_256_assist_2( &temp1, &temp3 );
|
aes_key_256_assist_2(&temp1, &temp3);
|
||||||
key_schedule[5] = temp3;
|
key_schedule[5] = temp3;
|
||||||
aes_key_256_assist_1( &temp1, _mm_aeskeygenassist_si128( temp3, 0x04 ) );
|
aes_key_256_assist_1(&temp1, _mm_aeskeygenassist_si128(temp3, 0x04));
|
||||||
key_schedule[6] = temp1;
|
key_schedule[6] = temp1;
|
||||||
aes_key_256_assist_2( &temp1, &temp3 );
|
aes_key_256_assist_2(&temp1, &temp3);
|
||||||
key_schedule[7] = temp3;
|
key_schedule[7] = temp3;
|
||||||
aes_key_256_assist_1( &temp1, _mm_aeskeygenassist_si128( temp3, 0x08 ) );
|
aes_key_256_assist_1(&temp1, _mm_aeskeygenassist_si128(temp3, 0x08));
|
||||||
key_schedule[8] = temp1;
|
key_schedule[8] = temp1;
|
||||||
aes_key_256_assist_2( &temp1, &temp3 );
|
aes_key_256_assist_2(&temp1, &temp3);
|
||||||
key_schedule[9] = temp3;
|
key_schedule[9] = temp3;
|
||||||
aes_key_256_assist_1( &temp1, _mm_aeskeygenassist_si128( temp3, 0x10 ) );
|
aes_key_256_assist_1(&temp1, _mm_aeskeygenassist_si128(temp3, 0x10));
|
||||||
key_schedule[10] = temp1;
|
key_schedule[10] = temp1;
|
||||||
aes_key_256_assist_2( &temp1, &temp3 );
|
aes_key_256_assist_2(&temp1, &temp3);
|
||||||
key_schedule[11] = temp3;
|
key_schedule[11] = temp3;
|
||||||
aes_key_256_assist_1( &temp1, _mm_aeskeygenassist_si128( temp3, 0x20 ) );
|
aes_key_256_assist_1(&temp1, _mm_aeskeygenassist_si128(temp3, 0x20));
|
||||||
key_schedule[12] = temp1;
|
key_schedule[12] = temp1;
|
||||||
aes_key_256_assist_2( &temp1, &temp3 );
|
aes_key_256_assist_2(&temp1, &temp3);
|
||||||
key_schedule[13] = temp3;
|
key_schedule[13] = temp3;
|
||||||
aes_key_256_assist_1( &temp1, _mm_aeskeygenassist_si128( temp3, 0x40 ) );
|
aes_key_256_assist_1(&temp1, _mm_aeskeygenassist_si128(temp3, 0x40));
|
||||||
key_schedule[14] = temp1;
|
key_schedule[14] = temp1;
|
||||||
#else
|
#else
|
||||||
asm( "movdqu (%1), %%xmm0 \n"
|
asm("movdqu (%1), %%xmm0 \n"
|
||||||
"movdqu %%xmm0, (%0) \n"
|
"movdqu %%xmm0, (%0) \n"
|
||||||
"add $16, %0 \n"
|
"add $16, %0 \n"
|
||||||
"movdqu 16(%1), %%xmm1 \n"
|
"movdqu 16(%1), %%xmm1 \n"
|
||||||
|
|
@ -660,27 +660,27 @@ static void aesni_setkey_enc_256( unsigned char *rk,
|
||||||
"aeskeygenassist $0x20, %%xmm1, %%xmm2 \ncall 1b \n"
|
"aeskeygenassist $0x20, %%xmm1, %%xmm2 \ncall 1b \n"
|
||||||
"aeskeygenassist $0x40, %%xmm1, %%xmm2 \ncall 1b \n"
|
"aeskeygenassist $0x40, %%xmm1, %%xmm2 \ncall 1b \n"
|
||||||
:
|
:
|
||||||
: "r" (rk), "r" (key)
|
: "r"(rk), "r"(key)
|
||||||
: "memory", "cc", "0" );
|
: "memory", "cc", "0");
|
||||||
#endif /* POLARSSL_HAVE_MSVC_X64_INTRINSICS */
|
#endif /* POLARSSL_HAVE_MSVC_X64_INTRINSICS */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Key expansion, wrapper
|
* Key expansion, wrapper
|
||||||
*/
|
*/
|
||||||
int aesni_setkey_enc( unsigned char *rk,
|
int aesni_setkey_enc(unsigned char* rk,
|
||||||
const unsigned char *key,
|
const unsigned char* key,
|
||||||
size_t bits )
|
size_t bits)
|
||||||
{
|
{
|
||||||
switch( bits )
|
switch (bits)
|
||||||
{
|
{
|
||||||
case 128: aesni_setkey_enc_128( rk, key ); break;
|
case 128: aesni_setkey_enc_128(rk, key); break;
|
||||||
case 192: aesni_setkey_enc_192( rk, key ); break;
|
case 192: aesni_setkey_enc_192(rk, key); break;
|
||||||
case 256: aesni_setkey_enc_256( rk, key ); break;
|
case 256: aesni_setkey_enc_256(rk, key); break;
|
||||||
default : return( POLARSSL_ERR_AES_INVALID_KEY_LENGTH );
|
default: return (POLARSSL_ERR_AES_INVALID_KEY_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
return( 0 );
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,11 @@
|
||||||
#define POLARSSL_AESNI_CLMUL 0x00000002u
|
#define POLARSSL_AESNI_CLMUL 0x00000002u
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief AES-NI features detection routine
|
* \brief AES-NI features detection routine
|
||||||
*
|
*
|
||||||
* \param what The feature to detect
|
* \param what The feature to detect
|
||||||
|
|
@ -44,9 +45,9 @@ extern "C" {
|
||||||
*
|
*
|
||||||
* \return 1 if CPU has support for the feature, 0 otherwise
|
* \return 1 if CPU has support for the feature, 0 otherwise
|
||||||
*/
|
*/
|
||||||
int aesni_supports( unsigned int what );
|
int aesni_supports(unsigned int what);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief AES-NI AES-ECB block en(de)cryption
|
* \brief AES-NI AES-ECB block en(de)cryption
|
||||||
*
|
*
|
||||||
* \param ctx AES context
|
* \param ctx AES context
|
||||||
|
|
@ -56,12 +57,12 @@ int aesni_supports( unsigned int what );
|
||||||
*
|
*
|
||||||
* \return 0 on success (cannot fail)
|
* \return 0 on success (cannot fail)
|
||||||
*/
|
*/
|
||||||
int aesni_crypt_ecb( aes_context *ctx,
|
int aesni_crypt_ecb(aes_context* ctx,
|
||||||
int mode,
|
int mode,
|
||||||
const unsigned char input[16],
|
const unsigned char input[16],
|
||||||
unsigned char output[16] );
|
unsigned char output[16]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief GCM multiplication: c = a * b in GF(2^128)
|
* \brief GCM multiplication: c = a * b in GF(2^128)
|
||||||
*
|
*
|
||||||
* \param c Result
|
* \param c Result
|
||||||
|
|
@ -71,21 +72,21 @@ int aesni_crypt_ecb( aes_context *ctx,
|
||||||
* \note Both operands and result are bit strings interpreted as
|
* \note Both operands and result are bit strings interpreted as
|
||||||
* elements of GF(2^128) as per the GCM spec.
|
* elements of GF(2^128) as per the GCM spec.
|
||||||
*/
|
*/
|
||||||
void aesni_gcm_mult( unsigned char c[16],
|
void aesni_gcm_mult(unsigned char c[16],
|
||||||
const unsigned char a[16],
|
const unsigned char a[16],
|
||||||
const unsigned char b[16] );
|
const unsigned char b[16]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Compute decryption round keys from encryption round keys
|
* \brief Compute decryption round keys from encryption round keys
|
||||||
*
|
*
|
||||||
* \param invkey Round keys for the equivalent inverse cipher
|
* \param invkey Round keys for the equivalent inverse cipher
|
||||||
* \param fwdkey Original round keys (for encryption)
|
* \param fwdkey Original round keys (for encryption)
|
||||||
* \param nr Number of rounds (that is, number of round keys minus one)
|
* \param nr Number of rounds (that is, number of round keys minus one)
|
||||||
*/
|
*/
|
||||||
void aesni_inverse_key( unsigned char *invkey,
|
void aesni_inverse_key(unsigned char* invkey,
|
||||||
const unsigned char *fwdkey, int nr );
|
const unsigned char* fwdkey, int nr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Perform key expansion (for encryption)
|
* \brief Perform key expansion (for encryption)
|
||||||
*
|
*
|
||||||
* \param rk Destination buffer where the round keys are written
|
* \param rk Destination buffer where the round keys are written
|
||||||
|
|
@ -94,9 +95,9 @@ void aesni_inverse_key( unsigned char *invkey,
|
||||||
*
|
*
|
||||||
* \return 0 if successful, or POLARSSL_ERR_AES_INVALID_KEY_LENGTH
|
* \return 0 if successful, or POLARSSL_ERR_AES_INVALID_KEY_LENGTH
|
||||||
*/
|
*/
|
||||||
int aesni_setkey_enc( unsigned char *rk,
|
int aesni_setkey_enc(unsigned char* rk,
|
||||||
const unsigned char *key,
|
const unsigned char* key,
|
||||||
size_t bits );
|
size_t bits);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,22 +65,134 @@ static void bn_sub(u8* d, const u8* a, const u8* b, const u8* N, u32 n)
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr u8 inv256[0x80] = {
|
static constexpr u8 inv256[0x80] = {
|
||||||
0x01, 0xab, 0xcd, 0xb7, 0x39, 0xa3, 0xc5, 0xef,
|
0x01,
|
||||||
0xf1, 0x1b, 0x3d, 0xa7, 0x29, 0x13, 0x35, 0xdf,
|
0xab,
|
||||||
0xe1, 0x8b, 0xad, 0x97, 0x19, 0x83, 0xa5, 0xcf,
|
0xcd,
|
||||||
0xd1, 0xfb, 0x1d, 0x87, 0x09, 0xf3, 0x15, 0xbf,
|
0xb7,
|
||||||
0xc1, 0x6b, 0x8d, 0x77, 0xf9, 0x63, 0x85, 0xaf,
|
0x39,
|
||||||
0xb1, 0xdb, 0xfd, 0x67, 0xe9, 0xd3, 0xf5, 0x9f,
|
0xa3,
|
||||||
0xa1, 0x4b, 0x6d, 0x57, 0xd9, 0x43, 0x65, 0x8f,
|
0xc5,
|
||||||
0x91, 0xbb, 0xdd, 0x47, 0xc9, 0xb3, 0xd5, 0x7f,
|
0xef,
|
||||||
0x81, 0x2b, 0x4d, 0x37, 0xb9, 0x23, 0x45, 0x6f,
|
0xf1,
|
||||||
0x71, 0x9b, 0xbd, 0x27, 0xa9, 0x93, 0xb5, 0x5f,
|
0x1b,
|
||||||
0x61, 0x0b, 0x2d, 0x17, 0x99, 0x03, 0x25, 0x4f,
|
0x3d,
|
||||||
0x51, 0x7b, 0x9d, 0x07, 0x89, 0x73, 0x95, 0x3f,
|
0xa7,
|
||||||
0x41, 0xeb, 0x0d, 0xf7, 0x79, 0xe3, 0x05, 0x2f,
|
0x29,
|
||||||
0x31, 0x5b, 0x7d, 0xe7, 0x69, 0x53, 0x75, 0x1f,
|
0x13,
|
||||||
0x21, 0xcb, 0xed, 0xd7, 0x59, 0xc3, 0xe5, 0x0f,
|
0x35,
|
||||||
0x11, 0x3b, 0x5d, 0xc7, 0x49, 0x33, 0x55, 0xff,
|
0xdf,
|
||||||
|
0xe1,
|
||||||
|
0x8b,
|
||||||
|
0xad,
|
||||||
|
0x97,
|
||||||
|
0x19,
|
||||||
|
0x83,
|
||||||
|
0xa5,
|
||||||
|
0xcf,
|
||||||
|
0xd1,
|
||||||
|
0xfb,
|
||||||
|
0x1d,
|
||||||
|
0x87,
|
||||||
|
0x09,
|
||||||
|
0xf3,
|
||||||
|
0x15,
|
||||||
|
0xbf,
|
||||||
|
0xc1,
|
||||||
|
0x6b,
|
||||||
|
0x8d,
|
||||||
|
0x77,
|
||||||
|
0xf9,
|
||||||
|
0x63,
|
||||||
|
0x85,
|
||||||
|
0xaf,
|
||||||
|
0xb1,
|
||||||
|
0xdb,
|
||||||
|
0xfd,
|
||||||
|
0x67,
|
||||||
|
0xe9,
|
||||||
|
0xd3,
|
||||||
|
0xf5,
|
||||||
|
0x9f,
|
||||||
|
0xa1,
|
||||||
|
0x4b,
|
||||||
|
0x6d,
|
||||||
|
0x57,
|
||||||
|
0xd9,
|
||||||
|
0x43,
|
||||||
|
0x65,
|
||||||
|
0x8f,
|
||||||
|
0x91,
|
||||||
|
0xbb,
|
||||||
|
0xdd,
|
||||||
|
0x47,
|
||||||
|
0xc9,
|
||||||
|
0xb3,
|
||||||
|
0xd5,
|
||||||
|
0x7f,
|
||||||
|
0x81,
|
||||||
|
0x2b,
|
||||||
|
0x4d,
|
||||||
|
0x37,
|
||||||
|
0xb9,
|
||||||
|
0x23,
|
||||||
|
0x45,
|
||||||
|
0x6f,
|
||||||
|
0x71,
|
||||||
|
0x9b,
|
||||||
|
0xbd,
|
||||||
|
0x27,
|
||||||
|
0xa9,
|
||||||
|
0x93,
|
||||||
|
0xb5,
|
||||||
|
0x5f,
|
||||||
|
0x61,
|
||||||
|
0x0b,
|
||||||
|
0x2d,
|
||||||
|
0x17,
|
||||||
|
0x99,
|
||||||
|
0x03,
|
||||||
|
0x25,
|
||||||
|
0x4f,
|
||||||
|
0x51,
|
||||||
|
0x7b,
|
||||||
|
0x9d,
|
||||||
|
0x07,
|
||||||
|
0x89,
|
||||||
|
0x73,
|
||||||
|
0x95,
|
||||||
|
0x3f,
|
||||||
|
0x41,
|
||||||
|
0xeb,
|
||||||
|
0x0d,
|
||||||
|
0xf7,
|
||||||
|
0x79,
|
||||||
|
0xe3,
|
||||||
|
0x05,
|
||||||
|
0x2f,
|
||||||
|
0x31,
|
||||||
|
0x5b,
|
||||||
|
0x7d,
|
||||||
|
0xe7,
|
||||||
|
0x69,
|
||||||
|
0x53,
|
||||||
|
0x75,
|
||||||
|
0x1f,
|
||||||
|
0x21,
|
||||||
|
0xcb,
|
||||||
|
0xed,
|
||||||
|
0xd7,
|
||||||
|
0x59,
|
||||||
|
0xc3,
|
||||||
|
0xe5,
|
||||||
|
0x0f,
|
||||||
|
0x11,
|
||||||
|
0x3b,
|
||||||
|
0x5d,
|
||||||
|
0xc7,
|
||||||
|
0x49,
|
||||||
|
0x33,
|
||||||
|
0x55,
|
||||||
|
0xff,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void bn_mon_muladd_dig(u8* d, const u8* a, u8 b, const u8* N, u32 n)
|
static void bn_mon_muladd_dig(u8* d, const u8* a, u8 b, const u8* N, u32 n)
|
||||||
|
|
@ -384,7 +496,8 @@ static bool check_ecdsa(const struct point* Q, u8* R, u8* S, const u8* hash)
|
||||||
|
|
||||||
void ecdsa_set_curve(const u8* p, const u8* a, const u8* b, const u8* N, const u8* Gx, const u8* Gy)
|
void ecdsa_set_curve(const u8* p, const u8* a, const u8* b, const u8* N, const u8* Gx, const u8* Gy)
|
||||||
{
|
{
|
||||||
if (ec_curve_initialized) return;
|
if (ec_curve_initialized)
|
||||||
|
return;
|
||||||
|
|
||||||
memcpy(ec_p, p, 20);
|
memcpy(ec_p, p, 20);
|
||||||
memcpy(ec_a, a, 20);
|
memcpy(ec_a, a, 20);
|
||||||
|
|
@ -403,7 +516,8 @@ void ecdsa_set_curve(const u8* p, const u8* a, const u8* b, const u8* N, const u
|
||||||
|
|
||||||
void ecdsa_set_pub(const u8* Q)
|
void ecdsa_set_pub(const u8* Q)
|
||||||
{
|
{
|
||||||
if (ec_pub_initialized) return;
|
if (ec_pub_initialized)
|
||||||
|
return;
|
||||||
|
|
||||||
memcpy(ec_Q.x, Q, 20);
|
memcpy(ec_Q.x, Q, 20);
|
||||||
memcpy(ec_Q.y, Q + 20, 20);
|
memcpy(ec_Q.y, Q + 20, 20);
|
||||||
|
|
|
||||||
|
|
@ -65,153 +65,118 @@ constexpr u8 SC_ISO_SERIES_INTERNAL_KEY_3[PASSPHRASE_KEY_LEN] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr u8 PKG_AES_KEY_IDU[0x10] = {
|
constexpr u8 PKG_AES_KEY_IDU[0x10] = {
|
||||||
0x5d, 0xb9, 0x11, 0xe6, 0xb7, 0xe5, 0x0a, 0x7d, 0x32, 0x15, 0x38, 0xfd, 0x7c, 0x66, 0xf1, 0x7b
|
0x5d, 0xb9, 0x11, 0xe6, 0xb7, 0xe5, 0x0a, 0x7d, 0x32, 0x15, 0x38, 0xfd, 0x7c, 0x66, 0xf1, 0x7b};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 PKG_AES_KEY[0x10] = {
|
constexpr u8 PKG_AES_KEY[0x10] = {
|
||||||
0x2e, 0x7b, 0x71, 0xd7, 0xc9, 0xc9, 0xa1, 0x4e, 0xa3, 0x22, 0x1f, 0x18, 0x88, 0x28, 0xb8, 0xf8
|
0x2e, 0x7b, 0x71, 0xd7, 0xc9, 0xc9, 0xa1, 0x4e, 0xa3, 0x22, 0x1f, 0x18, 0x88, 0x28, 0xb8, 0xf8};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 PKG_AES_KEY2[0x10] = {
|
constexpr u8 PKG_AES_KEY2[0x10] = {
|
||||||
0x07, 0xf2, 0xc6, 0x82, 0x90, 0xb5, 0x0d, 0x2c, 0x33, 0x81, 0x8d, 0x70, 0x9b, 0x60, 0xe6, 0x2b
|
0x07, 0xf2, 0xc6, 0x82, 0x90, 0xb5, 0x0d, 0x2c, 0x33, 0x81, 0x8d, 0x70, 0x9b, 0x60, 0xe6, 0x2b};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 PKG_AES_KEY_VITA_1[0x10] = {
|
constexpr u8 PKG_AES_KEY_VITA_1[0x10] = {
|
||||||
0xE3, 0x1A, 0x70, 0xC9, 0xCE, 0x1D, 0xD7, 0x2B, 0xF3, 0xC0, 0x62, 0x29, 0x63, 0xF2, 0xEC, 0xCB
|
0xE3, 0x1A, 0x70, 0xC9, 0xCE, 0x1D, 0xD7, 0x2B, 0xF3, 0xC0, 0x62, 0x29, 0x63, 0xF2, 0xEC, 0xCB};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 PKG_AES_KEY_VITA_2[0x10] = {
|
constexpr u8 PKG_AES_KEY_VITA_2[0x10] = {
|
||||||
0x42, 0x3A, 0xCA, 0x3A, 0x2B, 0xD5, 0x64, 0x9F, 0x96, 0x86, 0xAB, 0xAD, 0x6F, 0xD8, 0x80, 0x1F
|
0x42, 0x3A, 0xCA, 0x3A, 0x2B, 0xD5, 0x64, 0x9F, 0x96, 0x86, 0xAB, 0xAD, 0x6F, 0xD8, 0x80, 0x1F};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 PKG_AES_KEY_VITA_3[0x10] = {
|
constexpr u8 PKG_AES_KEY_VITA_3[0x10] = {
|
||||||
0xAF, 0x07, 0xFD, 0x59, 0x65, 0x25, 0x27, 0xBA, 0xF1, 0x33, 0x89, 0x66, 0x8B, 0x17, 0xD9, 0xEA
|
0xAF, 0x07, 0xFD, 0x59, 0x65, 0x25, 0x27, 0xBA, 0xF1, 0x33, 0x89, 0x66, 0x8B, 0x17, 0xD9, 0xEA};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 NP_IDPS[0x10] = {
|
constexpr u8 NP_IDPS[0x10] = {
|
||||||
0x5E, 0x06, 0xE0, 0x4F, 0xD9, 0x4A, 0x71, 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
|
0x5E, 0x06, 0xE0, 0x4F, 0xD9, 0x4A, 0x71, 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 NP_KLIC_FREE[0x10] = {
|
constexpr u8 NP_KLIC_FREE[0x10] = {
|
||||||
0x72, 0xF9, 0x90, 0x78, 0x8F, 0x9C, 0xFF, 0x74, 0x57, 0x25, 0xF0, 0x8E, 0x4C, 0x12, 0x83, 0x87
|
0x72, 0xF9, 0x90, 0x78, 0x8F, 0x9C, 0xFF, 0x74, 0x57, 0x25, 0xF0, 0x8E, 0x4C, 0x12, 0x83, 0x87};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 NP_OMAC_KEY_2[0x10] = {
|
constexpr u8 NP_OMAC_KEY_2[0x10] = {
|
||||||
0x6B, 0xA5, 0x29, 0x76, 0xEF, 0xDA, 0x16, 0xEF, 0x3C, 0x33, 0x9F, 0xB2, 0x97, 0x1E, 0x25, 0x6B
|
0x6B, 0xA5, 0x29, 0x76, 0xEF, 0xDA, 0x16, 0xEF, 0x3C, 0x33, 0x9F, 0xB2, 0x97, 0x1E, 0x25, 0x6B};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 NP_OMAC_KEY_3[0x10] = {
|
constexpr u8 NP_OMAC_KEY_3[0x10] = {
|
||||||
0x9B, 0x51, 0x5F, 0xEA, 0xCF, 0x75, 0x06, 0x49, 0x81, 0xAA, 0x60, 0x4D, 0x91, 0xA5, 0x4E, 0x97
|
0x9B, 0x51, 0x5F, 0xEA, 0xCF, 0x75, 0x06, 0x49, 0x81, 0xAA, 0x60, 0x4D, 0x91, 0xA5, 0x4E, 0x97};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 NP_KLIC_KEY[0x10] = {
|
constexpr u8 NP_KLIC_KEY[0x10] = {
|
||||||
0xF2, 0xFB, 0xCA, 0x7A, 0x75, 0xB0, 0x4E, 0xDC, 0x13, 0x90, 0x63, 0x8C, 0xCD, 0xFD, 0xD1, 0xEE
|
0xF2, 0xFB, 0xCA, 0x7A, 0x75, 0xB0, 0x4E, 0xDC, 0x13, 0x90, 0x63, 0x8C, 0xCD, 0xFD, 0xD1, 0xEE};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 NP_RIF_KEY[0x10] = {
|
constexpr u8 NP_RIF_KEY[0x10] = {
|
||||||
0xDA, 0x7D, 0x4B, 0x5E, 0x49, 0x9A, 0x4F, 0x53, 0xB1, 0xC1, 0xA1, 0x4A, 0x74, 0x84, 0x44, 0x3B
|
0xDA, 0x7D, 0x4B, 0x5E, 0x49, 0x9A, 0x4F, 0x53, 0xB1, 0xC1, 0xA1, 0x4A, 0x74, 0x84, 0x44, 0x3B};
|
||||||
};
|
|
||||||
|
|
||||||
// PSP Minis
|
// PSP Minis
|
||||||
constexpr u8 NP_PSP_KEY_1[0x10] = {
|
constexpr u8 NP_PSP_KEY_1[0x10] = {
|
||||||
0x2A, 0x6A, 0xFB, 0xCF, 0x43, 0xD1, 0x57, 0x9F, 0x7D, 0x73, 0x87, 0x41, 0xA1, 0x3B, 0xD4, 0x2E
|
0x2A, 0x6A, 0xFB, 0xCF, 0x43, 0xD1, 0x57, 0x9F, 0x7D, 0x73, 0x87, 0x41, 0xA1, 0x3B, 0xD4, 0x2E};
|
||||||
};
|
|
||||||
|
|
||||||
// PSP Remasters
|
// PSP Remasters
|
||||||
constexpr u8 NP_PSP_KEY_2[0x10] = {
|
constexpr u8 NP_PSP_KEY_2[0x10] = {
|
||||||
0x0D, 0xB8, 0x57, 0x32, 0x36, 0x6C, 0xD7, 0x34, 0xFC, 0x87, 0x9E, 0x74, 0x33, 0x43, 0xBB, 0x4F
|
0x0D, 0xB8, 0x57, 0x32, 0x36, 0x6C, 0xD7, 0x34, 0xFC, 0x87, 0x9E, 0x74, 0x33, 0x43, 0xBB, 0x4F};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 NP_PSX_KEY[0x10] = {
|
constexpr u8 NP_PSX_KEY[0x10] = {
|
||||||
0x52, 0xC0, 0xB5, 0xCA, 0x76, 0xD6, 0x13, 0x4B, 0xB4, 0x5F, 0xC6, 0x6C, 0xA6, 0x37, 0xF2, 0xC1
|
0x52, 0xC0, 0xB5, 0xCA, 0x76, 0xD6, 0x13, 0x4B, 0xB4, 0x5F, 0xC6, 0x6C, 0xA6, 0x37, 0xF2, 0xC1};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 RAP_KEY[0x10] = {
|
constexpr u8 RAP_KEY[0x10] = {
|
||||||
0x86, 0x9F, 0x77, 0x45, 0xC1, 0x3F, 0xD8, 0x90, 0xCC, 0xF2, 0x91, 0x88, 0xE3, 0xCC, 0x3E, 0xDF
|
0x86, 0x9F, 0x77, 0x45, 0xC1, 0x3F, 0xD8, 0x90, 0xCC, 0xF2, 0x91, 0x88, 0xE3, 0xCC, 0x3E, 0xDF};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 RAP_PBOX[0x10] = {
|
constexpr u8 RAP_PBOX[0x10] = {
|
||||||
0x0C, 0x03, 0x06, 0x04, 0x01, 0x0B, 0x0F, 0x08, 0x02, 0x07, 0x00, 0x05, 0x0A, 0x0E, 0x0D, 0x09
|
0x0C, 0x03, 0x06, 0x04, 0x01, 0x0B, 0x0F, 0x08, 0x02, 0x07, 0x00, 0x05, 0x0A, 0x0E, 0x0D, 0x09};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 RAP_E1[0x10] = {
|
constexpr u8 RAP_E1[0x10] = {
|
||||||
0xA9, 0x3E, 0x1F, 0xD6, 0x7C, 0x55, 0xA3, 0x29, 0xB7, 0x5F, 0xDD, 0xA6, 0x2A, 0x95, 0xC7, 0xA5
|
0xA9, 0x3E, 0x1F, 0xD6, 0x7C, 0x55, 0xA3, 0x29, 0xB7, 0x5F, 0xDD, 0xA6, 0x2A, 0x95, 0xC7, 0xA5};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 RAP_E2[0x10] = {
|
constexpr u8 RAP_E2[0x10] = {
|
||||||
0x67, 0xD4, 0x5D, 0xA3, 0x29, 0x6D, 0x00, 0x6A, 0x4E, 0x7C, 0x53, 0x7B, 0xF5, 0x53, 0x8C, 0x74
|
0x67, 0xD4, 0x5D, 0xA3, 0x29, 0x6D, 0x00, 0x6A, 0x4E, 0x7C, 0x53, 0x7B, 0xF5, 0x53, 0x8C, 0x74};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 SDAT_KEY[0x10] = {
|
constexpr u8 SDAT_KEY[0x10] = {
|
||||||
0x0D, 0x65, 0x5E, 0xF8, 0xE6, 0x74, 0xA9, 0x8A, 0xB8, 0x50, 0x5C, 0xFA, 0x7D, 0x01, 0x29, 0x33
|
0x0D, 0x65, 0x5E, 0xF8, 0xE6, 0x74, 0xA9, 0x8A, 0xB8, 0x50, 0x5C, 0xFA, 0x7D, 0x01, 0x29, 0x33};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 EDAT_KEY_0[0x10] = {
|
constexpr u8 EDAT_KEY_0[0x10] = {
|
||||||
0xBE, 0x95, 0x9C, 0xA8, 0x30, 0x8D, 0xEF, 0xA2, 0xE5, 0xE1, 0x80, 0xC6, 0x37, 0x12, 0xA9, 0xAE
|
0xBE, 0x95, 0x9C, 0xA8, 0x30, 0x8D, 0xEF, 0xA2, 0xE5, 0xE1, 0x80, 0xC6, 0x37, 0x12, 0xA9, 0xAE};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 EDAT_HASH_0[0x10] = {
|
constexpr u8 EDAT_HASH_0[0x10] = {
|
||||||
0xEF, 0xFE, 0x5B, 0xD1, 0x65, 0x2E, 0xEB, 0xC1, 0x19, 0x18, 0xCF, 0x7C, 0x04, 0xD4, 0xF0, 0x11
|
0xEF, 0xFE, 0x5B, 0xD1, 0x65, 0x2E, 0xEB, 0xC1, 0x19, 0x18, 0xCF, 0x7C, 0x04, 0xD4, 0xF0, 0x11};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 EDAT_KEY_1[0x10] = {
|
constexpr u8 EDAT_KEY_1[0x10] = {
|
||||||
0x4C, 0xA9, 0xC1, 0x4B, 0x01, 0xC9, 0x53, 0x09, 0x96, 0x9B, 0xEC, 0x68, 0xAA, 0x0B, 0xC0, 0x81
|
0x4C, 0xA9, 0xC1, 0x4B, 0x01, 0xC9, 0x53, 0x09, 0x96, 0x9B, 0xEC, 0x68, 0xAA, 0x0B, 0xC0, 0x81};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 EDAT_HASH_1[0x10] = {
|
constexpr u8 EDAT_HASH_1[0x10] = {
|
||||||
0x3D, 0x92, 0x69, 0x9B, 0x70, 0x5B, 0x07, 0x38, 0x54, 0xD8, 0xFC, 0xC6, 0xC7, 0x67, 0x27, 0x47
|
0x3D, 0x92, 0x69, 0x9B, 0x70, 0x5B, 0x07, 0x38, 0x54, 0xD8, 0xFC, 0xC6, 0xC7, 0x67, 0x27, 0x47};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 EDAT_IV[0x10] = {
|
constexpr u8 EDAT_IV[0x10] = {
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 VSH_CURVE_P[0x14] = {
|
constexpr u8 VSH_CURVE_P[0x14] = {
|
||||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 VSH_CURVE_A[0x14] = {
|
constexpr u8 VSH_CURVE_A[0x14] = {
|
||||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 VSH_CURVE_B[0x14] = {
|
constexpr u8 VSH_CURVE_B[0x14] = {
|
||||||
0xA6, 0x8B, 0xED, 0xC3, 0x34, 0x18, 0x02, 0x9C, 0x1D, 0x3C, 0xE3, 0x3B, 0x9A, 0x32, 0x1F, 0xCC, 0xBB, 0x9E, 0x0F, 0x0B
|
0xA6, 0x8B, 0xED, 0xC3, 0x34, 0x18, 0x02, 0x9C, 0x1D, 0x3C, 0xE3, 0x3B, 0x9A, 0x32, 0x1F, 0xCC, 0xBB, 0x9E, 0x0F, 0x0B};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 VSH_CURVE_N[0x15] = {
|
constexpr u8 VSH_CURVE_N[0x15] = {
|
||||||
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xB5, 0xAE, 0x3C, 0x52, 0x3E, 0x63, 0x94, 0x4F, 0x21, 0x27
|
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xB5, 0xAE, 0x3C, 0x52, 0x3E, 0x63, 0x94, 0x4F, 0x21, 0x27};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 VSH_CURVE_GX[0x14] = {
|
constexpr u8 VSH_CURVE_GX[0x14] = {
|
||||||
0x12, 0x8E, 0xC4, 0x25, 0x64, 0x87, 0xFD, 0x8F, 0xDF, 0x64, 0xE2, 0x43, 0x7B, 0xC0, 0xA1, 0xF6, 0xD5, 0xAF, 0xDE, 0x2C
|
0x12, 0x8E, 0xC4, 0x25, 0x64, 0x87, 0xFD, 0x8F, 0xDF, 0x64, 0xE2, 0x43, 0x7B, 0xC0, 0xA1, 0xF6, 0xD5, 0xAF, 0xDE, 0x2C};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 VSH_CURVE_GY[0x14] = {
|
constexpr u8 VSH_CURVE_GY[0x14] = {
|
||||||
0x59, 0x58, 0x55, 0x7E, 0xB1, 0xDB, 0x00, 0x12, 0x60, 0x42, 0x55, 0x24, 0xDB, 0xC3, 0x79, 0xD5, 0xAC, 0x5F, 0x4A, 0xDF
|
0x59, 0x58, 0x55, 0x7E, 0xB1, 0xDB, 0x00, 0x12, 0x60, 0x42, 0x55, 0x24, 0xDB, 0xC3, 0x79, 0xD5, 0xAC, 0x5F, 0x4A, 0xDF};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 VSH_PUB[0x28] = {
|
constexpr u8 VSH_PUB[0x28] = {
|
||||||
0x62, 0x27, 0xB0, 0x0A, 0x02, 0x85, 0x6F, 0xB0, 0x41, 0x08, 0x87, 0x67, 0x19, 0xE0, 0xA0, 0x18, 0x32, 0x91, 0xEE, 0xB9,
|
0x62, 0x27, 0xB0, 0x0A, 0x02, 0x85, 0x6F, 0xB0, 0x41, 0x08, 0x87, 0x67, 0x19, 0xE0, 0xA0, 0x18, 0x32, 0x91, 0xEE, 0xB9,
|
||||||
0x6E, 0x73, 0x6A, 0xBF, 0x81, 0xF7, 0x0E, 0xE9, 0x16, 0x1B, 0x0D, 0xDE, 0xB0, 0x26, 0x76, 0x1A, 0xFF, 0x7B, 0xC8, 0x5B
|
0x6E, 0x73, 0x6A, 0xBF, 0x81, 0xF7, 0x0E, 0xE9, 0x16, 0x1B, 0x0D, 0xDE, 0xB0, 0x26, 0x76, 0x1A, 0xFF, 0x7B, 0xC8, 0x5B};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 SCEPKG_RIV[0x10] = {
|
constexpr u8 SCEPKG_RIV[0x10] = {
|
||||||
0x4A, 0xCE, 0xF0, 0x12, 0x24, 0xFB, 0xEE, 0xDF, 0x82, 0x45, 0xF8, 0xFF, 0x10, 0x21, 0x1E, 0x6E
|
0x4A, 0xCE, 0xF0, 0x12, 0x24, 0xFB, 0xEE, 0xDF, 0x82, 0x45, 0xF8, 0xFF, 0x10, 0x21, 0x1E, 0x6E};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 SCEPKG_ERK[0x20] = {
|
constexpr u8 SCEPKG_ERK[0x20] = {
|
||||||
0xA9, 0x78, 0x18, 0xBD, 0x19, 0x3A, 0x67, 0xA1, 0x6F, 0xE8, 0x3A, 0x85, 0x5E, 0x1B, 0xE9, 0xFB, 0x56, 0x40, 0x93, 0x8D,
|
0xA9, 0x78, 0x18, 0xBD, 0x19, 0x3A, 0x67, 0xA1, 0x6F, 0xE8, 0x3A, 0x85, 0x5E, 0x1B, 0xE9, 0xFB, 0x56, 0x40, 0x93, 0x8D,
|
||||||
0x4D, 0xBC, 0xB2, 0xCB, 0x52, 0xC5, 0xA2, 0xF8, 0xB0, 0x2B, 0x10, 0x31
|
0x4D, 0xBC, 0xB2, 0xCB, 0x52, 0xC5, 0xA2, 0xF8, 0xB0, 0x2B, 0x10, 0x31};
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 PUP_KEY[0x40] = {
|
constexpr u8 PUP_KEY[0x40] = {
|
||||||
0xF4, 0x91, 0xAD, 0x94, 0xC6, 0x81, 0x10, 0x96, 0x91, 0x5F, 0xD5, 0xD2, 0x44, 0x81, 0xAE, 0xDC, 0xED, 0xED, 0xBE, 0x6B,
|
0xF4, 0x91, 0xAD, 0x94, 0xC6, 0x81, 0x10, 0x96, 0x91, 0x5F, 0xD5, 0xD2, 0x44, 0x81, 0xAE, 0xDC, 0xED, 0xED, 0xBE, 0x6B,
|
||||||
0xE5, 0x13, 0x72, 0x4D, 0xD8, 0xF7, 0xB6, 0x91, 0xE8, 0x8A, 0x38, 0xF4, 0xB5, 0x16, 0x2B, 0xFB, 0xEC, 0xBE, 0x3A, 0x62,
|
0xE5, 0x13, 0x72, 0x4D, 0xD8, 0xF7, 0xB6, 0x91, 0xE8, 0x8A, 0x38, 0xF4, 0xB5, 0x16, 0x2B, 0xFB, 0xEC, 0xBE, 0x3A, 0x62,
|
||||||
0x18, 0x5D, 0xD7, 0xC9, 0x4D, 0xA2, 0x22, 0x5A, 0xDA, 0x3F, 0xBF, 0xCE, 0x55, 0x5B, 0x9E, 0xA9, 0x64, 0x98, 0x29, 0xEB,
|
0x18, 0x5D, 0xD7, 0xC9, 0x4D, 0xA2, 0x22, 0x5A, 0xDA, 0x3F, 0xBF, 0xCE, 0x55, 0x5B, 0x9E, 0xA9, 0x64, 0x98, 0x29, 0xEB,
|
||||||
0x30, 0xCE, 0x83, 0x66
|
0x30, 0xCE, 0x83, 0x66};
|
||||||
};
|
|
||||||
|
|
||||||
// name; location; notes
|
// name; location; notes
|
||||||
constexpr s64 PAID_01 = 0x0003CD28CB47D3C1L; // spu_token_processor.self; CoreOS; Only for 2E - 083.007
|
constexpr s64 PAID_01 = 0x0003CD28CB47D3C1L; // spu_token_processor.self; CoreOS; Only for 2E - 083.007
|
||||||
constexpr s64 PAID_02 = 0x1010000001000001L; // vsh / games / utilities; /dev_flash/, cell_root/target/images; only for 2E - 080.006
|
constexpr s64 PAID_02 = 0x1010000001000001L; // vsh / games / utilities; /dev_flash/, cell_root/target/images; only for 2E - 080.006
|
||||||
constexpr s64 PAID_03 = 0x1010000001000003L; // retail games and their updates
|
constexpr s64 PAID_03 = 0x1010000001000003L; // retail games and their updates
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "lz.h"
|
#include "lz.h"
|
||||||
|
|
||||||
void decode_range(unsigned int *range, unsigned int *code, unsigned char **src)
|
void decode_range(unsigned int* range, unsigned int* code, unsigned char** src)
|
||||||
{
|
{
|
||||||
if (!((*range) >> 24))
|
if (!((*range) >> 24))
|
||||||
{
|
{
|
||||||
|
|
@ -15,20 +15,22 @@ void decode_range(unsigned int *range, unsigned int *code, unsigned char **src)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int decode_bit(unsigned int *range, unsigned int *code, int *index, unsigned char **src, unsigned char *c)
|
int decode_bit(unsigned int* range, unsigned int* code, int* index, unsigned char** src, unsigned char* c)
|
||||||
{
|
{
|
||||||
decode_range(range, code, src);
|
decode_range(range, code, src);
|
||||||
|
|
||||||
unsigned int val = ((*range) >> 8) * (*c);
|
unsigned int val = ((*range) >> 8) * (*c);
|
||||||
|
|
||||||
*c -= ((*c) >> 3);
|
*c -= ((*c) >> 3);
|
||||||
if (index) (*index) <<= 1;
|
if (index)
|
||||||
|
(*index) <<= 1;
|
||||||
|
|
||||||
if (*code < val)
|
if (*code < val)
|
||||||
{
|
{
|
||||||
*range = val;
|
*range = val;
|
||||||
*c += 31;
|
*c += 31;
|
||||||
if (index) (*index)++;
|
if (index)
|
||||||
|
(*index)++;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -39,7 +41,7 @@ int decode_bit(unsigned int *range, unsigned int *code, int *index, unsigned cha
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int decode_number(unsigned char *ptr, int index, int *bit_flag, unsigned int *range, unsigned int *code, unsigned char **src)
|
int decode_number(unsigned char* ptr, int index, int* bit_flag, unsigned int* range, unsigned int* code, unsigned char** src)
|
||||||
{
|
{
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
|
||||||
|
|
@ -79,7 +81,7 @@ int decode_number(unsigned char *ptr, int index, int *bit_flag, unsigned int *ra
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int decode_word(unsigned char *ptr, int index, int *bit_flag, unsigned int *range, unsigned int *code, unsigned char **src)
|
int decode_word(unsigned char* ptr, int index, int* bit_flag, unsigned int* range, unsigned int* code, unsigned char** src)
|
||||||
{
|
{
|
||||||
int i = 1;
|
int i = 1;
|
||||||
index /= 8;
|
index /= 8;
|
||||||
|
|
@ -120,7 +122,7 @@ int decode_word(unsigned char *ptr, int index, int *bit_flag, unsigned int *rang
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int decompress(unsigned char *out, unsigned char *in, unsigned int size)
|
int decompress(unsigned char* out, unsigned char* in, unsigned int size)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
|
|
@ -133,8 +135,8 @@ int decompress(unsigned char *out, unsigned char *in, unsigned int size)
|
||||||
const unsigned char *buf_start, *buf_end;
|
const unsigned char *buf_start, *buf_end;
|
||||||
unsigned char prev = 0;
|
unsigned char prev = 0;
|
||||||
|
|
||||||
unsigned char *start = out;
|
unsigned char* start = out;
|
||||||
const unsigned char *end = (out + size);
|
const unsigned char* end = (out + size);
|
||||||
unsigned char head = in[0];
|
unsigned char head = in[0];
|
||||||
|
|
||||||
unsigned int range = 0xFFFFFFFF;
|
unsigned int range = 0xFFFFFFFF;
|
||||||
|
|
@ -163,8 +165,10 @@ int decompress(unsigned char *out, unsigned char *in, unsigned int size)
|
||||||
if (!decode_bit(&range, &code, 0, &in, tmp_sect1)) // Raw char.
|
if (!decode_bit(&range, &code, 0, &in, tmp_sect1)) // Raw char.
|
||||||
{
|
{
|
||||||
// Adjust offset and check for stream end.
|
// Adjust offset and check for stream end.
|
||||||
if (offset > 0) offset--;
|
if (offset > 0)
|
||||||
if (start == end) return static_cast<int>(start - out);
|
offset--;
|
||||||
|
if (start == end)
|
||||||
|
return static_cast<int>(start - out);
|
||||||
|
|
||||||
// Locate first section.
|
// Locate first section.
|
||||||
int sect = ((((((static_cast<int>(start - out)) & 7) << 8) + prev) >> head) & 7) * 0xFF - 1;
|
int sect = ((((((static_cast<int>(start - out)) & 7) << 8) + prev) >> head) & 7) * 0xFF - 1;
|
||||||
|
|
@ -205,7 +209,8 @@ int decompress(unsigned char *out, unsigned char *in, unsigned int size)
|
||||||
|
|
||||||
// Decode the data length (8 bit fields).
|
// Decode the data length (8 bit fields).
|
||||||
data_length = decode_number(tmp_sect1, index, &bit_flag, &range, &code, &in);
|
data_length = decode_number(tmp_sect1, index, &bit_flag, &range, &code, &in);
|
||||||
if (data_length == 0xFF) return static_cast<int>(start - out); // End of stream.
|
if (data_length == 0xFF)
|
||||||
|
return static_cast<int>(start - out); // End of stream.
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -234,7 +239,8 @@ int decompress(unsigned char *out, unsigned char *in, unsigned int size)
|
||||||
if ((diff > 0) || (bit_flag != 0))
|
if ((diff > 0) || (bit_flag != 0))
|
||||||
{
|
{
|
||||||
// Adjust diff if needed.
|
// Adjust diff if needed.
|
||||||
if (bit_flag == 0) diff -= 8;
|
if (bit_flag == 0)
|
||||||
|
diff -= 8;
|
||||||
|
|
||||||
// Locate section.
|
// Locate section.
|
||||||
tmp_sect3 = tmp + 0x928 + diff;
|
tmp_sect3 = tmp + 0x928 + diff;
|
||||||
|
|
@ -272,7 +278,6 @@ int decompress(unsigned char *out, unsigned char *in, unsigned int size)
|
||||||
{
|
{
|
||||||
*start++ = *buf_start++;
|
*start++ = *buf_start++;
|
||||||
} while (start < buf_end);
|
} while (start < buf_end);
|
||||||
|
|
||||||
}
|
}
|
||||||
prev = *(start - 1);
|
prev = *(start - 1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@
|
||||||
|
|
||||||
// Reverse-engineered custom Lempel–Ziv–Markov based compression.
|
// Reverse-engineered custom Lempel–Ziv–Markov based compression.
|
||||||
|
|
||||||
void decode_range(unsigned int *range, unsigned int *code, unsigned char **src);
|
void decode_range(unsigned int* range, unsigned int* code, unsigned char** src);
|
||||||
int decode_bit(unsigned int *range, unsigned int *code, int *index, unsigned char **src, unsigned char *c);
|
int decode_bit(unsigned int* range, unsigned int* code, int* index, unsigned char** src, unsigned char* c);
|
||||||
int decode_number(unsigned char *ptr, int index, int *bit_flag, unsigned int *range, unsigned int *code, unsigned char **src);
|
int decode_number(unsigned char* ptr, int index, int* bit_flag, unsigned int* range, unsigned int* code, unsigned char** src);
|
||||||
int decode_word(unsigned char *ptr, int index, int *bit_flag, unsigned int *range, unsigned int *code, unsigned char **src);
|
int decode_word(unsigned char* ptr, int index, int* bit_flag, unsigned int* range, unsigned int* code, unsigned char** src);
|
||||||
int decompress(unsigned char *out, unsigned char *in, unsigned int size);
|
int decompress(unsigned char* out, unsigned char* in, unsigned int size);
|
||||||
|
|
|
||||||
|
|
@ -37,40 +37,37 @@
|
||||||
* 32-bit integer manipulation macros (little endian)
|
* 32-bit integer manipulation macros (little endian)
|
||||||
*/
|
*/
|
||||||
#ifndef GET_UINT32_LE
|
#ifndef GET_UINT32_LE
|
||||||
#define GET_UINT32_LE(n,b,i) \
|
#define GET_UINT32_LE(n, b, i) \
|
||||||
{ \
|
{ \
|
||||||
(n) = ( static_cast<uint32_t>((b)[(i) ]) ) \
|
(n) = (static_cast<uint32_t>((b)[(i)])) | (static_cast<uint32_t>((b)[(i) + 1]) << 8) | (static_cast<uint32_t>((b)[(i) + 2]) << 16) | (static_cast<uint32_t>((b)[(i) + 3]) << 24); \
|
||||||
| ( static_cast<uint32_t>((b)[(i) + 1]) << 8 ) \
|
}
|
||||||
| ( static_cast<uint32_t>((b)[(i) + 2]) << 16 ) \
|
|
||||||
| ( static_cast<uint32_t>((b)[(i) + 3]) << 24 );\
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef PUT_UINT32_LE
|
#ifndef PUT_UINT32_LE
|
||||||
#define PUT_UINT32_LE(n,b,i) \
|
#define PUT_UINT32_LE(n, b, i) \
|
||||||
{ \
|
{ \
|
||||||
(b)[(i) ] = static_cast<unsigned char>(( (n) ) & 0xFF ); \
|
(b)[(i)] = static_cast<unsigned char>(((n)) & 0xFF); \
|
||||||
(b)[(i) + 1] = static_cast<unsigned char>(( (n) >> 8 ) & 0xFF ); \
|
(b)[(i) + 1] = static_cast<unsigned char>(((n) >> 8) & 0xFF); \
|
||||||
(b)[(i) + 2] = static_cast<unsigned char>(( (n) >> 16 ) & 0xFF ); \
|
(b)[(i) + 2] = static_cast<unsigned char>(((n) >> 16) & 0xFF); \
|
||||||
(b)[(i) + 3] = static_cast<unsigned char>(( (n) >> 24 ) & 0xFF ); \
|
(b)[(i) + 3] = static_cast<unsigned char>(((n) >> 24) & 0xFF); \
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void mbedtls_md5_init( mbedtls_md5_context *ctx )
|
void mbedtls_md5_init(mbedtls_md5_context* ctx)
|
||||||
{
|
{
|
||||||
memset( ctx, 0, sizeof( mbedtls_md5_context ) );
|
memset(ctx, 0, sizeof(mbedtls_md5_context));
|
||||||
}
|
}
|
||||||
|
|
||||||
void mbedtls_md5_free( mbedtls_md5_context *ctx )
|
void mbedtls_md5_free(mbedtls_md5_context* ctx)
|
||||||
{
|
{
|
||||||
if( ctx == NULL )
|
if (ctx == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mbedtls_zeroize( ctx, sizeof( mbedtls_md5_context ) );
|
mbedtls_zeroize(ctx, sizeof(mbedtls_md5_context));
|
||||||
}
|
}
|
||||||
|
|
||||||
void mbedtls_md5_clone( mbedtls_md5_context *dst,
|
void mbedtls_md5_clone(mbedtls_md5_context* dst,
|
||||||
const mbedtls_md5_context *src )
|
const mbedtls_md5_context* src)
|
||||||
{
|
{
|
||||||
*dst = *src;
|
*dst = *src;
|
||||||
}
|
}
|
||||||
|
|
@ -78,7 +75,7 @@ void mbedtls_md5_clone( mbedtls_md5_context *dst,
|
||||||
/*
|
/*
|
||||||
* MD5 context setup
|
* MD5 context setup
|
||||||
*/
|
*/
|
||||||
int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx )
|
int mbedtls_md5_starts_ret(mbedtls_md5_context* ctx)
|
||||||
{
|
{
|
||||||
ctx->total[0] = 0;
|
ctx->total[0] = 0;
|
||||||
ctx->total[1] = 0;
|
ctx->total[1] = 0;
|
||||||
|
|
@ -88,132 +85,133 @@ int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx )
|
||||||
ctx->state[2] = 0x98BADCFE;
|
ctx->state[2] = 0x98BADCFE;
|
||||||
ctx->state[3] = 0x10325476;
|
ctx->state[3] = 0x10325476;
|
||||||
|
|
||||||
return( 0 );
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||||
void mbedtls_md5_starts( mbedtls_md5_context *ctx )
|
void mbedtls_md5_starts(mbedtls_md5_context* ctx)
|
||||||
{
|
{
|
||||||
mbedtls_md5_starts_ret( ctx );
|
mbedtls_md5_starts_ret(ctx);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(MBEDTLS_MD5_PROCESS_ALT)
|
#if !defined(MBEDTLS_MD5_PROCESS_ALT)
|
||||||
int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
|
int mbedtls_internal_md5_process(mbedtls_md5_context* ctx,
|
||||||
const unsigned char data[64] )
|
const unsigned char data[64])
|
||||||
{
|
{
|
||||||
uint32_t X[16], A, B, C, D;
|
uint32_t X[16], A, B, C, D;
|
||||||
|
|
||||||
GET_UINT32_LE( X[ 0], data, 0 );
|
GET_UINT32_LE(X[0], data, 0);
|
||||||
GET_UINT32_LE( X[ 1], data, 4 );
|
GET_UINT32_LE(X[1], data, 4);
|
||||||
GET_UINT32_LE( X[ 2], data, 8 );
|
GET_UINT32_LE(X[2], data, 8);
|
||||||
GET_UINT32_LE( X[ 3], data, 12 );
|
GET_UINT32_LE(X[3], data, 12);
|
||||||
GET_UINT32_LE( X[ 4], data, 16 );
|
GET_UINT32_LE(X[4], data, 16);
|
||||||
GET_UINT32_LE( X[ 5], data, 20 );
|
GET_UINT32_LE(X[5], data, 20);
|
||||||
GET_UINT32_LE( X[ 6], data, 24 );
|
GET_UINT32_LE(X[6], data, 24);
|
||||||
GET_UINT32_LE( X[ 7], data, 28 );
|
GET_UINT32_LE(X[7], data, 28);
|
||||||
GET_UINT32_LE( X[ 8], data, 32 );
|
GET_UINT32_LE(X[8], data, 32);
|
||||||
GET_UINT32_LE( X[ 9], data, 36 );
|
GET_UINT32_LE(X[9], data, 36);
|
||||||
GET_UINT32_LE( X[10], data, 40 );
|
GET_UINT32_LE(X[10], data, 40);
|
||||||
GET_UINT32_LE( X[11], data, 44 );
|
GET_UINT32_LE(X[11], data, 44);
|
||||||
GET_UINT32_LE( X[12], data, 48 );
|
GET_UINT32_LE(X[12], data, 48);
|
||||||
GET_UINT32_LE( X[13], data, 52 );
|
GET_UINT32_LE(X[13], data, 52);
|
||||||
GET_UINT32_LE( X[14], data, 56 );
|
GET_UINT32_LE(X[14], data, 56);
|
||||||
GET_UINT32_LE( X[15], data, 60 );
|
GET_UINT32_LE(X[15], data, 60);
|
||||||
|
|
||||||
#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
|
#define S(x, n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
|
||||||
|
|
||||||
#define P(a,b,c,d,k,s,t) \
|
#define P(a, b, c, d, k, s, t) \
|
||||||
{ \
|
{ \
|
||||||
a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \
|
a += F(b, c, d) + X[k] + t; \
|
||||||
}
|
a = S(a, s) + b; \
|
||||||
|
}
|
||||||
|
|
||||||
A = ctx->state[0];
|
A = ctx->state[0];
|
||||||
B = ctx->state[1];
|
B = ctx->state[1];
|
||||||
C = ctx->state[2];
|
C = ctx->state[2];
|
||||||
D = ctx->state[3];
|
D = ctx->state[3];
|
||||||
|
|
||||||
#define F(x,y,z) (z ^ (x & (y ^ z)))
|
#define F(x, y, z) (z ^ (x & (y ^ z)))
|
||||||
|
|
||||||
P( A, B, C, D, 0, 7, 0xD76AA478 );
|
P(A, B, C, D, 0, 7, 0xD76AA478);
|
||||||
P( D, A, B, C, 1, 12, 0xE8C7B756 );
|
P(D, A, B, C, 1, 12, 0xE8C7B756);
|
||||||
P( C, D, A, B, 2, 17, 0x242070DB );
|
P(C, D, A, B, 2, 17, 0x242070DB);
|
||||||
P( B, C, D, A, 3, 22, 0xC1BDCEEE );
|
P(B, C, D, A, 3, 22, 0xC1BDCEEE);
|
||||||
P( A, B, C, D, 4, 7, 0xF57C0FAF );
|
P(A, B, C, D, 4, 7, 0xF57C0FAF);
|
||||||
P( D, A, B, C, 5, 12, 0x4787C62A );
|
P(D, A, B, C, 5, 12, 0x4787C62A);
|
||||||
P( C, D, A, B, 6, 17, 0xA8304613 );
|
P(C, D, A, B, 6, 17, 0xA8304613);
|
||||||
P( B, C, D, A, 7, 22, 0xFD469501 );
|
P(B, C, D, A, 7, 22, 0xFD469501);
|
||||||
P( A, B, C, D, 8, 7, 0x698098D8 );
|
P(A, B, C, D, 8, 7, 0x698098D8);
|
||||||
P( D, A, B, C, 9, 12, 0x8B44F7AF );
|
P(D, A, B, C, 9, 12, 0x8B44F7AF);
|
||||||
P( C, D, A, B, 10, 17, 0xFFFF5BB1 );
|
P(C, D, A, B, 10, 17, 0xFFFF5BB1);
|
||||||
P( B, C, D, A, 11, 22, 0x895CD7BE );
|
P(B, C, D, A, 11, 22, 0x895CD7BE);
|
||||||
P( A, B, C, D, 12, 7, 0x6B901122 );
|
P(A, B, C, D, 12, 7, 0x6B901122);
|
||||||
P( D, A, B, C, 13, 12, 0xFD987193 );
|
P(D, A, B, C, 13, 12, 0xFD987193);
|
||||||
P( C, D, A, B, 14, 17, 0xA679438E );
|
P(C, D, A, B, 14, 17, 0xA679438E);
|
||||||
P( B, C, D, A, 15, 22, 0x49B40821 );
|
P(B, C, D, A, 15, 22, 0x49B40821);
|
||||||
|
|
||||||
#undef F
|
#undef F
|
||||||
|
|
||||||
#define F(x,y,z) (y ^ (z & (x ^ y)))
|
#define F(x, y, z) (y ^ (z & (x ^ y)))
|
||||||
|
|
||||||
P( A, B, C, D, 1, 5, 0xF61E2562 );
|
P(A, B, C, D, 1, 5, 0xF61E2562);
|
||||||
P( D, A, B, C, 6, 9, 0xC040B340 );
|
P(D, A, B, C, 6, 9, 0xC040B340);
|
||||||
P( C, D, A, B, 11, 14, 0x265E5A51 );
|
P(C, D, A, B, 11, 14, 0x265E5A51);
|
||||||
P( B, C, D, A, 0, 20, 0xE9B6C7AA );
|
P(B, C, D, A, 0, 20, 0xE9B6C7AA);
|
||||||
P( A, B, C, D, 5, 5, 0xD62F105D );
|
P(A, B, C, D, 5, 5, 0xD62F105D);
|
||||||
P( D, A, B, C, 10, 9, 0x02441453 );
|
P(D, A, B, C, 10, 9, 0x02441453);
|
||||||
P( C, D, A, B, 15, 14, 0xD8A1E681 );
|
P(C, D, A, B, 15, 14, 0xD8A1E681);
|
||||||
P( B, C, D, A, 4, 20, 0xE7D3FBC8 );
|
P(B, C, D, A, 4, 20, 0xE7D3FBC8);
|
||||||
P( A, B, C, D, 9, 5, 0x21E1CDE6 );
|
P(A, B, C, D, 9, 5, 0x21E1CDE6);
|
||||||
P( D, A, B, C, 14, 9, 0xC33707D6 );
|
P(D, A, B, C, 14, 9, 0xC33707D6);
|
||||||
P( C, D, A, B, 3, 14, 0xF4D50D87 );
|
P(C, D, A, B, 3, 14, 0xF4D50D87);
|
||||||
P( B, C, D, A, 8, 20, 0x455A14ED );
|
P(B, C, D, A, 8, 20, 0x455A14ED);
|
||||||
P( A, B, C, D, 13, 5, 0xA9E3E905 );
|
P(A, B, C, D, 13, 5, 0xA9E3E905);
|
||||||
P( D, A, B, C, 2, 9, 0xFCEFA3F8 );
|
P(D, A, B, C, 2, 9, 0xFCEFA3F8);
|
||||||
P( C, D, A, B, 7, 14, 0x676F02D9 );
|
P(C, D, A, B, 7, 14, 0x676F02D9);
|
||||||
P( B, C, D, A, 12, 20, 0x8D2A4C8A );
|
P(B, C, D, A, 12, 20, 0x8D2A4C8A);
|
||||||
|
|
||||||
#undef F
|
#undef F
|
||||||
|
|
||||||
#define F(x,y,z) (x ^ y ^ z)
|
#define F(x, y, z) (x ^ y ^ z)
|
||||||
|
|
||||||
P( A, B, C, D, 5, 4, 0xFFFA3942 );
|
P(A, B, C, D, 5, 4, 0xFFFA3942);
|
||||||
P( D, A, B, C, 8, 11, 0x8771F681 );
|
P(D, A, B, C, 8, 11, 0x8771F681);
|
||||||
P( C, D, A, B, 11, 16, 0x6D9D6122 );
|
P(C, D, A, B, 11, 16, 0x6D9D6122);
|
||||||
P( B, C, D, A, 14, 23, 0xFDE5380C );
|
P(B, C, D, A, 14, 23, 0xFDE5380C);
|
||||||
P( A, B, C, D, 1, 4, 0xA4BEEA44 );
|
P(A, B, C, D, 1, 4, 0xA4BEEA44);
|
||||||
P( D, A, B, C, 4, 11, 0x4BDECFA9 );
|
P(D, A, B, C, 4, 11, 0x4BDECFA9);
|
||||||
P( C, D, A, B, 7, 16, 0xF6BB4B60 );
|
P(C, D, A, B, 7, 16, 0xF6BB4B60);
|
||||||
P( B, C, D, A, 10, 23, 0xBEBFBC70 );
|
P(B, C, D, A, 10, 23, 0xBEBFBC70);
|
||||||
P( A, B, C, D, 13, 4, 0x289B7EC6 );
|
P(A, B, C, D, 13, 4, 0x289B7EC6);
|
||||||
P( D, A, B, C, 0, 11, 0xEAA127FA );
|
P(D, A, B, C, 0, 11, 0xEAA127FA);
|
||||||
P( C, D, A, B, 3, 16, 0xD4EF3085 );
|
P(C, D, A, B, 3, 16, 0xD4EF3085);
|
||||||
P( B, C, D, A, 6, 23, 0x04881D05 );
|
P(B, C, D, A, 6, 23, 0x04881D05);
|
||||||
P( A, B, C, D, 9, 4, 0xD9D4D039 );
|
P(A, B, C, D, 9, 4, 0xD9D4D039);
|
||||||
P( D, A, B, C, 12, 11, 0xE6DB99E5 );
|
P(D, A, B, C, 12, 11, 0xE6DB99E5);
|
||||||
P( C, D, A, B, 15, 16, 0x1FA27CF8 );
|
P(C, D, A, B, 15, 16, 0x1FA27CF8);
|
||||||
P( B, C, D, A, 2, 23, 0xC4AC5665 );
|
P(B, C, D, A, 2, 23, 0xC4AC5665);
|
||||||
|
|
||||||
#undef F
|
#undef F
|
||||||
|
|
||||||
#define F(x,y,z) (y ^ (x | ~z))
|
#define F(x, y, z) (y ^ (x | ~z))
|
||||||
|
|
||||||
P( A, B, C, D, 0, 6, 0xF4292244 );
|
P(A, B, C, D, 0, 6, 0xF4292244);
|
||||||
P( D, A, B, C, 7, 10, 0x432AFF97 );
|
P(D, A, B, C, 7, 10, 0x432AFF97);
|
||||||
P( C, D, A, B, 14, 15, 0xAB9423A7 );
|
P(C, D, A, B, 14, 15, 0xAB9423A7);
|
||||||
P( B, C, D, A, 5, 21, 0xFC93A039 );
|
P(B, C, D, A, 5, 21, 0xFC93A039);
|
||||||
P( A, B, C, D, 12, 6, 0x655B59C3 );
|
P(A, B, C, D, 12, 6, 0x655B59C3);
|
||||||
P( D, A, B, C, 3, 10, 0x8F0CCC92 );
|
P(D, A, B, C, 3, 10, 0x8F0CCC92);
|
||||||
P( C, D, A, B, 10, 15, 0xFFEFF47D );
|
P(C, D, A, B, 10, 15, 0xFFEFF47D);
|
||||||
P( B, C, D, A, 1, 21, 0x85845DD1 );
|
P(B, C, D, A, 1, 21, 0x85845DD1);
|
||||||
P( A, B, C, D, 8, 6, 0x6FA87E4F );
|
P(A, B, C, D, 8, 6, 0x6FA87E4F);
|
||||||
P( D, A, B, C, 15, 10, 0xFE2CE6E0 );
|
P(D, A, B, C, 15, 10, 0xFE2CE6E0);
|
||||||
P( C, D, A, B, 6, 15, 0xA3014314 );
|
P(C, D, A, B, 6, 15, 0xA3014314);
|
||||||
P( B, C, D, A, 13, 21, 0x4E0811A1 );
|
P(B, C, D, A, 13, 21, 0x4E0811A1);
|
||||||
P( A, B, C, D, 4, 6, 0xF7537E82 );
|
P(A, B, C, D, 4, 6, 0xF7537E82);
|
||||||
P( D, A, B, C, 11, 10, 0xBD3AF235 );
|
P(D, A, B, C, 11, 10, 0xBD3AF235);
|
||||||
P( C, D, A, B, 2, 15, 0x2AD7D2BB );
|
P(C, D, A, B, 2, 15, 0x2AD7D2BB);
|
||||||
P( B, C, D, A, 9, 21, 0xEB86D391 );
|
P(B, C, D, A, 9, 21, 0xEB86D391);
|
||||||
|
|
||||||
#undef F
|
#undef F
|
||||||
|
|
||||||
|
|
@ -222,14 +220,14 @@ int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
|
||||||
ctx->state[2] += C;
|
ctx->state[2] += C;
|
||||||
ctx->state[3] += D;
|
ctx->state[3] += D;
|
||||||
|
|
||||||
return( 0 );
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||||
void mbedtls_md5_process( mbedtls_md5_context *ctx,
|
void mbedtls_md5_process(mbedtls_md5_context* ctx,
|
||||||
const unsigned char data[64] )
|
const unsigned char data[64])
|
||||||
{
|
{
|
||||||
mbedtls_internal_md5_process( ctx, data );
|
mbedtls_internal_md5_process(ctx, data);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif /* !MBEDTLS_MD5_PROCESS_ALT */
|
#endif /* !MBEDTLS_MD5_PROCESS_ALT */
|
||||||
|
|
@ -237,16 +235,16 @@ void mbedtls_md5_process( mbedtls_md5_context *ctx,
|
||||||
/*
|
/*
|
||||||
* MD5 process buffer
|
* MD5 process buffer
|
||||||
*/
|
*/
|
||||||
int mbedtls_md5_update_ret( mbedtls_md5_context *ctx,
|
int mbedtls_md5_update_ret(mbedtls_md5_context* ctx,
|
||||||
const unsigned char *input,
|
const unsigned char* input,
|
||||||
size_t ilen )
|
size_t ilen)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
size_t fill;
|
size_t fill;
|
||||||
uint32_t left;
|
uint32_t left;
|
||||||
|
|
||||||
if( ilen == 0 )
|
if (ilen == 0)
|
||||||
return( 0 );
|
return (0);
|
||||||
|
|
||||||
left = ctx->total[0] & 0x3F;
|
left = ctx->total[0] & 0x3F;
|
||||||
fill = 64 - left;
|
fill = 64 - left;
|
||||||
|
|
@ -254,51 +252,51 @@ int mbedtls_md5_update_ret( mbedtls_md5_context *ctx,
|
||||||
ctx->total[0] += static_cast<uint32_t>(ilen);
|
ctx->total[0] += static_cast<uint32_t>(ilen);
|
||||||
ctx->total[0] &= 0xFFFFFFFF;
|
ctx->total[0] &= 0xFFFFFFFF;
|
||||||
|
|
||||||
if( ctx->total[0] < static_cast<uint32_t>(ilen) )
|
if (ctx->total[0] < static_cast<uint32_t>(ilen))
|
||||||
ctx->total[1]++;
|
ctx->total[1]++;
|
||||||
|
|
||||||
if( left && ilen >= fill )
|
if (left && ilen >= fill)
|
||||||
{
|
{
|
||||||
memcpy( ctx->buffer + left, input, fill );
|
memcpy(ctx->buffer + left, input, fill);
|
||||||
if( ( ret = mbedtls_internal_md5_process( ctx, ctx->buffer ) ) != 0 )
|
if ((ret = mbedtls_internal_md5_process(ctx, ctx->buffer)) != 0)
|
||||||
return( ret );
|
return (ret);
|
||||||
|
|
||||||
input += fill;
|
input += fill;
|
||||||
ilen -= fill;
|
ilen -= fill;
|
||||||
left = 0;
|
left = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while( ilen >= 64 )
|
while (ilen >= 64)
|
||||||
{
|
{
|
||||||
if( ( ret = mbedtls_internal_md5_process( ctx, input ) ) != 0 )
|
if ((ret = mbedtls_internal_md5_process(ctx, input)) != 0)
|
||||||
return( ret );
|
return (ret);
|
||||||
|
|
||||||
input += 64;
|
input += 64;
|
||||||
ilen -= 64;
|
ilen -= 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ilen > 0 )
|
if (ilen > 0)
|
||||||
{
|
{
|
||||||
memcpy( ctx->buffer + left, input, ilen );
|
memcpy(ctx->buffer + left, input, ilen);
|
||||||
}
|
}
|
||||||
|
|
||||||
return( 0 );
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||||
void mbedtls_md5_update( mbedtls_md5_context *ctx,
|
void mbedtls_md5_update(mbedtls_md5_context* ctx,
|
||||||
const unsigned char *input,
|
const unsigned char* input,
|
||||||
size_t ilen )
|
size_t ilen)
|
||||||
{
|
{
|
||||||
mbedtls_md5_update_ret( ctx, input, ilen );
|
mbedtls_md5_update_ret(ctx, input, ilen);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* MD5 final digest
|
* MD5 final digest
|
||||||
*/
|
*/
|
||||||
int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx,
|
int mbedtls_md5_finish_ret(mbedtls_md5_context* ctx,
|
||||||
unsigned char output[16] )
|
unsigned char output[16])
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
uint32_t used;
|
uint32_t used;
|
||||||
|
|
@ -311,51 +309,50 @@ int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx,
|
||||||
|
|
||||||
ctx->buffer[used++] = 0x80;
|
ctx->buffer[used++] = 0x80;
|
||||||
|
|
||||||
if( used <= 56 )
|
if (used <= 56)
|
||||||
{
|
{
|
||||||
/* Enough room for padding + length in current block */
|
/* Enough room for padding + length in current block */
|
||||||
memset( ctx->buffer + used, 0, 56 - used );
|
memset(ctx->buffer + used, 0, 56 - used);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* We'll need an extra block */
|
/* We'll need an extra block */
|
||||||
memset( ctx->buffer + used, 0, 64 - used );
|
memset(ctx->buffer + used, 0, 64 - used);
|
||||||
|
|
||||||
if( ( ret = mbedtls_internal_md5_process( ctx, ctx->buffer ) ) != 0 )
|
if ((ret = mbedtls_internal_md5_process(ctx, ctx->buffer)) != 0)
|
||||||
return( ret );
|
return (ret);
|
||||||
|
|
||||||
memset( ctx->buffer, 0, 56 );
|
memset(ctx->buffer, 0, 56);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add message length
|
* Add message length
|
||||||
*/
|
*/
|
||||||
high = ( ctx->total[0] >> 29 )
|
high = (ctx->total[0] >> 29) | (ctx->total[1] << 3);
|
||||||
| ( ctx->total[1] << 3 );
|
low = (ctx->total[0] << 3);
|
||||||
low = ( ctx->total[0] << 3 );
|
|
||||||
|
|
||||||
PUT_UINT32_LE( low, ctx->buffer, 56 );
|
PUT_UINT32_LE(low, ctx->buffer, 56);
|
||||||
PUT_UINT32_LE( high, ctx->buffer, 60 );
|
PUT_UINT32_LE(high, ctx->buffer, 60);
|
||||||
|
|
||||||
if( ( ret = mbedtls_internal_md5_process( ctx, ctx->buffer ) ) != 0 )
|
if ((ret = mbedtls_internal_md5_process(ctx, ctx->buffer)) != 0)
|
||||||
return( ret );
|
return (ret);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Output final state
|
* Output final state
|
||||||
*/
|
*/
|
||||||
PUT_UINT32_LE( ctx->state[0], output, 0 );
|
PUT_UINT32_LE(ctx->state[0], output, 0);
|
||||||
PUT_UINT32_LE( ctx->state[1], output, 4 );
|
PUT_UINT32_LE(ctx->state[1], output, 4);
|
||||||
PUT_UINT32_LE( ctx->state[2], output, 8 );
|
PUT_UINT32_LE(ctx->state[2], output, 8);
|
||||||
PUT_UINT32_LE( ctx->state[3], output, 12 );
|
PUT_UINT32_LE(ctx->state[3], output, 12);
|
||||||
|
|
||||||
return( 0 );
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||||
void mbedtls_md5_finish( mbedtls_md5_context *ctx,
|
void mbedtls_md5_finish(mbedtls_md5_context* ctx,
|
||||||
unsigned char output[16] )
|
unsigned char output[16])
|
||||||
{
|
{
|
||||||
mbedtls_md5_finish_ret( ctx, output );
|
mbedtls_md5_finish_ret(ctx, output);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -364,36 +361,36 @@ void mbedtls_md5_finish( mbedtls_md5_context *ctx,
|
||||||
/*
|
/*
|
||||||
* output = MD5( input buffer )
|
* output = MD5( input buffer )
|
||||||
*/
|
*/
|
||||||
int mbedtls_md5_ret( const unsigned char *input,
|
int mbedtls_md5_ret(const unsigned char* input,
|
||||||
size_t ilen,
|
size_t ilen,
|
||||||
unsigned char output[16] )
|
unsigned char output[16])
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
mbedtls_md5_context ctx;
|
mbedtls_md5_context ctx;
|
||||||
|
|
||||||
mbedtls_md5_init( &ctx );
|
mbedtls_md5_init(&ctx);
|
||||||
|
|
||||||
if( ( ret = mbedtls_md5_starts_ret( &ctx ) ) != 0 )
|
if ((ret = mbedtls_md5_starts_ret(&ctx)) != 0)
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
if( ( ret = mbedtls_md5_update_ret( &ctx, input, ilen ) ) != 0 )
|
if ((ret = mbedtls_md5_update_ret(&ctx, input, ilen)) != 0)
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
if( ( ret = mbedtls_md5_finish_ret( &ctx, output ) ) != 0 )
|
if ((ret = mbedtls_md5_finish_ret(&ctx, output)) != 0)
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
mbedtls_md5_free( &ctx );
|
mbedtls_md5_free(&ctx);
|
||||||
|
|
||||||
return( ret );
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||||
void mbedtls_md5( const unsigned char *input,
|
void mbedtls_md5(const unsigned char* input,
|
||||||
size_t ilen,
|
size_t ilen,
|
||||||
unsigned char output[16] )
|
unsigned char output[16])
|
||||||
{
|
{
|
||||||
mbedtls_md5_ret( input, ilen, output );
|
mbedtls_md5_ret(input, ilen, output);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -402,77 +399,74 @@ void mbedtls_md5( const unsigned char *input,
|
||||||
* RFC 1321 test vectors
|
* RFC 1321 test vectors
|
||||||
*/
|
*/
|
||||||
static const unsigned char md5_test_buf[7][81] =
|
static const unsigned char md5_test_buf[7][81] =
|
||||||
{
|
{
|
||||||
{ "" },
|
{""},
|
||||||
{ "a" },
|
{"a"},
|
||||||
{ "abc" },
|
{"abc"},
|
||||||
{ "message digest" },
|
{"message digest"},
|
||||||
{ "abcdefghijklmnopqrstuvwxyz" },
|
{"abcdefghijklmnopqrstuvwxyz"},
|
||||||
{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" },
|
{"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"},
|
||||||
{ "12345678901234567890123456789012345678901234567890123456789012"
|
{"12345678901234567890123456789012345678901234567890123456789012"
|
||||||
"345678901234567890" }
|
"345678901234567890"}};
|
||||||
};
|
|
||||||
|
|
||||||
static const size_t md5_test_buflen[7] =
|
static const size_t md5_test_buflen[7] =
|
||||||
{
|
{
|
||||||
0, 1, 3, 14, 26, 62, 80
|
0, 1, 3, 14, 26, 62, 80};
|
||||||
};
|
|
||||||
|
|
||||||
static const unsigned char md5_test_sum[7][16] =
|
static const unsigned char md5_test_sum[7][16] =
|
||||||
{
|
{
|
||||||
{ 0xD4, 0x1D, 0x8C, 0xD9, 0x8F, 0x00, 0xB2, 0x04,
|
{0xD4, 0x1D, 0x8C, 0xD9, 0x8F, 0x00, 0xB2, 0x04,
|
||||||
0xE9, 0x80, 0x09, 0x98, 0xEC, 0xF8, 0x42, 0x7E },
|
0xE9, 0x80, 0x09, 0x98, 0xEC, 0xF8, 0x42, 0x7E},
|
||||||
{ 0x0C, 0xC1, 0x75, 0xB9, 0xC0, 0xF1, 0xB6, 0xA8,
|
{0x0C, 0xC1, 0x75, 0xB9, 0xC0, 0xF1, 0xB6, 0xA8,
|
||||||
0x31, 0xC3, 0x99, 0xE2, 0x69, 0x77, 0x26, 0x61 },
|
0x31, 0xC3, 0x99, 0xE2, 0x69, 0x77, 0x26, 0x61},
|
||||||
{ 0x90, 0x01, 0x50, 0x98, 0x3C, 0xD2, 0x4F, 0xB0,
|
{0x90, 0x01, 0x50, 0x98, 0x3C, 0xD2, 0x4F, 0xB0,
|
||||||
0xD6, 0x96, 0x3F, 0x7D, 0x28, 0xE1, 0x7F, 0x72 },
|
0xD6, 0x96, 0x3F, 0x7D, 0x28, 0xE1, 0x7F, 0x72},
|
||||||
{ 0xF9, 0x6B, 0x69, 0x7D, 0x7C, 0xB7, 0x93, 0x8D,
|
{0xF9, 0x6B, 0x69, 0x7D, 0x7C, 0xB7, 0x93, 0x8D,
|
||||||
0x52, 0x5A, 0x2F, 0x31, 0xAA, 0xF1, 0x61, 0xD0 },
|
0x52, 0x5A, 0x2F, 0x31, 0xAA, 0xF1, 0x61, 0xD0},
|
||||||
{ 0xC3, 0xFC, 0xD3, 0xD7, 0x61, 0x92, 0xE4, 0x00,
|
{0xC3, 0xFC, 0xD3, 0xD7, 0x61, 0x92, 0xE4, 0x00,
|
||||||
0x7D, 0xFB, 0x49, 0x6C, 0xCA, 0x67, 0xE1, 0x3B },
|
0x7D, 0xFB, 0x49, 0x6C, 0xCA, 0x67, 0xE1, 0x3B},
|
||||||
{ 0xD1, 0x74, 0xAB, 0x98, 0xD2, 0x77, 0xD9, 0xF5,
|
{0xD1, 0x74, 0xAB, 0x98, 0xD2, 0x77, 0xD9, 0xF5,
|
||||||
0xA5, 0x61, 0x1C, 0x2C, 0x9F, 0x41, 0x9D, 0x9F },
|
0xA5, 0x61, 0x1C, 0x2C, 0x9F, 0x41, 0x9D, 0x9F},
|
||||||
{ 0x57, 0xED, 0xF4, 0xA2, 0x2B, 0xE3, 0xC9, 0x55,
|
{0x57, 0xED, 0xF4, 0xA2, 0x2B, 0xE3, 0xC9, 0x55,
|
||||||
0xAC, 0x49, 0xDA, 0x2E, 0x21, 0x07, 0xB6, 0x7A }
|
0xAC, 0x49, 0xDA, 0x2E, 0x21, 0x07, 0xB6, 0x7A}};
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Checkup routine
|
* Checkup routine
|
||||||
*/
|
*/
|
||||||
int mbedtls_md5_self_test( int verbose )
|
int mbedtls_md5_self_test(int verbose)
|
||||||
{
|
{
|
||||||
int i, ret = 0;
|
int i, ret = 0;
|
||||||
unsigned char md5sum[16];
|
unsigned char md5sum[16];
|
||||||
|
|
||||||
for( i = 0; i < 7; i++ )
|
for (i = 0; i < 7; i++)
|
||||||
{
|
{
|
||||||
if( verbose != 0 )
|
if (verbose != 0)
|
||||||
mbedtls_printf( " MD5 test #%d: ", i + 1 );
|
mbedtls_printf(" MD5 test #%d: ", i + 1);
|
||||||
|
|
||||||
ret = mbedtls_md5_ret( md5_test_buf[i], md5_test_buflen[i], md5sum );
|
ret = mbedtls_md5_ret(md5_test_buf[i], md5_test_buflen[i], md5sum);
|
||||||
if( ret != 0 )
|
if (ret != 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if( memcmp( md5sum, md5_test_sum[i], 16 ) != 0 )
|
if (memcmp(md5sum, md5_test_sum[i], 16) != 0)
|
||||||
{
|
{
|
||||||
ret = 1;
|
ret = 1;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( verbose != 0 )
|
if (verbose != 0)
|
||||||
mbedtls_printf( "passed\n" );
|
mbedtls_printf("passed\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if( verbose != 0 )
|
if (verbose != 0)
|
||||||
mbedtls_printf( "\n" );
|
mbedtls_printf("\n");
|
||||||
|
|
||||||
return( 0 );
|
return (0);
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
if( verbose != 0 )
|
if (verbose != 0)
|
||||||
mbedtls_printf( "failed\n" );
|
mbedtls_printf("failed\n");
|
||||||
|
|
||||||
return( ret );
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* MBEDTLS_SELF_TEST */
|
#endif /* MBEDTLS_SELF_TEST */
|
||||||
|
|
|
||||||
|
|
@ -37,14 +37,15 @@
|
||||||
#define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED -0x002F /**< MD5 hardware accelerator failed */
|
#define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED -0x002F /**< MD5 hardware accelerator failed */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(MBEDTLS_MD5_ALT)
|
#if !defined(MBEDTLS_MD5_ALT)
|
||||||
// Regular implementation
|
// Regular implementation
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief MD5 context structure
|
* \brief MD5 context structure
|
||||||
*
|
*
|
||||||
* \warning MD5 is considered a weak message digest and its use
|
* \warning MD5 is considered a weak message digest and its use
|
||||||
|
|
@ -52,19 +53,18 @@ extern "C" {
|
||||||
* stronger message digests instead.
|
* stronger message digests instead.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef struct mbedtls_md5_context
|
typedef struct mbedtls_md5_context
|
||||||
{
|
{
|
||||||
uint32_t total[2]; /*!< number of bytes processed */
|
uint32_t total[2]; /*!< number of bytes processed */
|
||||||
uint32_t state[4]; /*!< intermediate digest state */
|
uint32_t state[4]; /*!< intermediate digest state */
|
||||||
unsigned char buffer[64]; /*!< data block being processed */
|
unsigned char buffer[64]; /*!< data block being processed */
|
||||||
}
|
} mbedtls_md5_context;
|
||||||
mbedtls_md5_context;
|
|
||||||
|
|
||||||
#else /* MBEDTLS_MD5_ALT */
|
#else /* MBEDTLS_MD5_ALT */
|
||||||
#include "md5_alt.h"
|
#include "md5_alt.h"
|
||||||
#endif /* MBEDTLS_MD5_ALT */
|
#endif /* MBEDTLS_MD5_ALT */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Initialize MD5 context
|
* \brief Initialize MD5 context
|
||||||
*
|
*
|
||||||
* \param ctx MD5 context to be initialized
|
* \param ctx MD5 context to be initialized
|
||||||
|
|
@ -74,9 +74,9 @@ mbedtls_md5_context;
|
||||||
* stronger message digests instead.
|
* stronger message digests instead.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void mbedtls_md5_init( mbedtls_md5_context *ctx );
|
void mbedtls_md5_init(mbedtls_md5_context* ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Clear MD5 context
|
* \brief Clear MD5 context
|
||||||
*
|
*
|
||||||
* \param ctx MD5 context to be cleared
|
* \param ctx MD5 context to be cleared
|
||||||
|
|
@ -86,9 +86,9 @@ void mbedtls_md5_init( mbedtls_md5_context *ctx );
|
||||||
* stronger message digests instead.
|
* stronger message digests instead.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void mbedtls_md5_free( mbedtls_md5_context *ctx );
|
void mbedtls_md5_free(mbedtls_md5_context* ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Clone (the state of) an MD5 context
|
* \brief Clone (the state of) an MD5 context
|
||||||
*
|
*
|
||||||
* \param dst The destination context
|
* \param dst The destination context
|
||||||
|
|
@ -99,10 +99,10 @@ void mbedtls_md5_free( mbedtls_md5_context *ctx );
|
||||||
* stronger message digests instead.
|
* stronger message digests instead.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void mbedtls_md5_clone( mbedtls_md5_context *dst,
|
void mbedtls_md5_clone(mbedtls_md5_context* dst,
|
||||||
const mbedtls_md5_context *src );
|
const mbedtls_md5_context* src);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief MD5 context setup
|
* \brief MD5 context setup
|
||||||
*
|
*
|
||||||
* \param ctx context to be initialized
|
* \param ctx context to be initialized
|
||||||
|
|
@ -114,9 +114,9 @@ void mbedtls_md5_clone( mbedtls_md5_context *dst,
|
||||||
* stronger message digests instead.
|
* stronger message digests instead.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx );
|
int mbedtls_md5_starts_ret(mbedtls_md5_context* ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief MD5 process buffer
|
* \brief MD5 process buffer
|
||||||
*
|
*
|
||||||
* \param ctx MD5 context
|
* \param ctx MD5 context
|
||||||
|
|
@ -130,11 +130,11 @@ int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx );
|
||||||
* stronger message digests instead.
|
* stronger message digests instead.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int mbedtls_md5_update_ret( mbedtls_md5_context *ctx,
|
int mbedtls_md5_update_ret(mbedtls_md5_context* ctx,
|
||||||
const unsigned char *input,
|
const unsigned char* input,
|
||||||
size_t ilen );
|
size_t ilen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief MD5 final digest
|
* \brief MD5 final digest
|
||||||
*
|
*
|
||||||
* \param ctx MD5 context
|
* \param ctx MD5 context
|
||||||
|
|
@ -147,10 +147,10 @@ int mbedtls_md5_update_ret( mbedtls_md5_context *ctx,
|
||||||
* stronger message digests instead.
|
* stronger message digests instead.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx,
|
int mbedtls_md5_finish_ret(mbedtls_md5_context* ctx,
|
||||||
unsigned char output[16] );
|
unsigned char output[16]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief MD5 process data block (internal use only)
|
* \brief MD5 process data block (internal use only)
|
||||||
*
|
*
|
||||||
* \param ctx MD5 context
|
* \param ctx MD5 context
|
||||||
|
|
@ -163,8 +163,8 @@ int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx,
|
||||||
* stronger message digests instead.
|
* stronger message digests instead.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
|
int mbedtls_internal_md5_process(mbedtls_md5_context* ctx,
|
||||||
const unsigned char data[64] );
|
const unsigned char data[64]);
|
||||||
|
|
||||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||||
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||||
|
|
@ -172,7 +172,7 @@ int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
|
||||||
#else
|
#else
|
||||||
#define MBEDTLS_DEPRECATED
|
#define MBEDTLS_DEPRECATED
|
||||||
#endif
|
#endif
|
||||||
/**
|
/**
|
||||||
* \brief MD5 context setup
|
* \brief MD5 context setup
|
||||||
*
|
*
|
||||||
* \deprecated Superseded by mbedtls_md5_starts_ret() in 2.7.0
|
* \deprecated Superseded by mbedtls_md5_starts_ret() in 2.7.0
|
||||||
|
|
@ -184,9 +184,9 @@ int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
|
||||||
* stronger message digests instead.
|
* stronger message digests instead.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
MBEDTLS_DEPRECATED void mbedtls_md5_starts( mbedtls_md5_context *ctx );
|
MBEDTLS_DEPRECATED void mbedtls_md5_starts(mbedtls_md5_context* ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief MD5 process buffer
|
* \brief MD5 process buffer
|
||||||
*
|
*
|
||||||
* \deprecated Superseded by mbedtls_md5_update_ret() in 2.7.0
|
* \deprecated Superseded by mbedtls_md5_update_ret() in 2.7.0
|
||||||
|
|
@ -200,11 +200,11 @@ MBEDTLS_DEPRECATED void mbedtls_md5_starts( mbedtls_md5_context *ctx );
|
||||||
* stronger message digests instead.
|
* stronger message digests instead.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
MBEDTLS_DEPRECATED void mbedtls_md5_update( mbedtls_md5_context *ctx,
|
MBEDTLS_DEPRECATED void mbedtls_md5_update(mbedtls_md5_context* ctx,
|
||||||
const unsigned char *input,
|
const unsigned char* input,
|
||||||
size_t ilen );
|
size_t ilen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief MD5 final digest
|
* \brief MD5 final digest
|
||||||
*
|
*
|
||||||
* \deprecated Superseded by mbedtls_md5_finish_ret() in 2.7.0
|
* \deprecated Superseded by mbedtls_md5_finish_ret() in 2.7.0
|
||||||
|
|
@ -217,10 +217,10 @@ MBEDTLS_DEPRECATED void mbedtls_md5_update( mbedtls_md5_context *ctx,
|
||||||
* stronger message digests instead.
|
* stronger message digests instead.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
MBEDTLS_DEPRECATED void mbedtls_md5_finish( mbedtls_md5_context *ctx,
|
MBEDTLS_DEPRECATED void mbedtls_md5_finish(mbedtls_md5_context* ctx,
|
||||||
unsigned char output[16] );
|
unsigned char output[16]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief MD5 process data block (internal use only)
|
* \brief MD5 process data block (internal use only)
|
||||||
*
|
*
|
||||||
* \deprecated Superseded by mbedtls_internal_md5_process() in 2.7.0
|
* \deprecated Superseded by mbedtls_internal_md5_process() in 2.7.0
|
||||||
|
|
@ -233,13 +233,13 @@ MBEDTLS_DEPRECATED void mbedtls_md5_finish( mbedtls_md5_context *ctx,
|
||||||
* stronger message digests instead.
|
* stronger message digests instead.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
MBEDTLS_DEPRECATED void mbedtls_md5_process( mbedtls_md5_context *ctx,
|
MBEDTLS_DEPRECATED void mbedtls_md5_process(mbedtls_md5_context* ctx,
|
||||||
const unsigned char data[64] );
|
const unsigned char data[64]);
|
||||||
|
|
||||||
#undef MBEDTLS_DEPRECATED
|
#undef MBEDTLS_DEPRECATED
|
||||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Output = MD5( input buffer )
|
* \brief Output = MD5( input buffer )
|
||||||
*
|
*
|
||||||
* \param input buffer holding the data
|
* \param input buffer holding the data
|
||||||
|
|
@ -253,9 +253,9 @@ MBEDTLS_DEPRECATED void mbedtls_md5_process( mbedtls_md5_context *ctx,
|
||||||
* stronger message digests instead.
|
* stronger message digests instead.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int mbedtls_md5_ret( const unsigned char *input,
|
int mbedtls_md5_ret(const unsigned char* input,
|
||||||
size_t ilen,
|
size_t ilen,
|
||||||
unsigned char output[16] );
|
unsigned char output[16]);
|
||||||
|
|
||||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||||
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||||
|
|
@ -263,7 +263,7 @@ int mbedtls_md5_ret( const unsigned char *input,
|
||||||
#else
|
#else
|
||||||
#define MBEDTLS_DEPRECATED
|
#define MBEDTLS_DEPRECATED
|
||||||
#endif
|
#endif
|
||||||
/**
|
/**
|
||||||
* \brief Output = MD5( input buffer )
|
* \brief Output = MD5( input buffer )
|
||||||
*
|
*
|
||||||
* \deprecated Superseded by mbedtls_md5_ret() in 2.7.0
|
* \deprecated Superseded by mbedtls_md5_ret() in 2.7.0
|
||||||
|
|
@ -277,16 +277,16 @@ int mbedtls_md5_ret( const unsigned char *input,
|
||||||
* stronger message digests instead.
|
* stronger message digests instead.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
MBEDTLS_DEPRECATED void mbedtls_md5( const unsigned char *input,
|
MBEDTLS_DEPRECATED void mbedtls_md5(const unsigned char* input,
|
||||||
size_t ilen,
|
size_t ilen,
|
||||||
unsigned char output[16] );
|
unsigned char output[16]);
|
||||||
|
|
||||||
#undef MBEDTLS_DEPRECATED
|
#undef MBEDTLS_DEPRECATED
|
||||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
||||||
|
|
||||||
#if defined(MBEDTLS_SELF_TEST)
|
#if defined(MBEDTLS_SELF_TEST)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Checkup routine
|
* \brief Checkup routine
|
||||||
*
|
*
|
||||||
* \return 0 if successful, or 1 if the test failed
|
* \return 0 if successful, or 1 if the test failed
|
||||||
|
|
@ -296,7 +296,7 @@ MBEDTLS_DEPRECATED void mbedtls_md5( const unsigned char *input,
|
||||||
* stronger message digests instead.
|
* stronger message digests instead.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int mbedtls_md5_self_test( int verbose );
|
int mbedtls_md5_self_test(int verbose);
|
||||||
|
|
||||||
#endif /* MBEDTLS_SELF_TEST */
|
#endif /* MBEDTLS_SELF_TEST */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,29 +35,26 @@
|
||||||
* 32-bit integer manipulation macros (big endian)
|
* 32-bit integer manipulation macros (big endian)
|
||||||
*/
|
*/
|
||||||
#ifndef GET_UINT32_BE
|
#ifndef GET_UINT32_BE
|
||||||
#define GET_UINT32_BE(n,b,i) \
|
#define GET_UINT32_BE(n, b, i) \
|
||||||
{ \
|
{ \
|
||||||
(n) = ( static_cast<uint32_t>((b)[(i) ]) << 24 ) \
|
(n) = (static_cast<uint32_t>((b)[(i)]) << 24) | (static_cast<uint32_t>((b)[(i) + 1]) << 16) | (static_cast<uint32_t>((b)[(i) + 2]) << 8) | (static_cast<uint32_t>((b)[(i) + 3])); \
|
||||||
| ( static_cast<uint32_t>((b)[(i) + 1]) << 16 ) \
|
}
|
||||||
| ( static_cast<uint32_t>((b)[(i) + 2]) << 8 ) \
|
|
||||||
| ( static_cast<uint32_t>((b)[(i) + 3]) );\
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef PUT_UINT32_BE
|
#ifndef PUT_UINT32_BE
|
||||||
#define PUT_UINT32_BE(n,b,i) \
|
#define PUT_UINT32_BE(n, b, i) \
|
||||||
{ \
|
{ \
|
||||||
(b)[(i) ] = static_cast<unsigned char> ( (n) >> 24 ); \
|
(b)[(i)] = static_cast<unsigned char>((n) >> 24); \
|
||||||
(b)[(i) + 1] = static_cast<unsigned char> ( (n) >> 16 ); \
|
(b)[(i) + 1] = static_cast<unsigned char>((n) >> 16); \
|
||||||
(b)[(i) + 2] = static_cast<unsigned char> ( (n) >> 8 ); \
|
(b)[(i) + 2] = static_cast<unsigned char>((n) >> 8); \
|
||||||
(b)[(i) + 3] = static_cast<unsigned char> ( (n) ); \
|
(b)[(i) + 3] = static_cast<unsigned char>((n)); \
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SHA-1 context setup
|
* SHA-1 context setup
|
||||||
*/
|
*/
|
||||||
void sha1_starts( sha1_context *ctx )
|
void sha1_starts(sha1_context* ctx)
|
||||||
{
|
{
|
||||||
ctx->total[0] = 0;
|
ctx->total[0] = 0;
|
||||||
ctx->total[1] = 0;
|
ctx->total[1] = 0;
|
||||||
|
|
@ -69,40 +66,40 @@ void sha1_starts( sha1_context *ctx )
|
||||||
ctx->state[4] = 0xC3D2E1F0;
|
ctx->state[4] = 0xC3D2E1F0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sha1_process( sha1_context *ctx, const unsigned char data[64] )
|
void sha1_process(sha1_context* ctx, const unsigned char data[64])
|
||||||
{
|
{
|
||||||
uint32_t temp, W[16], A, B, C, D, E;
|
uint32_t temp, W[16], A, B, C, D, E;
|
||||||
|
|
||||||
GET_UINT32_BE( W[ 0], data, 0 );
|
GET_UINT32_BE(W[0], data, 0);
|
||||||
GET_UINT32_BE( W[ 1], data, 4 );
|
GET_UINT32_BE(W[1], data, 4);
|
||||||
GET_UINT32_BE( W[ 2], data, 8 );
|
GET_UINT32_BE(W[2], data, 8);
|
||||||
GET_UINT32_BE( W[ 3], data, 12 );
|
GET_UINT32_BE(W[3], data, 12);
|
||||||
GET_UINT32_BE( W[ 4], data, 16 );
|
GET_UINT32_BE(W[4], data, 16);
|
||||||
GET_UINT32_BE( W[ 5], data, 20 );
|
GET_UINT32_BE(W[5], data, 20);
|
||||||
GET_UINT32_BE( W[ 6], data, 24 );
|
GET_UINT32_BE(W[6], data, 24);
|
||||||
GET_UINT32_BE( W[ 7], data, 28 );
|
GET_UINT32_BE(W[7], data, 28);
|
||||||
GET_UINT32_BE( W[ 8], data, 32 );
|
GET_UINT32_BE(W[8], data, 32);
|
||||||
GET_UINT32_BE( W[ 9], data, 36 );
|
GET_UINT32_BE(W[9], data, 36);
|
||||||
GET_UINT32_BE( W[10], data, 40 );
|
GET_UINT32_BE(W[10], data, 40);
|
||||||
GET_UINT32_BE( W[11], data, 44 );
|
GET_UINT32_BE(W[11], data, 44);
|
||||||
GET_UINT32_BE( W[12], data, 48 );
|
GET_UINT32_BE(W[12], data, 48);
|
||||||
GET_UINT32_BE( W[13], data, 52 );
|
GET_UINT32_BE(W[13], data, 52);
|
||||||
GET_UINT32_BE( W[14], data, 56 );
|
GET_UINT32_BE(W[14], data, 56);
|
||||||
GET_UINT32_BE( W[15], data, 60 );
|
GET_UINT32_BE(W[15], data, 60);
|
||||||
|
|
||||||
#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
|
#define S(x, n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
|
||||||
|
|
||||||
#define R(t) \
|
#define R(t) \
|
||||||
( \
|
( \
|
||||||
temp = W[(t - 3) & 0x0F] ^ W[(t - 8) & 0x0F] ^ \
|
temp = W[(t - 3) & 0x0F] ^ W[(t - 8) & 0x0F] ^ \
|
||||||
W[(t - 14) & 0x0F] ^ W[ t & 0x0F], \
|
W[(t - 14) & 0x0F] ^ W[t & 0x0F], \
|
||||||
( W[t & 0x0F] = S(temp,1) ) \
|
(W[t & 0x0F] = S(temp, 1)))
|
||||||
)
|
|
||||||
|
|
||||||
#define P(a,b,c,d,e,x) \
|
#define P(a, b, c, d, e, x) \
|
||||||
{ \
|
{ \
|
||||||
e += S(a,5) + F(b,c,d) + K + x; b = S(b,30); \
|
e += S(a, 5) + F(b, c, d) + K + x; \
|
||||||
}
|
b = S(b, 30); \
|
||||||
|
}
|
||||||
|
|
||||||
A = ctx->state[0];
|
A = ctx->state[0];
|
||||||
B = ctx->state[1];
|
B = ctx->state[1];
|
||||||
|
|
@ -110,110 +107,110 @@ void sha1_process( sha1_context *ctx, const unsigned char data[64] )
|
||||||
D = ctx->state[3];
|
D = ctx->state[3];
|
||||||
E = ctx->state[4];
|
E = ctx->state[4];
|
||||||
|
|
||||||
#define F(x,y,z) (z ^ (x & (y ^ z)))
|
#define F(x, y, z) (z ^ (x & (y ^ z)))
|
||||||
#define K 0x5A827999
|
#define K 0x5A827999
|
||||||
|
|
||||||
P( A, B, C, D, E, W[0] );
|
P(A, B, C, D, E, W[0]);
|
||||||
P( E, A, B, C, D, W[1] );
|
P(E, A, B, C, D, W[1]);
|
||||||
P( D, E, A, B, C, W[2] );
|
P(D, E, A, B, C, W[2]);
|
||||||
P( C, D, E, A, B, W[3] );
|
P(C, D, E, A, B, W[3]);
|
||||||
P( B, C, D, E, A, W[4] );
|
P(B, C, D, E, A, W[4]);
|
||||||
P( A, B, C, D, E, W[5] );
|
P(A, B, C, D, E, W[5]);
|
||||||
P( E, A, B, C, D, W[6] );
|
P(E, A, B, C, D, W[6]);
|
||||||
P( D, E, A, B, C, W[7] );
|
P(D, E, A, B, C, W[7]);
|
||||||
P( C, D, E, A, B, W[8] );
|
P(C, D, E, A, B, W[8]);
|
||||||
P( B, C, D, E, A, W[9] );
|
P(B, C, D, E, A, W[9]);
|
||||||
P( A, B, C, D, E, W[10] );
|
P(A, B, C, D, E, W[10]);
|
||||||
P( E, A, B, C, D, W[11] );
|
P(E, A, B, C, D, W[11]);
|
||||||
P( D, E, A, B, C, W[12] );
|
P(D, E, A, B, C, W[12]);
|
||||||
P( C, D, E, A, B, W[13] );
|
P(C, D, E, A, B, W[13]);
|
||||||
P( B, C, D, E, A, W[14] );
|
P(B, C, D, E, A, W[14]);
|
||||||
P( A, B, C, D, E, W[15] );
|
P(A, B, C, D, E, W[15]);
|
||||||
P( E, A, B, C, D, R(16) );
|
P(E, A, B, C, D, R(16));
|
||||||
P( D, E, A, B, C, R(17) );
|
P(D, E, A, B, C, R(17));
|
||||||
P( C, D, E, A, B, R(18) );
|
P(C, D, E, A, B, R(18));
|
||||||
P( B, C, D, E, A, R(19) );
|
P(B, C, D, E, A, R(19));
|
||||||
|
|
||||||
#undef K
|
#undef K
|
||||||
#undef F
|
#undef F
|
||||||
|
|
||||||
#define F(x,y,z) (x ^ y ^ z)
|
#define F(x, y, z) (x ^ y ^ z)
|
||||||
#define K 0x6ED9EBA1
|
#define K 0x6ED9EBA1
|
||||||
|
|
||||||
P( A, B, C, D, E, R(20) );
|
P(A, B, C, D, E, R(20));
|
||||||
P( E, A, B, C, D, R(21) );
|
P(E, A, B, C, D, R(21));
|
||||||
P( D, E, A, B, C, R(22) );
|
P(D, E, A, B, C, R(22));
|
||||||
P( C, D, E, A, B, R(23) );
|
P(C, D, E, A, B, R(23));
|
||||||
P( B, C, D, E, A, R(24) );
|
P(B, C, D, E, A, R(24));
|
||||||
P( A, B, C, D, E, R(25) );
|
P(A, B, C, D, E, R(25));
|
||||||
P( E, A, B, C, D, R(26) );
|
P(E, A, B, C, D, R(26));
|
||||||
P( D, E, A, B, C, R(27) );
|
P(D, E, A, B, C, R(27));
|
||||||
P( C, D, E, A, B, R(28) );
|
P(C, D, E, A, B, R(28));
|
||||||
P( B, C, D, E, A, R(29) );
|
P(B, C, D, E, A, R(29));
|
||||||
P( A, B, C, D, E, R(30) );
|
P(A, B, C, D, E, R(30));
|
||||||
P( E, A, B, C, D, R(31) );
|
P(E, A, B, C, D, R(31));
|
||||||
P( D, E, A, B, C, R(32) );
|
P(D, E, A, B, C, R(32));
|
||||||
P( C, D, E, A, B, R(33) );
|
P(C, D, E, A, B, R(33));
|
||||||
P( B, C, D, E, A, R(34) );
|
P(B, C, D, E, A, R(34));
|
||||||
P( A, B, C, D, E, R(35) );
|
P(A, B, C, D, E, R(35));
|
||||||
P( E, A, B, C, D, R(36) );
|
P(E, A, B, C, D, R(36));
|
||||||
P( D, E, A, B, C, R(37) );
|
P(D, E, A, B, C, R(37));
|
||||||
P( C, D, E, A, B, R(38) );
|
P(C, D, E, A, B, R(38));
|
||||||
P( B, C, D, E, A, R(39) );
|
P(B, C, D, E, A, R(39));
|
||||||
|
|
||||||
#undef K
|
#undef K
|
||||||
#undef F
|
#undef F
|
||||||
|
|
||||||
#define F(x,y,z) ((x & y) | (z & (x | y)))
|
#define F(x, y, z) ((x & y) | (z & (x | y)))
|
||||||
#define K 0x8F1BBCDC
|
#define K 0x8F1BBCDC
|
||||||
|
|
||||||
P( A, B, C, D, E, R(40) );
|
P(A, B, C, D, E, R(40));
|
||||||
P( E, A, B, C, D, R(41) );
|
P(E, A, B, C, D, R(41));
|
||||||
P( D, E, A, B, C, R(42) );
|
P(D, E, A, B, C, R(42));
|
||||||
P( C, D, E, A, B, R(43) );
|
P(C, D, E, A, B, R(43));
|
||||||
P( B, C, D, E, A, R(44) );
|
P(B, C, D, E, A, R(44));
|
||||||
P( A, B, C, D, E, R(45) );
|
P(A, B, C, D, E, R(45));
|
||||||
P( E, A, B, C, D, R(46) );
|
P(E, A, B, C, D, R(46));
|
||||||
P( D, E, A, B, C, R(47) );
|
P(D, E, A, B, C, R(47));
|
||||||
P( C, D, E, A, B, R(48) );
|
P(C, D, E, A, B, R(48));
|
||||||
P( B, C, D, E, A, R(49) );
|
P(B, C, D, E, A, R(49));
|
||||||
P( A, B, C, D, E, R(50) );
|
P(A, B, C, D, E, R(50));
|
||||||
P( E, A, B, C, D, R(51) );
|
P(E, A, B, C, D, R(51));
|
||||||
P( D, E, A, B, C, R(52) );
|
P(D, E, A, B, C, R(52));
|
||||||
P( C, D, E, A, B, R(53) );
|
P(C, D, E, A, B, R(53));
|
||||||
P( B, C, D, E, A, R(54) );
|
P(B, C, D, E, A, R(54));
|
||||||
P( A, B, C, D, E, R(55) );
|
P(A, B, C, D, E, R(55));
|
||||||
P( E, A, B, C, D, R(56) );
|
P(E, A, B, C, D, R(56));
|
||||||
P( D, E, A, B, C, R(57) );
|
P(D, E, A, B, C, R(57));
|
||||||
P( C, D, E, A, B, R(58) );
|
P(C, D, E, A, B, R(58));
|
||||||
P( B, C, D, E, A, R(59) );
|
P(B, C, D, E, A, R(59));
|
||||||
|
|
||||||
#undef K
|
#undef K
|
||||||
#undef F
|
#undef F
|
||||||
|
|
||||||
#define F(x,y,z) (x ^ y ^ z)
|
#define F(x, y, z) (x ^ y ^ z)
|
||||||
#define K 0xCA62C1D6
|
#define K 0xCA62C1D6
|
||||||
|
|
||||||
P( A, B, C, D, E, R(60) );
|
P(A, B, C, D, E, R(60));
|
||||||
P( E, A, B, C, D, R(61) );
|
P(E, A, B, C, D, R(61));
|
||||||
P( D, E, A, B, C, R(62) );
|
P(D, E, A, B, C, R(62));
|
||||||
P( C, D, E, A, B, R(63) );
|
P(C, D, E, A, B, R(63));
|
||||||
P( B, C, D, E, A, R(64) );
|
P(B, C, D, E, A, R(64));
|
||||||
P( A, B, C, D, E, R(65) );
|
P(A, B, C, D, E, R(65));
|
||||||
P( E, A, B, C, D, R(66) );
|
P(E, A, B, C, D, R(66));
|
||||||
P( D, E, A, B, C, R(67) );
|
P(D, E, A, B, C, R(67));
|
||||||
P( C, D, E, A, B, R(68) );
|
P(C, D, E, A, B, R(68));
|
||||||
P( B, C, D, E, A, R(69) );
|
P(B, C, D, E, A, R(69));
|
||||||
P( A, B, C, D, E, R(70) );
|
P(A, B, C, D, E, R(70));
|
||||||
P( E, A, B, C, D, R(71) );
|
P(E, A, B, C, D, R(71));
|
||||||
P( D, E, A, B, C, R(72) );
|
P(D, E, A, B, C, R(72));
|
||||||
P( C, D, E, A, B, R(73) );
|
P(C, D, E, A, B, R(73));
|
||||||
P( B, C, D, E, A, R(74) );
|
P(B, C, D, E, A, R(74));
|
||||||
P( A, B, C, D, E, R(75) );
|
P(A, B, C, D, E, R(75));
|
||||||
P( E, A, B, C, D, R(76) );
|
P(E, A, B, C, D, R(76));
|
||||||
P( D, E, A, B, C, R(77) );
|
P(D, E, A, B, C, R(77));
|
||||||
P( C, D, E, A, B, R(78) );
|
P(C, D, E, A, B, R(78));
|
||||||
P( B, C, D, E, A, R(79) );
|
P(B, C, D, E, A, R(79));
|
||||||
|
|
||||||
#undef K
|
#undef K
|
||||||
#undef F
|
#undef F
|
||||||
|
|
@ -228,13 +225,13 @@ void sha1_process( sha1_context *ctx, const unsigned char data[64] )
|
||||||
/*
|
/*
|
||||||
* SHA-1 process buffer
|
* SHA-1 process buffer
|
||||||
*/
|
*/
|
||||||
void sha1_update( sha1_context *ctx, const unsigned char *input, size_t ilen )
|
void sha1_update(sha1_context* ctx, const unsigned char* input, size_t ilen)
|
||||||
{
|
{
|
||||||
size_t fill;
|
size_t fill;
|
||||||
uint32_t left;
|
uint32_t left;
|
||||||
|
|
||||||
// TODO:: Syphurith: Orz. It is said that size_t is an unsigned type..
|
// TODO:: Syphurith: Orz. It is said that size_t is an unsigned type..
|
||||||
if( ilen <= 0 )
|
if (ilen <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
left = ctx->total[0] & 0x3F;
|
left = ctx->total[0] & 0x3F;
|
||||||
|
|
@ -243,155 +240,153 @@ void sha1_update( sha1_context *ctx, const unsigned char *input, size_t ilen )
|
||||||
ctx->total[0] += static_cast<uint32_t>(ilen);
|
ctx->total[0] += static_cast<uint32_t>(ilen);
|
||||||
ctx->total[0] &= 0xFFFFFFFF;
|
ctx->total[0] &= 0xFFFFFFFF;
|
||||||
|
|
||||||
if( ctx->total[0] < static_cast<uint32_t>(ilen) )
|
if (ctx->total[0] < static_cast<uint32_t>(ilen))
|
||||||
ctx->total[1]++;
|
ctx->total[1]++;
|
||||||
|
|
||||||
if( left && ilen >= fill )
|
if (left && ilen >= fill)
|
||||||
{
|
{
|
||||||
memcpy( ctx->buffer + left, input, fill );
|
memcpy(ctx->buffer + left, input, fill);
|
||||||
sha1_process( ctx, ctx->buffer );
|
sha1_process(ctx, ctx->buffer);
|
||||||
input += fill;
|
input += fill;
|
||||||
ilen -= fill;
|
ilen -= fill;
|
||||||
left = 0;
|
left = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while( ilen >= 64 )
|
while (ilen >= 64)
|
||||||
{
|
{
|
||||||
sha1_process( ctx, input );
|
sha1_process(ctx, input);
|
||||||
input += 64;
|
input += 64;
|
||||||
ilen -= 64;
|
ilen -= 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ilen > 0 )
|
if (ilen > 0)
|
||||||
memcpy( ctx->buffer + left, input, ilen );
|
memcpy(ctx->buffer + left, input, ilen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const unsigned char sha1_padding[64] =
|
static const unsigned char sha1_padding[64] =
|
||||||
{
|
{
|
||||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SHA-1 final digest
|
* SHA-1 final digest
|
||||||
*/
|
*/
|
||||||
void sha1_finish( sha1_context *ctx, unsigned char output[20] )
|
void sha1_finish(sha1_context* ctx, unsigned char output[20])
|
||||||
{
|
{
|
||||||
uint32_t last, padn;
|
uint32_t last, padn;
|
||||||
uint32_t high, low;
|
uint32_t high, low;
|
||||||
unsigned char msglen[8];
|
unsigned char msglen[8];
|
||||||
|
|
||||||
high = ( ctx->total[0] >> 29 )
|
high = (ctx->total[0] >> 29) | (ctx->total[1] << 3);
|
||||||
| ( ctx->total[1] << 3 );
|
low = (ctx->total[0] << 3);
|
||||||
low = ( ctx->total[0] << 3 );
|
|
||||||
|
|
||||||
PUT_UINT32_BE( high, msglen, 0 );
|
PUT_UINT32_BE(high, msglen, 0);
|
||||||
PUT_UINT32_BE( low, msglen, 4 );
|
PUT_UINT32_BE(low, msglen, 4);
|
||||||
|
|
||||||
last = ctx->total[0] & 0x3F;
|
last = ctx->total[0] & 0x3F;
|
||||||
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
|
padn = (last < 56) ? (56 - last) : (120 - last);
|
||||||
|
|
||||||
sha1_update( ctx, sha1_padding, padn );
|
sha1_update(ctx, sha1_padding, padn);
|
||||||
sha1_update( ctx, msglen, 8 );
|
sha1_update(ctx, msglen, 8);
|
||||||
|
|
||||||
PUT_UINT32_BE( ctx->state[0], output, 0 );
|
PUT_UINT32_BE(ctx->state[0], output, 0);
|
||||||
PUT_UINT32_BE( ctx->state[1], output, 4 );
|
PUT_UINT32_BE(ctx->state[1], output, 4);
|
||||||
PUT_UINT32_BE( ctx->state[2], output, 8 );
|
PUT_UINT32_BE(ctx->state[2], output, 8);
|
||||||
PUT_UINT32_BE( ctx->state[3], output, 12 );
|
PUT_UINT32_BE(ctx->state[3], output, 12);
|
||||||
PUT_UINT32_BE( ctx->state[4], output, 16 );
|
PUT_UINT32_BE(ctx->state[4], output, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* output = SHA-1( input buffer )
|
* output = SHA-1( input buffer )
|
||||||
*/
|
*/
|
||||||
void sha1( const unsigned char *input, size_t ilen, unsigned char output[20] )
|
void sha1(const unsigned char* input, size_t ilen, unsigned char output[20])
|
||||||
{
|
{
|
||||||
sha1_context ctx;
|
sha1_context ctx;
|
||||||
|
|
||||||
sha1_starts( &ctx );
|
sha1_starts(&ctx);
|
||||||
sha1_update( &ctx, input, ilen );
|
sha1_update(&ctx, input, ilen);
|
||||||
sha1_finish( &ctx, output );
|
sha1_finish(&ctx, output);
|
||||||
|
|
||||||
mbedtls_zeroize( &ctx, sizeof( sha1_context ) );
|
mbedtls_zeroize(&ctx, sizeof(sha1_context));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SHA-1 HMAC context setup
|
* SHA-1 HMAC context setup
|
||||||
*/
|
*/
|
||||||
void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, size_t keylen )
|
void sha1_hmac_starts(sha1_context* ctx, const unsigned char* key, size_t keylen)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
unsigned char sum[20];
|
unsigned char sum[20];
|
||||||
|
|
||||||
if( keylen > 64 )
|
if (keylen > 64)
|
||||||
{
|
{
|
||||||
sha1( key, keylen, sum );
|
sha1(key, keylen, sum);
|
||||||
keylen = 20;
|
keylen = 20;
|
||||||
key = sum;
|
key = sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset( ctx->ipad, 0x36, 64 );
|
memset(ctx->ipad, 0x36, 64);
|
||||||
memset( ctx->opad, 0x5C, 64 );
|
memset(ctx->opad, 0x5C, 64);
|
||||||
|
|
||||||
for( i = 0; i < keylen; i++ )
|
for (i = 0; i < keylen; i++)
|
||||||
{
|
{
|
||||||
ctx->ipad[i] ^= key[i];
|
ctx->ipad[i] ^= key[i];
|
||||||
ctx->opad[i] ^= key[i];
|
ctx->opad[i] ^= key[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
sha1_starts( ctx );
|
sha1_starts(ctx);
|
||||||
sha1_update( ctx, ctx->ipad, 64 );
|
sha1_update(ctx, ctx->ipad, 64);
|
||||||
|
|
||||||
mbedtls_zeroize( sum, sizeof( sum ) );
|
mbedtls_zeroize(sum, sizeof(sum));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SHA-1 HMAC process buffer
|
* SHA-1 HMAC process buffer
|
||||||
*/
|
*/
|
||||||
void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, size_t ilen )
|
void sha1_hmac_update(sha1_context* ctx, const unsigned char* input, size_t ilen)
|
||||||
{
|
{
|
||||||
sha1_update( ctx, input, ilen );
|
sha1_update(ctx, input, ilen);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SHA-1 HMAC final digest
|
* SHA-1 HMAC final digest
|
||||||
*/
|
*/
|
||||||
void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] )
|
void sha1_hmac_finish(sha1_context* ctx, unsigned char output[20])
|
||||||
{
|
{
|
||||||
unsigned char tmpbuf[20];
|
unsigned char tmpbuf[20];
|
||||||
|
|
||||||
sha1_finish( ctx, tmpbuf );
|
sha1_finish(ctx, tmpbuf);
|
||||||
sha1_starts( ctx );
|
sha1_starts(ctx);
|
||||||
sha1_update( ctx, ctx->opad, 64 );
|
sha1_update(ctx, ctx->opad, 64);
|
||||||
sha1_update( ctx, tmpbuf, 20 );
|
sha1_update(ctx, tmpbuf, 20);
|
||||||
sha1_finish( ctx, output );
|
sha1_finish(ctx, output);
|
||||||
|
|
||||||
memset( tmpbuf, 0, sizeof( tmpbuf ) );
|
memset(tmpbuf, 0, sizeof(tmpbuf));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SHA1 HMAC context reset
|
* SHA1 HMAC context reset
|
||||||
*/
|
*/
|
||||||
void sha1_hmac_reset( sha1_context *ctx )
|
void sha1_hmac_reset(sha1_context* ctx)
|
||||||
{
|
{
|
||||||
sha1_starts( ctx );
|
sha1_starts(ctx);
|
||||||
sha1_update( ctx, ctx->ipad, 64 );
|
sha1_update(ctx, ctx->ipad, 64);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* output = HMAC-SHA-1( hmac key, input buffer )
|
* output = HMAC-SHA-1( hmac key, input buffer )
|
||||||
*/
|
*/
|
||||||
void sha1_hmac( const unsigned char *key, size_t keylen,
|
void sha1_hmac(const unsigned char* key, size_t keylen,
|
||||||
const unsigned char *input, size_t ilen,
|
const unsigned char* input, size_t ilen,
|
||||||
unsigned char output[20] )
|
unsigned char output[20])
|
||||||
{
|
{
|
||||||
sha1_context ctx;
|
sha1_context ctx;
|
||||||
|
|
||||||
sha1_hmac_starts( &ctx, key, keylen );
|
sha1_hmac_starts(&ctx, key, keylen);
|
||||||
sha1_hmac_update( &ctx, input, ilen );
|
sha1_hmac_update(&ctx, input, ilen);
|
||||||
sha1_hmac_finish( &ctx, output );
|
sha1_hmac_finish(&ctx, output);
|
||||||
|
|
||||||
memset( &ctx, 0, sizeof( sha1_context ) );
|
memset(&ctx, 0, sizeof(sha1_context));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,58 +51,59 @@ typedef struct
|
||||||
|
|
||||||
unsigned char ipad[64]; /*!< HMAC: inner padding */
|
unsigned char ipad[64]; /*!< HMAC: inner padding */
|
||||||
unsigned char opad[64]; /*!< HMAC: outer padding */
|
unsigned char opad[64]; /*!< HMAC: outer padding */
|
||||||
}
|
} sha1_context;
|
||||||
sha1_context;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief SHA-1 context setup
|
* \brief SHA-1 context setup
|
||||||
*
|
*
|
||||||
* \param ctx context to be initialized
|
* \param ctx context to be initialized
|
||||||
*/
|
*/
|
||||||
void sha1_starts( sha1_context *ctx );
|
void sha1_starts(sha1_context* ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief SHA-1 process buffer
|
* \brief SHA-1 process buffer
|
||||||
*
|
*
|
||||||
* \param ctx SHA-1 context
|
* \param ctx SHA-1 context
|
||||||
* \param input buffer holding the data
|
* \param input buffer holding the data
|
||||||
* \param ilen length of the input data
|
* \param ilen length of the input data
|
||||||
*/
|
*/
|
||||||
void sha1_update( sha1_context *ctx, const unsigned char *input, size_t ilen );
|
void sha1_update(sha1_context* ctx, const unsigned char* input, size_t ilen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief SHA-1 final digest
|
* \brief SHA-1 final digest
|
||||||
*
|
*
|
||||||
* \param ctx SHA-1 context
|
* \param ctx SHA-1 context
|
||||||
* \param output SHA-1 checksum result
|
* \param output SHA-1 checksum result
|
||||||
*/
|
*/
|
||||||
void sha1_finish( sha1_context *ctx, unsigned char output[20] );
|
void sha1_finish(sha1_context* ctx, unsigned char output[20]);
|
||||||
|
|
||||||
/* Internal use */
|
/* Internal use */
|
||||||
void sha1_process( sha1_context *ctx, const unsigned char data[64] );
|
void sha1_process(sha1_context* ctx, const unsigned char data[64]);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Output = SHA-1( input buffer )
|
* \brief Output = SHA-1( input buffer )
|
||||||
*
|
*
|
||||||
* \param input buffer holding the data
|
* \param input buffer holding the data
|
||||||
* \param ilen length of the input data
|
* \param ilen length of the input data
|
||||||
* \param output SHA-1 checksum result
|
* \param output SHA-1 checksum result
|
||||||
*/
|
*/
|
||||||
void sha1( const unsigned char *input, size_t ilen, unsigned char output[20] );
|
void sha1(const unsigned char* input, size_t ilen, unsigned char output[20]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Output = SHA-1( file contents )
|
* \brief Output = SHA-1( file contents )
|
||||||
*
|
*
|
||||||
* \param path input file name
|
* \param path input file name
|
||||||
|
|
@ -110,42 +111,42 @@ void sha1( const unsigned char *input, size_t ilen, unsigned char output[20] );
|
||||||
*
|
*
|
||||||
* \return 0 if successful, or POLARSSL_ERR_SHA1_FILE_IO_ERROR
|
* \return 0 if successful, or POLARSSL_ERR_SHA1_FILE_IO_ERROR
|
||||||
*/
|
*/
|
||||||
int sha1_file( const char *path, unsigned char output[20] );
|
int sha1_file(const char* path, unsigned char output[20]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief SHA-1 HMAC context setup
|
* \brief SHA-1 HMAC context setup
|
||||||
*
|
*
|
||||||
* \param ctx HMAC context to be initialized
|
* \param ctx HMAC context to be initialized
|
||||||
* \param key HMAC secret key
|
* \param key HMAC secret key
|
||||||
* \param keylen length of the HMAC key
|
* \param keylen length of the HMAC key
|
||||||
*/
|
*/
|
||||||
void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, size_t keylen );
|
void sha1_hmac_starts(sha1_context* ctx, const unsigned char* key, size_t keylen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief SHA-1 HMAC process buffer
|
* \brief SHA-1 HMAC process buffer
|
||||||
*
|
*
|
||||||
* \param ctx HMAC context
|
* \param ctx HMAC context
|
||||||
* \param input buffer holding the data
|
* \param input buffer holding the data
|
||||||
* \param ilen length of the input data
|
* \param ilen length of the input data
|
||||||
*/
|
*/
|
||||||
void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, size_t ilen );
|
void sha1_hmac_update(sha1_context* ctx, const unsigned char* input, size_t ilen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief SHA-1 HMAC final digest
|
* \brief SHA-1 HMAC final digest
|
||||||
*
|
*
|
||||||
* \param ctx HMAC context
|
* \param ctx HMAC context
|
||||||
* \param output SHA-1 HMAC checksum result
|
* \param output SHA-1 HMAC checksum result
|
||||||
*/
|
*/
|
||||||
void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] );
|
void sha1_hmac_finish(sha1_context* ctx, unsigned char output[20]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief SHA-1 HMAC context reset
|
* \brief SHA-1 HMAC context reset
|
||||||
*
|
*
|
||||||
* \param ctx HMAC context to be reset
|
* \param ctx HMAC context to be reset
|
||||||
*/
|
*/
|
||||||
void sha1_hmac_reset( sha1_context *ctx );
|
void sha1_hmac_reset(sha1_context* ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Output = HMAC-SHA-1( hmac key, input buffer )
|
* \brief Output = HMAC-SHA-1( hmac key, input buffer )
|
||||||
*
|
*
|
||||||
* \param key HMAC secret key
|
* \param key HMAC secret key
|
||||||
|
|
@ -154,9 +155,9 @@ void sha1_hmac_reset( sha1_context *ctx );
|
||||||
* \param ilen length of the input data
|
* \param ilen length of the input data
|
||||||
* \param output HMAC-SHA-1 result
|
* \param output HMAC-SHA-1 result
|
||||||
*/
|
*/
|
||||||
void sha1_hmac( const unsigned char *key, size_t keylen,
|
void sha1_hmac(const unsigned char* key, size_t keylen,
|
||||||
const unsigned char *input, size_t ilen,
|
const unsigned char* input, size_t ilen,
|
||||||
unsigned char output[20] );
|
unsigned char output[20]);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,45 +52,44 @@
|
||||||
* 32-bit integer manipulation macros (big endian)
|
* 32-bit integer manipulation macros (big endian)
|
||||||
*/
|
*/
|
||||||
#ifndef GET_UINT32_BE
|
#ifndef GET_UINT32_BE
|
||||||
#define GET_UINT32_BE(n,b,i) \
|
#define GET_UINT32_BE(n, b, i) \
|
||||||
do { \
|
do \
|
||||||
(n) = ( static_cast<uint32_t>((b)[(i) ]) << 24 ) \
|
{ \
|
||||||
| ( static_cast<uint32_t>((b)[(i) + 1]) << 16 ) \
|
(n) = (static_cast<uint32_t>((b)[(i)]) << 24) | (static_cast<uint32_t>((b)[(i) + 1]) << 16) | (static_cast<uint32_t>((b)[(i) + 2]) << 8) | (static_cast<uint32_t>((b)[(i) + 3])); \
|
||||||
| ( static_cast<uint32_t>((b)[(i) + 2]) << 8 ) \
|
} while (0)
|
||||||
| ( static_cast<uint32_t>((b)[(i) + 3]) );\
|
|
||||||
} while( 0 )
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef PUT_UINT32_BE
|
#ifndef PUT_UINT32_BE
|
||||||
#define PUT_UINT32_BE(n,b,i) \
|
#define PUT_UINT32_BE(n, b, i) \
|
||||||
do { \
|
do \
|
||||||
(b)[(i) ] = static_cast<unsigned char> ( (n) >> 24 ); \
|
{ \
|
||||||
(b)[(i) + 1] = static_cast<unsigned char> ( (n) >> 16 ); \
|
(b)[(i)] = static_cast<unsigned char>((n) >> 24); \
|
||||||
(b)[(i) + 2] = static_cast<unsigned char> ( (n) >> 8 ); \
|
(b)[(i) + 1] = static_cast<unsigned char>((n) >> 16); \
|
||||||
(b)[(i) + 3] = static_cast<unsigned char> ( (n) ); \
|
(b)[(i) + 2] = static_cast<unsigned char>((n) >> 8); \
|
||||||
} while( 0 )
|
(b)[(i) + 3] = static_cast<unsigned char>((n)); \
|
||||||
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void mbedtls_sha256_init( mbedtls_sha256_context *ctx )
|
void mbedtls_sha256_init(mbedtls_sha256_context* ctx)
|
||||||
{
|
{
|
||||||
SHA256_VALIDATE( ctx != NULL );
|
SHA256_VALIDATE(ctx != NULL);
|
||||||
|
|
||||||
memset( ctx, 0, sizeof( mbedtls_sha256_context ) );
|
memset(ctx, 0, sizeof(mbedtls_sha256_context));
|
||||||
}
|
}
|
||||||
|
|
||||||
void mbedtls_sha256_free( mbedtls_sha256_context *ctx )
|
void mbedtls_sha256_free(mbedtls_sha256_context* ctx)
|
||||||
{
|
{
|
||||||
if( ctx == NULL )
|
if (ctx == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mbedtls_zeroize(ctx, sizeof(mbedtls_sha256_context));
|
mbedtls_zeroize(ctx, sizeof(mbedtls_sha256_context));
|
||||||
}
|
}
|
||||||
|
|
||||||
void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
|
void mbedtls_sha256_clone(mbedtls_sha256_context* dst,
|
||||||
const mbedtls_sha256_context *src )
|
const mbedtls_sha256_context* src)
|
||||||
{
|
{
|
||||||
SHA256_VALIDATE( dst != NULL );
|
SHA256_VALIDATE(dst != NULL);
|
||||||
SHA256_VALIDATE( src != NULL );
|
SHA256_VALIDATE(src != NULL);
|
||||||
|
|
||||||
*dst = *src;
|
*dst = *src;
|
||||||
}
|
}
|
||||||
|
|
@ -98,15 +97,15 @@ void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
|
||||||
/*
|
/*
|
||||||
* SHA-256 context setup
|
* SHA-256 context setup
|
||||||
*/
|
*/
|
||||||
int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 )
|
int mbedtls_sha256_starts_ret(mbedtls_sha256_context* ctx, int is224)
|
||||||
{
|
{
|
||||||
SHA256_VALIDATE_RET( ctx != NULL );
|
SHA256_VALIDATE_RET(ctx != NULL);
|
||||||
SHA256_VALIDATE_RET( is224 == 0 || is224 == 1 );
|
SHA256_VALIDATE_RET(is224 == 0 || is224 == 1);
|
||||||
|
|
||||||
ctx->total[0] = 0;
|
ctx->total[0] = 0;
|
||||||
ctx->total[1] = 0;
|
ctx->total[1] = 0;
|
||||||
|
|
||||||
if( is224 == 0 )
|
if (is224 == 0)
|
||||||
{
|
{
|
||||||
/* SHA-256 */
|
/* SHA-256 */
|
||||||
ctx->state[0] = 0x6A09E667;
|
ctx->state[0] = 0x6A09E667;
|
||||||
|
|
@ -133,130 +132,185 @@ int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 )
|
||||||
|
|
||||||
ctx->is224 = is224;
|
ctx->is224 = is224;
|
||||||
|
|
||||||
return( 0 );
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||||
void mbedtls_sha256_starts( mbedtls_sha256_context *ctx,
|
void mbedtls_sha256_starts(mbedtls_sha256_context* ctx,
|
||||||
int is224 )
|
int is224)
|
||||||
{
|
{
|
||||||
mbedtls_sha256_starts_ret( ctx, is224 );
|
mbedtls_sha256_starts_ret(ctx, is224);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(MBEDTLS_SHA256_PROCESS_ALT)
|
#if !defined(MBEDTLS_SHA256_PROCESS_ALT)
|
||||||
static const uint32_t K[] =
|
static const uint32_t K[] =
|
||||||
{
|
{
|
||||||
0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
|
0x428A2F98,
|
||||||
0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
|
0x71374491,
|
||||||
0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
|
0xB5C0FBCF,
|
||||||
0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
|
0xE9B5DBA5,
|
||||||
0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
|
0x3956C25B,
|
||||||
0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
|
0x59F111F1,
|
||||||
0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
|
0x923F82A4,
|
||||||
0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
|
0xAB1C5ED5,
|
||||||
0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
|
0xD807AA98,
|
||||||
0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
|
0x12835B01,
|
||||||
0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
|
0x243185BE,
|
||||||
0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
|
0x550C7DC3,
|
||||||
0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
|
0x72BE5D74,
|
||||||
0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
|
0x80DEB1FE,
|
||||||
0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
|
0x9BDC06A7,
|
||||||
0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2,
|
0xC19BF174,
|
||||||
|
0xE49B69C1,
|
||||||
|
0xEFBE4786,
|
||||||
|
0x0FC19DC6,
|
||||||
|
0x240CA1CC,
|
||||||
|
0x2DE92C6F,
|
||||||
|
0x4A7484AA,
|
||||||
|
0x5CB0A9DC,
|
||||||
|
0x76F988DA,
|
||||||
|
0x983E5152,
|
||||||
|
0xA831C66D,
|
||||||
|
0xB00327C8,
|
||||||
|
0xBF597FC7,
|
||||||
|
0xC6E00BF3,
|
||||||
|
0xD5A79147,
|
||||||
|
0x06CA6351,
|
||||||
|
0x14292967,
|
||||||
|
0x27B70A85,
|
||||||
|
0x2E1B2138,
|
||||||
|
0x4D2C6DFC,
|
||||||
|
0x53380D13,
|
||||||
|
0x650A7354,
|
||||||
|
0x766A0ABB,
|
||||||
|
0x81C2C92E,
|
||||||
|
0x92722C85,
|
||||||
|
0xA2BFE8A1,
|
||||||
|
0xA81A664B,
|
||||||
|
0xC24B8B70,
|
||||||
|
0xC76C51A3,
|
||||||
|
0xD192E819,
|
||||||
|
0xD6990624,
|
||||||
|
0xF40E3585,
|
||||||
|
0x106AA070,
|
||||||
|
0x19A4C116,
|
||||||
|
0x1E376C08,
|
||||||
|
0x2748774C,
|
||||||
|
0x34B0BCB5,
|
||||||
|
0x391C0CB3,
|
||||||
|
0x4ED8AA4A,
|
||||||
|
0x5B9CCA4F,
|
||||||
|
0x682E6FF3,
|
||||||
|
0x748F82EE,
|
||||||
|
0x78A5636F,
|
||||||
|
0x84C87814,
|
||||||
|
0x8CC70208,
|
||||||
|
0x90BEFFFA,
|
||||||
|
0xA4506CEB,
|
||||||
|
0xBEF9A3F7,
|
||||||
|
0xC67178F2,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SHR(x,n) (((x) & 0xFFFFFFFF) >> (n))
|
#define SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
|
||||||
#define ROTR(x,n) (SHR(x,n) | ((x) << (32 - (n))))
|
#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
|
||||||
|
|
||||||
#define S0(x) (ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3))
|
#define S0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3))
|
||||||
#define S1(x) (ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10))
|
#define S1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10))
|
||||||
|
|
||||||
#define S2(x) (ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22))
|
#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
|
||||||
#define S3(x) (ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25))
|
#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
|
||||||
|
|
||||||
#define F0(x,y,z) (((x) & (y)) | ((z) & ((x) | (y))))
|
#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
|
||||||
#define F1(x,y,z) ((z) ^ ((x) & ((y) ^ (z))))
|
#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
|
||||||
|
|
||||||
#define R(t) \
|
#define R(t) \
|
||||||
( \
|
( \
|
||||||
W[t] = S1(W[(t) - 2]) + W[(t) - 7] + \
|
W[t] = S1(W[(t) - 2]) + W[(t) - 7] + \
|
||||||
S0(W[(t) - 15]) + W[(t) - 16] \
|
S0(W[(t) - 15]) + W[(t) - 16])
|
||||||
)
|
|
||||||
|
|
||||||
#define P(a,b,c,d,e,f,g,h,x,K) \
|
#define P(a, b, c, d, e, f, g, h, x, K) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
temp1 = (h) + S3(e) + F1((e),(f),(g)) + (K) + (x); \
|
temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x); \
|
||||||
temp2 = S2(a) + F0((a),(b),(c)); \
|
temp2 = S2(a) + F0((a), (b), (c)); \
|
||||||
(d) += temp1; (h) = temp1 + temp2; \
|
(d) += temp1; \
|
||||||
} while( 0 )
|
(h) = temp1 + temp2; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
|
int mbedtls_internal_sha256_process(mbedtls_sha256_context* ctx,
|
||||||
const unsigned char data[64] )
|
const unsigned char data[64])
|
||||||
{
|
{
|
||||||
uint32_t temp1, temp2, W[64];
|
uint32_t temp1, temp2, W[64];
|
||||||
uint32_t A[8];
|
uint32_t A[8];
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
SHA256_VALIDATE_RET( ctx != NULL );
|
SHA256_VALIDATE_RET(ctx != NULL);
|
||||||
SHA256_VALIDATE_RET( (const unsigned char *)data != NULL );
|
SHA256_VALIDATE_RET((const unsigned char*)data != NULL);
|
||||||
|
|
||||||
for( i = 0; i < 8; i++ )
|
for (i = 0; i < 8; i++)
|
||||||
A[i] = ctx->state[i];
|
A[i] = ctx->state[i];
|
||||||
|
|
||||||
#if defined(MBEDTLS_SHA256_SMALLER)
|
#if defined(MBEDTLS_SHA256_SMALLER)
|
||||||
for( i = 0; i < 64; i++ )
|
for (i = 0; i < 64; i++)
|
||||||
{
|
{
|
||||||
if( i < 16 )
|
if (i < 16)
|
||||||
GET_UINT32_BE( W[i], data, 4 * i );
|
GET_UINT32_BE(W[i], data, 4 * i);
|
||||||
else
|
else
|
||||||
R( i );
|
R(i);
|
||||||
|
|
||||||
P( A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], W[i], K[i] );
|
P(A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], W[i], K[i]);
|
||||||
|
|
||||||
temp1 = A[7]; A[7] = A[6]; A[6] = A[5]; A[5] = A[4]; A[4] = A[3];
|
temp1 = A[7];
|
||||||
A[3] = A[2]; A[2] = A[1]; A[1] = A[0]; A[0] = temp1;
|
A[7] = A[6];
|
||||||
|
A[6] = A[5];
|
||||||
|
A[5] = A[4];
|
||||||
|
A[4] = A[3];
|
||||||
|
A[3] = A[2];
|
||||||
|
A[2] = A[1];
|
||||||
|
A[1] = A[0];
|
||||||
|
A[0] = temp1;
|
||||||
}
|
}
|
||||||
#else /* MBEDTLS_SHA256_SMALLER */
|
#else /* MBEDTLS_SHA256_SMALLER */
|
||||||
for( i = 0; i < 16; i++ )
|
for (i = 0; i < 16; i++)
|
||||||
GET_UINT32_BE( W[i], data, 4 * i );
|
GET_UINT32_BE(W[i], data, 4 * i);
|
||||||
|
|
||||||
for( i = 0; i < 16; i += 8 )
|
for (i = 0; i < 16; i += 8)
|
||||||
{
|
{
|
||||||
P( A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], W[i+0], K[i+0] );
|
P(A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], W[i + 0], K[i + 0]);
|
||||||
P( A[7], A[0], A[1], A[2], A[3], A[4], A[5], A[6], W[i+1], K[i+1] );
|
P(A[7], A[0], A[1], A[2], A[3], A[4], A[5], A[6], W[i + 1], K[i + 1]);
|
||||||
P( A[6], A[7], A[0], A[1], A[2], A[3], A[4], A[5], W[i+2], K[i+2] );
|
P(A[6], A[7], A[0], A[1], A[2], A[3], A[4], A[5], W[i + 2], K[i + 2]);
|
||||||
P( A[5], A[6], A[7], A[0], A[1], A[2], A[3], A[4], W[i+3], K[i+3] );
|
P(A[5], A[6], A[7], A[0], A[1], A[2], A[3], A[4], W[i + 3], K[i + 3]);
|
||||||
P( A[4], A[5], A[6], A[7], A[0], A[1], A[2], A[3], W[i+4], K[i+4] );
|
P(A[4], A[5], A[6], A[7], A[0], A[1], A[2], A[3], W[i + 4], K[i + 4]);
|
||||||
P( A[3], A[4], A[5], A[6], A[7], A[0], A[1], A[2], W[i+5], K[i+5] );
|
P(A[3], A[4], A[5], A[6], A[7], A[0], A[1], A[2], W[i + 5], K[i + 5]);
|
||||||
P( A[2], A[3], A[4], A[5], A[6], A[7], A[0], A[1], W[i+6], K[i+6] );
|
P(A[2], A[3], A[4], A[5], A[6], A[7], A[0], A[1], W[i + 6], K[i + 6]);
|
||||||
P( A[1], A[2], A[3], A[4], A[5], A[6], A[7], A[0], W[i+7], K[i+7] );
|
P(A[1], A[2], A[3], A[4], A[5], A[6], A[7], A[0], W[i + 7], K[i + 7]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for( i = 16; i < 64; i += 8 )
|
for (i = 16; i < 64; i += 8)
|
||||||
{
|
{
|
||||||
P( A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], R(i+0), K[i+0] );
|
P(A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], R(i + 0), K[i + 0]);
|
||||||
P( A[7], A[0], A[1], A[2], A[3], A[4], A[5], A[6], R(i+1), K[i+1] );
|
P(A[7], A[0], A[1], A[2], A[3], A[4], A[5], A[6], R(i + 1), K[i + 1]);
|
||||||
P( A[6], A[7], A[0], A[1], A[2], A[3], A[4], A[5], R(i+2), K[i+2] );
|
P(A[6], A[7], A[0], A[1], A[2], A[3], A[4], A[5], R(i + 2), K[i + 2]);
|
||||||
P( A[5], A[6], A[7], A[0], A[1], A[2], A[3], A[4], R(i+3), K[i+3] );
|
P(A[5], A[6], A[7], A[0], A[1], A[2], A[3], A[4], R(i + 3), K[i + 3]);
|
||||||
P( A[4], A[5], A[6], A[7], A[0], A[1], A[2], A[3], R(i+4), K[i+4] );
|
P(A[4], A[5], A[6], A[7], A[0], A[1], A[2], A[3], R(i + 4), K[i + 4]);
|
||||||
P( A[3], A[4], A[5], A[6], A[7], A[0], A[1], A[2], R(i+5), K[i+5] );
|
P(A[3], A[4], A[5], A[6], A[7], A[0], A[1], A[2], R(i + 5), K[i + 5]);
|
||||||
P( A[2], A[3], A[4], A[5], A[6], A[7], A[0], A[1], R(i+6), K[i+6] );
|
P(A[2], A[3], A[4], A[5], A[6], A[7], A[0], A[1], R(i + 6), K[i + 6]);
|
||||||
P( A[1], A[2], A[3], A[4], A[5], A[6], A[7], A[0], R(i+7), K[i+7] );
|
P(A[1], A[2], A[3], A[4], A[5], A[6], A[7], A[0], R(i + 7), K[i + 7]);
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_SHA256_SMALLER */
|
#endif /* MBEDTLS_SHA256_SMALLER */
|
||||||
|
|
||||||
for( i = 0; i < 8; i++ )
|
for (i = 0; i < 8; i++)
|
||||||
ctx->state[i] += A[i];
|
ctx->state[i] += A[i];
|
||||||
|
|
||||||
return( 0 );
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||||
void mbedtls_sha256_process( mbedtls_sha256_context *ctx,
|
void mbedtls_sha256_process(mbedtls_sha256_context* ctx,
|
||||||
const unsigned char data[64] )
|
const unsigned char data[64])
|
||||||
{
|
{
|
||||||
mbedtls_internal_sha256_process( ctx, data );
|
mbedtls_internal_sha256_process(ctx, data);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif /* !MBEDTLS_SHA256_PROCESS_ALT */
|
#endif /* !MBEDTLS_SHA256_PROCESS_ALT */
|
||||||
|
|
@ -264,19 +318,19 @@ void mbedtls_sha256_process( mbedtls_sha256_context *ctx,
|
||||||
/*
|
/*
|
||||||
* SHA-256 process buffer
|
* SHA-256 process buffer
|
||||||
*/
|
*/
|
||||||
int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
|
int mbedtls_sha256_update_ret(mbedtls_sha256_context* ctx,
|
||||||
const unsigned char *input,
|
const unsigned char* input,
|
||||||
size_t ilen )
|
size_t ilen)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
size_t fill;
|
size_t fill;
|
||||||
uint32_t left;
|
uint32_t left;
|
||||||
|
|
||||||
SHA256_VALIDATE_RET( ctx != NULL );
|
SHA256_VALIDATE_RET(ctx != NULL);
|
||||||
SHA256_VALIDATE_RET( ilen == 0 || input != NULL );
|
SHA256_VALIDATE_RET(ilen == 0 || input != NULL);
|
||||||
|
|
||||||
if( ilen == 0 )
|
if (ilen == 0)
|
||||||
return( 0 );
|
return (0);
|
||||||
|
|
||||||
left = ctx->total[0] & 0x3F;
|
left = ctx->total[0] & 0x3F;
|
||||||
fill = 64 - left;
|
fill = 64 - left;
|
||||||
|
|
@ -284,57 +338,57 @@ int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
|
||||||
ctx->total[0] += static_cast<uint32_t>(ilen);
|
ctx->total[0] += static_cast<uint32_t>(ilen);
|
||||||
ctx->total[0] &= 0xFFFFFFFF;
|
ctx->total[0] &= 0xFFFFFFFF;
|
||||||
|
|
||||||
if( ctx->total[0] < static_cast<uint32_t>(ilen) )
|
if (ctx->total[0] < static_cast<uint32_t>(ilen))
|
||||||
ctx->total[1]++;
|
ctx->total[1]++;
|
||||||
|
|
||||||
if( left && ilen >= fill )
|
if (left && ilen >= fill)
|
||||||
{
|
{
|
||||||
memcpy( ctx->buffer + left, input, fill );
|
memcpy(ctx->buffer + left, input, fill);
|
||||||
|
|
||||||
if( ( ret = mbedtls_internal_sha256_process( ctx, ctx->buffer ) ) != 0 )
|
if ((ret = mbedtls_internal_sha256_process(ctx, ctx->buffer)) != 0)
|
||||||
return( ret );
|
return (ret);
|
||||||
|
|
||||||
input += fill;
|
input += fill;
|
||||||
ilen -= fill;
|
ilen -= fill;
|
||||||
left = 0;
|
left = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while( ilen >= 64 )
|
while (ilen >= 64)
|
||||||
{
|
{
|
||||||
if( ( ret = mbedtls_internal_sha256_process( ctx, input ) ) != 0 )
|
if ((ret = mbedtls_internal_sha256_process(ctx, input)) != 0)
|
||||||
return( ret );
|
return (ret);
|
||||||
|
|
||||||
input += 64;
|
input += 64;
|
||||||
ilen -= 64;
|
ilen -= 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ilen > 0 )
|
if (ilen > 0)
|
||||||
memcpy( ctx->buffer + left, input, ilen );
|
memcpy(ctx->buffer + left, input, ilen);
|
||||||
|
|
||||||
return( 0 );
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||||
void mbedtls_sha256_update( mbedtls_sha256_context *ctx,
|
void mbedtls_sha256_update(mbedtls_sha256_context* ctx,
|
||||||
const unsigned char *input,
|
const unsigned char* input,
|
||||||
size_t ilen )
|
size_t ilen)
|
||||||
{
|
{
|
||||||
mbedtls_sha256_update_ret( ctx, input, ilen );
|
mbedtls_sha256_update_ret(ctx, input, ilen);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SHA-256 final digest
|
* SHA-256 final digest
|
||||||
*/
|
*/
|
||||||
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
|
int mbedtls_sha256_finish_ret(mbedtls_sha256_context* ctx,
|
||||||
unsigned char output[32] )
|
unsigned char output[32])
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
uint32_t used;
|
uint32_t used;
|
||||||
uint32_t high, low;
|
uint32_t high, low;
|
||||||
|
|
||||||
SHA256_VALIDATE_RET( ctx != NULL );
|
SHA256_VALIDATE_RET(ctx != NULL);
|
||||||
SHA256_VALIDATE_RET( (unsigned char *)output != NULL );
|
SHA256_VALIDATE_RET((unsigned char*)output != NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add padding: 0x80 then 0x00 until 8 bytes remain for the length
|
* Add padding: 0x80 then 0x00 until 8 bytes remain for the length
|
||||||
|
|
@ -343,57 +397,56 @@ int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
|
||||||
|
|
||||||
ctx->buffer[used++] = 0x80;
|
ctx->buffer[used++] = 0x80;
|
||||||
|
|
||||||
if( used <= 56 )
|
if (used <= 56)
|
||||||
{
|
{
|
||||||
/* Enough room for padding + length in current block */
|
/* Enough room for padding + length in current block */
|
||||||
memset( ctx->buffer + used, 0, 56 - used );
|
memset(ctx->buffer + used, 0, 56 - used);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* We'll need an extra block */
|
/* We'll need an extra block */
|
||||||
memset( ctx->buffer + used, 0, 64 - used );
|
memset(ctx->buffer + used, 0, 64 - used);
|
||||||
|
|
||||||
if( ( ret = mbedtls_internal_sha256_process( ctx, ctx->buffer ) ) != 0 )
|
if ((ret = mbedtls_internal_sha256_process(ctx, ctx->buffer)) != 0)
|
||||||
return( ret );
|
return (ret);
|
||||||
|
|
||||||
memset( ctx->buffer, 0, 56 );
|
memset(ctx->buffer, 0, 56);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add message length
|
* Add message length
|
||||||
*/
|
*/
|
||||||
high = ( ctx->total[0] >> 29 )
|
high = (ctx->total[0] >> 29) | (ctx->total[1] << 3);
|
||||||
| ( ctx->total[1] << 3 );
|
low = (ctx->total[0] << 3);
|
||||||
low = ( ctx->total[0] << 3 );
|
|
||||||
|
|
||||||
PUT_UINT32_BE( high, ctx->buffer, 56 );
|
PUT_UINT32_BE(high, ctx->buffer, 56);
|
||||||
PUT_UINT32_BE( low, ctx->buffer, 60 );
|
PUT_UINT32_BE(low, ctx->buffer, 60);
|
||||||
|
|
||||||
if( ( ret = mbedtls_internal_sha256_process( ctx, ctx->buffer ) ) != 0 )
|
if ((ret = mbedtls_internal_sha256_process(ctx, ctx->buffer)) != 0)
|
||||||
return( ret );
|
return (ret);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Output final state
|
* Output final state
|
||||||
*/
|
*/
|
||||||
PUT_UINT32_BE( ctx->state[0], output, 0 );
|
PUT_UINT32_BE(ctx->state[0], output, 0);
|
||||||
PUT_UINT32_BE( ctx->state[1], output, 4 );
|
PUT_UINT32_BE(ctx->state[1], output, 4);
|
||||||
PUT_UINT32_BE( ctx->state[2], output, 8 );
|
PUT_UINT32_BE(ctx->state[2], output, 8);
|
||||||
PUT_UINT32_BE( ctx->state[3], output, 12 );
|
PUT_UINT32_BE(ctx->state[3], output, 12);
|
||||||
PUT_UINT32_BE( ctx->state[4], output, 16 );
|
PUT_UINT32_BE(ctx->state[4], output, 16);
|
||||||
PUT_UINT32_BE( ctx->state[5], output, 20 );
|
PUT_UINT32_BE(ctx->state[5], output, 20);
|
||||||
PUT_UINT32_BE( ctx->state[6], output, 24 );
|
PUT_UINT32_BE(ctx->state[6], output, 24);
|
||||||
|
|
||||||
if( ctx->is224 == 0 )
|
if (ctx->is224 == 0)
|
||||||
PUT_UINT32_BE( ctx->state[7], output, 28 );
|
PUT_UINT32_BE(ctx->state[7], output, 28);
|
||||||
|
|
||||||
return( 0 );
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||||
void mbedtls_sha256_finish( mbedtls_sha256_context *ctx,
|
void mbedtls_sha256_finish(mbedtls_sha256_context* ctx,
|
||||||
unsigned char output[32] )
|
unsigned char output[32])
|
||||||
{
|
{
|
||||||
mbedtls_sha256_finish_ret( ctx, output );
|
mbedtls_sha256_finish_ret(ctx, output);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -402,41 +455,41 @@ void mbedtls_sha256_finish( mbedtls_sha256_context *ctx,
|
||||||
/*
|
/*
|
||||||
* output = SHA-256( input buffer )
|
* output = SHA-256( input buffer )
|
||||||
*/
|
*/
|
||||||
int mbedtls_sha256_ret( const unsigned char *input,
|
int mbedtls_sha256_ret(const unsigned char* input,
|
||||||
size_t ilen,
|
size_t ilen,
|
||||||
unsigned char output[32],
|
unsigned char output[32],
|
||||||
int is224 )
|
int is224)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
mbedtls_sha256_context ctx;
|
mbedtls_sha256_context ctx;
|
||||||
|
|
||||||
SHA256_VALIDATE_RET( is224 == 0 || is224 == 1 );
|
SHA256_VALIDATE_RET(is224 == 0 || is224 == 1);
|
||||||
SHA256_VALIDATE_RET( ilen == 0 || input != NULL );
|
SHA256_VALIDATE_RET(ilen == 0 || input != NULL);
|
||||||
SHA256_VALIDATE_RET( (unsigned char *)output != NULL );
|
SHA256_VALIDATE_RET((unsigned char*)output != NULL);
|
||||||
|
|
||||||
mbedtls_sha256_init( &ctx );
|
mbedtls_sha256_init(&ctx);
|
||||||
|
|
||||||
if( ( ret = mbedtls_sha256_starts_ret( &ctx, is224 ) ) != 0 )
|
if ((ret = mbedtls_sha256_starts_ret(&ctx, is224)) != 0)
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
if( ( ret = mbedtls_sha256_update_ret( &ctx, input, ilen ) ) != 0 )
|
if ((ret = mbedtls_sha256_update_ret(&ctx, input, ilen)) != 0)
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
if( ( ret = mbedtls_sha256_finish_ret( &ctx, output ) ) != 0 )
|
if ((ret = mbedtls_sha256_finish_ret(&ctx, output)) != 0)
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
mbedtls_sha256_free( &ctx );
|
mbedtls_sha256_free(&ctx);
|
||||||
|
|
||||||
return( ret );
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||||
void mbedtls_sha256( const unsigned char *input,
|
void mbedtls_sha256(const unsigned char* input,
|
||||||
size_t ilen,
|
size_t ilen,
|
||||||
unsigned char output[32],
|
unsigned char output[32],
|
||||||
int is224 )
|
int is224)
|
||||||
{
|
{
|
||||||
mbedtls_sha256_ret( input, ilen, output, is224 );
|
mbedtls_sha256_ret(input, ilen, output, is224);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -37,60 +37,60 @@
|
||||||
#define MBEDTLS_ERR_SHA256_BAD_INPUT_DATA -0x0074 /**< SHA-256 input data was malformed. */
|
#define MBEDTLS_ERR_SHA256_BAD_INPUT_DATA -0x0074 /**< SHA-256 input data was malformed. */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(MBEDTLS_SHA256_ALT)
|
#if !defined(MBEDTLS_SHA256_ALT)
|
||||||
// Regular implementation
|
// Regular implementation
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief The SHA-256 context structure.
|
* \brief The SHA-256 context structure.
|
||||||
*
|
*
|
||||||
* The structure is used both for SHA-256 and for SHA-224
|
* The structure is used both for SHA-256 and for SHA-224
|
||||||
* checksum calculations. The choice between these two is
|
* checksum calculations. The choice between these two is
|
||||||
* made in the call to mbedtls_sha256_starts_ret().
|
* made in the call to mbedtls_sha256_starts_ret().
|
||||||
*/
|
*/
|
||||||
typedef struct mbedtls_sha256_context
|
typedef struct mbedtls_sha256_context
|
||||||
{
|
{
|
||||||
uint32_t total[2]; /*!< The number of Bytes processed. */
|
uint32_t total[2]; /*!< The number of Bytes processed. */
|
||||||
uint32_t state[8]; /*!< The intermediate digest state. */
|
uint32_t state[8]; /*!< The intermediate digest state. */
|
||||||
unsigned char buffer[64]; /*!< The data block being processed. */
|
unsigned char buffer[64]; /*!< The data block being processed. */
|
||||||
int is224; /*!< Determines which function to use:
|
int is224; /*!< Determines which function to use:
|
||||||
0: Use SHA-256, or 1: Use SHA-224. */
|
0: Use SHA-256, or 1: Use SHA-224. */
|
||||||
}
|
} mbedtls_sha256_context;
|
||||||
mbedtls_sha256_context;
|
|
||||||
|
|
||||||
#else /* MBEDTLS_SHA256_ALT */
|
#else /* MBEDTLS_SHA256_ALT */
|
||||||
#include "sha256_alt.h"
|
#include "sha256_alt.h"
|
||||||
#endif /* MBEDTLS_SHA256_ALT */
|
#endif /* MBEDTLS_SHA256_ALT */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief This function initializes a SHA-256 context.
|
* \brief This function initializes a SHA-256 context.
|
||||||
*
|
*
|
||||||
* \param ctx The SHA-256 context to initialize. This must not be \c NULL.
|
* \param ctx The SHA-256 context to initialize. This must not be \c NULL.
|
||||||
*/
|
*/
|
||||||
void mbedtls_sha256_init( mbedtls_sha256_context *ctx );
|
void mbedtls_sha256_init(mbedtls_sha256_context* ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief This function clears a SHA-256 context.
|
* \brief This function clears a SHA-256 context.
|
||||||
*
|
*
|
||||||
* \param ctx The SHA-256 context to clear. This may be \c NULL, in which
|
* \param ctx The SHA-256 context to clear. This may be \c NULL, in which
|
||||||
* case this function returns immediately. If it is not \c NULL,
|
* case this function returns immediately. If it is not \c NULL,
|
||||||
* it must point to an initialized SHA-256 context.
|
* it must point to an initialized SHA-256 context.
|
||||||
*/
|
*/
|
||||||
void mbedtls_sha256_free( mbedtls_sha256_context *ctx );
|
void mbedtls_sha256_free(mbedtls_sha256_context* ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief This function clones the state of a SHA-256 context.
|
* \brief This function clones the state of a SHA-256 context.
|
||||||
*
|
*
|
||||||
* \param dst The destination context. This must be initialized.
|
* \param dst The destination context. This must be initialized.
|
||||||
* \param src The context to clone. This must be initialized.
|
* \param src The context to clone. This must be initialized.
|
||||||
*/
|
*/
|
||||||
void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
|
void mbedtls_sha256_clone(mbedtls_sha256_context* dst,
|
||||||
const mbedtls_sha256_context *src );
|
const mbedtls_sha256_context* src);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief This function starts a SHA-224 or SHA-256 checksum
|
* \brief This function starts a SHA-224 or SHA-256 checksum
|
||||||
* calculation.
|
* calculation.
|
||||||
*
|
*
|
||||||
|
|
@ -101,9 +101,9 @@ void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
|
||||||
* \return \c 0 on success.
|
* \return \c 0 on success.
|
||||||
* \return A negative error code on failure.
|
* \return A negative error code on failure.
|
||||||
*/
|
*/
|
||||||
int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
|
int mbedtls_sha256_starts_ret(mbedtls_sha256_context* ctx, int is224);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief This function feeds an input buffer into an ongoing
|
* \brief This function feeds an input buffer into an ongoing
|
||||||
* SHA-256 checksum calculation.
|
* SHA-256 checksum calculation.
|
||||||
*
|
*
|
||||||
|
|
@ -116,11 +116,11 @@ int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
|
||||||
* \return \c 0 on success.
|
* \return \c 0 on success.
|
||||||
* \return A negative error code on failure.
|
* \return A negative error code on failure.
|
||||||
*/
|
*/
|
||||||
int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
|
int mbedtls_sha256_update_ret(mbedtls_sha256_context* ctx,
|
||||||
const unsigned char *input,
|
const unsigned char* input,
|
||||||
size_t ilen );
|
size_t ilen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief This function finishes the SHA-256 operation, and writes
|
* \brief This function finishes the SHA-256 operation, and writes
|
||||||
* the result to the output buffer.
|
* the result to the output buffer.
|
||||||
*
|
*
|
||||||
|
|
@ -132,10 +132,10 @@ int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
|
||||||
* \return \c 0 on success.
|
* \return \c 0 on success.
|
||||||
* \return A negative error code on failure.
|
* \return A negative error code on failure.
|
||||||
*/
|
*/
|
||||||
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
|
int mbedtls_sha256_finish_ret(mbedtls_sha256_context* ctx,
|
||||||
unsigned char output[32] );
|
unsigned char output[32]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief This function processes a single data block within
|
* \brief This function processes a single data block within
|
||||||
* the ongoing SHA-256 computation. This function is for
|
* the ongoing SHA-256 computation. This function is for
|
||||||
* internal use only.
|
* internal use only.
|
||||||
|
|
@ -147,8 +147,8 @@ int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
|
||||||
* \return \c 0 on success.
|
* \return \c 0 on success.
|
||||||
* \return A negative error code on failure.
|
* \return A negative error code on failure.
|
||||||
*/
|
*/
|
||||||
int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
|
int mbedtls_internal_sha256_process(mbedtls_sha256_context* ctx,
|
||||||
const unsigned char data[64] );
|
const unsigned char data[64]);
|
||||||
|
|
||||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||||
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||||
|
|
@ -156,7 +156,7 @@ int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
|
||||||
#else
|
#else
|
||||||
#define MBEDTLS_DEPRECATED
|
#define MBEDTLS_DEPRECATED
|
||||||
#endif
|
#endif
|
||||||
/**
|
/**
|
||||||
* \brief This function starts a SHA-224 or SHA-256 checksum
|
* \brief This function starts a SHA-224 or SHA-256 checksum
|
||||||
* calculation.
|
* calculation.
|
||||||
*
|
*
|
||||||
|
|
@ -166,10 +166,10 @@ int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
|
||||||
* \param is224 Determines which function to use. This must be
|
* \param is224 Determines which function to use. This must be
|
||||||
* either \c 0 for SHA-256, or \c 1 for SHA-224.
|
* either \c 0 for SHA-256, or \c 1 for SHA-224.
|
||||||
*/
|
*/
|
||||||
MBEDTLS_DEPRECATED void mbedtls_sha256_starts( mbedtls_sha256_context *ctx,
|
MBEDTLS_DEPRECATED void mbedtls_sha256_starts(mbedtls_sha256_context* ctx,
|
||||||
int is224 );
|
int is224);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief This function feeds an input buffer into an ongoing
|
* \brief This function feeds an input buffer into an ongoing
|
||||||
* SHA-256 checksum calculation.
|
* SHA-256 checksum calculation.
|
||||||
*
|
*
|
||||||
|
|
@ -181,11 +181,11 @@ MBEDTLS_DEPRECATED void mbedtls_sha256_starts( mbedtls_sha256_context *ctx,
|
||||||
* buffer of length \p ilen Bytes.
|
* buffer of length \p ilen Bytes.
|
||||||
* \param ilen The length of the input data in Bytes.
|
* \param ilen The length of the input data in Bytes.
|
||||||
*/
|
*/
|
||||||
MBEDTLS_DEPRECATED void mbedtls_sha256_update( mbedtls_sha256_context *ctx,
|
MBEDTLS_DEPRECATED void mbedtls_sha256_update(mbedtls_sha256_context* ctx,
|
||||||
const unsigned char *input,
|
const unsigned char* input,
|
||||||
size_t ilen );
|
size_t ilen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief This function finishes the SHA-256 operation, and writes
|
* \brief This function finishes the SHA-256 operation, and writes
|
||||||
* the result to the output buffer.
|
* the result to the output buffer.
|
||||||
*
|
*
|
||||||
|
|
@ -196,10 +196,10 @@ MBEDTLS_DEPRECATED void mbedtls_sha256_update( mbedtls_sha256_context *ctx,
|
||||||
* \param output The SHA-224 or SHA-256 checksum result. This must be
|
* \param output The SHA-224 or SHA-256 checksum result. This must be
|
||||||
* a writable buffer of length \c 32 Bytes.
|
* a writable buffer of length \c 32 Bytes.
|
||||||
*/
|
*/
|
||||||
MBEDTLS_DEPRECATED void mbedtls_sha256_finish( mbedtls_sha256_context *ctx,
|
MBEDTLS_DEPRECATED void mbedtls_sha256_finish(mbedtls_sha256_context* ctx,
|
||||||
unsigned char output[32] );
|
unsigned char output[32]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief This function processes a single data block within
|
* \brief This function processes a single data block within
|
||||||
* the ongoing SHA-256 computation. This function is for
|
* the ongoing SHA-256 computation. This function is for
|
||||||
* internal use only.
|
* internal use only.
|
||||||
|
|
@ -210,13 +210,13 @@ MBEDTLS_DEPRECATED void mbedtls_sha256_finish( mbedtls_sha256_context *ctx,
|
||||||
* \param data The buffer holding one block of data. This must be
|
* \param data The buffer holding one block of data. This must be
|
||||||
* a readable buffer of size \c 64 Bytes.
|
* a readable buffer of size \c 64 Bytes.
|
||||||
*/
|
*/
|
||||||
MBEDTLS_DEPRECATED void mbedtls_sha256_process( mbedtls_sha256_context *ctx,
|
MBEDTLS_DEPRECATED void mbedtls_sha256_process(mbedtls_sha256_context* ctx,
|
||||||
const unsigned char data[64] );
|
const unsigned char data[64]);
|
||||||
|
|
||||||
#undef MBEDTLS_DEPRECATED
|
#undef MBEDTLS_DEPRECATED
|
||||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief This function calculates the SHA-224 or SHA-256
|
* \brief This function calculates the SHA-224 or SHA-256
|
||||||
* checksum of a buffer.
|
* checksum of a buffer.
|
||||||
*
|
*
|
||||||
|
|
@ -234,10 +234,10 @@ MBEDTLS_DEPRECATED void mbedtls_sha256_process( mbedtls_sha256_context *ctx,
|
||||||
* \param is224 Determines which function to use. This must be
|
* \param is224 Determines which function to use. This must be
|
||||||
* either \c 0 for SHA-256, or \c 1 for SHA-224.
|
* either \c 0 for SHA-256, or \c 1 for SHA-224.
|
||||||
*/
|
*/
|
||||||
int mbedtls_sha256_ret( const unsigned char *input,
|
int mbedtls_sha256_ret(const unsigned char* input,
|
||||||
size_t ilen,
|
size_t ilen,
|
||||||
unsigned char output[32],
|
unsigned char output[32],
|
||||||
int is224 );
|
int is224);
|
||||||
|
|
||||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||||
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||||
|
|
@ -246,7 +246,7 @@ int mbedtls_sha256_ret( const unsigned char *input,
|
||||||
#define MBEDTLS_DEPRECATED
|
#define MBEDTLS_DEPRECATED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief This function calculates the SHA-224 or SHA-256 checksum
|
* \brief This function calculates the SHA-224 or SHA-256 checksum
|
||||||
* of a buffer.
|
* of a buffer.
|
||||||
*
|
*
|
||||||
|
|
@ -266,10 +266,10 @@ int mbedtls_sha256_ret( const unsigned char *input,
|
||||||
* \param is224 Determines which function to use. This must be either
|
* \param is224 Determines which function to use. This must be either
|
||||||
* \c 0 for SHA-256, or \c 1 for SHA-224.
|
* \c 0 for SHA-256, or \c 1 for SHA-224.
|
||||||
*/
|
*/
|
||||||
MBEDTLS_DEPRECATED void mbedtls_sha256( const unsigned char *input,
|
MBEDTLS_DEPRECATED void mbedtls_sha256(const unsigned char* input,
|
||||||
size_t ilen,
|
size_t ilen,
|
||||||
unsigned char output[32],
|
unsigned char output[32],
|
||||||
int is224 );
|
int is224);
|
||||||
|
|
||||||
#undef MBEDTLS_DEPRECATED
|
#undef MBEDTLS_DEPRECATED
|
||||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
LOG_CHANNEL(edat_log, "EDAT");
|
LOG_CHANNEL(edat_log, "EDAT");
|
||||||
|
|
||||||
void generate_key(int crypto_mode, int version, unsigned char *key_final, unsigned char *iv_final, unsigned char *key, unsigned char *iv)
|
void generate_key(int crypto_mode, int version, unsigned char* key_final, unsigned char* iv_final, unsigned char* key, unsigned char* iv)
|
||||||
{
|
{
|
||||||
int mode = crypto_mode & 0xF0000000;
|
int mode = crypto_mode & 0xF0000000;
|
||||||
uchar temp_iv[16]{};
|
uchar temp_iv[16]{};
|
||||||
|
|
@ -42,7 +42,7 @@ void generate_key(int crypto_mode, int version, unsigned char *key_final, unsign
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void generate_hash(int hash_mode, int version, unsigned char *hash_final, unsigned char *hash)
|
void generate_hash(int hash_mode, int version, unsigned char* hash_final, unsigned char* hash)
|
||||||
{
|
{
|
||||||
int mode = hash_mode & 0xF0000000;
|
int mode = hash_mode & 0xF0000000;
|
||||||
uchar temp_iv[16]{};
|
uchar temp_iv[16]{};
|
||||||
|
|
@ -67,7 +67,7 @@ void generate_hash(int hash_mode, int version, unsigned char *hash_final, unsign
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool decrypt(int hash_mode, int crypto_mode, int version, unsigned char *in, unsigned char *out, usz length, unsigned char *key, unsigned char *iv, unsigned char *hash, unsigned char *test_hash)
|
bool decrypt(int hash_mode, int crypto_mode, int version, unsigned char* in, unsigned char* out, usz length, unsigned char* key, unsigned char* iv, unsigned char* hash, unsigned char* test_hash)
|
||||||
{
|
{
|
||||||
// Setup buffers for key, iv and hash.
|
// Setup buffers for key, iv and hash.
|
||||||
unsigned char key_final[0x10] = {};
|
unsigned char key_final[0x10] = {};
|
||||||
|
|
@ -104,7 +104,7 @@ bool decrypt(int hash_mode, int crypto_mode, int version, unsigned char *in, uns
|
||||||
{
|
{
|
||||||
return cmac_hash_compare(hash_final_10, 0x10, in, length, test_hash, 0x10);
|
return cmac_hash_compare(hash_final_10, 0x10, in, length, test_hash, 0x10);
|
||||||
}
|
}
|
||||||
else if ((hash_mode & 0xFF) == 0x04) //0x10 SHA1-HMAC
|
else if ((hash_mode & 0xFF) == 0x04) // 0x10 SHA1-HMAC
|
||||||
{
|
{
|
||||||
return hmac_hash_compare(hash_final_10, 0x10, in, length, test_hash, 0x10);
|
return hmac_hash_compare(hash_final_10, 0x10, in, length, test_hash, 0x10);
|
||||||
}
|
}
|
||||||
|
|
@ -143,10 +143,10 @@ std::tuple<u64, s32, s32> dec_section(unsigned char* metadata)
|
||||||
return std::make_tuple(offset, length, compression_end);
|
return std::make_tuple(offset, length, compression_end);
|
||||||
}
|
}
|
||||||
|
|
||||||
u128 get_block_key(int block, NPD_HEADER *npd)
|
u128 get_block_key(int block, NPD_HEADER* npd)
|
||||||
{
|
{
|
||||||
unsigned char empty_key[0x10] = {};
|
unsigned char empty_key[0x10] = {};
|
||||||
unsigned char *src_key = (npd->version <= 1) ? empty_key : npd->dev_hash;
|
unsigned char* src_key = (npd->version <= 1) ? empty_key : npd->dev_hash;
|
||||||
u128 dest_key{};
|
u128 dest_key{};
|
||||||
std::memcpy(&dest_key, src_key, 0xC);
|
std::memcpy(&dest_key, src_key, 0xC);
|
||||||
|
|
||||||
|
|
@ -158,15 +158,15 @@ u128 get_block_key(int block, NPD_HEADER *npd)
|
||||||
// for out data, allocate a buffer the size of 'edat->block_size'
|
// for out data, allocate a buffer the size of 'edat->block_size'
|
||||||
// Also, set 'in file' to the beginning of the encrypted data, which may be offset if inside another file, but normally just reset to beginning of file
|
// Also, set 'in file' to the beginning of the encrypted data, which may be offset if inside another file, but normally just reset to beginning of file
|
||||||
// returns number of bytes written, -1 for error
|
// returns number of bytes written, -1 for error
|
||||||
s64 decrypt_block(const fs::file* in, u8* out, EDAT_HEADER *edat, NPD_HEADER *npd, u8* crypt_key, u32 block_num, u32 total_blocks, u64 size_left, bool is_out_buffer_aligned = false)
|
s64 decrypt_block(const fs::file* in, u8* out, EDAT_HEADER* edat, NPD_HEADER* npd, u8* crypt_key, u32 block_num, u32 total_blocks, u64 size_left, bool is_out_buffer_aligned = false)
|
||||||
{
|
{
|
||||||
// Get metadata info and setup buffers.
|
// Get metadata info and setup buffers.
|
||||||
const int metadata_section_size = ((edat->flags & EDAT_COMPRESSED_FLAG) != 0 || (edat->flags & EDAT_FLAG_0x20) != 0) ? 0x20 : 0x10;
|
const int metadata_section_size = ((edat->flags & EDAT_COMPRESSED_FLAG) != 0 || (edat->flags & EDAT_FLAG_0x20) != 0) ? 0x20 : 0x10;
|
||||||
const int metadata_offset = 0x100;
|
const int metadata_offset = 0x100;
|
||||||
|
|
||||||
u8 hash[0x10] = { 0 };
|
u8 hash[0x10] = {0};
|
||||||
u8 key_result[0x10] = { 0 };
|
u8 key_result[0x10] = {0};
|
||||||
u8 hash_result[0x14] = { 0 };
|
u8 hash_result[0x14] = {0};
|
||||||
|
|
||||||
u64 offset = 0;
|
u64 offset = 0;
|
||||||
u64 metadata_sec_offset = 0;
|
u64 metadata_sec_offset = 0;
|
||||||
|
|
@ -344,10 +344,10 @@ s64 decrypt_block(const fs::file* in, u8* out, EDAT_HEADER *edat, NPD_HEADER *np
|
||||||
// set file offset to beginning before calling
|
// set file offset to beginning before calling
|
||||||
bool check_data(u8* key, EDAT_HEADER* edat, NPD_HEADER* npd, const fs::file* f, bool verbose)
|
bool check_data(u8* key, EDAT_HEADER* edat, NPD_HEADER* npd, const fs::file* f, bool verbose)
|
||||||
{
|
{
|
||||||
u8 header[0xA0] = { 0 };
|
u8 header[0xA0] = {0};
|
||||||
u8 empty_header[0xA0] = { 0 };
|
u8 empty_header[0xA0] = {0};
|
||||||
u8 header_hash[0x10] = { 0 };
|
u8 header_hash[0x10] = {0};
|
||||||
u8 metadata_hash[0x10] = { 0 };
|
u8 metadata_hash[0x10] = {0};
|
||||||
|
|
||||||
const u64 file_offset = f->pos();
|
const u64 file_offset = f->pos();
|
||||||
|
|
||||||
|
|
@ -402,8 +402,8 @@ bool check_data(u8* key, EDAT_HEADER* edat, NPD_HEADER* npd, const fs::file* f,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup header key and iv buffers.
|
// Setup header key and iv buffers.
|
||||||
unsigned char header_key[0x10] = { 0 };
|
unsigned char header_key[0x10] = {0};
|
||||||
unsigned char header_iv[0x10] = { 0 };
|
unsigned char header_iv[0x10] = {0};
|
||||||
|
|
||||||
// Test the header hash (located at offset 0xA0).
|
// Test the header hash (located at offset 0xA0).
|
||||||
if (!decrypt(hash_mode, crypto_mode, (npd->version == 4), header, empty_header, 0xA0, header_key, header_iv, key, header_hash))
|
if (!decrypt(hash_mode, crypto_mode, (npd->version == 4), header, empty_header, 0xA0, header_key, header_iv, key, header_hash))
|
||||||
|
|
@ -474,12 +474,12 @@ bool check_data(u8* key, EDAT_HEADER* edat, NPD_HEADER* npd, const fs::file* f,
|
||||||
if ((edat->flags & EDAT_DEBUG_DATA_FLAG) == 0)
|
if ((edat->flags & EDAT_DEBUG_DATA_FLAG) == 0)
|
||||||
{
|
{
|
||||||
// Setup buffers.
|
// Setup buffers.
|
||||||
unsigned char metadata_signature[0x28] = { 0 };
|
unsigned char metadata_signature[0x28] = {0};
|
||||||
unsigned char header_signature[0x28] = { 0 };
|
unsigned char header_signature[0x28] = {0};
|
||||||
unsigned char signature_hash[20] = { 0 };
|
unsigned char signature_hash[20] = {0};
|
||||||
unsigned char signature_r[0x15] = { 0 };
|
unsigned char signature_r[0x15] = {0};
|
||||||
unsigned char signature_s[0x15] = { 0 };
|
unsigned char signature_s[0x15] = {0};
|
||||||
unsigned char zero_buf[0x15] = { 0 };
|
unsigned char zero_buf[0x15] = {0};
|
||||||
|
|
||||||
// Setup ECDSA curve and public key.
|
// Setup ECDSA curve and public key.
|
||||||
ecdsa_set_curve(VSH_CURVE_P, VSH_CURVE_A, VSH_CURVE_B, VSH_CURVE_N, VSH_CURVE_GX, VSH_CURVE_GY);
|
ecdsa_set_curve(VSH_CURVE_P, VSH_CURVE_A, VSH_CURVE_B, VSH_CURVE_N, VSH_CURVE_GX, VSH_CURVE_GY);
|
||||||
|
|
@ -503,7 +503,7 @@ bool check_data(u8* key, EDAT_HEADER* edat, NPD_HEADER* npd, const fs::file* f,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Setup signature hash.
|
// Setup signature hash.
|
||||||
if ((edat->flags & EDAT_FLAG_0x20) != 0) //Sony failed again, they used buffer from 0x100 with half size of real metadata.
|
if ((edat->flags & EDAT_FLAG_0x20) != 0) // Sony failed again, they used buffer from 0x100 with half size of real metadata.
|
||||||
{
|
{
|
||||||
const usz metadata_buf_size = block_num * 0x10;
|
const usz metadata_buf_size = block_num * 0x10;
|
||||||
|
|
||||||
|
|
@ -553,7 +553,7 @@ bool check_data(u8* key, EDAT_HEADER* edat, NPD_HEADER* npd, const fs::file* f,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool validate_dev_klic(const u8* klicensee, NPD_HEADER *npd)
|
bool validate_dev_klic(const u8* klicensee, NPD_HEADER* npd)
|
||||||
{
|
{
|
||||||
if ((npd->license & 0x3) != 0x3)
|
if ((npd->license & 0x3) != 0x3)
|
||||||
{
|
{
|
||||||
|
|
@ -718,7 +718,7 @@ bool VerifyEDATHeaderWithKLicense(const fs::file& input, const std::string& inpu
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrypts full file
|
// Decrypts full file
|
||||||
fs::file DecryptEDAT(const fs::file& input, const std::string& input_file_name, int mode, u8 *custom_klic)
|
fs::file DecryptEDAT(const fs::file& input, const std::string& input_file_name, int mode, u8* custom_klic)
|
||||||
{
|
{
|
||||||
if (!input)
|
if (!input)
|
||||||
{
|
{
|
||||||
|
|
@ -853,7 +853,7 @@ bool EDATADecrypter::ReadHeader()
|
||||||
|
|
||||||
// k the ecdsa_verify function in this check_data function takes a ridiculous amount of time
|
// k the ecdsa_verify function in this check_data function takes a ridiculous amount of time
|
||||||
// like it slows down load time by a factor of x20, at least, so its ignored for now
|
// like it slows down load time by a factor of x20, at least, so its ignored for now
|
||||||
//if (!check_data(reinterpret_cast<u8*>(&dec_key), &edatHeader, &npdHeader, &edata_file, false))
|
// if (!check_data(reinterpret_cast<u8*>(&dec_key), &edatHeader, &npdHeader, &edata_file, false))
|
||||||
//{
|
//{
|
||||||
// edat_log.error("NPDRM check_data() failed!");
|
// edat_log.error("NPDRM check_data() failed!");
|
||||||
// return false;
|
// return false;
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,10 @@ struct loaded_npdrm_keys
|
||||||
|
|
||||||
void install_decryption_key(u128 key)
|
void install_decryption_key(u128 key)
|
||||||
{
|
{
|
||||||
dec_keys_pos.atomic_op([&](u64& pos) { dec_keys[pos++ % std::size(dec_keys)] = key; });
|
dec_keys_pos.atomic_op([&](u64& pos)
|
||||||
|
{
|
||||||
|
dec_keys[pos++ % std::size(dec_keys)] = key;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Check if correct for ELF files usage
|
// TODO: Check if correct for ELF files usage
|
||||||
|
|
@ -59,10 +62,10 @@ struct EDAT_HEADER
|
||||||
};
|
};
|
||||||
|
|
||||||
// Decrypts full file, or null/empty file
|
// Decrypts full file, or null/empty file
|
||||||
extern fs::file DecryptEDAT(const fs::file& input, const std::string& input_file_name, int mode, u8 *custom_klic);
|
extern fs::file DecryptEDAT(const fs::file& input, const std::string& input_file_name, int mode, u8* custom_klic);
|
||||||
|
|
||||||
extern void read_npd_edat_header(const fs::file* input, NPD_HEADER& NPD, EDAT_HEADER& EDAT);
|
extern void read_npd_edat_header(const fs::file* input, NPD_HEADER& NPD, EDAT_HEADER& EDAT);
|
||||||
extern bool VerifyEDATHeaderWithKLicense(const fs::file& input, const std::string& input_file_name, const u8* custom_klic, NPD_HEADER *npd_out = nullptr);
|
extern bool VerifyEDATHeaderWithKLicense(const fs::file& input, const std::string& input_file_name, const u8* custom_klic, NPD_HEADER* npd_out = nullptr);
|
||||||
|
|
||||||
u128 GetEdatRifKeyFromRapFile(const fs::file& rap_file);
|
u128 GetEdatRifKeyFromRapFile(const fs::file& rap_file);
|
||||||
|
|
||||||
|
|
@ -84,20 +87,12 @@ struct EDATADecrypter final : fs::file_base
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EDATADecrypter(fs::file&& input, u128 dec_key = {}, std::string file_name = {}, bool is_key_final = true) noexcept
|
EDATADecrypter(fs::file&& input, u128 dec_key = {}, std::string file_name = {}, bool is_key_final = true) noexcept
|
||||||
: m_edata_file(std::move(input))
|
: m_edata_file(std::move(input)), edata_file(m_edata_file), m_file_name(std::move(file_name)), m_is_key_final(is_key_final), dec_key(dec_key)
|
||||||
, edata_file(m_edata_file)
|
|
||||||
, m_file_name(std::move(file_name))
|
|
||||||
, m_is_key_final(is_key_final)
|
|
||||||
, dec_key(dec_key)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
EDATADecrypter(const fs::file& input, u128 dec_key = {}, std::string file_name = {}, bool is_key_final = true) noexcept
|
EDATADecrypter(const fs::file& input, u128 dec_key = {}, std::string file_name = {}, bool is_key_final = true) noexcept
|
||||||
: m_edata_file(fs::file{})
|
: m_edata_file(fs::file{}), edata_file(input), m_file_name(std::move(file_name)), m_is_key_final(is_key_final), dec_key(dec_key)
|
||||||
, edata_file(input)
|
|
||||||
, m_file_name(std::move(file_name))
|
|
||||||
, m_is_key_final(is_key_final)
|
|
||||||
, dec_key(dec_key)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -140,7 +135,8 @@ public:
|
||||||
const s64 new_pos =
|
const s64 new_pos =
|
||||||
whence == fs::seek_set ? offset :
|
whence == fs::seek_set ? offset :
|
||||||
whence == fs::seek_cur ? offset + pos :
|
whence == fs::seek_cur ? offset + pos :
|
||||||
whence == fs::seek_end ? offset + size() : -1;
|
whence == fs::seek_end ? offset + size() :
|
||||||
|
-1;
|
||||||
|
|
||||||
if (new_pos < 0)
|
if (new_pos < 0)
|
||||||
{
|
{
|
||||||
|
|
@ -152,7 +148,10 @@ public:
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 size() override { return file_size; }
|
u64 size() override
|
||||||
|
{
|
||||||
|
return file_size;
|
||||||
|
}
|
||||||
|
|
||||||
fs::file_id get_id() override
|
fs::file_id get_id() override
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,7 @@
|
||||||
LOG_CHANNEL(pkg_log, "PKG");
|
LOG_CHANNEL(pkg_log, "PKG");
|
||||||
|
|
||||||
package_reader::package_reader(const std::string& path, fs::file file)
|
package_reader::package_reader(const std::string& path, fs::file file)
|
||||||
: m_path(path)
|
: m_path(path), m_file(std::move(file))
|
||||||
, m_file(std::move(file))
|
|
||||||
{
|
{
|
||||||
if (!m_file && !m_file.open(path))
|
if (!m_file && !m_file.open(path))
|
||||||
{
|
{
|
||||||
|
|
@ -108,10 +107,10 @@ bool package_reader::read_header()
|
||||||
pkg_log.notice("Extended header: main_and_ext_headers_hmac_offset = 0x%x = %d", ext_header.main_and_ext_headers_hmac_offset, ext_header.main_and_ext_headers_hmac_offset);
|
pkg_log.notice("Extended header: main_and_ext_headers_hmac_offset = 0x%x = %d", ext_header.main_and_ext_headers_hmac_offset, ext_header.main_and_ext_headers_hmac_offset);
|
||||||
pkg_log.notice("Extended header: metadata_header_hmac_offset = 0x%x = %d", ext_header.metadata_header_hmac_offset, ext_header.metadata_header_hmac_offset);
|
pkg_log.notice("Extended header: metadata_header_hmac_offset = 0x%x = %d", ext_header.metadata_header_hmac_offset, ext_header.metadata_header_hmac_offset);
|
||||||
pkg_log.notice("Extended header: tail_offset = 0x%x = %d", ext_header.tail_offset, ext_header.tail_offset);
|
pkg_log.notice("Extended header: tail_offset = 0x%x = %d", ext_header.tail_offset, ext_header.tail_offset);
|
||||||
//pkg_log.notice("Extended header: padding1 = 0x%x = %d", ext_header.padding1, ext_header.padding1);
|
// pkg_log.notice("Extended header: padding1 = 0x%x = %d", ext_header.padding1, ext_header.padding1);
|
||||||
pkg_log.notice("Extended header: pkg_key_id = 0x%x = %d", ext_header.pkg_key_id, ext_header.pkg_key_id);
|
pkg_log.notice("Extended header: pkg_key_id = 0x%x = %d", ext_header.pkg_key_id, ext_header.pkg_key_id);
|
||||||
pkg_log.notice("Extended header: full_header_hmac_offset = 0x%x = %d", ext_header.full_header_hmac_offset, ext_header.full_header_hmac_offset);
|
pkg_log.notice("Extended header: full_header_hmac_offset = 0x%x = %d", ext_header.full_header_hmac_offset, ext_header.full_header_hmac_offset);
|
||||||
//pkg_log.notice("Extended header: padding2 = 0x%x = %d", ext_header.padding2, ext_header.padding2);
|
// pkg_log.notice("Extended header: padding2 = 0x%x = %d", ext_header.padding2, ext_header.padding2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_header.pkg_magic != std::bit_cast<le_t<u32>>("\x7FPKG"_u32))
|
if (m_header.pkg_magic != std::bit_cast<le_t<u32>>("\x7FPKG"_u32))
|
||||||
|
|
@ -500,7 +499,9 @@ bool package_reader::set_decryption_key()
|
||||||
// TODO: Not all the keys seem to match the content types. I was only able to install a dlc (0x16) with PKG_AES_KEY_VITA_1
|
// TODO: Not all the keys seem to match the content types. I was only able to install a dlc (0x16) with PKG_AES_KEY_VITA_1
|
||||||
|
|
||||||
aes_context ctx;
|
aes_context ctx;
|
||||||
aes_setkey_enc(&ctx, m_metadata.content_type == 0x15u ? PKG_AES_KEY_VITA_1 : m_metadata.content_type == 0x16u ? PKG_AES_KEY_VITA_2 : PKG_AES_KEY_VITA_3, 128);
|
aes_setkey_enc(&ctx, m_metadata.content_type == 0x15u ? PKG_AES_KEY_VITA_1 : m_metadata.content_type == 0x16u ? PKG_AES_KEY_VITA_2 :
|
||||||
|
PKG_AES_KEY_VITA_3,
|
||||||
|
128);
|
||||||
aes_crypt_ecb(&ctx, AES_ENCRYPT, reinterpret_cast<const uchar*>(&m_header.klicensee), m_dec_key.data());
|
aes_crypt_ecb(&ctx, AES_ENCRYPT, reinterpret_cast<const uchar*>(&m_header.klicensee), m_dec_key.data());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -915,14 +916,12 @@ bool package_reader::fill_data(std::map<std::string, install_entry*>& all_instal
|
||||||
|
|
||||||
auto map_ptr = &*all_install_entries.try_emplace(true_path).first;
|
auto map_ptr = &*all_install_entries.try_emplace(true_path).first;
|
||||||
|
|
||||||
m_install_entries.push_back({
|
m_install_entries.push_back({.weak_reference = map_ptr,
|
||||||
.weak_reference = map_ptr,
|
|
||||||
.name = std::string(name),
|
.name = std::string(name),
|
||||||
.file_offset = entry.file_offset,
|
.file_offset = entry.file_offset,
|
||||||
.file_size = entry.file_size,
|
.file_size = entry.file_size,
|
||||||
.type = entry.type,
|
.type = entry.type,
|
||||||
.pad = entry.pad
|
.pad = entry.pad});
|
||||||
});
|
|
||||||
|
|
||||||
if (map_ptr->second && !(entry.type & PKG_FILE_ENTRY_OVERWRITE))
|
if (map_ptr->second && !(entry.type & PKG_FILE_ENTRY_OVERWRITE))
|
||||||
{
|
{
|
||||||
|
|
@ -946,7 +945,7 @@ bool package_reader::fill_data(std::map<std::string, install_entry*>& all_instal
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::file DecryptEDAT(const fs::file& input, const std::string& input_file_name, int mode, u8 *custom_klic);
|
fs::file DecryptEDAT(const fs::file& input, const std::string& input_file_name, int mode, u8* custom_klic);
|
||||||
|
|
||||||
void package_reader::extract_worker()
|
void package_reader::extract_worker()
|
||||||
{
|
{
|
||||||
|
|
@ -964,7 +963,8 @@ void package_reader::extract_worker()
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}).first;
|
})
|
||||||
|
.first;
|
||||||
|
|
||||||
if (index >= m_install_entries.size())
|
if (index >= m_install_entries.size())
|
||||||
{
|
{
|
||||||
|
|
@ -1027,7 +1027,7 @@ void package_reader::extract_worker()
|
||||||
pkg_log.warning("NPDRM EDAT!");
|
pkg_log.warning("NPDRM EDAT!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fs::file out{ path, did_overwrite ? fs::rewrite : fs::write_new })
|
if (fs::file out{path, did_overwrite ? fs::rewrite : fs::write_new})
|
||||||
{
|
{
|
||||||
bool extract_success = true;
|
bool extract_success = true;
|
||||||
|
|
||||||
|
|
@ -1038,9 +1038,7 @@ void package_reader::extract_worker()
|
||||||
usz m_pos;
|
usz m_pos;
|
||||||
|
|
||||||
explicit pkg_file_reader(std::function<u64(u64, void* buffer, u64)> read_func, const install_entry& entry) noexcept
|
explicit pkg_file_reader(std::function<u64(u64, void* buffer, u64)> read_func, const install_entry& entry) noexcept
|
||||||
: m_read_func(std::move(read_func))
|
: m_read_func(std::move(read_func)), m_entry(entry), m_pos(0)
|
||||||
, m_entry(entry)
|
|
||||||
, m_pos(0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1078,7 +1076,8 @@ void package_reader::extract_worker()
|
||||||
const s64 new_pos =
|
const s64 new_pos =
|
||||||
whence == fs::seek_set ? offset :
|
whence == fs::seek_set ? offset :
|
||||||
whence == fs::seek_cur ? offset + m_pos :
|
whence == fs::seek_cur ? offset + m_pos :
|
||||||
whence == fs::seek_end ? offset + size() : -1;
|
whence == fs::seek_end ? offset + size() :
|
||||||
|
-1;
|
||||||
|
|
||||||
if (new_pos < 0)
|
if (new_pos < 0)
|
||||||
{
|
{
|
||||||
|
|
@ -1178,7 +1177,8 @@ void package_reader::extract_worker()
|
||||||
}
|
}
|
||||||
|
|
||||||
return read_size + size_cache_end;
|
return read_size + size_cache_end;
|
||||||
}, entry);
|
},
|
||||||
|
entry);
|
||||||
|
|
||||||
fs::file in_data;
|
fs::file in_data;
|
||||||
in_data.reset(std::move(reader));
|
in_data.reset(std::move(reader));
|
||||||
|
|
@ -1373,7 +1373,8 @@ package_install_result package_reader::extract_data(std::deque<package_reader>&
|
||||||
|
|
||||||
void package_reader::archive_seek(const s64 new_offset, const fs::seek_mode damode)
|
void package_reader::archive_seek(const s64 new_offset, const fs::seek_mode damode)
|
||||||
{
|
{
|
||||||
if (m_file) m_file.seek(new_offset, damode);
|
if (m_file)
|
||||||
|
m_file.seek(new_offset, damode);
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 package_reader::archive_read(void* data_ptr, const u64 num_bytes)
|
u64 package_reader::archive_read(void* data_ptr, const u64 num_bytes)
|
||||||
|
|
|
||||||
|
|
@ -144,22 +144,23 @@ private:
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
public:
|
|
||||||
be_t<u32> drm_type{ 0 };
|
|
||||||
be_t<u32> content_type{ 0 };
|
|
||||||
be_t<u32> package_type{ 0 };
|
|
||||||
be_t<u64> package_size{ 0 };
|
|
||||||
u8 qa_digest[24]{ 0 };
|
|
||||||
|
|
||||||
be_t<u64> unk_0x9{ 0 };
|
public:
|
||||||
be_t<u64> unk_0xB{ 0 };
|
be_t<u32> drm_type{0};
|
||||||
|
be_t<u32> content_type{0};
|
||||||
|
be_t<u32> package_type{0};
|
||||||
|
be_t<u64> package_size{0};
|
||||||
|
u8 qa_digest[24]{0};
|
||||||
|
|
||||||
|
be_t<u64> unk_0x9{0};
|
||||||
|
be_t<u64> unk_0xB{0};
|
||||||
|
|
||||||
struct package_revision
|
struct package_revision
|
||||||
{
|
{
|
||||||
struct package_revision_data
|
struct package_revision_data
|
||||||
{
|
{
|
||||||
u8 make_package_npdrm_ver[2]{ 0 };
|
u8 make_package_npdrm_ver[2]{0};
|
||||||
u8 version[2]{ 0 };
|
u8 version[2]{0};
|
||||||
} data{};
|
} data{};
|
||||||
|
|
||||||
std::string make_package_npdrm_ver;
|
std::string make_package_npdrm_ver;
|
||||||
|
|
@ -180,10 +181,10 @@ public:
|
||||||
{
|
{
|
||||||
struct software_revision_data
|
struct software_revision_data
|
||||||
{
|
{
|
||||||
u8 unk[1]{ 0 };
|
u8 unk[1]{0};
|
||||||
u8 firmware_version[3]{ 0 };
|
u8 firmware_version[3]{0};
|
||||||
u8 version[2]{ 0 };
|
u8 version[2]{0};
|
||||||
u8 app_version[2]{ 0 };
|
u8 app_version[2]{0};
|
||||||
} data{};
|
} data{};
|
||||||
|
|
||||||
std::string unk; // maybe hardware id
|
std::string unk; // maybe hardware id
|
||||||
|
|
@ -212,9 +213,9 @@ public:
|
||||||
|
|
||||||
struct vita_item_info // size is 0x28 (40)
|
struct vita_item_info // size is 0x28 (40)
|
||||||
{
|
{
|
||||||
be_t<u32> offset{ 0 };
|
be_t<u32> offset{0};
|
||||||
be_t<u32> size{ 0 };
|
be_t<u32> size{0};
|
||||||
u8 sha256[32]{ 0 };
|
u8 sha256[32]{0};
|
||||||
|
|
||||||
std::string to_string() const
|
std::string to_string() const
|
||||||
{
|
{
|
||||||
|
|
@ -224,12 +225,12 @@ public:
|
||||||
|
|
||||||
struct vita_sfo_info // size is 0x38 (56)
|
struct vita_sfo_info // size is 0x38 (56)
|
||||||
{
|
{
|
||||||
be_t<u32> param_offset{ 0 };
|
be_t<u32> param_offset{0};
|
||||||
be_t<u16> param_size{ 0 };
|
be_t<u16> param_size{0};
|
||||||
be_t<u32> unk_1{ 0 }; // seen values: 0x00000001-0x00000018, 0x0000001b-0x0000001c
|
be_t<u32> unk_1{0}; // seen values: 0x00000001-0x00000018, 0x0000001b-0x0000001c
|
||||||
be_t<u32> psp2_system_ver{ 0 }; // BCD encoded
|
be_t<u32> psp2_system_ver{0}; // BCD encoded
|
||||||
u8 unk_2[8]{ 0 };
|
u8 unk_2[8]{0};
|
||||||
u8 param_digest[32]{ 0 }; // SHA256 of param_data. Called ParamDigest: This is sha256 digest of param.sfo.
|
u8 param_digest[32]{0}; // SHA256 of param_data. Called ParamDigest: This is sha256 digest of param.sfo.
|
||||||
|
|
||||||
std::string to_string() const
|
std::string to_string() const
|
||||||
{
|
{
|
||||||
|
|
@ -240,10 +241,10 @@ public:
|
||||||
|
|
||||||
struct vita_unknown_data_info // size is 0x48 (72)
|
struct vita_unknown_data_info // size is 0x48 (72)
|
||||||
{
|
{
|
||||||
be_t<u32> unknown_data_offset{ 0 };
|
be_t<u32> unknown_data_offset{0};
|
||||||
be_t<u16> unknown_data_size{ 0 }; // ex: 0x320
|
be_t<u16> unknown_data_size{0}; // ex: 0x320
|
||||||
u8 unk[32]{ 0 };
|
u8 unk[32]{0};
|
||||||
u8 unknown_data_sha256[32]{ 0 };
|
u8 unknown_data_sha256[32]{0};
|
||||||
|
|
||||||
std::string to_string() const
|
std::string to_string() const
|
||||||
{
|
{
|
||||||
|
|
@ -254,13 +255,13 @@ public:
|
||||||
|
|
||||||
struct vita_entirety_info // size is 0x38 (56)
|
struct vita_entirety_info // size is 0x38 (56)
|
||||||
{
|
{
|
||||||
be_t<u32> entirety_data_offset{ 0 }; // located just before SFO
|
be_t<u32> entirety_data_offset{0}; // located just before SFO
|
||||||
be_t<u32> entirety_data_size{ 0 }; // ex: 0xA0, C0, 0x100, 0x120, 0x160
|
be_t<u32> entirety_data_size{0}; // ex: 0xA0, C0, 0x100, 0x120, 0x160
|
||||||
be_t<u16> flags{ 0 }; // ex: EE 00, FE 10, FE 78, FE F8, FF 10, FF 90, FF D0, flags indicating which digests it embeds
|
be_t<u16> flags{0}; // ex: EE 00, FE 10, FE 78, FE F8, FF 10, FF 90, FF D0, flags indicating which digests it embeds
|
||||||
be_t<u16> unk_1{ 0 }; // always 00 00
|
be_t<u16> unk_1{0}; // always 00 00
|
||||||
be_t<u32> unk_2{ 0 }; // ex: 1, 0
|
be_t<u32> unk_2{0}; // ex: 1, 0
|
||||||
u8 unk_3[8]{ 0 };
|
u8 unk_3[8]{0};
|
||||||
u8 entirety_digest[32]{ 0 };
|
u8 entirety_digest[32]{0};
|
||||||
|
|
||||||
std::string to_string() const
|
std::string to_string() const
|
||||||
{
|
{
|
||||||
|
|
@ -271,9 +272,9 @@ public:
|
||||||
|
|
||||||
struct vita_version_info // size is 0x28 (40)
|
struct vita_version_info // size is 0x28 (40)
|
||||||
{
|
{
|
||||||
be_t<u32> publishing_tools_version{ 0 };
|
be_t<u32> publishing_tools_version{0};
|
||||||
be_t<u32> psf_builder_version{ 0 };
|
be_t<u32> psf_builder_version{0};
|
||||||
u8 padding[32]{ 0 };
|
u8 padding[32]{0};
|
||||||
|
|
||||||
std::string to_string() const
|
std::string to_string() const
|
||||||
{
|
{
|
||||||
|
|
@ -284,10 +285,10 @@ public:
|
||||||
|
|
||||||
struct vita_self_info // size is 0x38 (56)
|
struct vita_self_info // size is 0x38 (56)
|
||||||
{
|
{
|
||||||
be_t<u32> self_info_offset{ 0 }; // offset to the first self_info_data_element
|
be_t<u32> self_info_offset{0}; // offset to the first self_info_data_element
|
||||||
be_t<u32> self_info_size{ 0 }; // usually 0x10 or 0x20
|
be_t<u32> self_info_size{0}; // usually 0x10 or 0x20
|
||||||
u8 unk[16]{ 0 };
|
u8 unk[16]{0};
|
||||||
u8 self_sha256[32]{ 0 };
|
u8 self_sha256[32]{0};
|
||||||
|
|
||||||
std::string to_string() const
|
std::string to_string() const
|
||||||
{
|
{
|
||||||
|
|
@ -346,17 +347,26 @@ public:
|
||||||
error_dirty
|
error_dirty
|
||||||
};
|
};
|
||||||
|
|
||||||
bool is_valid() const { return m_is_valid; }
|
bool is_valid() const
|
||||||
|
{
|
||||||
|
return m_is_valid;
|
||||||
|
}
|
||||||
package_install_result check_target_app_version() const;
|
package_install_result check_target_app_version() const;
|
||||||
static package_install_result extract_data(std::deque<package_reader>& readers, std::deque<std::string>& bootable_paths);
|
static package_install_result extract_data(std::deque<package_reader>& readers, std::deque<std::string>& bootable_paths);
|
||||||
const psf::registry& get_psf() const { return m_psf; }
|
const psf::registry& get_psf() const
|
||||||
result get_result() const { return m_result; };
|
{
|
||||||
|
return m_psf;
|
||||||
|
}
|
||||||
|
result get_result() const
|
||||||
|
{
|
||||||
|
return m_result;
|
||||||
|
};
|
||||||
|
|
||||||
int get_progress(int maximum = 100) const;
|
int get_progress(int maximum = 100) const;
|
||||||
|
|
||||||
void abort_extract();
|
void abort_extract();
|
||||||
|
|
||||||
fs::file &file()
|
fs::file& file()
|
||||||
{
|
{
|
||||||
return m_file;
|
return m_file;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,6 @@ void WriteShdr(const fs::file& f, Elf32_Shdr& shdr)
|
||||||
Write32(f, shdr.sh_entsize);
|
Write32(f, shdr.sh_entsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void program_identification_header::Load(const fs::file& f)
|
void program_identification_header::Load(const fs::file& f)
|
||||||
{
|
{
|
||||||
program_authority_id = Read64(f);
|
program_authority_id = Read64(f);
|
||||||
|
|
@ -601,8 +600,7 @@ void ext_hdr::Load(const fs::file& f)
|
||||||
}
|
}
|
||||||
|
|
||||||
SCEDecrypter::SCEDecrypter(const fs::file& s)
|
SCEDecrypter::SCEDecrypter(const fs::file& s)
|
||||||
: sce_f(s)
|
: sce_f(s), data_buf_length(0)
|
||||||
, data_buf_length(0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -789,15 +787,15 @@ std::vector<fs::file> SCEDecrypter::MakeFile()
|
||||||
if (out_f.pos() != out_f.size())
|
if (out_f.pos() != out_f.size())
|
||||||
fmt::throw_exception("MakeELF written bytes (%llu) does not equal buffer size (%llu).", out_f.pos(), out_f.size());
|
fmt::throw_exception("MakeELF written bytes (%llu) does not equal buffer size (%llu).", out_f.pos(), out_f.size());
|
||||||
|
|
||||||
if (is_valid) vec.push_back(std::move(out_f));
|
if (is_valid)
|
||||||
|
vec.push_back(std::move(out_f));
|
||||||
}
|
}
|
||||||
|
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
SELFDecrypter::SELFDecrypter(const fs::file& s)
|
SELFDecrypter::SELFDecrypter(const fs::file& s)
|
||||||
: self_f(s)
|
: self_f(s), key_v()
|
||||||
, key_v()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -843,13 +841,13 @@ bool SELFDecrypter::LoadHeaders(bool isElf32, SelfAdditionalInfo* out_info)
|
||||||
if (isElf32)
|
if (isElf32)
|
||||||
{
|
{
|
||||||
phdr32_arr.clear();
|
phdr32_arr.clear();
|
||||||
if(elf32_hdr.e_phoff == 0 && elf32_hdr.e_phnum)
|
if (elf32_hdr.e_phoff == 0 && elf32_hdr.e_phnum)
|
||||||
{
|
{
|
||||||
self_log.error("ELF program header offset is null!");
|
self_log.error("ELF program header offset is null!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
self_f.seek(m_ext_hdr.phdr_offset);
|
self_f.seek(m_ext_hdr.phdr_offset);
|
||||||
for(u32 i = 0; i < elf32_hdr.e_phnum; ++i)
|
for (u32 i = 0; i < elf32_hdr.e_phnum; ++i)
|
||||||
{
|
{
|
||||||
phdr32_arr.emplace_back();
|
phdr32_arr.emplace_back();
|
||||||
phdr32_arr.back().Load(self_f);
|
phdr32_arr.back().Load(self_f);
|
||||||
|
|
@ -878,7 +876,7 @@ bool SELFDecrypter::LoadHeaders(bool isElf32, SelfAdditionalInfo* out_info)
|
||||||
m_seg_ext_hdr.clear();
|
m_seg_ext_hdr.clear();
|
||||||
self_f.seek(m_ext_hdr.segment_ext_hdr_offset);
|
self_f.seek(m_ext_hdr.segment_ext_hdr_offset);
|
||||||
|
|
||||||
for(u32 i = 0; i < (isElf32 ? elf32_hdr.e_phnum : elf64_hdr.e_phnum); ++i)
|
for (u32 i = 0; i < (isElf32 ? elf32_hdr.e_phnum : elf64_hdr.e_phnum); ++i)
|
||||||
{
|
{
|
||||||
if (self_f.pos() >= self_f.size())
|
if (self_f.pos() >= self_f.size())
|
||||||
{
|
{
|
||||||
|
|
@ -934,7 +932,7 @@ bool SELFDecrypter::LoadHeaders(bool isElf32, SelfAdditionalInfo* out_info)
|
||||||
|
|
||||||
self_f.seek(m_ext_hdr.shdr_offset);
|
self_f.seek(m_ext_hdr.shdr_offset);
|
||||||
|
|
||||||
for(u32 i = 0; i < elf32_hdr.e_shnum; ++i)
|
for (u32 i = 0; i < elf32_hdr.e_shnum; ++i)
|
||||||
{
|
{
|
||||||
shdr32_arr.emplace_back();
|
shdr32_arr.emplace_back();
|
||||||
shdr32_arr.back().Load(self_f);
|
shdr32_arr.back().Load(self_f);
|
||||||
|
|
@ -951,7 +949,7 @@ bool SELFDecrypter::LoadHeaders(bool isElf32, SelfAdditionalInfo* out_info)
|
||||||
|
|
||||||
self_f.seek(m_ext_hdr.shdr_offset);
|
self_f.seek(m_ext_hdr.shdr_offset);
|
||||||
|
|
||||||
for(u32 i = 0; i < elf64_hdr.e_shnum; ++i)
|
for (u32 i = 0; i < elf64_hdr.e_shnum; ++i)
|
||||||
{
|
{
|
||||||
shdr64_arr.emplace_back();
|
shdr64_arr.emplace_back();
|
||||||
shdr64_arr.back().Load(self_f);
|
shdr64_arr.back().Load(self_f);
|
||||||
|
|
@ -986,12 +984,12 @@ void SELFDecrypter::ShowHeaders(bool isElf32)
|
||||||
self_log.notice("----------------------------------------------------");
|
self_log.notice("----------------------------------------------------");
|
||||||
self_log.notice("ELF program headers");
|
self_log.notice("ELF program headers");
|
||||||
self_log.notice("----------------------------------------------------");
|
self_log.notice("----------------------------------------------------");
|
||||||
for(unsigned int i = 0; i < ((isElf32) ? phdr32_arr.size() : phdr64_arr.size()); i++)
|
for (unsigned int i = 0; i < ((isElf32) ? phdr32_arr.size() : phdr64_arr.size()); i++)
|
||||||
isElf32 ? phdr32_arr[i].Show() : phdr64_arr[i].Show();
|
isElf32 ? phdr32_arr[i].Show() : phdr64_arr[i].Show();
|
||||||
self_log.notice("----------------------------------------------------");
|
self_log.notice("----------------------------------------------------");
|
||||||
self_log.notice("Section info");
|
self_log.notice("Section info");
|
||||||
self_log.notice("----------------------------------------------------");
|
self_log.notice("----------------------------------------------------");
|
||||||
for(unsigned int i = 0; i < m_seg_ext_hdr.size(); i++)
|
for (unsigned int i = 0; i < m_seg_ext_hdr.size(); i++)
|
||||||
m_seg_ext_hdr[i].Show();
|
m_seg_ext_hdr[i].Show();
|
||||||
self_log.notice("----------------------------------------------------");
|
self_log.notice("----------------------------------------------------");
|
||||||
self_log.notice("SCE version info");
|
self_log.notice("SCE version info");
|
||||||
|
|
@ -1000,17 +998,17 @@ void SELFDecrypter::ShowHeaders(bool isElf32)
|
||||||
self_log.notice("----------------------------------------------------");
|
self_log.notice("----------------------------------------------------");
|
||||||
self_log.notice("Control info");
|
self_log.notice("Control info");
|
||||||
self_log.notice("----------------------------------------------------");
|
self_log.notice("----------------------------------------------------");
|
||||||
for(unsigned int i = 0; i < m_supplemental_hdr_arr.size(); i++)
|
for (unsigned int i = 0; i < m_supplemental_hdr_arr.size(); i++)
|
||||||
m_supplemental_hdr_arr[i].Show();
|
m_supplemental_hdr_arr[i].Show();
|
||||||
self_log.notice("----------------------------------------------------");
|
self_log.notice("----------------------------------------------------");
|
||||||
self_log.notice("ELF section headers");
|
self_log.notice("ELF section headers");
|
||||||
self_log.notice("----------------------------------------------------");
|
self_log.notice("----------------------------------------------------");
|
||||||
for(unsigned int i = 0; i < ((isElf32) ? shdr32_arr.size() : shdr64_arr.size()); i++)
|
for (unsigned int i = 0; i < ((isElf32) ? shdr32_arr.size() : shdr64_arr.size()); i++)
|
||||||
isElf32 ? shdr32_arr[i].Show() : shdr64_arr[i].Show();
|
isElf32 ? shdr32_arr[i].Show() : shdr64_arr[i].Show();
|
||||||
self_log.notice("----------------------------------------------------");
|
self_log.notice("----------------------------------------------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SELFDecrypter::DecryptNPDRM(u8 *metadata, u32 metadata_size)
|
bool SELFDecrypter::DecryptNPDRM(u8* metadata, u32 metadata_size)
|
||||||
{
|
{
|
||||||
aes_context aes;
|
aes_context aes;
|
||||||
u8 npdrm_key[0x10];
|
u8 npdrm_key[0x10];
|
||||||
|
|
@ -1191,7 +1189,7 @@ bool SELFDecrypter::DecryptData()
|
||||||
if (meta_shdr[i].encrypted == 3)
|
if (meta_shdr[i].encrypted == 3)
|
||||||
{
|
{
|
||||||
// Make sure the key and iv are not out of boundaries.
|
// Make sure the key and iv are not out of boundaries.
|
||||||
if((meta_shdr[i].key_idx <= meta_hdr.key_count - 1) && (meta_shdr[i].iv_idx <= meta_hdr.key_count))
|
if ((meta_shdr[i].key_idx <= meta_hdr.key_count - 1) && (meta_shdr[i].iv_idx <= meta_hdr.key_count))
|
||||||
{
|
{
|
||||||
// Get the key and iv from the previously stored key buffer.
|
// Get the key and iv from the previously stored key buffer.
|
||||||
memcpy(data_key, data_keys.get() + meta_shdr[i].key_idx * 0x10, 0x10);
|
memcpy(data_key, data_keys.get() + meta_shdr[i].key_idx * 0x10, 0x10);
|
||||||
|
|
@ -1257,7 +1255,8 @@ bool SELFDecrypter::GetKeyFromRap(const char* content_id, u8* npdrm_key)
|
||||||
{
|
{
|
||||||
self_log.fatal("Failed to locate the game license file: %s."
|
self_log.fatal("Failed to locate the game license file: %s."
|
||||||
"\nEnsure the .rap license file is placed in the dev_hdd0/home/%s/exdata folder with a lowercase file extension."
|
"\nEnsure the .rap license file is placed in the dev_hdd0/home/%s/exdata folder with a lowercase file extension."
|
||||||
"\nIf you need assistance on dumping the license file from your PS3, read our quickstart guide: https://rpcs3.net/quickstart", rap_path, Emu.GetUsr());
|
"\nIf you need assistance on dumping the license file from your PS3, read our quickstart guide: https://rpcs3.net/quickstart",
|
||||||
|
rap_path, Emu.GetUsr());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1277,7 +1276,8 @@ bool SELFDecrypter::GetKeyFromRap(const char* content_id, u8* npdrm_key)
|
||||||
|
|
||||||
static bool IsSelfElf32(const fs::file& f)
|
static bool IsSelfElf32(const fs::file& f)
|
||||||
{
|
{
|
||||||
if (!f) return false;
|
if (!f)
|
||||||
|
return false;
|
||||||
|
|
||||||
f.seek(0);
|
f.seek(0);
|
||||||
|
|
||||||
|
|
@ -1454,7 +1454,7 @@ bool verify_npdrm_self_headers(const fs::file& self, u8* klic_key, NPD_HEADER* n
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get_npdrm_self_header(const fs::file& self, NPD_HEADER &npd_out)
|
bool get_npdrm_self_header(const fs::file& self, NPD_HEADER& npd_out)
|
||||||
{
|
{
|
||||||
if (!self)
|
if (!self)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,6 @@ struct supplemental_header
|
||||||
void Show() const;
|
void Show() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct MetadataInfo
|
struct MetadataInfo
|
||||||
{
|
{
|
||||||
u8 key[0x10];
|
u8 key[0x10];
|
||||||
|
|
@ -242,7 +241,7 @@ struct SelfSection
|
||||||
|
|
||||||
struct Elf32_Ehdr
|
struct Elf32_Ehdr
|
||||||
{
|
{
|
||||||
//u8 e_ident[16]; // ELF identification
|
// u8 e_ident[16]; // ELF identification
|
||||||
u32 e_magic;
|
u32 e_magic;
|
||||||
u8 e_class;
|
u8 e_class;
|
||||||
u8 e_data;
|
u8 e_data;
|
||||||
|
|
@ -265,9 +264,18 @@ struct Elf32_Ehdr
|
||||||
|
|
||||||
void Load(const fs::file& f);
|
void Load(const fs::file& f);
|
||||||
static void Show() {}
|
static void Show() {}
|
||||||
bool IsLittleEndian() const { return e_data == 1; }
|
bool IsLittleEndian() const
|
||||||
bool CheckMagic() const { return e_magic == 0x7F454C46; }
|
{
|
||||||
u32 GetEntry() const { return e_entry; }
|
return e_data == 1;
|
||||||
|
}
|
||||||
|
bool CheckMagic() const
|
||||||
|
{
|
||||||
|
return e_magic == 0x7F454C46;
|
||||||
|
}
|
||||||
|
u32 GetEntry() const
|
||||||
|
{
|
||||||
|
return e_entry;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Elf32_Shdr
|
struct Elf32_Shdr
|
||||||
|
|
@ -306,7 +314,7 @@ struct Elf32_Phdr
|
||||||
|
|
||||||
struct Elf64_Ehdr
|
struct Elf64_Ehdr
|
||||||
{
|
{
|
||||||
//u8 e_ident[16]; // ELF identification
|
// u8 e_ident[16]; // ELF identification
|
||||||
u32 e_magic;
|
u32 e_magic;
|
||||||
u8 e_class;
|
u8 e_class;
|
||||||
u8 e_data;
|
u8 e_data;
|
||||||
|
|
@ -329,8 +337,14 @@ struct Elf64_Ehdr
|
||||||
|
|
||||||
void Load(const fs::file& f);
|
void Load(const fs::file& f);
|
||||||
static void Show() {}
|
static void Show() {}
|
||||||
bool CheckMagic() const { return e_magic == 0x7F454C46; }
|
bool CheckMagic() const
|
||||||
u64 GetEntry() const { return e_entry; }
|
{
|
||||||
|
return e_magic == 0x7F454C46;
|
||||||
|
}
|
||||||
|
u64 GetEntry() const
|
||||||
|
{
|
||||||
|
return e_entry;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Elf64_Shdr
|
struct Elf64_Shdr
|
||||||
|
|
@ -347,7 +361,7 @@ struct Elf64_Shdr
|
||||||
u64 sh_entsize; // size of entries, if section has table
|
u64 sh_entsize; // size of entries, if section has table
|
||||||
|
|
||||||
void Load(const fs::file& f);
|
void Load(const fs::file& f);
|
||||||
static void Show(){}
|
static void Show() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Elf64_Phdr
|
struct Elf64_Phdr
|
||||||
|
|
@ -362,7 +376,7 @@ struct Elf64_Phdr
|
||||||
u64 p_align; // Segment alignment
|
u64 p_align; // Segment alignment
|
||||||
|
|
||||||
void Load(const fs::file& f);
|
void Load(const fs::file& f);
|
||||||
static void Show(){}
|
static void Show() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SceHeader
|
struct SceHeader
|
||||||
|
|
@ -376,8 +390,11 @@ struct SceHeader
|
||||||
u64 se_esize;
|
u64 se_esize;
|
||||||
|
|
||||||
void Load(const fs::file& f);
|
void Load(const fs::file& f);
|
||||||
static void Show(){}
|
static void Show() {}
|
||||||
bool CheckMagic() const { return se_magic == 0x53434500; }
|
bool CheckMagic() const
|
||||||
|
{
|
||||||
|
return se_magic == 0x53434500;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ext_hdr
|
struct ext_hdr
|
||||||
|
|
@ -394,7 +411,7 @@ struct ext_hdr
|
||||||
u64 padding;
|
u64 padding;
|
||||||
|
|
||||||
void Load(const fs::file& f);
|
void Load(const fs::file& f);
|
||||||
static void Show(){}
|
static void Show() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SelfAdditionalInfo
|
struct SelfAdditionalInfo
|
||||||
|
|
@ -478,12 +495,12 @@ public:
|
||||||
void ShowHeaders(bool isElf32);
|
void ShowHeaders(bool isElf32);
|
||||||
bool LoadMetadata(const u8* klic_key);
|
bool LoadMetadata(const u8* klic_key);
|
||||||
bool DecryptData();
|
bool DecryptData();
|
||||||
bool DecryptNPDRM(u8 *metadata, u32 metadata_size);
|
bool DecryptNPDRM(u8* metadata, u32 metadata_size);
|
||||||
const NPD_HEADER* GetNPDHeader() const;
|
const NPD_HEADER* GetNPDHeader() const;
|
||||||
static bool GetKeyFromRap(const char *content_id, u8 *npdrm_key);
|
static bool GetKeyFromRap(const char* content_id, u8* npdrm_key);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<typename EHdr, typename SHdr, typename PHdr>
|
template <typename EHdr, typename SHdr, typename PHdr>
|
||||||
void WriteElf(fs::file& e, EHdr ehdr, SHdr shdr, PHdr phdr)
|
void WriteElf(fs::file& e, EHdr ehdr, SHdr shdr, PHdr phdr)
|
||||||
{
|
{
|
||||||
// Set initial offset.
|
// Set initial offset.
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,11 @@ u64 hex_to_u64(const char* hex_str)
|
||||||
while (length--)
|
while (length--)
|
||||||
{
|
{
|
||||||
c = *hex_str++;
|
c = *hex_str++;
|
||||||
if((c >= '0') && (c <= '9'))
|
if ((c >= '0') && (c <= '9'))
|
||||||
tmp = c - '0';
|
tmp = c - '0';
|
||||||
else if((c >= 'a') && (c <= 'f'))
|
else if ((c >= 'a') && (c <= 'f'))
|
||||||
tmp = c - 'a' + 10;
|
tmp = c - 'a' + 10;
|
||||||
else if((c >= 'A') && (c <= 'F'))
|
else if ((c >= 'A') && (c <= 'F'))
|
||||||
tmp = c - 'A' + 10;
|
tmp = c - 'A' + 10;
|
||||||
else
|
else
|
||||||
tmp = 0;
|
tmp = 0;
|
||||||
|
|
@ -64,9 +64,8 @@ void hex_to_bytes(unsigned char* data, const char* hex_str, unsigned int str_len
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Crypto functions (AES128-CBC, AES128-ECB, SHA1-HMAC and AES-CMAC).
|
// Crypto functions (AES128-CBC, AES128-ECB, SHA1-HMAC and AES-CMAC).
|
||||||
void aescbc128_decrypt(unsigned char *key, unsigned char *iv, unsigned char *in, unsigned char *out, usz len)
|
void aescbc128_decrypt(unsigned char* key, unsigned char* iv, unsigned char* in, unsigned char* out, usz len)
|
||||||
{
|
{
|
||||||
aes_context ctx;
|
aes_context ctx;
|
||||||
aes_setkey_dec(&ctx, key, 128);
|
aes_setkey_dec(&ctx, key, 128);
|
||||||
|
|
@ -76,7 +75,7 @@ void aescbc128_decrypt(unsigned char *key, unsigned char *iv, unsigned char *in,
|
||||||
memset(iv, 0, 0x10);
|
memset(iv, 0, 0x10);
|
||||||
}
|
}
|
||||||
|
|
||||||
void aescbc128_encrypt(unsigned char *key, unsigned char *iv, unsigned char *in, unsigned char *out, usz len)
|
void aescbc128_encrypt(unsigned char* key, unsigned char* iv, unsigned char* in, unsigned char* out, usz len)
|
||||||
{
|
{
|
||||||
aes_context ctx;
|
aes_context ctx;
|
||||||
aes_setkey_enc(&ctx, key, 128);
|
aes_setkey_enc(&ctx, key, 128);
|
||||||
|
|
@ -86,14 +85,14 @@ void aescbc128_encrypt(unsigned char *key, unsigned char *iv, unsigned char *in,
|
||||||
memset(iv, 0, 0x10);
|
memset(iv, 0, 0x10);
|
||||||
}
|
}
|
||||||
|
|
||||||
void aesecb128_encrypt(unsigned char *key, unsigned char *in, unsigned char *out)
|
void aesecb128_encrypt(unsigned char* key, unsigned char* in, unsigned char* out)
|
||||||
{
|
{
|
||||||
aes_context ctx;
|
aes_context ctx;
|
||||||
aes_setkey_enc(&ctx, key, 128);
|
aes_setkey_enc(&ctx, key, 128);
|
||||||
aes_crypt_ecb(&ctx, AES_ENCRYPT, in, out);
|
aes_crypt_ecb(&ctx, AES_ENCRYPT, in, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hmac_hash_compare(unsigned char *key, int key_len, unsigned char *in, usz in_len, unsigned char *hash, usz hash_len)
|
bool hmac_hash_compare(unsigned char* key, int key_len, unsigned char* in, usz in_len, unsigned char* hash, usz hash_len)
|
||||||
{
|
{
|
||||||
const std::unique_ptr<u8[]> out(new u8[key_len]);
|
const std::unique_ptr<u8[]> out(new u8[key_len]);
|
||||||
|
|
||||||
|
|
@ -102,12 +101,12 @@ bool hmac_hash_compare(unsigned char *key, int key_len, unsigned char *in, usz i
|
||||||
return std::memcmp(out.get(), hash, hash_len) == 0;
|
return std::memcmp(out.get(), hash, hash_len) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hmac_hash_forge(unsigned char *key, int key_len, unsigned char *in, usz in_len, unsigned char *hash)
|
void hmac_hash_forge(unsigned char* key, int key_len, unsigned char* in, usz in_len, unsigned char* hash)
|
||||||
{
|
{
|
||||||
sha1_hmac(key, key_len, in, in_len, hash);
|
sha1_hmac(key, key_len, in, in_len, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmac_hash_compare(unsigned char *key, int key_len, unsigned char *in, usz in_len, unsigned char *hash, usz hash_len)
|
bool cmac_hash_compare(unsigned char* key, int key_len, unsigned char* in, usz in_len, unsigned char* hash, usz hash_len)
|
||||||
{
|
{
|
||||||
const std::unique_ptr<u8[]> out(new u8[key_len]);
|
const std::unique_ptr<u8[]> out(new u8[key_len]);
|
||||||
|
|
||||||
|
|
@ -118,7 +117,7 @@ bool cmac_hash_compare(unsigned char *key, int key_len, unsigned char *in, usz i
|
||||||
return std::memcmp(out.get(), hash, hash_len) == 0;
|
return std::memcmp(out.get(), hash, hash_len) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmac_hash_forge(unsigned char *key, int /*key_len*/, unsigned char *in, usz in_len, unsigned char *hash)
|
void cmac_hash_forge(unsigned char* key, int /*key_len*/, unsigned char* in, usz in_len, unsigned char* hash)
|
||||||
{
|
{
|
||||||
aes_context ctx;
|
aes_context ctx;
|
||||||
aes_setkey_enc(&ctx, key, 128);
|
aes_setkey_enc(&ctx, key, 128);
|
||||||
|
|
@ -160,13 +159,12 @@ std::string sha256_get_hash(const char* data, usz size, bool lower_case)
|
||||||
return res_hash_string;
|
return res_hash_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mbedtls_zeroize(void *v, size_t n)
|
void mbedtls_zeroize(void* v, size_t n)
|
||||||
{
|
{
|
||||||
static void *(*const volatile unop_memset)(void *, int, size_t) = &memset;
|
static void* (*const volatile unop_memset)(void*, int, size_t) = &memset;
|
||||||
(void)unop_memset(v, 0, n);
|
(void)unop_memset(v, 0, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SC passphrase crypto
|
// SC passphrase crypto
|
||||||
|
|
||||||
void sc_form_key(const u8* sc_key, const std::array<u8, PASSPHRASE_KEY_LEN>& laid_paid, u8* key)
|
void sc_form_key(const u8* sc_key, const std::array<u8, PASSPHRASE_KEY_LEN>& laid_paid, u8* key)
|
||||||
|
|
@ -229,7 +227,7 @@ const u8* vtrm_portability_type_mapper(int type)
|
||||||
// No idea what this type stands for
|
// No idea what this type stands for
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
//case 0: return key_for_type_1;
|
// case 0: return key_for_type_1;
|
||||||
case 1: return SC_ISO_SERIES_KEY_2;
|
case 1: return SC_ISO_SERIES_KEY_2;
|
||||||
case 2: return SC_ISO_SERIES_KEY_1;
|
case 2: return SC_ISO_SERIES_KEY_1;
|
||||||
case 3: return SC_KEY_FOR_MASTER_2;
|
case 3: return SC_KEY_FOR_MASTER_2;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,10 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
enum { CRYPTO_MAX_PATH = 4096 };
|
enum
|
||||||
|
{
|
||||||
|
CRYPTO_MAX_PATH = 4096
|
||||||
|
};
|
||||||
|
|
||||||
char* extract_file_name(const char* file_path, char real_file_name[CRYPTO_MAX_PATH]);
|
char* extract_file_name(const char* file_path, char real_file_name[CRYPTO_MAX_PATH]);
|
||||||
|
|
||||||
|
|
@ -16,17 +19,17 @@ std::string sha256_get_hash(const char* data, usz size, bool lower_case);
|
||||||
|
|
||||||
// Hex string conversion auxiliary functions.
|
// Hex string conversion auxiliary functions.
|
||||||
u64 hex_to_u64(const char* hex_str);
|
u64 hex_to_u64(const char* hex_str);
|
||||||
void hex_to_bytes(unsigned char *data, const char *hex_str, unsigned int str_length);
|
void hex_to_bytes(unsigned char* data, const char* hex_str, unsigned int str_length);
|
||||||
|
|
||||||
// Crypto functions (AES128-CBC, AES128-ECB, SHA1-HMAC and AES-CMAC).
|
// Crypto functions (AES128-CBC, AES128-ECB, SHA1-HMAC and AES-CMAC).
|
||||||
void aescbc128_decrypt(unsigned char *key, unsigned char *iv, unsigned char *in, unsigned char *out, usz len);
|
void aescbc128_decrypt(unsigned char* key, unsigned char* iv, unsigned char* in, unsigned char* out, usz len);
|
||||||
void aescbc128_encrypt(unsigned char *key, unsigned char *iv, unsigned char *in, unsigned char *out, usz len);
|
void aescbc128_encrypt(unsigned char* key, unsigned char* iv, unsigned char* in, unsigned char* out, usz len);
|
||||||
void aesecb128_encrypt(unsigned char *key, unsigned char *in, unsigned char *out);
|
void aesecb128_encrypt(unsigned char* key, unsigned char* in, unsigned char* out);
|
||||||
bool hmac_hash_compare(unsigned char *key, int key_len, unsigned char *in, usz in_len, unsigned char *hash, usz hash_len);
|
bool hmac_hash_compare(unsigned char* key, int key_len, unsigned char* in, usz in_len, unsigned char* hash, usz hash_len);
|
||||||
void hmac_hash_forge(unsigned char *key, int key_len, unsigned char *in, usz in_len, unsigned char *hash);
|
void hmac_hash_forge(unsigned char* key, int key_len, unsigned char* in, usz in_len, unsigned char* hash);
|
||||||
bool cmac_hash_compare(unsigned char *key, int key_len, unsigned char *in, usz in_len, unsigned char *hash, usz hash_len);
|
bool cmac_hash_compare(unsigned char* key, int key_len, unsigned char* in, usz in_len, unsigned char* hash, usz hash_len);
|
||||||
void cmac_hash_forge(unsigned char *key, int key_len, unsigned char *in, usz in_len, unsigned char *hash);
|
void cmac_hash_forge(unsigned char* key, int key_len, unsigned char* in, usz in_len, unsigned char* hash);
|
||||||
void mbedtls_zeroize(void *v, size_t n);
|
void mbedtls_zeroize(void* v, size_t n);
|
||||||
|
|
||||||
// SC passphrase crypto
|
// SC passphrase crypto
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,6 @@ enum class AudioStateEvent : u32
|
||||||
class AudioBackend
|
class AudioBackend
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
struct VolumeParam
|
struct VolumeParam
|
||||||
{
|
{
|
||||||
f32 initial_volume = 1.0f;
|
f32 initial_volume = 1.0f;
|
||||||
|
|
@ -93,7 +92,10 @@ public:
|
||||||
virtual f64 GetCallbackFrameLen() = 0;
|
virtual f64 GetCallbackFrameLen() = 0;
|
||||||
|
|
||||||
// Returns true if audio is currently being played, false otherwise. Reflects end result of Play() and Pause() calls.
|
// Returns true if audio is currently being played, false otherwise. Reflects end result of Play() and Pause() calls.
|
||||||
virtual bool IsPlaying() { return m_playing; }
|
virtual bool IsPlaying()
|
||||||
|
{
|
||||||
|
return m_playing;
|
||||||
|
}
|
||||||
|
|
||||||
// Start playing enqueued data.
|
// Start playing enqueued data.
|
||||||
virtual void Play() = 0;
|
virtual void Play() = 0;
|
||||||
|
|
@ -105,17 +107,26 @@ public:
|
||||||
* This virtual method should be reimplemented if backend can fail to be initialized under non-error conditions
|
* This virtual method should be reimplemented if backend can fail to be initialized under non-error conditions
|
||||||
* eg. when there is no audio devices attached
|
* eg. when there is no audio devices attached
|
||||||
*/
|
*/
|
||||||
virtual bool Initialized() { return true; }
|
virtual bool Initialized()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This virtual method should be reimplemented if backend can fail during normal operation
|
* This virtual method should be reimplemented if backend can fail during normal operation
|
||||||
*/
|
*/
|
||||||
virtual bool Operational() { return true; }
|
virtual bool Operational()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This virtual method should be reimplemented if backend can report device changes
|
* This virtual method should be reimplemented if backend can report device changes
|
||||||
*/
|
*/
|
||||||
virtual bool DefaultDeviceChanged() { return false; }
|
virtual bool DefaultDeviceChanged()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Helper methods
|
* Helper methods
|
||||||
|
|
@ -180,11 +191,12 @@ public:
|
||||||
/*
|
/*
|
||||||
* Downmix audio stream.
|
* Downmix audio stream.
|
||||||
*/
|
*/
|
||||||
template<AudioChannelCnt src_ch_cnt, audio_channel_layout dst_layout>
|
template <AudioChannelCnt src_ch_cnt, audio_channel_layout dst_layout>
|
||||||
static void downmix(u32 sample_cnt, const f32* src, f32* dst)
|
static void downmix(u32 sample_cnt, const f32* src, f32* dst)
|
||||||
{
|
{
|
||||||
const u32 dst_ch_cnt = default_layout_channel_count(dst_layout);
|
const u32 dst_ch_cnt = default_layout_channel_count(dst_layout);
|
||||||
if (static_cast<u32>(src_ch_cnt) <= dst_ch_cnt) fmt::throw_exception("src channel count must be bigger than dst channel count");
|
if (static_cast<u32>(src_ch_cnt) <= dst_ch_cnt)
|
||||||
|
fmt::throw_exception("src channel count must be bigger than dst channel count");
|
||||||
|
|
||||||
static constexpr f32 center_coef = std::numbers::sqrt2_v<f32> / 2;
|
static constexpr f32 center_coef = std::numbers::sqrt2_v<f32> / 2;
|
||||||
static constexpr f32 surround_coef = std::numbers::sqrt2_v<f32> / 2;
|
static constexpr f32 surround_coef = std::numbers::sqrt2_v<f32> / 2;
|
||||||
|
|
@ -377,7 +389,7 @@ protected:
|
||||||
audio_channel_layout m_layout = audio_channel_layout::automatic;
|
audio_channel_layout m_layout = audio_channel_layout::automatic;
|
||||||
|
|
||||||
std::timed_mutex m_cb_mutex{};
|
std::timed_mutex m_cb_mutex{};
|
||||||
std::function<u32(u32, void *)> m_write_callback{};
|
std::function<u32(u32, void*)> m_write_callback{};
|
||||||
|
|
||||||
shared_mutex m_state_cb_mutex{};
|
shared_mutex m_state_cb_mutex{};
|
||||||
std::function<void(AudioStateEvent)> m_state_callback{};
|
std::function<void(AudioStateEvent)> m_state_callback{};
|
||||||
|
|
@ -385,6 +397,5 @@ protected:
|
||||||
bool m_playing = false;
|
bool m_playing = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static constexpr f32 VOLUME_CHANGE_DURATION = 0.016f; // sec
|
static constexpr f32 VOLUME_CHANGE_DURATION = 0.016f; // sec
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ struct WAVHeader
|
||||||
{
|
{
|
||||||
struct RIFFHeader
|
struct RIFFHeader
|
||||||
{
|
{
|
||||||
u8 ID[4] = { 'R', 'I', 'F', 'F' };
|
u8 ID[4] = {'R', 'I', 'F', 'F'};
|
||||||
le_t<u32> Size{}; // FileSize - 8
|
le_t<u32> Size{}; // FileSize - 8
|
||||||
u8 WAVE[4] = { 'W', 'A', 'V', 'E' };
|
u8 WAVE[4] = {'W', 'A', 'V', 'E'};
|
||||||
|
|
||||||
RIFFHeader() = default;
|
RIFFHeader() = default;
|
||||||
|
|
||||||
|
|
@ -22,7 +22,7 @@ struct WAVHeader
|
||||||
|
|
||||||
struct FMTHeader
|
struct FMTHeader
|
||||||
{
|
{
|
||||||
u8 ID[4] = { 'f', 'm', 't', ' ' };
|
u8 ID[4] = {'f', 'm', 't', ' '};
|
||||||
le_t<u32> Size = 16;
|
le_t<u32> Size = 16;
|
||||||
le_t<u16> AudioFormat{}; // 1 for PCM, 3 for IEEE Floating Point
|
le_t<u16> AudioFormat{}; // 1 for PCM, 3 for IEEE Floating Point
|
||||||
le_t<u16> NumChannels{}; // 1, 2, 6, 8
|
le_t<u16> NumChannels{}; // 1, 2, 6, 8
|
||||||
|
|
@ -34,19 +34,14 @@ struct WAVHeader
|
||||||
FMTHeader() = default;
|
FMTHeader() = default;
|
||||||
|
|
||||||
FMTHeader(AudioChannelCnt ch, AudioFreq sample_rate, AudioSampleSize sample_size)
|
FMTHeader(AudioChannelCnt ch, AudioFreq sample_rate, AudioSampleSize sample_size)
|
||||||
: AudioFormat(sample_size == AudioSampleSize::FLOAT ? 3 : 1)
|
: AudioFormat(sample_size == AudioSampleSize::FLOAT ? 3 : 1), NumChannels(static_cast<u16>(ch)), SampleRate(static_cast<u32>(sample_rate)), ByteRate(SampleRate * NumChannels * static_cast<u32>(sample_size)), BlockAlign(NumChannels * static_cast<u32>(sample_size)), BitsPerSample(static_cast<u32>(sample_size) * 8)
|
||||||
, NumChannels(static_cast<u16>(ch))
|
|
||||||
, SampleRate(static_cast<u32>(sample_rate))
|
|
||||||
, ByteRate(SampleRate * NumChannels * static_cast<u32>(sample_size))
|
|
||||||
, BlockAlign(NumChannels * static_cast<u32>(sample_size))
|
|
||||||
, BitsPerSample(static_cast<u32>(sample_size) * 8)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
} FMT;
|
} FMT;
|
||||||
|
|
||||||
struct FACTChunk
|
struct FACTChunk
|
||||||
{
|
{
|
||||||
u8 ID[4] = { 'f', 'a', 'c', 't' };
|
u8 ID[4] = {'f', 'a', 'c', 't'};
|
||||||
le_t<u32> ChunkLength = 4;
|
le_t<u32> ChunkLength = 4;
|
||||||
le_t<u32> SampleLength = 0; // total samples per channel
|
le_t<u32> SampleLength = 0; // total samples per channel
|
||||||
|
|
||||||
|
|
@ -58,16 +53,13 @@ struct WAVHeader
|
||||||
}
|
}
|
||||||
} FACT;
|
} FACT;
|
||||||
|
|
||||||
u8 ID[4] = { 'd', 'a', 't', 'a' };
|
u8 ID[4] = {'d', 'a', 't', 'a'};
|
||||||
le_t<u32> Size{}; // size of data (256 * NumChannels * sizeof(f32))
|
le_t<u32> Size{}; // size of data (256 * NumChannels * sizeof(f32))
|
||||||
|
|
||||||
WAVHeader() = default;
|
WAVHeader() = default;
|
||||||
|
|
||||||
WAVHeader(AudioChannelCnt ch, AudioFreq sample_rate, AudioSampleSize sample_size)
|
WAVHeader(AudioChannelCnt ch, AudioFreq sample_rate, AudioSampleSize sample_size)
|
||||||
: RIFF(sizeof(RIFFHeader) + sizeof(FMTHeader))
|
: RIFF(sizeof(RIFFHeader) + sizeof(FMTHeader)), FMT(ch, sample_rate, sample_size), FACT(0), Size(0)
|
||||||
, FMT(ch, sample_rate, sample_size)
|
|
||||||
, FACT(0)
|
|
||||||
, Size(0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -85,6 +77,12 @@ public:
|
||||||
void Close();
|
void Close();
|
||||||
|
|
||||||
void WriteData(const void* buffer, u32 size);
|
void WriteData(const void* buffer, u32 size);
|
||||||
u16 GetCh() const { return m_header.FMT.NumChannels; }
|
u16 GetCh() const
|
||||||
u16 GetSampleSize() const { return m_header.FMT.BitsPerSample / 8; }
|
{
|
||||||
|
return m_header.FMT.NumChannels;
|
||||||
|
}
|
||||||
|
u16 GetSampleSize() const
|
||||||
|
{
|
||||||
|
return m_header.FMT.BitsPerSample / 8;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
#include "Emu/Audio/audio_device_enumerator.h"
|
#include "Emu/Audio/audio_device_enumerator.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <Windows.h>
|
#include <windows.h>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -23,7 +23,7 @@ CubebBackend::CubebBackend()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cubeb *ctx{};
|
cubeb* ctx{};
|
||||||
if (int err = cubeb_init(&ctx, "RPCS3", nullptr))
|
if (int err = cubeb_init(&ctx, "RPCS3", nullptr))
|
||||||
{
|
{
|
||||||
Cubeb.error("cubeb_init() failed: %i", err);
|
Cubeb.error("cubeb_init() failed: %i", err);
|
||||||
|
|
@ -112,8 +112,10 @@ bool CubebBackend::Open(std::string_view dev_id, AudioFreq freq, AudioSampleSize
|
||||||
|
|
||||||
const bool use_default_device = dev_id.empty() || dev_id == audio_device_enumerator::DEFAULT_DEV_ID;
|
const bool use_default_device = dev_id.empty() || dev_id == audio_device_enumerator::DEFAULT_DEV_ID;
|
||||||
|
|
||||||
if (use_default_device) Cubeb.notice("Trying to open default device");
|
if (use_default_device)
|
||||||
else Cubeb.notice("Trying to open device with dev_id='%s'", dev_id);
|
Cubeb.notice("Trying to open default device");
|
||||||
|
else
|
||||||
|
Cubeb.notice("Trying to open device with dev_id='%s'", dev_id);
|
||||||
|
|
||||||
device_handle device = GetDevice(use_default_device ? "" : dev_id);
|
device_handle device = GetDevice(use_default_device ? "" : dev_id);
|
||||||
|
|
||||||
|
|
@ -240,7 +242,8 @@ void CubebBackend::Play()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_playing) return;
|
if (m_playing)
|
||||||
|
return;
|
||||||
|
|
||||||
std::lock_guard lock(m_cb_mutex);
|
std::lock_guard lock(m_cb_mutex);
|
||||||
m_playing = true;
|
m_playing = true;
|
||||||
|
|
@ -254,7 +257,8 @@ void CubebBackend::Pause()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_playing) return;
|
if (!m_playing)
|
||||||
|
return;
|
||||||
|
|
||||||
std::lock_guard lock(m_cb_mutex);
|
std::lock_guard lock(m_cb_mutex);
|
||||||
m_playing = false;
|
m_playing = false;
|
||||||
|
|
@ -283,8 +287,10 @@ CubebBackend::device_handle CubebBackend::GetDevice(std::string_view dev_id)
|
||||||
{
|
{
|
||||||
const bool default_dev = dev_id.empty();
|
const bool default_dev = dev_id.empty();
|
||||||
|
|
||||||
if (default_dev) Cubeb.notice("Searching for default device");
|
if (default_dev)
|
||||||
else Cubeb.notice("Searching for device with dev_id='%s'", dev_id);
|
Cubeb.notice("Searching for default device");
|
||||||
|
else
|
||||||
|
Cubeb.notice("Searching for device with dev_id='%s'", dev_id);
|
||||||
|
|
||||||
cubeb_device_collection dev_collection{};
|
cubeb_device_collection dev_collection{};
|
||||||
if (int err = cubeb_enumerate_devices(m_ctx, CUBEB_DEVICE_TYPE_OUTPUT, &dev_collection))
|
if (int err = cubeb_enumerate_devices(m_ctx, CUBEB_DEVICE_TYPE_OUTPUT, &dev_collection))
|
||||||
|
|
@ -368,8 +374,7 @@ CubebBackend::device_handle CubebBackend::GetDefaultDeviceAlt(AudioFreq freq, Au
|
||||||
.rate = static_cast<u32>(freq),
|
.rate = static_cast<u32>(freq),
|
||||||
.channels = static_cast<u32>(ch_cnt),
|
.channels = static_cast<u32>(ch_cnt),
|
||||||
.layout = CUBEB_LAYOUT_UNDEFINED,
|
.layout = CUBEB_LAYOUT_UNDEFINED,
|
||||||
.prefs = CUBEB_STREAM_PREF_DISABLE_DEVICE_SWITCHING
|
.prefs = CUBEB_STREAM_PREF_DISABLE_DEVICE_SWITCHING};
|
||||||
};
|
|
||||||
|
|
||||||
u32 min_latency{};
|
u32 min_latency{};
|
||||||
if (int err = cubeb_get_min_latency(m_ctx, ¶m, &min_latency))
|
if (int err = cubeb_get_min_latency(m_ctx, ¶m, &min_latency))
|
||||||
|
|
@ -379,7 +384,10 @@ CubebBackend::device_handle CubebBackend::GetDefaultDeviceAlt(AudioFreq freq, Au
|
||||||
}
|
}
|
||||||
|
|
||||||
cubeb_stream* tmp_stream{};
|
cubeb_stream* tmp_stream{};
|
||||||
static auto dummy_data_cb = [](cubeb_stream*, void*, void const*, void*, long) -> long { return 0; };
|
static auto dummy_data_cb = [](cubeb_stream*, void*, void const*, void*, long) -> long
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
static auto dummy_state_cb = [](cubeb_stream*, void*, cubeb_state) {};
|
static auto dummy_state_cb = [](cubeb_stream*, void*, cubeb_state) {};
|
||||||
|
|
||||||
if (int err = cubeb_stream_init(m_ctx, &tmp_stream, "Default device detector", nullptr, nullptr, nullptr, ¶m, min_latency, dummy_data_cb, dummy_state_cb, nullptr))
|
if (int err = cubeb_stream_init(m_ctx, &tmp_stream, "Default device detector", nullptr, nullptr, nullptr, ¶m, min_latency, dummy_data_cb, dummy_state_cb, nullptr))
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,10 @@ public:
|
||||||
CubebBackend(const CubebBackend&) = delete;
|
CubebBackend(const CubebBackend&) = delete;
|
||||||
CubebBackend& operator=(const CubebBackend&) = delete;
|
CubebBackend& operator=(const CubebBackend&) = delete;
|
||||||
|
|
||||||
std::string_view GetName() const override { return "Cubeb"sv; }
|
std::string_view GetName() const override
|
||||||
|
{
|
||||||
|
return "Cubeb"sv;
|
||||||
|
}
|
||||||
|
|
||||||
bool Initialized() override;
|
bool Initialized() override;
|
||||||
bool Operational() override;
|
bool Operational() override;
|
||||||
|
|
@ -51,7 +54,7 @@ private:
|
||||||
static long data_cb(cubeb_stream* stream, void* user_ptr, void const* input_buffer, void* output_buffer, long nframes);
|
static long data_cb(cubeb_stream* stream, void* user_ptr, void const* input_buffer, void* output_buffer, long nframes);
|
||||||
static void state_cb(cubeb_stream* stream, void* user_ptr, cubeb_state state);
|
static void state_cb(cubeb_stream* stream, void* user_ptr, cubeb_state state);
|
||||||
static void device_collection_changed_cb(cubeb* context, void* user_ptr);
|
static void device_collection_changed_cb(cubeb* context, void* user_ptr);
|
||||||
static void log_cb(const char *fmt, ...);
|
static void log_cb(const char* fmt, ...);
|
||||||
|
|
||||||
struct device_handle
|
struct device_handle
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <Windows.h>
|
#include <windows.h>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -81,8 +81,7 @@ std::vector<audio_device_enumerator::audio_device> cubeb_enumerator::get_output_
|
||||||
{
|
{
|
||||||
.id = std::string{dev_info.device_id},
|
.id = std::string{dev_info.device_id},
|
||||||
.name = std::string{dev_info.friendly_name},
|
.name = std::string{dev_info.friendly_name},
|
||||||
.max_ch = dev_info.max_channels
|
.max_ch = dev_info.max_channels};
|
||||||
};
|
|
||||||
|
|
||||||
if (dev.id.empty())
|
if (dev.id.empty())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,12 @@
|
||||||
class cubeb_enumerator final : public audio_device_enumerator
|
class cubeb_enumerator final : public audio_device_enumerator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cubeb_enumerator();
|
cubeb_enumerator();
|
||||||
~cubeb_enumerator() override;
|
~cubeb_enumerator() override;
|
||||||
|
|
||||||
std::vector<audio_device> get_output_devices() override;
|
std::vector<audio_device> get_output_devices() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
cubeb* ctx{};
|
cubeb* ctx{};
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
bool com_init_success = false;
|
bool com_init_success = false;
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ LOG_CHANNEL(FAudio_, "FAudio");
|
||||||
FAudioBackend::FAudioBackend()
|
FAudioBackend::FAudioBackend()
|
||||||
: AudioBackend()
|
: AudioBackend()
|
||||||
{
|
{
|
||||||
FAudio *instance;
|
FAudio* instance;
|
||||||
|
|
||||||
if (u32 res = FAudioCreate(&instance, 0, FAUDIO_DEFAULT_PROCESSOR))
|
if (u32 res = FAudioCreate(&instance, 0, FAUDIO_DEFAULT_PROCESSOR))
|
||||||
{
|
{
|
||||||
|
|
@ -54,7 +54,8 @@ void FAudioBackend::Play()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_playing) return;
|
if (m_playing)
|
||||||
|
return;
|
||||||
|
|
||||||
std::lock_guard lock(m_cb_mutex);
|
std::lock_guard lock(m_cb_mutex);
|
||||||
m_playing = true;
|
m_playing = true;
|
||||||
|
|
@ -68,7 +69,8 @@ void FAudioBackend::Pause()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_playing) return;
|
if (!m_playing)
|
||||||
|
return;
|
||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard lock(m_cb_mutex);
|
std::lock_guard lock(m_cb_mutex);
|
||||||
|
|
@ -231,9 +233,9 @@ f64 FAudioBackend::GetCallbackFrameLen()
|
||||||
return std::max<f64>(min_latency, _10ms);
|
return std::max<f64>(min_latency, _10ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FAudioBackend::OnVoiceProcessingPassStart_func(FAudioVoiceCallback *cb_obj, u32 BytesRequired)
|
void FAudioBackend::OnVoiceProcessingPassStart_func(FAudioVoiceCallback* cb_obj, u32 BytesRequired)
|
||||||
{
|
{
|
||||||
FAudioBackend *faudio = static_cast<FAudioBackend *>(cb_obj);
|
FAudioBackend* faudio = static_cast<FAudioBackend*>(cb_obj);
|
||||||
|
|
||||||
std::unique_lock lock(faudio->m_cb_mutex, std::defer_lock);
|
std::unique_lock lock(faudio->m_cb_mutex, std::defer_lock);
|
||||||
if (BytesRequired && !faudio->m_reset_req.observe() && lock.try_lock_for(std::chrono::microseconds{50}) && faudio->m_write_callback && faudio->m_playing)
|
if (BytesRequired && !faudio->m_reset_req.observe() && lock.try_lock_for(std::chrono::microseconds{50}) && faudio->m_write_callback && faudio->m_playing)
|
||||||
|
|
@ -262,11 +264,11 @@ void FAudioBackend::OnVoiceProcessingPassStart_func(FAudioVoiceCallback *cb_obj,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FAudioBackend::OnCriticalError_func(FAudioEngineCallback *cb_obj, u32 Error)
|
void FAudioBackend::OnCriticalError_func(FAudioEngineCallback* cb_obj, u32 Error)
|
||||||
{
|
{
|
||||||
FAudio_.error("OnCriticalError() failed(0x%08x)", Error);
|
FAudio_.error("OnCriticalError() failed(0x%08x)", Error);
|
||||||
|
|
||||||
FAudioBackend *faudio = static_cast<FAudioBackend *>(cb_obj);
|
FAudioBackend* faudio = static_cast<FAudioBackend*>(cb_obj);
|
||||||
|
|
||||||
std::lock_guard lock(faudio->m_state_cb_mutex);
|
std::lock_guard lock(faudio->m_state_cb_mutex);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,10 @@ public:
|
||||||
FAudioBackend(const FAudioBackend&) = delete;
|
FAudioBackend(const FAudioBackend&) = delete;
|
||||||
FAudioBackend& operator=(const FAudioBackend&) = delete;
|
FAudioBackend& operator=(const FAudioBackend&) = delete;
|
||||||
|
|
||||||
std::string_view GetName() const override { return "FAudio"sv; }
|
std::string_view GetName() const override
|
||||||
|
{
|
||||||
|
return "FAudio"sv;
|
||||||
|
}
|
||||||
|
|
||||||
bool Initialized() override;
|
bool Initialized() override;
|
||||||
bool Operational() override;
|
bool Operational() override;
|
||||||
|
|
@ -43,10 +46,10 @@ private:
|
||||||
atomic_t<bool> m_reset_req = false;
|
atomic_t<bool> m_reset_req = false;
|
||||||
|
|
||||||
// FAudio voice callbacks
|
// FAudio voice callbacks
|
||||||
static void OnVoiceProcessingPassStart_func(FAudioVoiceCallback *cb_obj, u32 BytesRequired);
|
static void OnVoiceProcessingPassStart_func(FAudioVoiceCallback* cb_obj, u32 BytesRequired);
|
||||||
|
|
||||||
// FAudio engine callbacks
|
// FAudio engine callbacks
|
||||||
static void OnCriticalError_func(FAudioEngineCallback *cb_obj, u32 Error);
|
static void OnCriticalError_func(FAudioEngineCallback* cb_obj, u32 Error);
|
||||||
|
|
||||||
void CloseUnlocked();
|
void CloseUnlocked();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ LOG_CHANNEL(faudio_dev_enum);
|
||||||
|
|
||||||
faudio_enumerator::faudio_enumerator() : audio_device_enumerator()
|
faudio_enumerator::faudio_enumerator() : audio_device_enumerator()
|
||||||
{
|
{
|
||||||
FAudio *tmp{};
|
FAudio* tmp{};
|
||||||
|
|
||||||
if (u32 res = FAudioCreate(&tmp, 0, FAUDIO_DEFAULT_PROCESSOR))
|
if (u32 res = FAudioCreate(&tmp, 0, FAUDIO_DEFAULT_PROCESSOR))
|
||||||
{
|
{
|
||||||
|
|
@ -68,8 +68,7 @@ std::vector<audio_device_enumerator::audio_device> faudio_enumerator::get_output
|
||||||
{
|
{
|
||||||
.id = std::to_string(dev_idx),
|
.id = std::to_string(dev_idx),
|
||||||
.name = utf16_to_utf8(std::bit_cast<char16_t*>(&dev_info.DisplayName[0])),
|
.name = utf16_to_utf8(std::bit_cast<char16_t*>(&dev_info.DisplayName[0])),
|
||||||
.max_ch = dev_info.OutputFormat.Format.nChannels
|
.max_ch = dev_info.OutputFormat.Format.nChannels};
|
||||||
};
|
|
||||||
|
|
||||||
if (dev.name.empty())
|
if (dev.name.empty())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,11 @@
|
||||||
class faudio_enumerator final : public audio_device_enumerator
|
class faudio_enumerator final : public audio_device_enumerator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
faudio_enumerator();
|
faudio_enumerator();
|
||||||
~faudio_enumerator() override;
|
~faudio_enumerator() override;
|
||||||
|
|
||||||
std::vector<audio_device> get_output_devices() override;
|
std::vector<audio_device> get_output_devices() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
FAudio* instance{};
|
FAudio* instance{};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -8,20 +8,38 @@ public:
|
||||||
NullAudioBackend() {}
|
NullAudioBackend() {}
|
||||||
~NullAudioBackend() {}
|
~NullAudioBackend() {}
|
||||||
|
|
||||||
std::string_view GetName() const override { return "Null"sv; }
|
std::string_view GetName() const override
|
||||||
|
{
|
||||||
|
return "Null"sv;
|
||||||
|
}
|
||||||
|
|
||||||
bool Open(std::string_view /* dev_id */, AudioFreq /* freq */, AudioSampleSize /* sample_size */, AudioChannelCnt /* ch_cnt */, audio_channel_layout /*layout*/) override
|
bool Open(std::string_view /* dev_id */, AudioFreq /* freq */, AudioSampleSize /* sample_size */, AudioChannelCnt /* ch_cnt */, audio_channel_layout /*layout*/) override
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
void Close() override { m_playing = false; }
|
void Close() override
|
||||||
|
{
|
||||||
|
m_playing = false;
|
||||||
|
}
|
||||||
|
|
||||||
f64 GetCallbackFrameLen() override { return 0.01; };
|
f64 GetCallbackFrameLen() override
|
||||||
|
{
|
||||||
|
return 0.01;
|
||||||
|
};
|
||||||
|
|
||||||
void Play() override { m_playing = true; }
|
void Play() override
|
||||||
void Pause() override { m_playing = false; }
|
{
|
||||||
bool IsPlaying() override { return m_playing; }
|
m_playing = true;
|
||||||
|
}
|
||||||
|
void Pause() override
|
||||||
|
{
|
||||||
|
m_playing = false;
|
||||||
|
}
|
||||||
|
bool IsPlaying() override
|
||||||
|
{
|
||||||
|
return m_playing;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_playing = false;
|
bool m_playing = false;
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,11 @@
|
||||||
class null_enumerator final : public audio_device_enumerator
|
class null_enumerator final : public audio_device_enumerator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
null_enumerator() {};
|
null_enumerator() {};
|
||||||
~null_enumerator() override {};
|
~null_enumerator() override {};
|
||||||
|
|
||||||
std::vector<audio_device> get_output_devices() override { return {}; }
|
std::vector<audio_device> get_output_devices() override
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
#include "Utilities/StrUtil.h"
|
#include "Utilities/StrUtil.h"
|
||||||
|
|
||||||
#include "XAudio2Backend.h"
|
#include "XAudio2Backend.h"
|
||||||
#include <Windows.h>
|
#include <windows.h>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
|
|
||||||
#ifndef XAUDIO2_USE_DEFAULT_PROCESSOR
|
#ifndef XAUDIO2_USE_DEFAULT_PROCESSOR
|
||||||
|
|
@ -135,7 +135,8 @@ void XAudio2Backend::Play()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_playing) return;
|
if (m_playing)
|
||||||
|
return;
|
||||||
|
|
||||||
std::lock_guard lock(m_cb_mutex);
|
std::lock_guard lock(m_cb_mutex);
|
||||||
m_playing = true;
|
m_playing = true;
|
||||||
|
|
@ -184,7 +185,8 @@ void XAudio2Backend::Pause()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_playing) return;
|
if (!m_playing)
|
||||||
|
return;
|
||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard lock(m_cb_mutex);
|
std::lock_guard lock(m_cb_mutex);
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,10 @@ public:
|
||||||
XAudio2Backend(const XAudio2Backend&) = delete;
|
XAudio2Backend(const XAudio2Backend&) = delete;
|
||||||
XAudio2Backend& operator=(const XAudio2Backend&) = delete;
|
XAudio2Backend& operator=(const XAudio2Backend&) = delete;
|
||||||
|
|
||||||
std::string_view GetName() const override { return "XAudio2"sv; }
|
std::string_view GetName() const override
|
||||||
|
{
|
||||||
|
return "XAudio2"sv;
|
||||||
|
}
|
||||||
|
|
||||||
bool Initialized() override;
|
bool Initialized() override;
|
||||||
bool Operational() override;
|
bool Operational() override;
|
||||||
|
|
@ -68,13 +71,36 @@ private:
|
||||||
void OnCriticalError(HRESULT Error) override;
|
void OnCriticalError(HRESULT Error) override;
|
||||||
|
|
||||||
// IMMNotificationClient callbacks
|
// IMMNotificationClient callbacks
|
||||||
IFACEMETHODIMP_(ULONG) AddRef() override { return 1; };
|
IFACEMETHODIMP_(ULONG)
|
||||||
IFACEMETHODIMP_(ULONG) Release() override { return 1; };
|
AddRef() override
|
||||||
IFACEMETHODIMP QueryInterface(REFIID /*iid*/, void** /*object*/) override { return E_NOINTERFACE; };
|
{
|
||||||
IFACEMETHODIMP OnPropertyValueChanged(LPCWSTR /*device_id*/, const PROPERTYKEY /*key*/) override { return S_OK; };
|
return 1;
|
||||||
IFACEMETHODIMP OnDeviceAdded(LPCWSTR /*device_id*/) override { return S_OK; };
|
};
|
||||||
IFACEMETHODIMP OnDeviceRemoved(LPCWSTR /*device_id*/) override { return S_OK; };
|
IFACEMETHODIMP_(ULONG)
|
||||||
IFACEMETHODIMP OnDeviceStateChanged(LPCWSTR /*device_id*/, DWORD /*new_state*/) override { return S_OK; };
|
Release() override
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
};
|
||||||
|
IFACEMETHODIMP QueryInterface(REFIID /*iid*/, void** /*object*/) override
|
||||||
|
{
|
||||||
|
return E_NOINTERFACE;
|
||||||
|
};
|
||||||
|
IFACEMETHODIMP OnPropertyValueChanged(LPCWSTR /*device_id*/, const PROPERTYKEY /*key*/) override
|
||||||
|
{
|
||||||
|
return S_OK;
|
||||||
|
};
|
||||||
|
IFACEMETHODIMP OnDeviceAdded(LPCWSTR /*device_id*/) override
|
||||||
|
{
|
||||||
|
return S_OK;
|
||||||
|
};
|
||||||
|
IFACEMETHODIMP OnDeviceRemoved(LPCWSTR /*device_id*/) override
|
||||||
|
{
|
||||||
|
return S_OK;
|
||||||
|
};
|
||||||
|
IFACEMETHODIMP OnDeviceStateChanged(LPCWSTR /*device_id*/, DWORD /*new_state*/) override
|
||||||
|
{
|
||||||
|
return S_OK;
|
||||||
|
};
|
||||||
IFACEMETHODIMP OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR new_default_device_id) override;
|
IFACEMETHODIMP OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR new_default_device_id) override;
|
||||||
|
|
||||||
void CloseUnlocked();
|
void CloseUnlocked();
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include <wrl/client.h>
|
#include <wrl/client.h>
|
||||||
#include <Windows.h>
|
#include <windows.h>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
#include <mmdeviceapi.h>
|
#include <mmdeviceapi.h>
|
||||||
#include <Functiondiscoverykeys_devpkey.h>
|
#include <Functiondiscoverykeys_devpkey.h>
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@
|
||||||
class xaudio2_enumerator final : public audio_device_enumerator
|
class xaudio2_enumerator final : public audio_device_enumerator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
xaudio2_enumerator();
|
xaudio2_enumerator();
|
||||||
~xaudio2_enumerator() override;
|
~xaudio2_enumerator() override;
|
||||||
|
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue