mischelper.c 605 B

12345678910111213141516171819202122232425262728
  1. /**
  2. * \file mischelper.c
  3. *
  4. * Source file with miscellaneous helper functions.
  5. */
  6. #include <SDL_test.h>
  7. void
  8. SDLVisualTest_HashString(char* str, char hash[33])
  9. {
  10. SDLTest_Md5Context md5c;
  11. int i;
  12. if(!str)
  13. {
  14. SDLTest_LogError("str argument cannot be NULL");
  15. return;
  16. }
  17. SDLTest_Md5Init(&md5c);
  18. SDLTest_Md5Update(&md5c, (unsigned char*)str, SDL_strlen(str));
  19. SDLTest_Md5Final(&md5c);
  20. /* convert the md5 hash to an array of hexadecimal digits */
  21. for(i = 0; i < 16; i++)
  22. SDL_snprintf(hash + 2 * i, 33 - 2 * i, "%02x", (int)md5c.digest[i]);
  23. }