/* Mix in user's spam list */
for (spam = SpamList; spam; spam = spam->next)
{
- mutt_md5_process_bytes(spam->regex->pattern, strlen(spam->regex->pattern), &ctx);
- mutt_md5_process_bytes(spam->template, strlen(spam->template), &ctx);
+ mutt_md5_process(spam->regex->pattern, &ctx);
+ mutt_md5_process(spam->template, &ctx);
}
/* Mix in user's nospam list */
for (nospam = NoSpamList; nospam; nospam = nospam->next)
{
- mutt_md5_process_bytes(nospam->regex->pattern, strlen(nospam->regex->pattern), &ctx);
+ mutt_md5_process(nospam->regex->pattern, &ctx);
}
/* Get a hash and take its bytes as an (unsigned int) hash version */
unsigned char ipad[MD5_BLOCK_LEN], opad[MD5_BLOCK_LEN];
unsigned char secret[MD5_BLOCK_LEN + 1];
unsigned char hash_passwd[MD5_DIGEST_LEN];
- size_t secret_len, chal_len;
+ size_t secret_len;
secret_len = strlen(password);
- chal_len = strlen(challenge);
/* passwords longer than MD5_BLOCK_LEN bytes are substituted with their MD5
* digests */
/* inner hash: challenge and ipadded secret */
mutt_md5_init_ctx(&ctx);
mutt_md5_process_bytes(ipad, MD5_BLOCK_LEN, &ctx);
- mutt_md5_process_bytes(challenge, chal_len, &ctx);
+ mutt_md5_process(challenge, &ctx);
mutt_md5_finish_ctx(&ctx, response);
/* outer hash: inner hash and opadded secret */
* | mutt_md5_init_ctx() | Initialise the MD5 computation
* | mutt_md5_process_block() | Process a block with MD5
* | mutt_md5_process_bytes() | Process a block of data
+ * | mutt_md5_process() | Process a string
* | mutt_md5_read_ctx() | Read from the context into a buffer
* | mutt_md5_toascii() | Produce an ASCII MD5 digest from a buffer
*/
return mutt_md5_finish_ctx(&ctx, resbuf);
}
+/**
+ * mutt_md5_process - Process a NULL-terminated string
+ * @param s String to process
+ * @param ctx MD5 context
+ */
+void mutt_md5_process(const char *s, struct Md5Ctx *ctx)
+{
+ mutt_md5_process_bytes(s, strlen(s), ctx);
+}
+
/**
* mutt_md5_process_bytes - Process a block of data
* @param buffer Buffer to process
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_process(const char *s, struct Md5Ctx *ctx);
void mutt_md5_toascii(const void *resbuf, char *digest);
#endif /* _MUTT_MD5_H */
/* Compute the authentication hash to send to the server */
mutt_md5_init_ctx(&ctx);
- mutt_md5_process_bytes(pop_data->timestamp, strlen(pop_data->timestamp), &ctx);
- mutt_md5_process_bytes(pop_data->conn->account.pass,
- strlen(pop_data->conn->account.pass), &ctx);
+ mutt_md5_process(pop_data->timestamp, &ctx);
+ mutt_md5_process(pop_data->conn->account.pass, &ctx);
mutt_md5_finish_ctx(&ctx, digest);
mutt_md5_toascii(digest, hash);
NEOMUTT_TEST_ITEM(test_base64_lengths) \
NEOMUTT_TEST_ITEM(test_rfc2047) \
NEOMUTT_TEST_ITEM(test_md5) \
+ NEOMUTT_TEST_ITEM(test_md5_bytes) \
NEOMUTT_TEST_ITEM(test_md5_buffer)
/******************************************************************************
};
/* clang-format on */
-void test_md5(void)
+void test_md5_bytes(void)
{
for (size_t i = 0; i < mutt_array_size(test_data); ++i)
{
}
}
+void test_md5(void)
+{
+ for (size_t i = 0; i < mutt_array_size(test_data); ++i)
+ {
+ struct Md5Ctx ctx;
+ unsigned char buf[16];
+ char digest[33];
+ mutt_md5_init_ctx(&ctx);
+ mutt_md5_process(test_data[i].text, &ctx);
+ mutt_md5_finish_ctx(&ctx, buf);
+ mutt_md5_toascii(buf, digest);
+ if (!TEST_CHECK(strcmp(test_data[i].hash, digest) == 0))
+ {
+ TEST_MSG("Iteration: %zu", i);
+ TEST_MSG("Expected : %s", test_data[i].hash);
+ TEST_MSG("Actual : %s", digest);
+ }
+ }
+}
+
void test_md5_buffer(void)
{
for (size_t i = 0; i < mutt_array_size(test_data); ++i)