-I$(top_srcdir)/src/lib-otp
libauth_la_SOURCES = \
+ auth-digest.c \
auth-gs2.c \
auth-scram.c \
auth-scram-client.c \
headers = \
mycrypt.h \
+ auth-digest.h \
auth-gs2.h \
auth-scram.h \
auth-scram-client.h \
--- /dev/null
+/* Copyright (c) 2025 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "hash-method.h"
+
+#include "auth-digest.h"
+
+/*
+ * Processing
+ */
+
+void auth_digest_get_hash_a1_secret(const struct hash_method *hmethod,
+ const char *username, const char *realm,
+ const char *password,
+ unsigned char *digest_r)
+{
+ struct hash_method_context ctx;
+
+ /* A1 = unq(username) ":" unq(realm) ":" passwd */
+
+ hash_method_init(&ctx, hmethod);
+ hash_method_loop(&ctx, username, strlen(username));
+ hash_method_loop(&ctx, ":", 1);
+ hash_method_loop(&ctx, realm, strlen(realm));
+ hash_method_loop(&ctx, ":", 1);
+ hash_method_loop(&ctx, password, strlen(password));
+ hash_method_result(&ctx, digest_r);
+}
--- /dev/null
+#ifndef AUTH_DIGEST_H
+#define AUTH_DIGEST_H
+
+/*
+ * Processing
+ */
+
+void auth_digest_get_hash_a1_secret(const struct hash_method *hmethod,
+ const char *username, const char *realm,
+ const char *password,
+ unsigned char *digest_r);
+
+#endif
#include "sha2.h"
#include "otp.h"
#include "str.h"
+#include "auth-digest.h"
#include "password-scheme.h"
#include "password-scheme-private.h"
digest_md5_generate(const char *plaintext, const struct password_generate_params *params,
const unsigned char **raw_password_r, size_t *size_r)
{
- const char *realm, *str, *user;
+ static const struct hash_method *const hmethod = &hash_method_md5;
+ const char *realm, *user;
unsigned char *digest;
if (params->user == NULL)
}
/* user:realm:passwd */
- digest = t_malloc_no0(MD5_RESULTLEN);
- str = t_strdup_printf("%s:%s:%s", user, realm, plaintext);
- md5_get_digest(str, strlen(str), digest);
+ digest = t_malloc_no0(hmethod->digest_size);
+ auth_digest_get_hash_a1_secret(hmethod, user, realm, plaintext,
+ digest);
*raw_password_r = digest;
- *size_r = MD5_RESULTLEN;
+ *size_r = hmethod->digest_size;
}
static void