The qDecoder Project

qHash.c File Reference

Encoding/decoding API. More...


Functions

unsigned char * qHashMd5 (const void *data, size_t nbytes)
 Get MD5 digested HEX string.
char * qHashMd5Str (const void *data, size_t nbytes)
 Get MD5 digested ASCII string.
char * qHashMd5File (const char *filepath, size_t *nbytes)
 Get MD5 digested ASCII string.
unsigned int qHashFnv32 (unsigned int max, const void *data, size_t nbytes)
 Get FNV32 hash integer.


Detailed Description

Encoding/decoding API.


Function Documentation

unsigned char* qHashMd5 ( const void *  data,
size_t  nbytes 
)

Get MD5 digested HEX string.

Parameters:
data source object
nbytes size of data
Returns:
malloced 16+1 bytes digested HEX string which is terminated by NULL character
   unsigned char *md5 = qHashMd5((void*)"hello", 5);
   free(md5);

char* qHashMd5Str ( const void *  data,
size_t  nbytes 
)

Get MD5 digested ASCII string.

Parameters:
data source object
nbytes size of data
Returns:
malloced 32+1 bytes digested ASCII string which is terminated by NULL character
   char *md5str = qHashMd5Str((void*)"hello", 5);
   printf("%s\n", md5str);
   free(md5str);

char* qHashMd5File ( const char *  filepath,
size_t *  nbytes 
)

Get MD5 digested ASCII string.

Parameters:
filepath file path
nbytes size of data. Set to NULL to digest end of file
Returns:
malloced 32+1 bytes digested ASCII string which is terminated by NULL character
Note:
If the nbytes is set, qHashMd5File() will try to digest at lease nbytes then store actual digested size into nbytes. So if you set nbytes to over size than file size, finally nbytes will have actual file size.
   // case of digesting entire file
   char *md5str = qHashMd5File("/tmp/test.dat, NULL);
   printf("%s\n", md5str);
   free(md5str);

   // case of nbytes is set to 1 bytes length
   size_t nbytes = 1;
   char *md5str = qHashMd5File("/tmp/test.dat, &nbytes);
   printf("%s %d\n", md5str, nbytes);
   free(md5str);

   // case of nbytes is set to over size
   size_t nbytes = 100000;
   char *md5str = qHashMd5File("/tmp/test.dat, &nbytes);
   printf("%s %d\n", md5str, nbytes);
   free(md5str);

unsigned int qHashFnv32 ( unsigned int  max,
const void *  data,
size_t  nbytes 
)

Get FNV32 hash integer.

Parameters:
max hash range. 0 ~ (max-1). Set to 0 for full range
data source data
nbytes size of data
Returns:
FNV32 hash integer
   unsigned int fnv32;

   fnv32 = qHashFnv32(0, (void*)"hello", 5);
   printf("%u\n", fnv32);

   fnv32 = qHashFnv32(1000, (void*)"hello", 5);
   printf("%u\n", fnv32);


[Home] [About] [Examples] [Changes] [Download] [SVN Repository] [Install] [Reference]