diff --git a/randomx.sln b/randomx.sln index ddf3010..024e742 100644 --- a/randomx.sln +++ b/randomx.sln @@ -21,6 +21,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "api-example2", "vcxproj\api EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "code-generator", "vcxproj\code-generator.vcxproj", "{3E490DEC-1874-43AA-92DA-1AC57C217EAC}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "scratchpad-entropy", "vcxproj\scratchpad-entropy.vcxproj", "{FF8BD408-AFD8-43C6-BE98-4D03B37E840B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -93,6 +95,14 @@ Global {3E490DEC-1874-43AA-92DA-1AC57C217EAC}.Release|x64.Build.0 = Release|x64 {3E490DEC-1874-43AA-92DA-1AC57C217EAC}.Release|x86.ActiveCfg = Release|Win32 {3E490DEC-1874-43AA-92DA-1AC57C217EAC}.Release|x86.Build.0 = Release|Win32 + {FF8BD408-AFD8-43C6-BE98-4D03B37E840B}.Debug|x64.ActiveCfg = Debug|x64 + {FF8BD408-AFD8-43C6-BE98-4D03B37E840B}.Debug|x64.Build.0 = Debug|x64 + {FF8BD408-AFD8-43C6-BE98-4D03B37E840B}.Debug|x86.ActiveCfg = Debug|Win32 + {FF8BD408-AFD8-43C6-BE98-4D03B37E840B}.Debug|x86.Build.0 = Debug|Win32 + {FF8BD408-AFD8-43C6-BE98-4D03B37E840B}.Release|x64.ActiveCfg = Release|x64 + {FF8BD408-AFD8-43C6-BE98-4D03B37E840B}.Release|x64.Build.0 = Release|x64 + {FF8BD408-AFD8-43C6-BE98-4D03B37E840B}.Release|x86.ActiveCfg = Release|Win32 + {FF8BD408-AFD8-43C6-BE98-4D03B37E840B}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -105,6 +115,7 @@ Global {83EA3E54-5D91-4E01-8EF6-C1E718334F83} = {4A4A689F-86AF-41C0-A974-1080506D0923} {44947B9C-E6B1-4C06-BD01-F8EF43B59223} = {4A4A689F-86AF-41C0-A974-1080506D0923} {3E490DEC-1874-43AA-92DA-1AC57C217EAC} = {4A4A689F-86AF-41C0-A974-1080506D0923} + {FF8BD408-AFD8-43C6-BE98-4D03B37E840B} = {4A4A689F-86AF-41C0-A974-1080506D0923} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4EBC03DB-AE37-4141-8147-692F16E0ED02} diff --git a/src/tests/scratchpad-entropy.cpp b/src/tests/scratchpad-entropy.cpp new file mode 100644 index 0000000..ecb3c7d --- /dev/null +++ b/src/tests/scratchpad-entropy.cpp @@ -0,0 +1,50 @@ +#include +#include +#include "utility.hpp" +#include "../randomx.h" +#include "../virtual_machine.hpp" +#include "../blake2/endian.h" + +/* + Writes final scratchpads to disk as files with .spad extension, each file is 2048 KiB. + Command line parameters: + --count N number of files to generate (default = 1) + --seed S different seed will give different outputs (default = 0) + + Entropy can be estimated by compressing the files using 7zip in Ultra mode: + + 7z.exe a -t7z -m0=lzma2 -mx=9 scratchpads.7z *.spad +*/ + +int main(int argc, char** argv) { + int count, seedValue; + + readIntOption("--count", argc, argv, count, 1); + readIntOption("--seed", argc, argv, seedValue, 0); + + std::cout << "Generating " << count << " scratchpad(s) using seed " << seedValue << " ..." << std::endl; + + char seed[4]; + char input[4]; + char hash[RANDOMX_HASH_SIZE]; + + store32(&seed, seedValue); + + randomx_cache *cache = randomx_alloc_cache(RANDOMX_FLAG_DEFAULT); + randomx_init_cache(cache, &seed, sizeof seed); + randomx_vm *vm = randomx_create_vm(RANDOMX_FLAG_DEFAULT, cache, NULL); + + for (int i = 0; i < count; ++i) { + store32(&input, i); + randomx_calculate_hash(vm, &input, sizeof input, hash); + std::string filename("test-"); + filename += std::to_string(i); + filename += ".spad"; + dump((const char*)vm->getScratchpad(), randomx::ScratchpadSize, filename.c_str()); + } + + randomx_destroy_vm(vm); + randomx_release_cache(cache); + + return 0; +} diff --git a/src/virtual_machine.hpp b/src/virtual_machine.hpp index 40e48e3..f851e9f 100644 --- a/src/virtual_machine.hpp +++ b/src/virtual_machine.hpp @@ -37,6 +37,9 @@ public: randomx::RegisterFile *getRegisterFile() { return ® } + const void* getScratchpad() { + return scratchpad; + } protected: void initialize(); alignas(64) randomx::Program program; diff --git a/vcxproj/scratchpad-entropy.vcxproj b/vcxproj/scratchpad-entropy.vcxproj new file mode 100644 index 0000000..2e28337 --- /dev/null +++ b/vcxproj/scratchpad-entropy.vcxproj @@ -0,0 +1,128 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {FF8BD408-AFD8-43C6-BE98-4D03B37E840B} + scratchpadentropy + 10.0.17763.0 + + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + + + + {3346a4ad-c438-4324-8b77-47a16452954b} + + + + + + \ No newline at end of file diff --git a/vcxproj/scratchpad-entropy.vcxproj.filters b/vcxproj/scratchpad-entropy.vcxproj.filters new file mode 100644 index 0000000..a215bfa --- /dev/null +++ b/vcxproj/scratchpad-entropy.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file