Dependents:   TimeZoneDemo EthernetJackTestCode MMEx_Challenge ntp_mem ... more

Committer:
segundo
Date:
Wed Dec 15 18:01:30 2010 +0000
Revision:
7:4e2468d7d5cb
Parent:
0:ac1725ba162c

        

Who changed what in which revision?

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