aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil/md5.h
blob: 229b0692d41607fa34237473931d8e05ea659f68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * Copyright (C) 2003-2005 Benny Prijono <benny@prijono.org>
 * Copyright (C) 2012      C Elston, Katalix Systems Ltd <celston@katalix.com>
 *
 * MD5 code from pjlib-util http://www.pjsip.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 *  2012-08-21 - C Elston - Split md5_hmac function to allow incremental usage.
 *
 */
#ifndef __MD5_H__ /**@todo Should this be _CRYPT_MD5_H__ ?*/
#define __MD5_H__

#include "ws_symbol_export.h"

/**
 * @file md5.h
 * @brief MD5 Functions
 */

/* Don't define this group for Wireshark
 * @defgroup PJLIB_UTIL_MD5 MD5 Functions
 * @ingroup PJLIB_UTIL
 * @{
 */

#define md5_byte_t guint8

/** MD5 context. */
typedef struct md5_state_s
{
	guint32 buf[4];
	guint32 bits[2];
	guint32 in[16];
} md5_state_t;

/** Initialize the algorithm.
 *  @param pms		MD5 context.
 */
WS_DLL_PUBLIC
void md5_init(md5_state_t *pms);

/** Append a string to the message.
 *  @param pms		MD5 context.
 *  @param data		Data.
 *  @param nbytes	Length of data.
 */
WS_DLL_PUBLIC
void md5_append( md5_state_t *pms,
			     const guint8 *data, size_t nbytes);

/** Finish the message and return the digest.
 *  @param pms		MD5 context.
 *  @param digest	16 byte digest.
 */
WS_DLL_PUBLIC
void md5_finish(md5_state_t *pms, guint8 digest[16]);

typedef struct md5_hmac_state_s
{
    md5_state_t ctx;
    guint8 k_opad[65];
} md5_hmac_state_t;

WS_DLL_PUBLIC
void md5_hmac_init(md5_hmac_state_t *hctx,
                   const guint8* key, size_t key_len);

WS_DLL_PUBLIC
void md5_hmac_append(md5_hmac_state_t *hctx,
                     const guint8* text, size_t text_len);

WS_DLL_PUBLIC
void md5_hmac_finish(md5_hmac_state_t *hctx, guint8 digest[16]);

WS_DLL_PUBLIC
void md5_hmac(const guint8* text, size_t text_len, const guint8* key,
              size_t key_len, guint8 digest[16]);

/*
 * @}
 */

#endif	/* _CRYPT_MD5_H__ */