unsigned char m[16]; /* binary md5sum */
char name[_POSIX_PATH_MAX];
snprintf(name, sizeof(name), "%s|%s", hcache_get_ops()->name, folder);
- mutt_md5_buf(name, strlen(name), &m);
- snprintf(name, sizeof(name),
- "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
- m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8], m[9], m[10],
- m[11], m[12], m[13], m[14], m[15]);
-
+ mutt_md5_buf(name, strlen(name), m);
+ mutt_md5_toascii(m, name);
rc = snprintf(hcpath, sizeof(hcpath), "%s%s%s%s", path, slash ? "" : "/", name, suffix);
}
* | mutt_md5_process_block() | Process a block with MD5
* | mutt_md5_process_bytes() | Process a block of data
* | mutt_md5_read_ctx() | Read from the context into a buffer
+ * | mutt_md5_toascii() | Produce an ASCII MD5 digest from a buffer
*/
/* md5.c - Functions to compute MD5 message digest of files or memory blocks
/**
* mutt_md5_buf - Calculate the MD5 hash of a buffer
- * @param buffer Buffer to hash
- * @param len Length of buffer
- * @param resblock Buffer for result
+ * @param buffer Buffer to hash
+ * @param len Length of buffer
+ * @param resbuf Buffer for result
* @retval ptr Results buffer
*
* Compute MD5 message digest for LEN bytes beginning at Buffer. The result is
* always in little endian byte order, so that a byte-wise output yields to the
* wanted ASCII representation of the message digest.
*/
-void *mutt_md5_buf(const char *buffer, size_t len, void *resblock)
+void *mutt_md5_buf(const char *buffer, size_t len, void *resbuf)
{
struct Md5Ctx ctx;
mutt_md5_process_bytes(buffer, len, &ctx);
/* Put result in desired memory area. */
- return mutt_md5_finish_ctx(&ctx, resblock);
+ return mutt_md5_finish_ctx(&ctx, resbuf);
}
/**
}
}
+void mutt_md5_toascii(const void *resbuf, char *digest)
+{
+ const unsigned char *c = resbuf;
+ sprintf(digest, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
+ c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8], c[9], c[10],
+ c[11], c[12], c[13], c[14], c[15]);
+}
md5_uint32 buffer[32];
};
-void *mutt_md5_buf(const char *buffer, size_t len, void *resblock);
+void *mutt_md5_buf(const char *buffer, size_t len, void *resbuf);
void *mutt_md5_finish_ctx(struct Md5Ctx *ctx, void *resbuf);
void mutt_md5_init_ctx(struct Md5Ctx *ctx);
void mutt_md5_process_bytes(const void *buffer, size_t len, struct Md5Ctx *ctx);
+void mutt_md5_toascii(const void *resbuf, char *digest);
#endif /* _MUTT_MD5_H */
mutt_md5_process_bytes(pop_data->conn->account.pass,
strlen(pop_data->conn->account.pass), &ctx);
mutt_md5_finish_ctx(&ctx, digest);
-
- for (size_t i = 0; i < sizeof(digest); i++)
- sprintf(hash + 2 * i, "%02x", digest[i]);
+ mutt_md5_toascii(digest, hash);
/* Send APOP command to server */
snprintf(buf, sizeof(buf), "APOP %s %s\r\n", pop_data->conn->account.user, hash);