Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

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