4 * Copyright (C) 2006-2010, Brainspark B.V.
6 * This file is part of PolarSSL (http://www.polarssl.org)
7 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #ifndef POLARSSL_SHA1_H
27 #define POLARSSL_SHA1_H
30 * \brief SHA-1 context structure
32 #ifndef HAVE_SHA1_CONTEXT
33 #define HAVE_SHA1_CONTEXT
34 typedef struct sha1_context sha1_context;
39 unsigned long total[2]; /*!< number of bytes processed */
40 unsigned long state[5]; /*!< intermediate digest state */
41 unsigned char buffer[64]; /*!< data block being processed */
43 unsigned char ipad[64]; /*!< HMAC: inner padding */
44 unsigned char opad[64]; /*!< HMAC: outer padding */
52 * \brief SHA-1 context setup
54 * \param ctx context to be initialized
56 void sha1_starts( sha1_context *ctx );
59 * \brief SHA-1 process buffer
61 * \param ctx SHA-1 context
62 * \param input buffer holding the data
63 * \param ilen length of the input data
65 void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen );
68 * \brief SHA-1 final digest
70 * \param ctx SHA-1 context
71 * \param output SHA-1 checksum result
73 void sha1_finish( sha1_context *ctx, unsigned char output[20] );
76 * \brief Output = SHA-1( input buffer )
78 * \param input buffer holding the data
79 * \param ilen length of the input data
80 * \param output SHA-1 checksum result
82 void sha1( const unsigned char *input, int ilen, unsigned char output[20] );
85 * \brief Output = SHA-1( file contents )
87 * \param path input file name
88 * \param output SHA-1 checksum result
90 * \return 0 if successful, 1 if fopen failed,
91 * or 2 if fread failed
93 int sha1_file( const char *path, unsigned char output[20] );
96 * \brief SHA-1 HMAC context setup
98 * \param ctx HMAC context to be initialized
99 * \param key HMAC secret key
100 * \param keylen length of the HMAC key
102 void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, int keylen );
105 * \brief SHA-1 HMAC process buffer
107 * \param ctx HMAC context
108 * \param input buffer holding the data
109 * \param ilen length of the input data
111 void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, int ilen );
114 * \brief SHA-1 HMAC final digest
116 * \param ctx HMAC context
117 * \param output SHA-1 HMAC checksum result
119 void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] );
122 * \brief SHA-1 HMAC context reset
124 * \param ctx HMAC context to be reset
126 void sha1_hmac_reset( sha1_context *ctx );
129 * \brief Output = HMAC-SHA-1( hmac key, input buffer )
131 * \param key HMAC secret key
132 * \param keylen length of the HMAC key
133 * \param input buffer holding the data
134 * \param ilen length of the input data
135 * \param output HMAC-SHA-1 result
137 void sha1_hmac( const unsigned char *key, int keylen,
138 const unsigned char *input, int ilen,
139 unsigned char output[20] );