Changeset 34afea7 for lib/md5.h


Ignore:
Timestamp:
2015-01-31T23:58:57Z (9 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
0ca1d79
Parents:
e41cc40
git-author:
dequis <dx@…> (18-01-15 06:39:20)
git-committer:
dequis <dx@…> (31-01-15 23:58:57)
Message:

Use glib's GChecksum for md5/sha1

This changes behavior slightly:

  • md5_init()/sha1_init() allocate a GChecksum
  • md5_finish()/sha1_finish() close and free() it
  • md5_digest_keep() was added (no sha1 equivalent needed)

And yes, glib has this concept of "closing" the GChecksum, which means
it can't be used anymore after g_checksum_get_digest().

jabber_cache_add() actually seems to need to do that to generate some
random-ish values, so i kept that working by adding a md5_digest_keep()
function that copies the GChecksum before it gets closed

GChecksum was introduced in glib 2.16, so the configure script version
was bumped. We were already depending on glib 2.16 accidentally
(some post-3.2.2 code uses GHashTableIter)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/md5.h

    re41cc40 r34afea7  
    1 /*
    2  * MD5 hashing code copied from Lepton's crack <http://usuarios.lycos.es/reinob/>
    3  *
    4  * Adapted to be API-compatible with the previous (GPL-incompatible) code.
    5  */
    6 
    7 /*
    8  * This code implements the MD5 message-digest algorithm.
    9  * The algorithm is due to Ron Rivest.  This code was
    10  * written by Colin Plumb in 1993, no copyright is claimed.
    11  * This code is in the public domain; do with it what you wish.
    12  *
    13  * Equivalent code is available from RSA Data Security, Inc.
    14  * This code has been tested against that, and is equivalent,
    15  * except that you don't need to include two pages of legalese
    16  * with every copy.
    17  *
    18  * To compute the message digest of a chunk of bytes, declare an
    19  * MD5Context structure, pass it to MD5Init, call MD5Update as
    20  * needed on buffers full of bytes, and then call MD5Final, which
    21  * will fill a supplied 16-byte array with the digest.
    22  */
    23 
    241#ifndef _MD5_H
    252#define _MD5_H
    263
    27 #include <sys/types.h>
     4#include <glib.h>
    285#include <gmodule.h>
    29 #if(__sun)
    30 #include <inttypes.h>
    31 #else
    32 #include <stdint.h>
    33 #endif
    346
    35 typedef uint8_t md5_byte_t;
    36 typedef struct MD5Context {
    37         uint32_t buf[4];
    38         uint32_t bits[2];
    39         unsigned char in[64];
    40 } md5_state_t;
     7typedef guint8 md5_byte_t;
     8typedef GChecksum *md5_state_t;
    419
    42 G_MODULE_EXPORT void md5_init(struct MD5Context *context);
    43 G_MODULE_EXPORT void md5_append(struct MD5Context *context, const md5_byte_t *buf, unsigned int len);
    44 G_MODULE_EXPORT void md5_finish(struct MD5Context *context, md5_byte_t digest[16]);
    45 G_MODULE_EXPORT void md5_finish_ascii(struct MD5Context *context, char *ascii);
     10
     11#define MD5_HASH_SIZE 16
     12
     13void md5_init(md5_state_t *);
     14void md5_append(md5_state_t *, const guint8 *, unsigned int);
     15void md5_finish(md5_state_t *, guint8 digest[MD5_HASH_SIZE]);
     16void md5_digest_keep(md5_state_t *, guint8 digest[MD5_HASH_SIZE]);
     17void md5_free(md5_state_t *);
    4618
    4719#endif
Note: See TracChangeset for help on using the changeset viewer.