4 * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
6 * Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 /* $Cambridge: exim/src/src/pdkim/sha1.h,v 1.2 2009/06/10 07:34:05 tom Exp $ */
25 #ifndef POLARSSL_SHA1_H
26 #define POLARSSL_SHA1_H
29 * \brief SHA-1 context structure
31 #ifndef HAVE_SHA1_CONTEXT
32 #define HAVE_SHA1_CONTEXT
33 typedef struct sha1_context sha1_context;
38 unsigned long total[2]; /*!< number of bytes processed */
39 unsigned long state[5]; /*!< intermediate digest state */
40 unsigned char buffer[64]; /*!< data block being processed */
42 unsigned char ipad[64]; /*!< HMAC: inner padding */
43 unsigned char opad[64]; /*!< HMAC: outer padding */
51 * \brief SHA-1 context setup
53 * \param ctx context to be initialized
55 void sha1_starts( sha1_context *ctx );
58 * \brief SHA-1 process buffer
60 * \param ctx SHA-1 context
61 * \param input buffer holding the data
62 * \param ilen length of the input data
64 void sha1_update( sha1_context *ctx, unsigned char *input, int ilen );
67 * \brief SHA-1 final digest
69 * \param ctx SHA-1 context
70 * \param output SHA-1 checksum result
72 void sha1_finish( sha1_context *ctx, unsigned char output[20] );
75 * \brief Output = SHA-1( input buffer )
77 * \param input buffer holding the data
78 * \param ilen length of the input data
79 * \param output SHA-1 checksum result
81 void sha1_oneshot( unsigned char *input, int ilen, unsigned char output[20] );
84 * \brief Output = SHA-1( file contents )
86 * \param path input file name
87 * \param output SHA-1 checksum result
89 * \return 0 if successful, 1 if fopen failed,
90 * or 2 if fread failed
92 int sha1_file( char *path, unsigned char output[20] );
95 * \brief SHA-1 HMAC context setup
97 * \param ctx HMAC context to be initialized
98 * \param key HMAC secret key
99 * \param keylen length of the HMAC key
101 void sha1_hmac_starts( sha1_context *ctx, unsigned char *key, int keylen );
104 * \brief SHA-1 HMAC process buffer
106 * \param ctx HMAC context
107 * \param input buffer holding the data
108 * \param ilen length of the input data
110 void sha1_hmac_update( sha1_context *ctx, unsigned char *input, int ilen );
113 * \brief SHA-1 HMAC final digest
115 * \param ctx HMAC context
116 * \param output SHA-1 HMAC checksum result
118 void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] );
121 * \brief Output = HMAC-SHA-1( hmac key, input buffer )
123 * \param key HMAC secret key
124 * \param keylen length of the HMAC key
125 * \param input buffer holding the data
126 * \param ilen length of the input data
127 * \param output HMAC-SHA-1 result
129 void sha1_hmac( unsigned char *key, int keylen,
130 unsigned char *input, int ilen,
131 unsigned char output[20] );