1 /* $Cambridge: exim/src/src/pdkim/sha1.h,v 1.1.2.3 2009/03/17 14:56:55 tom Exp $ */
5 * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
7 * Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #ifndef POLARSSL_SHA1_H
24 #define POLARSSL_SHA1_H
27 * \brief SHA-1 context structure
29 #ifndef HAVE_SHA1_CONTEXT
30 #define HAVE_SHA1_CONTEXT
31 typedef struct sha1_context sha1_context;
36 unsigned long total[2]; /*!< number of bytes processed */
37 unsigned long state[5]; /*!< intermediate digest state */
38 unsigned char buffer[64]; /*!< data block being processed */
40 unsigned char ipad[64]; /*!< HMAC: inner padding */
41 unsigned char opad[64]; /*!< HMAC: outer padding */
49 * \brief SHA-1 context setup
51 * \param ctx context to be initialized
53 void sha1_starts( sha1_context *ctx );
56 * \brief SHA-1 process buffer
58 * \param ctx SHA-1 context
59 * \param input buffer holding the data
60 * \param ilen length of the input data
62 void sha1_update( sha1_context *ctx, unsigned char *input, int ilen );
65 * \brief SHA-1 final digest
67 * \param ctx SHA-1 context
68 * \param output SHA-1 checksum result
70 void sha1_finish( sha1_context *ctx, unsigned char output[20] );
73 * \brief Output = SHA-1( input buffer )
75 * \param input buffer holding the data
76 * \param ilen length of the input data
77 * \param output SHA-1 checksum result
79 void sha1_oneshot( unsigned char *input, int ilen, unsigned char output[20] );
82 * \brief Output = SHA-1( file contents )
84 * \param path input file name
85 * \param output SHA-1 checksum result
87 * \return 0 if successful, 1 if fopen failed,
88 * or 2 if fread failed
90 int sha1_file( char *path, unsigned char output[20] );
93 * \brief SHA-1 HMAC context setup
95 * \param ctx HMAC context to be initialized
96 * \param key HMAC secret key
97 * \param keylen length of the HMAC key
99 void sha1_hmac_starts( sha1_context *ctx, unsigned char *key, int keylen );
102 * \brief SHA-1 HMAC process buffer
104 * \param ctx HMAC context
105 * \param input buffer holding the data
106 * \param ilen length of the input data
108 void sha1_hmac_update( sha1_context *ctx, unsigned char *input, int ilen );
111 * \brief SHA-1 HMAC final digest
113 * \param ctx HMAC context
114 * \param output SHA-1 HMAC checksum result
116 void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] );
119 * \brief Output = HMAC-SHA-1( hmac key, input buffer )
121 * \param key HMAC secret key
122 * \param keylen length of the HMAC key
123 * \param input buffer holding the data
124 * \param ilen length of the input data
125 * \param output HMAC-SHA-1 result
127 void sha1_hmac( unsigned char *key, int keylen,
128 unsigned char *input, int ilen,
129 unsigned char output[20] );