scratchpad-entropy.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <string>
  2. #include <iostream>
  3. #include "utility.hpp"
  4. #include "../randomx.h"
  5. #include "../virtual_machine.hpp"
  6. #include "../blake2/endian.h"
  7. /*
  8. Writes final scratchpads to disk as files with .spad extension, each file is 2048 KiB.
  9. Command line parameters:
  10. --count N number of files to generate (default = 1)
  11. --seed S different seed will give different outputs (default = 0)
  12. Entropy can be estimated by compressing the files using 7zip in Ultra mode:
  13. 7z.exe a -t7z -m0=lzma2 -mx=9 scratchpads.7z *.spad
  14. */
  15. int main(int argc, char** argv) {
  16. int count, seedValue;
  17. readIntOption("--count", argc, argv, count, 1);
  18. readIntOption("--seed", argc, argv, seedValue, 0);
  19. std::cout << "Generating " << count << " scratchpad(s) using seed " << seedValue << " ..." << std::endl;
  20. char seed[4];
  21. char input[4];
  22. char hash[RANDOMX_HASH_SIZE];
  23. store32(&seed, seedValue);
  24. randomx_cache *cache = randomx_alloc_cache(RANDOMX_FLAG_DEFAULT);
  25. randomx_init_cache(cache, &seed, sizeof seed);
  26. randomx_vm *vm = randomx_create_vm(RANDOMX_FLAG_DEFAULT, cache, NULL);
  27. for (int i = 0; i < count; ++i) {
  28. store32(&input, i);
  29. randomx_calculate_hash(vm, &input, sizeof input, hash);
  30. std::string filename("test-");
  31. filename += std::to_string(i);
  32. filename += ".spad";
  33. dump((const char*)vm->getScratchpad(), randomx::ScratchpadSize, filename.c_str());
  34. }
  35. randomx_destroy_vm(vm);
  36. randomx_release_cache(cache);
  37. return 0;
  38. }