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.
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
;
37 unsigned long total
[2]; /*!< number of bytes processed */
38 unsigned long state
[5]; /*!< intermediate digest state */
39 unsigned char buffer
[64]; /*!< data block being processed */
41 unsigned char ipad
[64]; /*!< HMAC: inner padding */
42 unsigned char opad
[64]; /*!< HMAC: outer padding */
50 * \brief SHA-1 context setup
52 * \param ctx context to be initialized
54 void sha1_starts( sha1_context
*ctx
);
57 * \brief SHA-1 process buffer
59 * \param ctx SHA-1 context
60 * \param input buffer holding the data
61 * \param ilen length of the input data
63 void sha1_update( sha1_context
*ctx
, const unsigned char *input
, int ilen
);
66 * \brief SHA-1 final digest
68 * \param ctx SHA-1 context
69 * \param output SHA-1 checksum result
71 void sha1_finish( sha1_context
*ctx
, unsigned char output
[20] );
74 * \brief Output = SHA-1( input buffer )
76 * \param input buffer holding the data
77 * \param ilen length of the input data
78 * \param output SHA-1 checksum result
80 void polarssl_sha1( const unsigned char *input
, int ilen
, unsigned char output
[20] );
83 * \brief Output = SHA-1( file contents )
85 * \param path input file name
86 * \param output SHA-1 checksum result
88 * \return 0 if successful, 1 if fopen failed,
89 * or 2 if fread failed
91 int sha1_file( const char *path
, unsigned char output
[20] );
94 * \brief SHA-1 HMAC context setup
96 * \param ctx HMAC context to be initialized
97 * \param key HMAC secret key
98 * \param keylen length of the HMAC key
100 void sha1_hmac_starts( sha1_context
*ctx
, const unsigned char *key
, int keylen
);
103 * \brief SHA-1 HMAC process buffer
105 * \param ctx HMAC context
106 * \param input buffer holding the data
107 * \param ilen length of the input data
109 void sha1_hmac_update( sha1_context
*ctx
, const unsigned char *input
, int ilen
);
112 * \brief SHA-1 HMAC final digest
114 * \param ctx HMAC context
115 * \param output SHA-1 HMAC checksum result
117 void sha1_hmac_finish( sha1_context
*ctx
, unsigned char output
[20] );
120 * \brief SHA-1 HMAC context reset
122 * \param ctx HMAC context to be reset
124 void sha1_hmac_reset( sha1_context
*ctx
);
127 * \brief Output = HMAC-SHA-1( hmac key, input buffer )
129 * \param key HMAC secret key
130 * \param keylen length of the HMAC key
131 * \param input buffer holding the data
132 * \param ilen length of the input data
133 * \param output HMAC-SHA-1 result
135 void sha1_hmac( const unsigned char *key
, int keylen
,
136 const unsigned char *input
, int ilen
,
137 unsigned char output
[20] );
140 * \brief Checkup routine
142 * \return 0 if successful, or 1 if the test failed
144 int sha1_self_test( int verbose
);