NeoMutt  2025-09-05-55-g97fc89
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
auth_cram.c File Reference

IMAP CRAM-MD5 authentication method. More...

#include "config.h"
#include <string.h>
#include "private.h"
#include "mutt/lib.h"
#include "conn/lib.h"
#include "adata.h"
#include "auth.h"
+ Include dependency graph for auth_cram.c:

Go to the source code of this file.

Macros

#define MD5_BLOCK_LEN   64
 
#define MD5_DIGEST_LEN   16
 

Functions

static void hmac_md5 (const char *password, const char *challenge, unsigned char *response)
 Produce CRAM-MD5 challenge response.
 
enum ImapAuthRes imap_auth_cram_md5 (struct ImapAccountData *adata, const char *method)
 Authenticate using CRAM-MD5 - Implements ImapAuth::authenticate() -.
 

Detailed Description

IMAP CRAM-MD5 authentication method.

Authors
  • Brendan Cully
  • Richard Russon
  • Pietro Cerutti

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file auth_cram.c.

Macro Definition Documentation

◆ MD5_BLOCK_LEN

#define MD5_BLOCK_LEN   64

Definition at line 39 of file auth_cram.c.

◆ MD5_DIGEST_LEN

#define MD5_DIGEST_LEN   16

Definition at line 40 of file auth_cram.c.

Function Documentation

◆ hmac_md5()

static void hmac_md5 ( const char * password,
const char * challenge,
unsigned char * response )
static

Produce CRAM-MD5 challenge response.

Parameters
[in]passwordPassword to encrypt
[in]challengeChallenge from server
[out]responseBuffer for the response

Definition at line 48 of file auth_cram.c.

49{
50 struct Md5Ctx md5ctx = { 0 };
51 unsigned char ipad[MD5_BLOCK_LEN] = { 0 };
52 unsigned char opad[MD5_BLOCK_LEN] = { 0 };
53 unsigned char secret[MD5_BLOCK_LEN + 1] = { 0 };
54
55 size_t secret_len = strlen(password);
56
57 /* passwords longer than MD5_BLOCK_LEN bytes are substituted with their MD5
58 * digests */
59 if (secret_len > MD5_BLOCK_LEN)
60 {
61 unsigned char hash_passwd[MD5_DIGEST_LEN];
62 mutt_md5_bytes(password, secret_len, hash_passwd);
63 mutt_str_copy((char *) secret, (char *) hash_passwd, MD5_DIGEST_LEN);
64 secret_len = MD5_DIGEST_LEN;
65 }
66 else
67 {
68 mutt_str_copy((char *) secret, password, sizeof(secret));
69 }
70
71 memcpy(ipad, secret, secret_len);
72 memcpy(opad, secret, secret_len);
73
74 for (int i = 0; i < MD5_BLOCK_LEN; i++)
75 {
76 ipad[i] ^= 0x36;
77 opad[i] ^= 0x5c;
78 }
79
80 /* inner hash: challenge and ipadded secret */
81 mutt_md5_init_ctx(&md5ctx);
83 mutt_md5_process(challenge, &md5ctx);
84 mutt_md5_finish_ctx(&md5ctx, response);
85
86 /* outer hash: inner hash and opadded secret */
87 mutt_md5_init_ctx(&md5ctx);
89 mutt_md5_process_bytes(response, MD5_DIGEST_LEN, &md5ctx);
90 mutt_md5_finish_ctx(&md5ctx, response);
91}
#define MD5_BLOCK_LEN
Definition auth_cram.c:39
#define MD5_DIGEST_LEN
Definition auth_cram.c:40
void mutt_md5_process_bytes(const void *buf, size_t buflen, struct Md5Ctx *md5ctx)
Process a block of data.
Definition md5.c:373
void * mutt_md5_bytes(const void *buffer, size_t len, void *resbuf)
Calculate the MD5 hash of a buffer.
Definition md5.c:336
void mutt_md5_process(const char *str, struct Md5Ctx *md5ctx)
Process a NUL-terminated string.
Definition md5.c:355
void mutt_md5_init_ctx(struct Md5Ctx *md5ctx)
Initialise the MD5 computation.
Definition md5.c:261
void * mutt_md5_finish_ctx(struct Md5Ctx *md5ctx, void *resbuf)
Process the remaining bytes in the buffer.
Definition md5.c:285
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition string.c:581
Cursor for the MD5 hashing.
Definition md5.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function: