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 /* $Cambridge: exim/src/src/pdkim/sha1.h,v 1.3 2009/12/07 13:05:07 tom Exp $ */
28 #ifndef POLARSSL_SHA1_H
29 #define POLARSSL_SHA1_H
32 * \brief SHA-1 context structure
34 #ifndef HAVE_SHA1_CONTEXT
35 #define HAVE_SHA1_CONTEXT
36 typedef struct sha1_context sha1_context;
41 unsigned long total[2]; /*!< number of bytes processed */
42 unsigned long state[5]; /*!< intermediate digest state */
43 unsigned char buffer[64]; /*!< data block being processed */
45 unsigned char ipad[64]; /*!< HMAC: inner padding */
46 unsigned char opad[64]; /*!< HMAC: outer padding */
54 * \brief SHA-1 context setup
56 * \param ctx context to be initialized
58 void sha1_starts( sha1_context *ctx );
61 * \brief SHA-1 process buffer
63 * \param ctx SHA-1 context
64 * \param input buffer holding the data
65 * \param ilen length of the input data
67 void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen );
70 * \brief SHA-1 final digest
72 * \param ctx SHA-1 context
73 * \param output SHA-1 checksum result
75 void sha1_finish( sha1_context *ctx, unsigned char output[20] );
78 * \brief Output = SHA-1( input buffer )
80 * \param input buffer holding the data
81 * \param ilen length of the input data
82 * \param output SHA-1 checksum result
84 void sha1( const unsigned char *input, int ilen, unsigned char output[20] );
87 * \brief Output = SHA-1( file contents )
89 * \param path input file name
90 * \param output SHA-1 checksum result
92 * \return 0 if successful, 1 if fopen failed,
93 * or 2 if fread failed
95 int sha1_file( const char *path, unsigned char output[20] );
98 * \brief SHA-1 HMAC context setup
100 * \param ctx HMAC context to be initialized
101 * \param key HMAC secret key
102 * \param keylen length of the HMAC key
104 void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, int keylen );
107 * \brief SHA-1 HMAC process buffer
109 * \param ctx HMAC context
110 * \param input buffer holding the data
111 * \param ilen length of the input data
113 void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, int ilen );
116 * \brief SHA-1 HMAC final digest
118 * \param ctx HMAC context
119 * \param output SHA-1 HMAC checksum result
121 void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] );
124 * \brief SHA-1 HMAC context reset
126 * \param ctx HMAC context to be reset
128 void sha1_hmac_reset( sha1_context *ctx );
131 * \brief Output = HMAC-SHA-1( hmac key, input buffer )
133 * \param key HMAC secret key
134 * \param keylen length of the HMAC key
135 * \param input buffer holding the data
136 * \param ilen length of the input data
137 * \param output HMAC-SHA-1 result
139 void sha1_hmac( const unsigned char *key, int keylen,
140 const unsigned char *input, int ilen,
141 unsigned char output[20] );