Mercurial > hg > xmms-sid
diff src/xs_md5.c @ 657:acaba070cf49
Lots of cosmetic code cleanups; synced the de-gettextification from Audacious-SID, I suppose it makes some sense ...
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 02 Apr 2008 19:46:59 +0300 |
parents | a3fdd2d6c056 |
children | b0743dc9165d |
line wrap: on
line diff
--- a/src/xs_md5.c Wed Mar 26 08:55:29 2008 +0200 +++ b/src/xs_md5.c Wed Apr 02 19:46:59 2008 +0300 @@ -12,10 +12,11 @@ #include <glib.h> -#ifndef WORDS_BIGENDIAN +#if G_BYTE_ORDER == G_LITTLE_ENDIAN #define xs_md5_bytereverse(buf, len) /* Nothing */ #else -void xs_md5_bytereverse(guint8 *buf, guint l) +#if G_BYTE_ORDER == G_BIG_ENDIAN +static void xs_md5_bytereverse(guint8 *buf, guint l) { guint32 t; do { @@ -24,13 +25,16 @@ buf += sizeof(guint32); } while (--l); } +#else +#error Unsupported endianess! +#endif #endif /* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious * initialization constants. */ -void xs_md5_init(t_xs_md5state *ctx) +void xs_md5_init(xs_md5state_t *ctx) { ctx->buf[0] = 0x67452301; ctx->buf[1] = 0xefcdab89; @@ -53,7 +57,7 @@ #define MD5STEP(f, w, x, y, z, data, s) \ ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x ) -void xs_md5_transform(guint32 buf[4], guint32 const in[16]) +static void xs_md5_transform(guint32 buf[4], guint32 const in[16]) { register guint32 a, b, c, d; @@ -140,7 +144,7 @@ /* Update context to reflect the concatenation of another buffer full * of bytes. */ -void xs_md5_append(t_xs_md5state *ctx, const guint8 *buf, guint len) +void xs_md5_append(xs_md5state_t *ctx, const guint8 *buf, guint len) { guint32 t; @@ -153,7 +157,6 @@ t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ /* Handle any leading odd-sized chunks */ - if (t) { guint8 *p = (guint8 *) ctx->in + t; @@ -168,8 +171,8 @@ buf += t; len -= t; } + /* Process data in 64-byte chunks */ - while (len >= 64) { memcpy(ctx->in, buf, 64); xs_md5_bytereverse(ctx->in, 16); @@ -179,14 +182,13 @@ } /* Handle any remaining bytes of data. */ - memcpy(ctx->in, buf, len); } /* Final wrapup - pad to 64-byte boundary with the bit pattern * 1 0* (64-bit count of bits processed, MSB-first) */ -void xs_md5_finish(t_xs_md5state *ctx, t_xs_md5hash digest) +void xs_md5_finish(xs_md5state_t *ctx, xs_md5hash_t digest) { guint count; guint8 *p; @@ -205,15 +207,15 @@ /* Pad out to 56 mod 64 */ if (count < 8) { /* Two lots of padding: Pad the first block to 64 bytes */ - xs_memset(p, 0, count); + memset(p, 0, count); xs_md5_bytereverse(ctx->in, 16); xs_md5_transform(ctx->buf, (guint32 *) ctx->in); /* Now fill the next block with 56 bytes */ - xs_memset(ctx->in, 0, 56); + memset(ctx->in, 0, 56); } else { /* Pad block to 56 bytes */ - xs_memset(p, 0, count - 8); + memset(p, 0, count - 8); } xs_md5_bytereverse(ctx->in, 14); @@ -224,5 +226,5 @@ xs_md5_transform(ctx->buf, (guint32 *) ctx->in); xs_md5_bytereverse((guint8 *) ctx->buf, 4); memcpy(digest, ctx->buf, 16); - xs_memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */ + memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */ }