blob: af400dbed5bdd929a75b0f9ba3f9d28645e3673f [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 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00006 * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +00008 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakkerb96f1542010-07-18 20:36:00 +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
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020027#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020028#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
30#include POLARSSL_CONFIG_FILE
31#endif
Paul Bakker90995b52013-06-24 19:20:35 +020032
Rich Evans00ab4702015-02-06 13:43:58 +000033#include <stddef.h>
Paul Bakker23986e52011-04-24 08:57:21 +000034
Paul Bakker69e095c2011-12-10 21:55:01 +000035#define POLARSSL_ERR_MD2_FILE_IO_ERROR -0x0070 /**< Read/write error in file. */
36
Paul Bakker90995b52013-06-24 19:20:35 +020037#if !defined(POLARSSL_MD2_ALT)
38// Regular implementation
39//
40
Paul Bakker407a0da2013-06-27 14:29:21 +020041#ifdef __cplusplus
42extern "C" {
43#endif
44
Paul Bakker5121ce52009-01-03 21:22:43 +000045/**
46 * \brief MD2 context structure
47 */
48typedef struct
49{
50 unsigned char cksum[16]; /*!< checksum of the data block */
51 unsigned char state[48]; /*!< intermediate digest state */
52 unsigned char buffer[16]; /*!< data block being processed */
Paul Bakker23986e52011-04-24 08:57:21 +000053 size_t left; /*!< amount of data in buffer */
Paul Bakker5121ce52009-01-03 21:22:43 +000054}
55md2_context;
56
Paul Bakker5121ce52009-01-03 21:22:43 +000057/**
Paul Bakker5b4af392014-06-26 12:09:34 +020058 * \brief Initialize MD2 context
59 *
60 * \param ctx MD2 context to be initialized
61 */
62void md2_init( md2_context *ctx );
63
64/**
65 * \brief Clear MD2 context
66 *
67 * \param ctx MD2 context to be cleared
68 */
69void md2_free( md2_context *ctx );
70
71/**
Paul Bakker5121ce52009-01-03 21:22:43 +000072 * \brief MD2 context setup
73 *
74 * \param ctx context to be initialized
75 */
76void md2_starts( md2_context *ctx );
77
78/**
79 * \brief MD2 process buffer
80 *
81 * \param ctx MD2 context
82 * \param input buffer holding the data
83 * \param ilen length of the input data
84 */
Paul Bakker23986e52011-04-24 08:57:21 +000085void md2_update( md2_context *ctx, const unsigned char *input, size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000086
87/**
88 * \brief MD2 final digest
89 *
90 * \param ctx MD2 context
91 * \param output MD2 checksum result
92 */
93void md2_finish( md2_context *ctx, unsigned char output[16] );
94
Paul Bakker90995b52013-06-24 19:20:35 +020095#ifdef __cplusplus
96}
97#endif
98
99#else /* POLARSSL_MD2_ALT */
100#include "md2_alt.h"
101#endif /* POLARSSL_MD2_ALT */
102
103#ifdef __cplusplus
104extern "C" {
105#endif
106
Paul Bakker5121ce52009-01-03 21:22:43 +0000107/**
108 * \brief Output = MD2( input buffer )
109 *
110 * \param input buffer holding the data
111 * \param ilen length of the input data
112 * \param output MD2 checksum result
113 */
Paul Bakker23986e52011-04-24 08:57:21 +0000114void md2( const unsigned char *input, size_t ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000115
116/**
117 * \brief Output = MD2( file contents )
118 *
119 * \param path input file name
120 * \param output MD2 checksum result
121 *
Paul Bakker69e095c2011-12-10 21:55:01 +0000122 * \return 0 if successful, or POLARSSL_ERR_MD2_FILE_IO_ERROR
Paul Bakker5121ce52009-01-03 21:22:43 +0000123 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000124int md2_file( const char *path, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000125
126/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000127 * \brief Checkup routine
128 *
129 * \return 0 if successful, or 1 if the test failed
130 */
131int md2_self_test( int verbose );
132
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100133/* Internal use */
134void md2_process( md2_context *ctx );
135
Paul Bakker5121ce52009-01-03 21:22:43 +0000136#ifdef __cplusplus
137}
138#endif
139
140#endif /* md2.h */