2009-01-03 21:22:43 +00:00
|
|
|
/**
|
2016-01-03 16:14:14 +00:00
|
|
|
* \file md2.h
|
2009-01-04 16:27:10 +00:00
|
|
|
*
|
2011-01-06 12:28:03 +00:00
|
|
|
* \brief MD2 message digest algorithm (hash function)
|
|
|
|
*
|
2015-07-27 09:11:48 +00:00
|
|
|
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
2015-09-04 12:21:07 +00:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2010-07-18 20:36:00 +00:00
|
|
|
*
|
2015-09-04 12:21:07 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2010-07-18 20:36:00 +00:00
|
|
|
*
|
2015-09-04 12:21:07 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2009-01-04 16:27:10 +00:00
|
|
|
*
|
2015-09-04 12:21:07 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2009-01-04 16:27:10 +00:00
|
|
|
*
|
2015-09-04 12:21:07 +00:00
|
|
|
* This file is part of mbed TLS (https://tls.mbed.org)
|
2009-01-03 21:22:43 +00:00
|
|
|
*/
|
2015-04-08 10:49:31 +00:00
|
|
|
#ifndef MBEDTLS_MD2_H
|
|
|
|
#define MBEDTLS_MD2_H
|
2009-01-03 21:22:43 +00:00
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
#if !defined(MBEDTLS_CONFIG_FILE)
|
2013-06-24 17:20:35 +00:00
|
|
|
#include "config.h"
|
2014-04-29 10:39:06 +00:00
|
|
|
#else
|
2015-04-08 10:49:31 +00:00
|
|
|
#include MBEDTLS_CONFIG_FILE
|
2014-04-29 10:39:06 +00:00
|
|
|
#endif
|
2013-06-24 17:20:35 +00:00
|
|
|
|
2015-02-06 13:43:58 +00:00
|
|
|
#include <stddef.h>
|
2011-04-24 08:57:21 +00:00
|
|
|
|
2017-04-28 15:21:40 +00:00
|
|
|
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
|
|
|
|
!defined(inline) && !defined(__cplusplus)
|
|
|
|
#define inline __inline
|
|
|
|
#endif
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
#if !defined(MBEDTLS_MD2_ALT)
|
2013-06-24 17:20:35 +00:00
|
|
|
// Regular implementation
|
|
|
|
//
|
|
|
|
|
2013-06-27 12:29:21 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2009-01-03 21:22:43 +00:00
|
|
|
/**
|
|
|
|
* \brief MD2 context structure
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
unsigned char cksum[16]; /*!< checksum of the data block */
|
|
|
|
unsigned char state[48]; /*!< intermediate digest state */
|
|
|
|
unsigned char buffer[16]; /*!< data block being processed */
|
2011-04-24 08:57:21 +00:00
|
|
|
size_t left; /*!< amount of data in buffer */
|
2009-01-03 21:22:43 +00:00
|
|
|
}
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_md2_context;
|
2009-01-03 21:22:43 +00:00
|
|
|
|
2014-06-26 10:09:34 +00:00
|
|
|
/**
|
|
|
|
* \brief Initialize MD2 context
|
|
|
|
*
|
|
|
|
* \param ctx MD2 context to be initialized
|
|
|
|
*/
|
2015-04-08 10:49:31 +00:00
|
|
|
void mbedtls_md2_init( mbedtls_md2_context *ctx );
|
2014-06-26 10:09:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Clear MD2 context
|
|
|
|
*
|
|
|
|
* \param ctx MD2 context to be cleared
|
|
|
|
*/
|
2015-04-08 10:49:31 +00:00
|
|
|
void mbedtls_md2_free( mbedtls_md2_context *ctx );
|
2014-06-26 10:09:34 +00:00
|
|
|
|
2015-07-06 13:26:26 +00:00
|
|
|
/**
|
|
|
|
* \brief Clone (the state of) an MD2 context
|
|
|
|
*
|
|
|
|
* \param dst The destination context
|
|
|
|
* \param src The context to be cloned
|
|
|
|
*/
|
|
|
|
void mbedtls_md2_clone( mbedtls_md2_context *dst,
|
|
|
|
const mbedtls_md2_context *src );
|
|
|
|
|
2009-01-03 21:22:43 +00:00
|
|
|
/**
|
|
|
|
* \brief MD2 context setup
|
|
|
|
*
|
|
|
|
* \param ctx context to be initialized
|
2017-04-28 15:21:40 +00:00
|
|
|
*
|
|
|
|
* \return 0 if successful
|
|
|
|
*/
|
|
|
|
int mbedtls_md2_starts_ext( mbedtls_md2_context *ctx );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief MD2 process buffer
|
|
|
|
*
|
|
|
|
* \param ctx MD2 context
|
|
|
|
* \param input buffer holding the data
|
|
|
|
* \param ilen length of the input data
|
|
|
|
*
|
|
|
|
* \return 0 if successful
|
|
|
|
*/
|
|
|
|
int mbedtls_md2_update_ext( mbedtls_md2_context *ctx,
|
|
|
|
const unsigned char *input,
|
|
|
|
size_t ilen );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief MD2 final digest
|
|
|
|
*
|
|
|
|
* \param ctx MD2 context
|
|
|
|
* \param output MD2 checksum result
|
|
|
|
*
|
|
|
|
* \return 0 if successful
|
|
|
|
*/
|
|
|
|
int mbedtls_md2_finish_ext( mbedtls_md2_context *ctx,
|
|
|
|
unsigned char output[16] );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief MD2 process data block (internal use only)
|
|
|
|
*
|
|
|
|
* \param ctx MD2 context
|
|
|
|
*
|
|
|
|
* \return 0 if successful
|
|
|
|
*/
|
|
|
|
int mbedtls_md2_process_ext( mbedtls_md2_context *ctx );
|
|
|
|
|
|
|
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
|
|
|
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
|
|
|
#define MBEDTLS_DEPRECATED __attribute__((deprecated))
|
|
|
|
#else
|
|
|
|
#define MBEDTLS_DEPRECATED
|
|
|
|
#endif
|
|
|
|
/**
|
|
|
|
* \brief MD2 context setup
|
|
|
|
*
|
|
|
|
* \deprecated Superseded by mbedtls_md2_starts_ext() in 2.5.0
|
|
|
|
*
|
|
|
|
* \param ctx context to be initialized
|
2009-01-03 21:22:43 +00:00
|
|
|
*/
|
2017-04-28 15:21:40 +00:00
|
|
|
MBEDTLS_DEPRECATED static inline void mbedtls_md2_starts(
|
|
|
|
mbedtls_md2_context *ctx )
|
|
|
|
{
|
|
|
|
mbedtls_md2_starts_ext( ctx );
|
|
|
|
}
|
2009-01-03 21:22:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief MD2 process buffer
|
|
|
|
*
|
2017-04-28 15:21:40 +00:00
|
|
|
* \deprecated Superseded by mbedtls_md2_update_ext() in 2.5.0
|
|
|
|
*
|
2009-01-03 21:22:43 +00:00
|
|
|
* \param ctx MD2 context
|
|
|
|
* \param input buffer holding the data
|
|
|
|
* \param ilen length of the input data
|
|
|
|
*/
|
2017-04-28 15:21:40 +00:00
|
|
|
MBEDTLS_DEPRECATED static inline void mbedtls_md2_update(
|
|
|
|
mbedtls_md2_context *ctx,
|
|
|
|
const unsigned char *input,
|
|
|
|
size_t ilen )
|
|
|
|
{
|
|
|
|
mbedtls_md2_update_ext( ctx, input, ilen );
|
|
|
|
}
|
2009-01-03 21:22:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief MD2 final digest
|
|
|
|
*
|
2017-04-28 15:21:40 +00:00
|
|
|
* \deprecated Superseded by mbedtls_md2_finish_ext() in 2.5.0
|
|
|
|
*
|
2009-01-03 21:22:43 +00:00
|
|
|
* \param ctx MD2 context
|
|
|
|
* \param output MD2 checksum result
|
|
|
|
*/
|
2017-04-28 15:21:40 +00:00
|
|
|
MBEDTLS_DEPRECATED static inline void mbedtls_md2_finish(
|
|
|
|
mbedtls_md2_context *ctx,
|
|
|
|
unsigned char output[16] )
|
|
|
|
{
|
|
|
|
mbedtls_md2_finish_ext( ctx, output );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief MD2 process data block (internal use only)
|
|
|
|
*
|
|
|
|
* \deprecated Superseded by mbedtls_md2_process_ext() in 2.5.0
|
|
|
|
*
|
|
|
|
* \param ctx MD2 context
|
|
|
|
*/
|
|
|
|
MBEDTLS_DEPRECATED static inline void mbedtls_md2_process(
|
|
|
|
mbedtls_md2_context *ctx )
|
|
|
|
{
|
|
|
|
mbedtls_md2_process_ext( ctx );
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef MBEDTLS_DEPRECATED
|
|
|
|
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
2009-01-03 21:22:43 +00:00
|
|
|
|
2013-06-24 17:20:35 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
#else /* MBEDTLS_MD2_ALT */
|
2013-06-24 17:20:35 +00:00
|
|
|
#include "md2_alt.h"
|
2015-04-08 10:49:31 +00:00
|
|
|
#endif /* MBEDTLS_MD2_ALT */
|
2013-06-24 17:20:35 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2009-01-03 21:22:43 +00:00
|
|
|
/**
|
|
|
|
* \brief Output = MD2( input buffer )
|
|
|
|
*
|
|
|
|
* \param input buffer holding the data
|
|
|
|
* \param ilen length of the input data
|
|
|
|
* \param output MD2 checksum result
|
|
|
|
*/
|
2017-04-28 15:21:40 +00:00
|
|
|
int mbedtls_md2_ext( const unsigned char *input,
|
|
|
|
size_t ilen,
|
|
|
|
unsigned char output[16] );
|
|
|
|
|
|
|
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
|
|
|
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
|
|
|
#define MBEDTLS_DEPRECATED __attribute__((deprecated))
|
|
|
|
#else
|
|
|
|
#define MBEDTLS_DEPRECATED
|
|
|
|
#endif
|
|
|
|
/**
|
|
|
|
* \brief Output = MD2( input buffer )
|
|
|
|
*
|
|
|
|
* \deprecated Superseded by mbedtls_md2() in 2.5.0
|
|
|
|
*
|
|
|
|
* \param input buffer holding the data
|
|
|
|
* \param ilen length of the input data
|
|
|
|
* \param output MD2 checksum result
|
|
|
|
*
|
|
|
|
* \return 0 if successful
|
|
|
|
*/
|
|
|
|
MBEDTLS_DEPRECATED static inline void mbedtls_md2( const unsigned char *input,
|
|
|
|
size_t ilen,
|
|
|
|
unsigned char output[16] )
|
|
|
|
{
|
|
|
|
mbedtls_md2_ext( input, ilen, output );
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef MBEDTLS_DEPRECATED
|
|
|
|
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
2009-01-03 21:22:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Checkup routine
|
|
|
|
*
|
|
|
|
* \return 0 if successful, or 1 if the test failed
|
|
|
|
*/
|
2015-04-08 10:49:31 +00:00
|
|
|
int mbedtls_md2_self_test( int verbose );
|
2009-01-03 21:22:43 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
#endif /* mbedtls_md2.h */
|