blob: bcda2e3abb4aa93e2409c60bf6016f5c4a1f93e7 [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
30/**
31 * \brief MD2 context structure
32 */
33typedef struct
34{
35 unsigned char cksum[16]; /*!< checksum of the data block */
36 unsigned char state[48]; /*!< intermediate digest state */
37 unsigned char buffer[16]; /*!< data block being processed */
38
39 unsigned char ipad[64]; /*!< HMAC: inner padding */
40 unsigned char opad[64]; /*!< HMAC: outer padding */
41 int left; /*!< amount of data in buffer */
42}
43md2_context;
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49/**
50 * \brief MD2 context setup
51 *
52 * \param ctx context to be initialized
53 */
54void md2_starts( md2_context *ctx );
55
56/**
57 * \brief MD2 process buffer
58 *
59 * \param ctx MD2 context
60 * \param input buffer holding the data
61 * \param ilen length of the input data
62 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000063void md2_update( md2_context *ctx, const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000064
65/**
66 * \brief MD2 final digest
67 *
68 * \param ctx MD2 context
69 * \param output MD2 checksum result
70 */
71void md2_finish( md2_context *ctx, unsigned char output[16] );
72
73/**
74 * \brief Output = MD2( input buffer )
75 *
76 * \param input buffer holding the data
77 * \param ilen length of the input data
78 * \param output MD2 checksum result
79 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000080void md2( const unsigned char *input, int ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000081
82/**
83 * \brief Output = MD2( file contents )
84 *
85 * \param path input file name
86 * \param output MD2 checksum result
87 *
88 * \return 0 if successful, 1 if fopen failed,
89 * or 2 if fread failed
90 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000091int md2_file( const char *path, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000092
93/**
94 * \brief MD2 HMAC context setup
95 *
96 * \param ctx HMAC context to be initialized
97 * \param key HMAC secret key
98 * \param keylen length of the HMAC key
99 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000100void md2_hmac_starts( md2_context *ctx, const unsigned char *key, int keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000101
102/**
103 * \brief MD2 HMAC process buffer
104 *
105 * \param ctx HMAC context
106 * \param input buffer holding the data
107 * \param ilen length of the input data
108 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000109void md2_hmac_update( md2_context *ctx, const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000110
111/**
112 * \brief MD2 HMAC final digest
113 *
114 * \param ctx HMAC context
115 * \param output MD2 HMAC checksum result
116 */
117void md2_hmac_finish( md2_context *ctx, unsigned char output[16] );
118
119/**
Paul Bakker7d3b6612010-03-21 16:23:13 +0000120 * \brief MD2 HMAC context reset
121 *
122 * \param ctx HMAC context to be reset
123 */
124void md2_hmac_reset( md2_context *ctx );
125
126/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000127 * \brief Output = HMAC-MD2( hmac key, input buffer )
128 *
129 * \param key HMAC secret key
130 * \param keylen length of the HMAC key
131 * \param input buffer holding the data
132 * \param ilen length of the input data
133 * \param output HMAC-MD2 result
134 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000135void md2_hmac( const unsigned char *key, int keylen,
136 const unsigned char *input, int ilen,
Paul Bakker5121ce52009-01-03 21:22:43 +0000137 unsigned char output[16] );
138
139/**
140 * \brief Checkup routine
141 *
142 * \return 0 if successful, or 1 if the test failed
143 */
144int md2_self_test( int verbose );
145
146#ifdef __cplusplus
147}
148#endif
149
150#endif /* md2.h */