Mercurial > dovecot > original-hg > dovecot-1.2
changeset 5595:8d8f8b31ac82 HEAD
hmac-md5 API cleanups. Use arrays with MD5_RESULTLEN and CRAM_MD5_CONTEXTLEN
sizes instead of pointers. hmac_md5_set_cram_context() takes a const array
now.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 13 May 2007 13:18:50 +0300 |
parents | 36c8fbd896fc |
children | b676a52d365a |
files | src/auth/mech-cram-md5.c src/auth/password-scheme-cram-md5.c src/lib/hmac-md5.c src/lib/hmac-md5.h |
diffstat | 4 files changed, 14 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/auth/mech-cram-md5.c Sun May 13 13:09:56 2007 +0300 +++ b/src/auth/mech-cram-md5.c Sun May 13 13:18:50 2007 +0300 @@ -50,7 +50,8 @@ const char *credentials) { - unsigned char digest[16], context_digest[32]; + unsigned char digest[MD5_RESULTLEN]; + unsigned char context_digest[CRAM_MD5_CONTEXTLEN]; struct hmac_md5_context ctx; buffer_t *context_digest_buf; const char *response_hex; @@ -69,9 +70,9 @@ hmac_md5_update(&ctx, request->challenge, strlen(request->challenge)); hmac_md5_final(&ctx, digest); - response_hex = binary_to_hex(digest, 16); + response_hex = binary_to_hex(digest, sizeof(digest)); - if (memcmp(response_hex, request->response, 32) != 0) { + if (memcmp(response_hex, request->response, sizeof(digest)*2) != 0) { auth_request_log_info(&request->auth_request, "cram-md5", "password mismatch"); return FALSE;
--- a/src/auth/password-scheme-cram-md5.c Sun May 13 13:09:56 2007 +0300 +++ b/src/auth/password-scheme-cram-md5.c Sun May 13 13:18:50 2007 +0300 @@ -8,7 +8,7 @@ const char *password_generate_cram_md5(const char *plaintext) { struct hmac_md5_context ctx; - unsigned char context_digest[32]; + unsigned char context_digest[CRAM_MD5_CONTEXTLEN]; hmac_md5_init(&ctx, (const unsigned char *)plaintext, strlen(plaintext));
--- a/src/lib/hmac-md5.c Sun May 13 13:09:56 2007 +0300 +++ b/src/lib/hmac-md5.c Sun May 13 13:18:50 2007 +0300 @@ -54,7 +54,7 @@ } void hmac_md5_get_cram_context(struct hmac_md5_context *ctx, - unsigned char *context_digest) + unsigned char context_digest[CRAM_MD5_CONTEXTLEN]) { unsigned char *cdp; @@ -76,9 +76,9 @@ } void hmac_md5_set_cram_context(struct hmac_md5_context *ctx, - unsigned char *context_digest) + const unsigned char context_digest[CRAM_MD5_CONTEXTLEN]) { - unsigned char *cdp; + const unsigned char *cdp; #define CDGET(p, c) STMT_START { \ (c) = (*p++); \
--- a/src/lib/hmac-md5.h Sun May 13 13:09:56 2007 +0300 +++ b/src/lib/hmac-md5.h Sun May 13 13:18:50 2007 +0300 @@ -3,18 +3,21 @@ #include "md5.h" +#define CRAM_MD5_CONTEXTLEN 32 + struct hmac_md5_context { struct md5_context ctx, ctxo; }; void hmac_md5_init(struct hmac_md5_context *ctx, const unsigned char *key, size_t key_len); -void hmac_md5_final(struct hmac_md5_context *ctx, unsigned char *digest); +void hmac_md5_final(struct hmac_md5_context *ctx, + unsigned char digest[MD5_RESULTLEN]); void hmac_md5_get_cram_context(struct hmac_md5_context *ctx, - unsigned char *context_digest); + unsigned char context_digest[CRAM_MD5_CONTEXTLEN]); void hmac_md5_set_cram_context(struct hmac_md5_context *ctx, - unsigned char *context_digest); + const unsigned char context_digest[CRAM_MD5_CONTEXTLEN]); static inline void