From: Richard Russon Date: Thu, 16 Nov 2017 01:36:39 +0000 (+0000) Subject: rename md5 functions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9f844b4c2d28d4909ed6e84de46328f01638ea6c;p=neomutt rename md5 functions --- diff --git a/hcache/hcache.c b/hcache/hcache.c index 0c02d8d0c..906bd9a35 100644 --- a/hcache/hcache.c +++ b/hcache/hcache.c @@ -610,7 +610,7 @@ static const char *hcache_per_folder(const char *path, const char *folder, hcach unsigned char m[16]; /* binary md5sum */ char name[_POSIX_PATH_MAX]; snprintf(name, sizeof(name), "%s|%s", hcache_get_ops()->name, folder); - md5_buffer(name, strlen(name), &m); + 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], @@ -754,26 +754,26 @@ header_cache_t *mutt_hcache_open(const char *path, const char *folder, hcache_na hcachever = HCACHEVER; - md5_init_ctx(&ctx); + mutt_md5_init_ctx(&ctx); /* Seed with the compiled-in header structure hash */ - md5_process_bytes(&hcachever, sizeof(hcachever), &ctx); + mutt_md5_process_bytes(&hcachever, sizeof(hcachever), &ctx); /* Mix in user's spam list */ for (spam = SpamList; spam; spam = spam->next) { - md5_process_bytes(spam->regex->pattern, strlen(spam->regex->pattern), &ctx); - md5_process_bytes(spam->template, strlen(spam->template), &ctx); + mutt_md5_process_bytes(spam->regex->pattern, strlen(spam->regex->pattern), &ctx); + mutt_md5_process_bytes(spam->template, strlen(spam->template), &ctx); } /* Mix in user's nospam list */ for (nospam = NoSpamList; nospam; nospam = nospam->next) { - md5_process_bytes(nospam->regex->pattern, strlen(nospam->regex->pattern), &ctx); + mutt_md5_process_bytes(nospam->regex->pattern, strlen(nospam->regex->pattern), &ctx); } /* Get a hash and take its bytes as an (unsigned int) hash version */ - md5_finish_ctx(&ctx, digest.charval); + mutt_md5_finish_ctx(&ctx, digest.charval); hcachever = digest.intval; } diff --git a/imap/auth_cram.c b/imap/auth_cram.c index 3ce767601..81d69efcb 100644 --- a/imap/auth_cram.c +++ b/imap/auth_cram.c @@ -67,7 +67,7 @@ static void hmac_md5(const char *password, char *challenge, unsigned char *respo * digests */ if (secret_len > MD5_BLOCK_LEN) { - md5_buffer(password, secret_len, hash_passwd); + mutt_md5_buf(password, secret_len, hash_passwd); strfcpy((char *) secret, (char *) hash_passwd, MD5_DIGEST_LEN); secret_len = MD5_DIGEST_LEN; } @@ -86,16 +86,16 @@ static void hmac_md5(const char *password, char *challenge, unsigned char *respo } /* inner hash: challenge and ipadded secret */ - md5_init_ctx(&ctx); - md5_process_bytes(ipad, MD5_BLOCK_LEN, &ctx); - md5_process_bytes(challenge, chal_len, &ctx); - md5_finish_ctx(&ctx, response); + mutt_md5_init_ctx(&ctx); + mutt_md5_process_bytes(ipad, MD5_BLOCK_LEN, &ctx); + mutt_md5_process_bytes(challenge, chal_len, &ctx); + mutt_md5_finish_ctx(&ctx, response); /* outer hash: inner hash and opadded secret */ - md5_init_ctx(&ctx); - md5_process_bytes(opad, MD5_BLOCK_LEN, &ctx); - md5_process_bytes(response, MD5_DIGEST_LEN, &ctx); - md5_finish_ctx(&ctx, response); + mutt_md5_init_ctx(&ctx); + mutt_md5_process_bytes(opad, MD5_BLOCK_LEN, &ctx); + mutt_md5_process_bytes(response, MD5_DIGEST_LEN, &ctx); + mutt_md5_finish_ctx(&ctx, response); } /** diff --git a/mutt/md5.c b/mutt/md5.c index 787f25ed6..cd7f0230b 100644 --- a/mutt/md5.c +++ b/mutt/md5.c @@ -26,15 +26,15 @@ * * Calculate the MD5 cryptographic hash of a string, according to RFC1321. * - * | Function | Description - * | :------------------ | :---------------------------------------------------- - * | md5_buffer() | Calculate the MD5 hash of a buffer - * | md5_finish_ctx() | Process the remaining bytes in the buffer - * | md5_init_ctx() | Initialise the MD5 computation - * | md5_process_block() | Process a block with MD5 - * | md5_process_bytes() | Process a block of data - * | md5_read_ctx() | Read from the context into a buffer - * | md5_stream() | Compute MD5 message digest for bytes read from a file + * | Function | Description + * | :----------------------- | :---------------------------------------------------- + * | mutt_md5_buf() | Calculate the MD5 hash of a buffer + * | mutt_md5_finish_ctx() | Process the remaining bytes in the buffer + * | 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_read_ctx() | Read from the context into a buffer + * | mutt_md5_stream() | Compute MD5 message digest for bytes read from a file */ /* md5.c - Functions to compute MD5 message digest of files or memory blocks @@ -62,12 +62,12 @@ static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; /** - * md5_init_ctx - Initialise the MD5 computation + * mutt_md5_init_ctx - Initialise the MD5 computation * @param ctx MD5 context * * RFC1321, 3.3: Step 3 */ -void md5_init_ctx(struct Md5Ctx *ctx) +void mutt_md5_init_ctx(struct Md5Ctx *ctx) { ctx->A = 0x67452301; ctx->B = 0xefcdab89; @@ -93,7 +93,7 @@ static inline void set_uint32(char *cp, md5_uint32 v) } /** - * md5_read_ctx - Read from the context into a buffer + * mutt_md5_read_ctx - Read from the context into a buffer * @param ctx MD5 context * @param resbuf Buffer for result * @retval ptr Results buffer @@ -101,7 +101,7 @@ static inline void set_uint32(char *cp, md5_uint32 v) * Put result from CTX in first 16 bytes following RESBUF. * The result must be in little endian byte order. */ -void *md5_read_ctx(const struct Md5Ctx *ctx, void *resbuf) +void *mutt_md5_read_ctx(const struct Md5Ctx *ctx, void *resbuf) { char *r = resbuf; @@ -114,7 +114,7 @@ void *md5_read_ctx(const struct Md5Ctx *ctx, void *resbuf) } /** - * md5_finish_ctx - Process the remaining bytes in the buffer + * mutt_md5_finish_ctx - Process the remaining bytes in the buffer * @param ctx MD5 context * @param resbuf Buffer for result * @retval ptr Results buffer @@ -122,7 +122,7 @@ void *md5_read_ctx(const struct Md5Ctx *ctx, void *resbuf) * Process the remaining bytes in the internal buffer and the usual prologue * according to the standard and write the result to RESBUF. */ -void *md5_finish_ctx(struct Md5Ctx *ctx, void *resbuf) +void *mutt_md5_finish_ctx(struct Md5Ctx *ctx, void *resbuf) { /* Take yet unprocessed bytes into account. */ md5_uint32 bytes = ctx->buflen; @@ -140,13 +140,13 @@ void *md5_finish_ctx(struct Md5Ctx *ctx, void *resbuf) memcpy(&((char *) ctx->buffer)[bytes], fillbuf, (size - 2) * 4 - bytes); /* Process last bytes. */ - md5_process_block(ctx->buffer, size * 4, ctx); + mutt_md5_process_block(ctx->buffer, size * 4, ctx); - return md5_read_ctx(ctx, resbuf); + return mutt_md5_read_ctx(ctx, resbuf); } /** - * md5_stream - Compute MD5 message digest for bytes read from a file + * mutt_md5_stream - Compute MD5 message digest for bytes read from a file * @param stream File to read * @param resblock Buffer for result * @retval 0 Success @@ -155,14 +155,14 @@ void *md5_finish_ctx(struct Md5Ctx *ctx, void *resbuf) * The resulting message digest number will be written into the 16 bytes * beginning at RESBLOCK. */ -int md5_stream(FILE *stream, void *resblock) +int mutt_md5_stream(FILE *stream, void *resblock) { struct Md5Ctx ctx; char buffer[BLOCKSIZE + 72]; size_t sum; /* Initialize the computation context. */ - md5_init_ctx(&ctx); + mutt_md5_init_ctx(&ctx); /* Iterate over full file contents. */ while (true) @@ -201,22 +201,22 @@ int md5_stream(FILE *stream, void *resblock) /* Process buffer with BLOCKSIZE bytes. * Note that BLOCKSIZE % 64 == 0 */ - md5_process_block(buffer, BLOCKSIZE, &ctx); + mutt_md5_process_block(buffer, BLOCKSIZE, &ctx); } process_partial_block: /* Process any remaining bytes. */ if (sum > 0) - md5_process_bytes(buffer, sum, &ctx); + mutt_md5_process_bytes(buffer, sum, &ctx); /* Construct result in desired memory. */ - md5_finish_ctx(&ctx, resblock); + mutt_md5_finish_ctx(&ctx, resblock); return 0; } /** - * md5_buffer - Calculate the MD5 hash of a buffer + * 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 @@ -226,22 +226,22 @@ process_partial_block: * always in little endian byte order, so that a byte-wise output yields to the * wanted ASCII representation of the message digest. */ -void *md5_buffer(const char *buffer, size_t len, void *resblock) +void *mutt_md5_buf(const char *buffer, size_t len, void *resblock) { struct Md5Ctx ctx; /* Initialize the computation context. */ - md5_init_ctx(&ctx); + mutt_md5_init_ctx(&ctx); /* Process whole buffer but last len % 64 bytes. */ - md5_process_bytes(buffer, len, &ctx); + mutt_md5_process_bytes(buffer, len, &ctx); /* Put result in desired memory area. */ - return md5_finish_ctx(&ctx, resblock); + return mutt_md5_finish_ctx(&ctx, resblock); } /** - * md5_process_bytes - Process a block of data + * mutt_md5_process_bytes - Process a block of data * @param buffer Buffer to process * @param len Length of buffer * @param ctx MD5 context @@ -250,7 +250,7 @@ void *md5_buffer(const char *buffer, size_t len, void *resblock) * initialization function update the context for the next LEN bytes starting * at Buffer. It is NOT required that LEN is a multiple of 64. */ -void md5_process_bytes(const void *buffer, size_t len, struct Md5Ctx *ctx) +void mutt_md5_process_bytes(const void *buffer, size_t len, struct Md5Ctx *ctx) { /* When we already have some bits in our internal buffer concatenate both * inputs first. */ @@ -264,7 +264,7 @@ void md5_process_bytes(const void *buffer, size_t len, struct Md5Ctx *ctx) if (ctx->buflen > 64) { - md5_process_block(ctx->buffer, ctx->buflen & ~63, ctx); + mutt_md5_process_block(ctx->buffer, ctx->buflen & ~63, ctx); ctx->buflen &= 63; /* The regions in the following copy operation cannot overlap. */ @@ -284,14 +284,14 @@ void md5_process_bytes(const void *buffer, size_t len, struct Md5Ctx *ctx) if (UNALIGNED_P(buffer)) while (len > 64) { - md5_process_block(memcpy(ctx->buffer, buffer, 64), 64, ctx); + mutt_md5_process_block(memcpy(ctx->buffer, buffer, 64), 64, ctx); buffer = (const char *) buffer + 64; len -= 64; } else #endif { - md5_process_block(buffer, len & ~63, ctx); + mutt_md5_process_block(buffer, len & ~63, ctx); buffer = (const char *) buffer + (len & ~63); len &= 63; } @@ -306,7 +306,7 @@ void md5_process_bytes(const void *buffer, size_t len, struct Md5Ctx *ctx) left_over += len; if (left_over >= 64) { - md5_process_block(ctx->buffer, 64, ctx); + mutt_md5_process_block(ctx->buffer, 64, ctx); left_over -= 64; memcpy(ctx->buffer, &ctx->buffer[16], left_over); } @@ -324,7 +324,7 @@ void md5_process_bytes(const void *buffer, size_t len, struct Md5Ctx *ctx) #define FI(b, c, d) (c ^ (b | ~d)) /** - * md5_process_block - Process a block with MD5 + * mutt_md5_process_block - Process a block with MD5 * @param buffer Buffer to hash * @param len Length of buffer * @param ctx MD5 context @@ -332,7 +332,7 @@ void md5_process_bytes(const void *buffer, size_t len, struct Md5Ctx *ctx) * Process LEN bytes of Buffer, accumulating context into CTX. * LEN must be a multiple of 64. */ -void md5_process_block(const void *buffer, size_t len, struct Md5Ctx *ctx) +void mutt_md5_process_block(const void *buffer, size_t len, struct Md5Ctx *ctx) { md5_uint32 correct_words[16]; const md5_uint32 *words = buffer; diff --git a/mutt/md5.h b/mutt/md5.h index 3eb9564e3..6ae28336d 100644 --- a/mutt/md5.h +++ b/mutt/md5.h @@ -45,12 +45,12 @@ struct Md5Ctx md5_uint32 buffer[32]; }; -void *md5_buffer(const char *buffer, size_t len, void *resblock); -void *md5_finish_ctx(struct Md5Ctx *ctx, void *resbuf); -void md5_init_ctx(struct Md5Ctx *ctx); -void md5_process_block(const void *buffer, size_t len, struct Md5Ctx *ctx); -void md5_process_bytes(const void *buffer, size_t len, struct Md5Ctx *ctx); -void *md5_read_ctx(const struct Md5Ctx *ctx, void *resbuf); -int md5_stream(FILE *stream, void *resblock); +void *mutt_md5_buf(const char *buffer, size_t len, void *resblock); +void *mutt_md5_finish_ctx(struct Md5Ctx *ctx, void *resbuf); +void mutt_md5_init_ctx(struct Md5Ctx *ctx); +void mutt_md5_process_block(const void *buffer, size_t len, struct Md5Ctx *ctx); +void mutt_md5_process_bytes(const void *buffer, size_t len, struct Md5Ctx *ctx); +void *mutt_md5_read_ctx(const struct Md5Ctx *ctx, void *resbuf); +int mutt_md5_stream(FILE *stream, void *resblock); #endif /* _MUTT_MD5_H */ diff --git a/pgppubring.c b/pgppubring.c index b3cc8e1e5..de1653df0 100644 --- a/pgppubring.c +++ b/pgppubring.c @@ -201,13 +201,13 @@ static void pgp_make_pgp2_fingerprint(unsigned char *buff, unsigned char *digest struct Md5Ctx ctx; unsigned int size = 0; - md5_init_ctx(&ctx); + mutt_md5_init_ctx(&ctx); size = (buff[0] << 8) + buff[1]; size = ((size + 7) / 8); buff = &buff[2]; - md5_process_bytes(buff, size, &ctx); + mutt_md5_process_bytes(buff, size, &ctx); buff = &buff[size]; @@ -215,9 +215,9 @@ static void pgp_make_pgp2_fingerprint(unsigned char *buff, unsigned char *digest size = ((size + 7) / 8); buff = &buff[2]; - md5_process_bytes(buff, size, &ctx); + mutt_md5_process_bytes(buff, size, &ctx); - md5_finish_ctx(&ctx, digest); + mutt_md5_finish_ctx(&ctx, digest); } static char *binary_fingerprint_to_string(unsigned char *buff, size_t length) diff --git a/pop_auth.c b/pop_auth.c index 7856b7bb8..8fcf2a4ca 100644 --- a/pop_auth.c +++ b/pop_auth.c @@ -231,11 +231,11 @@ static enum PopAuthRes pop_auth_apop(struct PopData *pop_data, const char *metho mutt_message(_("Authenticating (APOP)...")); /* Compute the authentication hash to send to the server */ - md5_init_ctx(&ctx); - md5_process_bytes(pop_data->timestamp, strlen(pop_data->timestamp), &ctx); - md5_process_bytes(pop_data->conn->account.pass, - strlen(pop_data->conn->account.pass), &ctx); - md5_finish_ctx(&ctx, digest); + 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_finish_ctx(&ctx, digest); for (size_t i = 0; i < sizeof(digest); i++) sprintf(hash + 2 * i, "%02x", digest[i]);