blob: 1ab80c7bec421842084b02336f39ad1b257ddc4e [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 Bakker530927b2015-02-13 14:24:10 +01006 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
Manuel Pégourié-Gonnarde12abf92015-01-28 17:13:45 +00008 * This file is part of mbed TLS (https://polarssl.org)
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00009 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Paul Bakker5121ce52009-01-03 21:22:43 +000023 */
Paul Bakker40e46942009-01-03 21:51:57 +000024#ifndef POLARSSL_MD2_H
25#define POLARSSL_MD2_H
Paul Bakker5121ce52009-01-03 21:22:43 +000026
Paul Bakker4087c472013-06-12 16:49:10 +020027#include "config.h"
28
Paul Bakker23986e52011-04-24 08:57:21 +000029#include <string.h>
30
Paul Bakker69e095c2011-12-10 21:55:01 +000031#define POLARSSL_ERR_MD2_FILE_IO_ERROR -0x0070 /**< Read/write error in file. */
32
Paul Bakker4087c472013-06-12 16:49:10 +020033#if !defined(POLARSSL_MD2_ALT)
34// Regular implementation
35//
36
Paul Bakker5121ce52009-01-03 21:22:43 +000037/**
38 * \brief MD2 context structure
39 */
40typedef struct
41{
42 unsigned char cksum[16]; /*!< checksum of the data block */
43 unsigned char state[48]; /*!< intermediate digest state */
44 unsigned char buffer[16]; /*!< data block being processed */
45
Paul Bakkerfa1c5922011-10-06 14:18:49 +000046 unsigned char ipad[16]; /*!< HMAC: inner padding */
47 unsigned char opad[16]; /*!< HMAC: outer padding */
Paul Bakker23986e52011-04-24 08:57:21 +000048 size_t left; /*!< amount of data in buffer */
Paul Bakker5121ce52009-01-03 21:22:43 +000049}
50md2_context;
51
52#ifdef __cplusplus
53extern "C" {
54#endif
55
56/**
57 * \brief MD2 context setup
58 *
59 * \param ctx context to be initialized
60 */
61void md2_starts( md2_context *ctx );
62
63/**
64 * \brief MD2 process buffer
65 *
66 * \param ctx MD2 context
67 * \param input buffer holding the data
68 * \param ilen length of the input data
69 */
Paul Bakker23986e52011-04-24 08:57:21 +000070void md2_update( md2_context *ctx, const unsigned char *input, size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000071
72/**
73 * \brief MD2 final digest
74 *
75 * \param ctx MD2 context
76 * \param output MD2 checksum result
77 */
78void md2_finish( md2_context *ctx, unsigned char output[16] );
79
Paul Bakker4087c472013-06-12 16:49:10 +020080#ifdef __cplusplus
81}
82#endif
83
84#else /* POLARSSL_MD2_ALT */
85#include "md2_alt.h"
86#endif /* POLARSSL_MD2_ALT */
87
88#ifdef __cplusplus
89extern "C" {
90#endif
91
Paul Bakker5121ce52009-01-03 21:22:43 +000092/**
93 * \brief Output = MD2( input buffer )
94 *
95 * \param input buffer holding the data
96 * \param ilen length of the input data
97 * \param output MD2 checksum result
98 */
Paul Bakker23986e52011-04-24 08:57:21 +000099void md2( const unsigned char *input, size_t ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000100
101/**
102 * \brief Output = MD2( file contents )
103 *
104 * \param path input file name
105 * \param output MD2 checksum result
106 *
Paul Bakker69e095c2011-12-10 21:55:01 +0000107 * \return 0 if successful, or POLARSSL_ERR_MD2_FILE_IO_ERROR
Paul Bakker5121ce52009-01-03 21:22:43 +0000108 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000109int md2_file( const char *path, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000110
111/**
112 * \brief MD2 HMAC context setup
113 *
114 * \param ctx HMAC context to be initialized
115 * \param key HMAC secret key
116 * \param keylen length of the HMAC key
117 */
Paul Bakker23986e52011-04-24 08:57:21 +0000118void md2_hmac_starts( md2_context *ctx, const unsigned char *key, size_t keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000119
120/**
121 * \brief MD2 HMAC process buffer
122 *
123 * \param ctx HMAC context
124 * \param input buffer holding the data
125 * \param ilen length of the input data
126 */
Paul Bakker23986e52011-04-24 08:57:21 +0000127void md2_hmac_update( md2_context *ctx, const unsigned char *input, size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000128
129/**
130 * \brief MD2 HMAC final digest
131 *
132 * \param ctx HMAC context
133 * \param output MD2 HMAC checksum result
134 */
135void md2_hmac_finish( md2_context *ctx, unsigned char output[16] );
136
137/**
Paul Bakker7d3b6612010-03-21 16:23:13 +0000138 * \brief MD2 HMAC context reset
139 *
140 * \param ctx HMAC context to be reset
141 */
142void md2_hmac_reset( md2_context *ctx );
143
144/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000145 * \brief Output = HMAC-MD2( hmac key, input buffer )
146 *
147 * \param key HMAC secret key
148 * \param keylen length of the HMAC key
149 * \param input buffer holding the data
150 * \param ilen length of the input data
151 * \param output HMAC-MD2 result
152 */
Paul Bakker23986e52011-04-24 08:57:21 +0000153void md2_hmac( const unsigned char *key, size_t keylen,
154 const unsigned char *input, size_t ilen,
Paul Bakker5121ce52009-01-03 21:22:43 +0000155 unsigned char output[16] );
156
157/**
158 * \brief Checkup routine
159 *
160 * \return 0 if successful, or 1 if the test failed
161 */
162int md2_self_test( int verbose );
163
164#ifdef __cplusplus
165}
166#endif
167
168#endif /* md2.h */