From 1174899c4f299dd020a8e6489d0384ae24771978 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 31 Jul 2011 15:40:41 +0100 Subject: Having written the same stupid code (ASCII MD5 hashes) 205762 times, time to have a function for it.. --- lib/md5.c | 10 ++++++++++ lib/md5.h | 1 + 2 files changed, 11 insertions(+) (limited to 'lib') diff --git a/lib/md5.c b/lib/md5.c index 3c39eccd..e989ac6a 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -161,6 +161,16 @@ void md5_finish(struct MD5Context *ctx, md5_byte_t digest[16]) memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */ } +void md5_finish_ascii(struct MD5Context *context, char *ascii) +{ + md5_byte_t bin[16]; + int i; + + md5_finish(context, bin); + for (i = 0; i < 16; i ++) + sprintf(ascii + i * 2, "%02x", bin[i]); +} + /* The four core functions - F1 is optimized somewhat */ /* #define F1(x, y, z) (x & y | ~x & z) */ diff --git a/lib/md5.h b/lib/md5.h index 3ba28586..17da99b3 100644 --- a/lib/md5.h +++ b/lib/md5.h @@ -42,5 +42,6 @@ typedef struct MD5Context { G_MODULE_EXPORT void md5_init(struct MD5Context *context); G_MODULE_EXPORT void md5_append(struct MD5Context *context, const md5_byte_t *buf, unsigned int len); G_MODULE_EXPORT void md5_finish(struct MD5Context *context, md5_byte_t digest[16]); +G_MODULE_EXPORT void md5_finish_ascii(struct MD5Context *context, char *ascii); #endif -- cgit v1.2.3