blob: 262903962dc522baeb530b10b6cd86f46aec980a [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file md2.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker77b385e2009-07-28 17:23:11 +00004 * Copyright (C) 2006-2009, Paul Bakker <polarssl_maintainer at polarssl.org>
5 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00006 *
Paul Bakker77b385e2009-07-28 17:23:11 +00007 * Joined copyright on original XySSL code with: Christophe Devine
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Paul Bakker5121ce52009-01-03 21:22:43 +000022 */
Paul Bakker40e46942009-01-03 21:51:57 +000023#ifndef POLARSSL_MD2_H
24#define POLARSSL_MD2_H
Paul Bakker5121ce52009-01-03 21:22:43 +000025
26/**
27 * \brief MD2 context structure
28 */
29typedef struct
30{
31 unsigned char cksum[16]; /*!< checksum of the data block */
32 unsigned char state[48]; /*!< intermediate digest state */
33 unsigned char buffer[16]; /*!< data block being processed */
34
35 unsigned char ipad[64]; /*!< HMAC: inner padding */
36 unsigned char opad[64]; /*!< HMAC: outer padding */
37 int left; /*!< amount of data in buffer */
38}
39md2_context;
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45/**
46 * \brief MD2 context setup
47 *
48 * \param ctx context to be initialized
49 */
50void md2_starts( md2_context *ctx );
51
52/**
53 * \brief MD2 process buffer
54 *
55 * \param ctx MD2 context
56 * \param input buffer holding the data
57 * \param ilen length of the input data
58 */
59void md2_update( md2_context *ctx, unsigned char *input, int ilen );
60
61/**
62 * \brief MD2 final digest
63 *
64 * \param ctx MD2 context
65 * \param output MD2 checksum result
66 */
67void md2_finish( md2_context *ctx, unsigned char output[16] );
68
69/**
70 * \brief Output = MD2( input buffer )
71 *
72 * \param input buffer holding the data
73 * \param ilen length of the input data
74 * \param output MD2 checksum result
75 */
76void md2( unsigned char *input, int ilen, unsigned char output[16] );
77
78/**
79 * \brief Output = MD2( file contents )
80 *
81 * \param path input file name
82 * \param output MD2 checksum result
83 *
84 * \return 0 if successful, 1 if fopen failed,
85 * or 2 if fread failed
86 */
87int md2_file( char *path, unsigned char output[16] );
88
89/**
90 * \brief MD2 HMAC context setup
91 *
92 * \param ctx HMAC context to be initialized
93 * \param key HMAC secret key
94 * \param keylen length of the HMAC key
95 */
96void md2_hmac_starts( md2_context *ctx, unsigned char *key, int keylen );
97
98/**
99 * \brief MD2 HMAC process buffer
100 *
101 * \param ctx HMAC context
102 * \param input buffer holding the data
103 * \param ilen length of the input data
104 */
105void md2_hmac_update( md2_context *ctx, unsigned char *input, int ilen );
106
107/**
108 * \brief MD2 HMAC final digest
109 *
110 * \param ctx HMAC context
111 * \param output MD2 HMAC checksum result
112 */
113void md2_hmac_finish( md2_context *ctx, unsigned char output[16] );
114
115/**
116 * \brief Output = HMAC-MD2( hmac key, input buffer )
117 *
118 * \param key HMAC secret key
119 * \param keylen length of the HMAC key
120 * \param input buffer holding the data
121 * \param ilen length of the input data
122 * \param output HMAC-MD2 result
123 */
124void md2_hmac( unsigned char *key, int keylen,
125 unsigned char *input, int ilen,
126 unsigned char output[16] );
127
128/**
129 * \brief Checkup routine
130 *
131 * \return 0 if successful, or 1 if the test failed
132 */
133int md2_self_test( int verbose );
134
135#ifdef __cplusplus
136}
137#endif
138
139#endif /* md2.h */