Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a hash value for a given string. #753

Merged
merged 3 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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