2002-02-12 06:48:54 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
*
|
|
|
|
* gimpmd5.c
|
|
|
|
*
|
2008-03-30 00:56:44 +08:00
|
|
|
* Use of this code is deprecated! Use %GChecksum from GLib instead.
|
2002-02-12 06:48:54 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-05-03 06:54:21 +08:00
|
|
|
#include <glib-object.h>
|
|
|
|
|
|
|
|
#include "gimpmathtypes.h"
|
2002-02-12 06:48:54 +08:00
|
|
|
|
|
|
|
#include "gimpmd5.h"
|
|
|
|
|
|
|
|
|
2010-07-02 20:41:35 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimpmd5
|
|
|
|
* @title: GimpMD5
|
|
|
|
* @short_description: The MD5 message-digest algorithm
|
|
|
|
*
|
|
|
|
* The MD5 message-digest algorithm
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2002-02-12 06:48:54 +08:00
|
|
|
/**
|
|
|
|
* gimp_md5_get_digest:
|
2008-03-29 00:56:43 +08:00
|
|
|
* @buffer: byte buffer
|
2002-02-12 06:58:44 +08:00
|
|
|
* @buffer_size: buffer size (in bytes) or -1 if @buffer is nul-terminated.
|
2008-03-29 00:56:43 +08:00
|
|
|
* @digest: 16 bytes buffer receiving the hash code.
|
2003-09-28 07:02:39 +08:00
|
|
|
*
|
2008-03-29 00:56:43 +08:00
|
|
|
* This function is deprecated! Use %GChecksum from GLib instead.
|
2002-02-12 06:48:54 +08:00
|
|
|
*
|
2008-03-29 00:56:43 +08:00
|
|
|
* Get the md5 hash of a buffer. The result is put in the 16 bytes
|
|
|
|
* buffer @digest. For more information see RFC 1321.
|
2002-02-12 06:48:54 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_md5_get_digest (const gchar *buffer,
|
|
|
|
gint buffer_size,
|
|
|
|
guchar digest[16])
|
|
|
|
{
|
2008-03-30 00:56:44 +08:00
|
|
|
GChecksum *checksum;
|
|
|
|
gsize len = 16;
|
2002-02-12 06:48:54 +08:00
|
|
|
|
2002-02-12 06:58:44 +08:00
|
|
|
g_return_if_fail (buffer != NULL);
|
|
|
|
g_return_if_fail (digest != NULL);
|
2003-09-28 07:02:39 +08:00
|
|
|
|
2008-03-30 00:56:44 +08:00
|
|
|
checksum = g_checksum_new (G_CHECKSUM_MD5);
|
2003-09-28 07:02:39 +08:00
|
|
|
|
2008-04-21 23:39:32 +08:00
|
|
|
g_checksum_update (checksum, (const guchar *) buffer, buffer_size);
|
|
|
|
g_checksum_get_digest (checksum, digest, &len);
|
2008-03-30 00:56:44 +08:00
|
|
|
g_checksum_free (checksum);
|
2002-02-12 06:48:54 +08:00
|
|
|
}
|