api-example1.c 635 B

123456789101112131415161718192021222324
  1. #include "../randomx.h"
  2. #include <stdio.h>
  3. int main() {
  4. const char myKey[] = "RandomX example key";
  5. const char myInput[] = "RandomX example input";
  6. char hash[RANDOMX_HASH_SIZE];
  7. randomx_cache *myCache = randomx_alloc_cache(RANDOMX_FLAG_DEFAULT);
  8. randomx_init_cache(myCache, &myKey, sizeof myKey);
  9. randomx_vm *myMachine = randomx_create_vm(RANDOMX_FLAG_DEFAULT, myCache, NULL);
  10. randomx_calculate_hash(myMachine, &myInput, sizeof myInput, hash);
  11. randomx_destroy_vm(myMachine);
  12. randomx_release_cache(myCache);
  13. for (unsigned i = 0; i < RANDOMX_HASH_SIZE; ++i)
  14. printf("%02x", hash[i] & 0xff);
  15. printf("\n");
  16. return 0;
  17. }