Skip to content

Commit

Permalink
Add: Implemented a function that generates a hash value for an arbitr…
Browse files Browse the repository at this point in the history
…ary string. #753

This function is needed to catch duplicated results in reports.
  • Loading branch information
jhelmold authored Apr 5, 2023
2 parents ba1b52a + 588589f commit 2d1464a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
24 changes: 24 additions & 0 deletions util/authutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,30 @@ get_password_hashes (const gchar *password)
return hashes_out;
}

/**
* @brief Calculate the MD5 hash value for a given string
*
* @param string The String to be hashed
*
* @return A pointer to a gchar containing the hash value as a hexadecimal
* string, has to be freed by the caller.
*/
gchar *
get_md5_hash_from_string (const gchar *string)
{
g_assert (string);

gchar *hash_hex = NULL;
guchar *hash = g_malloc0 (gcry_md_get_algo_dlen (GCRY_MD_MD5));

gcry_md_hash_buffer (GCRY_MD_MD5, hash, string, strlen (string));
hash_hex = digest_hex (GCRY_MD_MD5, hash);

g_free (hash);

return hash_hex;
}

/**
* @brief Authenticate a credential pair against user file contents.
*
Expand Down
3 changes: 3 additions & 0 deletions util/authutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ gvm_auth_init (void);
int
gvm_authenticate_classic (const gchar *, const gchar *, const gchar *);

gchar *
get_md5_hash_from_string (const gchar *);

gchar *
get_password_hashes (const gchar *);

Expand Down

0 comments on commit 2d1464a

Please sign in to comment.