blob: 2726ca3efa3cb93003f8adf1b009bd237fbc804a [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file md2.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker37ca75d2011-01-06 12:28:03 +00004 * \brief MD2 message digest algorithm (hash function)
5 *
Paul Bakker84f12b72010-07-18 10:13:04 +00006 * Copyright (C) 2006-2010, Brainspark B.V.
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
Paul Bakker84f12b72010-07-18 10:13:04 +00009 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakkerb96f1542010-07-18 20:36:00 +000010 *
Paul Bakker77b385e2009-07-28 17:23:11 +000011 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000012 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000013 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Paul Bakker5121ce52009-01-03 21:22:43 +000026 */
Paul Bakker40e46942009-01-03 21:51:57 +000027#ifndef POLARSSL_MD2_H
28#define POLARSSL_MD2_H
Paul Bakker5121ce52009-01-03 21:22:43 +000029
Paul Bakker23986e52011-04-24 08:57:21 +000030#include <string.h>
31
Paul Bakker5121ce52009-01-03 21:22:43 +000032/**
33 * \brief MD2 context structure
34 */
35typedef struct
36{
37 unsigned char cksum[16]; /*!< checksum of the data block */
38 unsigned char state[48]; /*!< intermediate digest state */
39 unsigned char buffer[16]; /*!< data block being processed */
40
Paul Bakkerfa1c5922011-10-06 14:18:49 +000041 unsigned char ipad[16]; /*!< HMAC: inner padding */
42 unsigned char opad[16]; /*!< HMAC: outer padding */
Paul Bakker23986e52011-04-24 08:57:21 +000043 size_t left; /*!< amount of data in buffer */
Paul Bakker5121ce52009-01-03 21:22:43 +000044}
45md2_context;
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51/**
52 * \brief MD2 context setup
53 *
54 * \param ctx context to be initialized
55 */
56void md2_starts( md2_context *ctx );
57
58/**
59 * \brief MD2 process buffer
60 *
61 * \param ctx MD2 context
62 * \param input buffer holding the data
63 * \param ilen length of the input data
64 */
Paul Bakker23986e52011-04-24 08:57:21 +000065void md2_update( md2_context *ctx, const unsigned char *input, size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000066
67/**
68 * \brief MD2 final digest
69 *
70 * \param ctx MD2 context
71 * \param output MD2 checksum result
72 */
73void md2_finish( md2_context *ctx, unsigned char output[16] );
74
75/**
76 * \brief Output = MD2( input buffer )
77 *
78 * \param input buffer holding the data
79 * \param ilen length of the input data
80 * \param output MD2 checksum result
81 */
Paul Bakker23986e52011-04-24 08:57:21 +000082void md2( const unsigned char *input, size_t ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000083
84/**
85 * \brief Output = MD2( file contents )
86 *
87 * \param path input file name
88 * \param output MD2 checksum result
89 *
90 * \return 0 if successful, 1 if fopen failed,
91 * or 2 if fread failed
92 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000093int md2_file( const char *path, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000094
95/**
96 * \brief MD2 HMAC context setup
97 *
98 * \param ctx HMAC context to be initialized
99 * \param key HMAC secret key
100 * \param keylen length of the HMAC key
101 */
Paul Bakker23986e52011-04-24 08:57:21 +0000102void md2_hmac_starts( md2_context *ctx, const unsigned char *key, size_t keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000103
104/**
105 * \brief MD2 HMAC process buffer
106 *
107 * \param ctx HMAC context
108 * \param input buffer holding the data
109 * \param ilen length of the input data
110 */
Paul Bakker23986e52011-04-24 08:57:21 +0000111void md2_hmac_update( md2_context *ctx, const unsigned char *input, size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000112
113/**
114 * \brief MD2 HMAC final digest
115 *
116 * \param ctx HMAC context
117 * \param output MD2 HMAC checksum result
118 */
119void md2_hmac_finish( md2_context *ctx, unsigned char output[16] );
120
121/**
Paul Bakker7d3b6612010-03-21 16:23:13 +0000122 * \brief MD2 HMAC context reset
123 *
124 * \param ctx HMAC context to be reset
125 */
126void md2_hmac_reset( md2_context *ctx );
127
128/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000129 * \brief Output = HMAC-MD2( hmac key, input buffer )
130 *
131 * \param key HMAC secret key
132 * \param keylen length of the HMAC key
133 * \param input buffer holding the data
134 * \param ilen length of the input data
135 * \param output HMAC-MD2 result
136 */
Paul Bakker23986e52011-04-24 08:57:21 +0000137void md2_hmac( const unsigned char *key, size_t keylen,
138 const unsigned char *input, size_t ilen,
Paul Bakker5121ce52009-01-03 21:22:43 +0000139 unsigned char output[16] );
140
141/**
142 * \brief Checkup routine
143 *
144 * \return 0 if successful, or 1 if the test failed
145 */
146int md2_self_test( int verbose );
147
148#ifdef __cplusplus
149}
150#endif
151
152#endif /* md2.h */