All pastes #470427 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-05-04 08:30 UTC
rendered paste body
/***************************************************************************
 *
 *   hash_from_ascii
 *
 *   Converts a hash string into a binary hash and puts the result into
 *   destbuf. destbuf must be large enough to take hash.
 *
 *   No input checking is performed.
 *
 *   returns destbuf
 *
 ***************************************************************************/

guint8 *
hash_from_ascii (const gchar *hash_str, guint8 *destbuf)
{
	gchar hexnum[3] = { 0x00, 0x00, 0x00 };
	gint  i;

	g_return_val_if_fail (destbuf  != NULL, NULL);
	g_return_val_if_fail (hash_str != NULL, NULL);

	for (i = 0;  i < 16; ++i)
	{
		strncpy (hexnum, hash_str+(i*2), 2);
		destbuf[i] = (guint8) strtol (hexnum, NULL, 16);
	}

	return destbuf;
}