blob: 151a8f45de4add64173aed0b72409bdfd9e2016f [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002 * \file mbedtls_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 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020024#ifndef MBEDTLS_MD2_H
25#define MBEDTLS_MD2_H
Paul Bakker5121ce52009-01-03 21:22:43 +000026
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020027#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020028#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020031#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
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020035#if !defined(MBEDTLS_MD2_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020036// Regular implementation
37//
38
Paul Bakker407a0da2013-06-27 14:29:21 +020039#ifdef __cplusplus
40extern "C" {
41#endif
42
Paul Bakker5121ce52009-01-03 21:22:43 +000043/**
44 * \brief MD2 context structure
45 */
46typedef struct
47{
48 unsigned char cksum[16]; /*!< checksum of the data block */
49 unsigned char state[48]; /*!< intermediate digest state */
50 unsigned char buffer[16]; /*!< data block being processed */
Paul Bakker23986e52011-04-24 08:57:21 +000051 size_t left; /*!< amount of data in buffer */
Paul Bakker5121ce52009-01-03 21:22:43 +000052}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020053mbedtls_md2_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000054
Paul Bakker5121ce52009-01-03 21:22:43 +000055/**
Paul Bakker5b4af392014-06-26 12:09:34 +020056 * \brief Initialize MD2 context
57 *
58 * \param ctx MD2 context to be initialized
59 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060void mbedtls_md2_init( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020061
62/**
63 * \brief Clear MD2 context
64 *
65 * \param ctx MD2 context to be cleared
66 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020067void mbedtls_md2_free( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020068
69/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020070 * \brief Clone (the state of) an MD2 context
71 *
72 * \param dst The destination context
73 * \param src The context to be cloned
74 */
75void mbedtls_md2_clone( mbedtls_md2_context *dst,
76 const mbedtls_md2_context *src );
77
78/**
Paul Bakker5121ce52009-01-03 21:22:43 +000079 * \brief MD2 context setup
80 *
81 * \param ctx context to be initialized
82 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020083void mbedtls_md2_starts( mbedtls_md2_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +000084
85/**
86 * \brief MD2 process buffer
87 *
88 * \param ctx MD2 context
89 * \param input buffer holding the data
90 * \param ilen length of the input data
91 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020092void mbedtls_md2_update( mbedtls_md2_context *ctx, const unsigned char *input, size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000093
94/**
95 * \brief MD2 final digest
96 *
97 * \param ctx MD2 context
98 * \param output MD2 checksum result
99 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200100void mbedtls_md2_finish( mbedtls_md2_context *ctx, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000101
Paul Bakker90995b52013-06-24 19:20:35 +0200102#ifdef __cplusplus
103}
104#endif
105
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200106#else /* MBEDTLS_MD2_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200107#include "md2_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200108#endif /* MBEDTLS_MD2_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200109
110#ifdef __cplusplus
111extern "C" {
112#endif
113
Paul Bakker5121ce52009-01-03 21:22:43 +0000114/**
115 * \brief Output = MD2( input buffer )
116 *
117 * \param input buffer holding the data
118 * \param ilen length of the input data
119 * \param output MD2 checksum result
120 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200121void mbedtls_md2( const unsigned char *input, size_t ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000122
123/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000124 * \brief Checkup routine
125 *
126 * \return 0 if successful, or 1 if the test failed
127 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128int mbedtls_md2_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000129
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100130/* Internal use */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131void mbedtls_md2_process( mbedtls_md2_context *ctx );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100132
Paul Bakker5121ce52009-01-03 21:22:43 +0000133#ifdef __cplusplus
134}
135#endif
136
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200137#endif /* mbedtls_md2.h */