4 * \brief MD2 message digest algorithm (hash function)
6 * Copyright (C) 2006-2013, Brainspark B.V.
8 * This file is part of PolarSSL (http://www.polarssl.org)
9 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
11 * All rights reserved.
13 * 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.
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.
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.
27 #ifndef POLARSSL_MD2_H
28 #define POLARSSL_MD2_H
34 #define POLARSSL_ERR_MD2_FILE_IO_ERROR -0x0070 /**< Read/write error in file. */
36 #if !defined(POLARSSL_MD2_ALT)
37 // Regular implementation
41 * \brief MD2 context structure
45 unsigned char cksum
[16]; /*!< checksum of the data block */
46 unsigned char state
[48]; /*!< intermediate digest state */
47 unsigned char buffer
[16]; /*!< data block being processed */
49 unsigned char ipad
[16]; /*!< HMAC: inner padding */
50 unsigned char opad
[16]; /*!< HMAC: outer padding */
51 size_t left
; /*!< amount of data in buffer */
60 * \brief MD2 context setup
62 * \param ctx context to be initialized
64 void md2_starts( md2_context
*ctx
);
67 * \brief MD2 process buffer
69 * \param ctx MD2 context
70 * \param input buffer holding the data
71 * \param ilen length of the input data
73 void md2_update( md2_context
*ctx
, const unsigned char *input
, size_t ilen
);
76 * \brief MD2 final digest
78 * \param ctx MD2 context
79 * \param output MD2 checksum result
81 void md2_finish( md2_context
*ctx
, unsigned char output
[16] );
87 #else /* POLARSSL_MD2_ALT */
89 #endif /* POLARSSL_MD2_ALT */
96 * \brief Output = MD2( input buffer )
98 * \param input buffer holding the data
99 * \param ilen length of the input data
100 * \param output MD2 checksum result
102 void md2( const unsigned char *input
, size_t ilen
, unsigned char output
[16] );
105 * \brief Output = MD2( file contents )
107 * \param path input file name
108 * \param output MD2 checksum result
110 * \return 0 if successful, or POLARSSL_ERR_MD2_FILE_IO_ERROR
112 int md2_file( const char *path
, unsigned char output
[16] );
115 * \brief MD2 HMAC context setup
117 * \param ctx HMAC context to be initialized
118 * \param key HMAC secret key
119 * \param keylen length of the HMAC key
121 void md2_hmac_starts( md2_context
*ctx
, const unsigned char *key
, size_t keylen
);
124 * \brief MD2 HMAC process buffer
126 * \param ctx HMAC context
127 * \param input buffer holding the data
128 * \param ilen length of the input data
130 void md2_hmac_update( md2_context
*ctx
, const unsigned char *input
, size_t ilen
);
133 * \brief MD2 HMAC final digest
135 * \param ctx HMAC context
136 * \param output MD2 HMAC checksum result
138 void md2_hmac_finish( md2_context
*ctx
, unsigned char output
[16] );
141 * \brief MD2 HMAC context reset
143 * \param ctx HMAC context to be reset
145 void md2_hmac_reset( md2_context
*ctx
);
148 * \brief Output = HMAC-MD2( hmac key, input buffer )
150 * \param key HMAC secret key
151 * \param keylen length of the HMAC key
152 * \param input buffer holding the data
153 * \param ilen length of the input data
154 * \param output HMAC-MD2 result
156 void md2_hmac( const unsigned char *key
, size_t keylen
,
157 const unsigned char *input
, size_t ilen
,
158 unsigned char output
[16] );
161 * \brief Checkup routine
163 * \return 0 if successful, or 1 if the test failed
165 int md2_self_test( int verbose
);