-/* -*- mode: C; c-file-style: "gnu" -*- */
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* dbus-md5.c md5 implementation (based on L Peter Deutsch implementation)
*
* Copyright (C) 2003 Red Hat Inc.
* <ghost@aladdin.com>.
*/
+#include <config.h>
#include "dbus-internals.h"
#include "dbus-md5.h"
#include <string.h>
/**
* @defgroup DBusMD5 MD5 implementation
* @ingroup DBusInternals
- * @brief DBusMD5 interface
+ * @brief MD5 hash
*
* Types and functions related to computing MD5 sums.
*/
* The implementation of MD5 (see http://www.ietf.org/rfc/rfc1321.txt).
* This MD5 implementation was written by L. Peter Deutsch and
* is not derived from the RSA reference implementation in the
- * RFC. The version included in D-BUS comes from the Ghostscript
+ * RFC. The version included in D-Bus comes from the Ghostscript
* 7.05 distribution.
*
* @{
#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca)
#define T63 0x2ad7d2bb
#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e)
-#endif /* DOXYGEN_SHOULD_SKIP_THIS */
+#endif /* !DOXYGEN_SHOULD_SKIP_THIS */
static void
md5_process(DBusMD5Context *context, const unsigned char *data /*[64]*/)
/* some kind of security paranoia, though it seems pointless
* to me given the nonzeroed stuff flying around
*/
- memset ((void*)context, '\0', sizeof (DBusMD5Context));
+ _DBUS_ZERO(*context);
return TRUE;
}
{
DBusMD5Context context;
DBusString digest;
- const char hexdigits[16] = {
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
- 'a', 'b', 'c', 'd', 'e', 'f'
- };
- unsigned char *p;
- unsigned char *end;
- int orig_len;
_dbus_md5_init (&context);
_dbus_md5_update (&context, data);
- if (!_dbus_string_init (&digest, _DBUS_INT_MAX))
+ if (!_dbus_string_init (&digest))
return FALSE;
- orig_len = _dbus_string_get_length (ascii_output);
-
if (!_dbus_md5_final (&context, &digest))
goto error;
- _dbus_string_get_const_data (&digest, (const char **) &p);
- end = p + 16;
-
- while (p != end)
- {
- if (!_dbus_string_append_byte (ascii_output,
- hexdigits[(*p >> 4)]))
- goto error;
-
- if (!_dbus_string_append_byte (ascii_output,
- hexdigits[(*p & 0x0f)]))
- goto error;
-
- ++p;
- }
+ if (!_dbus_string_hex_encode (&digest, 0, ascii_output,
+ _dbus_string_get_length (ascii_output)))
+ goto error;
+ _dbus_string_free (&digest);
+
return TRUE;
error:
_dbus_string_free (&digest);
- _dbus_string_set_length (ascii_output, orig_len);
return FALSE;
}
_dbus_string_init_const_len (&input_str, input, input_len);
_dbus_string_init_const (&expected_str, expected);
- if (!_dbus_string_init (&results, _DBUS_INT_MAX))
+ if (!_dbus_string_init (&results))
_dbus_assert_not_reached ("no memory for md5 results");
if (!_dbus_md5_compute (&input_str, &results))