cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

mischelper.c (613B)


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