1 /* $Cambridge: exim/src/src/pdkim/sha1.h,v 1.1.2.2 2009/02/24 18:43:59 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
31 unsigned long total[2]; /*!< number of bytes processed */
32 unsigned long state[5]; /*!< intermediate digest state */
33 unsigned char buffer[64]; /*!< data block being processed */
35 unsigned char ipad[64]; /*!< HMAC: inner padding */
36 unsigned char opad[64]; /*!< HMAC: outer padding */
45 * \brief SHA-1 context setup
47 * \param ctx context to be initialized
49 void sha1_starts( sha1_context *ctx );
52 * \brief SHA-1 process buffer
54 * \param ctx SHA-1 context
55 * \param input buffer holding the data
56 * \param ilen length of the input data
58 void sha1_update( sha1_context *ctx, unsigned char *input, int ilen );
61 * \brief SHA-1 final digest
63 * \param ctx SHA-1 context
64 * \param output SHA-1 checksum result
66 void sha1_finish( sha1_context *ctx, unsigned char output[20] );
69 * \brief Output = SHA-1( input buffer )
71 * \param input buffer holding the data
72 * \param ilen length of the input data
73 * \param output SHA-1 checksum result
75 void sha1_oneshot( unsigned char *input, int ilen, unsigned char output[20] );
78 * \brief Output = SHA-1( file contents )
80 * \param path input file name
81 * \param output SHA-1 checksum result
83 * \return 0 if successful, 1 if fopen failed,
84 * or 2 if fread failed
86 int sha1_file( char *path, unsigned char output[20] );
89 * \brief SHA-1 HMAC context setup
91 * \param ctx HMAC context to be initialized
92 * \param key HMAC secret key
93 * \param keylen length of the HMAC key
95 void sha1_hmac_starts( sha1_context *ctx, unsigned char *key, int keylen );
98 * \brief SHA-1 HMAC process buffer
100 * \param ctx HMAC context
101 * \param input buffer holding the data
102 * \param ilen length of the input data
104 void sha1_hmac_update( sha1_context *ctx, unsigned char *input, int ilen );
107 * \brief SHA-1 HMAC final digest
109 * \param ctx HMAC context
110 * \param output SHA-1 HMAC checksum result
112 void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] );
115 * \brief Output = HMAC-SHA-1( hmac key, input buffer )
117 * \param key HMAC secret key
118 * \param keylen length of the HMAC key
119 * \param input buffer holding the data
120 * \param ilen length of the input data
121 * \param output HMAC-SHA-1 result
123 void sha1_hmac( unsigned char *key, int keylen,
124 unsigned char *input, int ilen,
125 unsigned char output[20] );