X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dbus%2Fdbus-md5.c;h=af71d5c52e22c154e62463c31338a4541afbabf5;hb=dbecdeabb20e0ce11121819c63373f0afba57c58;hp=dce18f89e21bba7cb7b2e75ffb503828b2dabaa9;hpb=c21511c01ab56d75f3aa4643761e9fd096a7f8be;p=platform%2Fupstream%2Fdbus.git diff --git a/dbus/dbus-md5.c b/dbus/dbus-md5.c index dce18f8..af71d5c 100644 --- a/dbus/dbus-md5.c +++ b/dbus/dbus-md5.c @@ -1,4 +1,4 @@ -/* -*- 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. @@ -34,6 +34,7 @@ * . */ +#include #include "dbus-internals.h" #include "dbus-md5.h" #include @@ -41,7 +42,7 @@ /** * @defgroup DBusMD5 MD5 implementation * @ingroup DBusInternals - * @brief DBusMD5 interface + * @brief MD5 hash * * Types and functions related to computing MD5 sums. */ @@ -54,7 +55,7 @@ * 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. * * @{ @@ -157,7 +158,7 @@ main(int argc, char **argv) #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]*/) @@ -451,7 +452,7 @@ _dbus_md5_final (DBusMD5Context *context, /* 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; } @@ -470,47 +471,27 @@ _dbus_md5_compute (const DBusString *data, { 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; } @@ -532,7 +513,7 @@ check_md5_binary (const unsigned char *input, _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))