]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - common/polarssl/sha1.h
   4  * \brief SHA-1 cryptographic hash function 
   6  *  Copyright (C) 2006-2013, Brainspark B.V. 
   8  *  This file is part of PolarSSL (http://www.polarssl.org) 
   9  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> 
  11  *  All rights reserved. 
  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. 
  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. 
  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. 
  27 #ifndef POLARSSL_SHA1_H 
  28 #define POLARSSL_SHA1_H 
  30 #include "polarssl_config.h" 
  36 typedef UINT32 
uint32_t; 
  41 #define POLARSSL_ERR_SHA1_FILE_IO_ERROR                -0x0076  /**< Read/write error in file. */ 
  43 #if !defined(POLARSSL_SHA1_ALT) 
  44 // Regular implementation 
  48  * \brief          SHA-1 context structure 
  52     uint32_t total
[2];          /*!< number of bytes processed  */ 
  53     uint32_t state
[5];          /*!< intermediate digest state  */ 
  54     unsigned char buffer
[64];   /*!< data block being processed */ 
  56     unsigned char ipad
[64];     /*!< HMAC: inner padding        */ 
  57     unsigned char opad
[64];     /*!< HMAC: outer padding        */ 
  66  * \brief          SHA-1 context setup 
  68  * \param ctx      context to be initialized 
  70 void sha1_starts( sha1_context 
*ctx 
); 
  73  * \brief          SHA-1 process buffer 
  75  * \param ctx      SHA-1 context 
  76  * \param input    buffer holding the  data 
  77  * \param ilen     length of the input data 
  79 void sha1_update( sha1_context 
*ctx
, const unsigned char *input
, size_t ilen 
); 
  82  * \brief          SHA-1 final digest 
  84  * \param ctx      SHA-1 context 
  85  * \param output   SHA-1 checksum result 
  87 void sha1_finish( sha1_context 
*ctx
, unsigned char output
[20] ); 
  90 void sha1_process( sha1_context 
*ctx
, const unsigned char data
[64] ); 
  96 #else  /* POLARSSL_SHA1_ALT */ 
  98 #endif /* POLARSSL_SHA1_ALT */ 
 105  * \brief          Output = SHA-1( input buffer ) 
 107  * \param input    buffer holding the  data 
 108  * \param ilen     length of the input data 
 109  * \param output   SHA-1 checksum result 
 111 void sha1( const unsigned char *input
, size_t ilen
, unsigned char output
[20] ); 
 114  * \brief          Output = SHA-1( file contents ) 
 116  * \param path     input file name 
 117  * \param output   SHA-1 checksum result 
 119  * \return         0 if successful, or POLARSSL_ERR_SHA1_FILE_IO_ERROR 
 121 int sha1_file( const char *path
, unsigned char output
[20] ); 
 124  * \brief          SHA-1 HMAC context setup 
 126  * \param ctx      HMAC context to be initialized 
 127  * \param key      HMAC secret key 
 128  * \param keylen   length of the HMAC key 
 130 void sha1_hmac_starts( sha1_context 
*ctx
, const unsigned char *key
, size_t keylen 
); 
 133  * \brief          SHA-1 HMAC process buffer 
 135  * \param ctx      HMAC context 
 136  * \param input    buffer holding the  data 
 137  * \param ilen     length of the input data 
 139 void sha1_hmac_update( sha1_context 
*ctx
, const unsigned char *input
, size_t ilen 
); 
 142  * \brief          SHA-1 HMAC final digest 
 144  * \param ctx      HMAC context 
 145  * \param output   SHA-1 HMAC checksum result 
 147 void sha1_hmac_finish( sha1_context 
*ctx
, unsigned char output
[20] ); 
 150  * \brief          SHA-1 HMAC context reset 
 152  * \param ctx      HMAC context to be reset 
 154 void sha1_hmac_reset( sha1_context 
*ctx 
); 
 157  * \brief          Output = HMAC-SHA-1( hmac key, input buffer ) 
 159  * \param key      HMAC secret key 
 160  * \param keylen   length of the HMAC key 
 161  * \param input    buffer holding the  data 
 162  * \param ilen     length of the input data 
 163  * \param output   HMAC-SHA-1 result 
 165 void sha1_hmac( const unsigned char *key
, size_t keylen
, 
 166                 const unsigned char *input
, size_t ilen
, 
 167                 unsigned char output
[20] ); 
 170  * \brief          Checkup routine 
 172  * \return         0 if successful, or 1 if the test failed 
 174 int sha1_self_test( int verbose 
);