bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2004-2018 Dovecot authors, see the included COPYING file */
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen#include "lib.h"
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen#include "md5.h"
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen#include "message-parser.h"
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen#include "mbox-md5.h"
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainenstruct mbox_md5_context {
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen struct md5_context hdr_md5_ctx;
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen};
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainenstatic struct mbox_md5_context *mbox_md5_all_init(void)
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen{
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen struct mbox_md5_context *ctx;
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen ctx = i_new(struct mbox_md5_context, 1);
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen md5_init(&ctx->hdr_md5_ctx);
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen return ctx;
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen}
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainenstatic void mbox_md5_all_more(struct mbox_md5_context *ctx,
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen struct message_header_line *hdr)
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen{
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen md5_update(&ctx->hdr_md5_ctx, hdr->value, hdr->value_len);
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen}
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainenstatic void mbox_md5_all_finish(struct mbox_md5_context *ctx,
9625595c47c665f5aee57ebfcb1fcbe9ad1bf3a0Martti Rannanjärvi unsigned char result[STATIC_ARRAY 16])
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen{
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen md5_final(&ctx->hdr_md5_ctx, result);
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen i_free(ctx);
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen}
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainenstruct mbox_md5_vfuncs mbox_md5_all = {
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen mbox_md5_all_init,
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen mbox_md5_all_more,
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen mbox_md5_all_finish
9743e5ac5bf6391157a4d1ab7119872b0979f8b7Timo Sirainen};