#include <string.h>
-#include "glibconfig.h"
#include "gchecksum.h"
-#include "glib.h"
+
+#include "gmem.h"
+#include "gtestutils.h"
+#include "gtypes.h"
#include "glibintl.h"
{
guint32 buf[4];
guint32 bits[2];
-
+
guchar data[MD5_DATASIZE];
guchar digest[MD5_DIGEST_LEN];
* reflect the addition of 16 longwords of new data. md5_sum_update()
* blocks the data and converts bytes into longwords for this routine.
*/
-static void
-md5_transform (guint32 buf[4],
- guint32 const in[16])
+static void
+md5_transform (guint32 buf[4],
+ guint32 const in[16])
{
register guint32 a, b, c, d;
/* This is the central step in the MD5 algorithm. */
#define md5_step(f, w, x, y, z, data, s) \
- ( w += f (x, y, z) + data, w = w << s | w >> (32 - s), w += x )
+ ( w += f (x, y, z) + data, w = w << s | w >> (32 - s), w += x )
a = buf[0];
b = buf[1];
md5_step (F1, d, a, b, c, in[13] + 0xfd987193, 12);
md5_step (F1, c, d, a, b, in[14] + 0xa679438e, 17);
md5_step (F1, b, c, d, a, in[15] + 0x49b40821, 22);
-
+
md5_step (F2, a, b, c, d, in[1] + 0xf61e2562, 5);
md5_step (F2, d, a, b, c, in[6] + 0xc040b340, 9);
md5_step (F2, c, d, a, b, in[11] + 0x265e5a51, 14);
}
memcpy (p, data, bit);
-
+
md5_byte_reverse (md5->data, 16);
md5_transform (md5->buf, (guint32 *) md5->data);
while (length >= MD5_DATASIZE)
{
memcpy (md5->data, data, MD5_DATASIZE);
-
+
md5_byte_reverse (md5->data, 16);
md5_transform (md5->buf, (guint32 *) md5->data);
{
/* Two lots of padding: Pad the first block to 64 bytes */
memset (p, 0, count);
-
+
md5_byte_reverse (md5->data, 16);
md5_transform (md5->buf, (guint32 *) md5->data);
md5_transform (md5->buf, (guint32 *) md5->data);
md5_byte_reverse ((guchar *) md5->buf, 4);
-
+
memcpy (md5->digest, md5->buf, 16);
/* Reset buffers in case they contain sensitive data */
subRound (D, E, A, B, C, f2, K2, expand (in, 37));
subRound (C, D, E, A, B, f2, K2, expand (in, 38));
subRound (B, C, D, E, A, f2, K2, expand (in, 39));
-
+
subRound (A, B, C, D, E, f3, K3, expand (in, 40));
subRound (E, A, B, C, D, f3, K3, expand (in, 41));
subRound (D, E, A, B, C, f3, K3, expand (in, 42));
memcpy (p, buffer, count);
return;
}
-
+
memcpy (p, buffer, dataCount);
sha_byte_reverse (sha1->data, SHA1_DATASIZE);
while (count >= SHA1_DATASIZE)
{
memcpy (sha1->data, buffer, SHA1_DATASIZE);
-
+
sha_byte_reverse (sha1->data, SHA1_DATASIZE);
sha1_transform (sha1->buf, sha1->data);
*
* Return value: the checksum length, or -1 if @checksum_type is
* not supported.
- *
+ *
* Since: 2.16
*/
gssize
* g_checksum_new:
* @checksum_type: the desired type of checksum
*
- * Creates a new #GChecksum, using the checksum algorithm @checksum_type.
+ * Creates a new #GChecksum, using the checksum algorithm @checksum_type.
* If the @checksum_type is not known, %NULL is returned.
* A #GChecksum can be used to compute the checksum, or digest, of an
* arbitrary binary blob, using different hashing algorithms.
* will be closed and it won't be possible to call g_checksum_update()
* on it anymore.
*
- * Return value: the newly created #GChecksum, or %NULL.
+ * Return value: the newly created #GChecksum, or %NULL.
* Use g_checksum_free() to free the memory allocated by it.
*
* Since: 2.16
*
* Once this function has been called the #GChecksum can no longer be
* updated with g_checksum_update().
- *
- * The hexadecimal characters will be lower case.
+ *
+ * The hexadecimal characters will be lower case.
*
* Return value: the hexadecimal representation of the checksum. The
* returned string is owned by the checksum and should not be modified
* or freed.
- *
+ *
* Since: 2.16
*/
G_CONST_RETURN gchar *
gchar *str = NULL;
g_return_val_if_fail (checksum != NULL, NULL);
-
+
if (checksum->digest_str)
return checksum->digest_str;
* Computes the checksum for a binary @data of @length. This is a
* convenience wrapper for g_checksum_new(), g_checksum_get_string()
* and g_checksum_free().
- *
+ *
* The hexadecimal string returned will be in lower case.
*
* Return value: the digest of the binary data as a string in hexadecimal.
* @length: the length of the string, or -1 if the string is null-terminated.
*
* Computes the checksum of a string.
- *
+ *
* The hexadecimal string returned will be in lower case.
*
* Return value: the checksum as a hexadecimal string. The returned string
* The hashing algorithm to be used by #GChecksum when performing the
* digest of some data.
*
- * Note that the #GChecksumType enumeration may be extended at a later
- * date to include new hashing algorithm types.
+ * Note that the #GChecksumType enumeration may be extended at a later
+ * date to include new hashing algorithm types.
*
* Since: 2.16
*/
*/
typedef struct _GChecksum GChecksum;
-gssize g_checksum_type_get_length (GChecksumType checksum_type);
+gssize g_checksum_type_get_length (GChecksumType checksum_type);
-GChecksum * g_checksum_new (GChecksumType checksum_type);
-void g_checksum_reset (GChecksum *checksum);
-GChecksum * g_checksum_copy (const GChecksum *checksum);
-void g_checksum_free (GChecksum *checksum);
-void g_checksum_update (GChecksum *checksum,
- const guchar *data,
- gssize length);
-G_CONST_RETURN gchar *g_checksum_get_string (GChecksum *checksum);
-void g_checksum_get_digest (GChecksum *checksum,
- guint8 *buffer,
- gsize *digest_len);
+GChecksum * g_checksum_new (GChecksumType checksum_type);
+void g_checksum_reset (GChecksum *checksum);
+GChecksum * g_checksum_copy (const GChecksum *checksum);
+void g_checksum_free (GChecksum *checksum);
+void g_checksum_update (GChecksum *checksum,
+ const guchar *data,
+ gssize length);
+G_CONST_RETURN gchar *g_checksum_get_string (GChecksum *checksum);
+void g_checksum_get_digest (GChecksum *checksum,
+ guint8 *buffer,
+ gsize *digest_len);
-gchar *g_compute_checksum_for_data (GChecksumType checksum_type,
- const guchar *data,
- gsize length);
-gchar *g_compute_checksum_for_string (GChecksumType checksum_type,
- const gchar *str,
- gssize length);
+gchar *g_compute_checksum_for_data (GChecksumType checksum_type,
+ const guchar *data,
+ gsize length);
+gchar *g_compute_checksum_for_string (GChecksumType checksum_type,
+ const gchar *str,
+ gssize length);
G_END_DECLS