blob: 4043423e30926414137f10b327aebce0c133226d [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file sha1.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker84f12b72010-07-18 10:13:04 +00004 * Copyright (C) 2006-2010, Brainspark B.V.
5 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakker77b385e2009-07-28 17:23:11 +00006 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00007 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00008 * 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.
12 *
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.
17 *
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.
Paul Bakker5121ce52009-01-03 21:22:43 +000021 */
Paul Bakker40e46942009-01-03 21:51:57 +000022#ifndef POLARSSL_SHA1_H
23#define POLARSSL_SHA1_H
Paul Bakker5121ce52009-01-03 21:22:43 +000024
25/**
26 * \brief SHA-1 context structure
27 */
28typedef struct
29{
30 unsigned long total[2]; /*!< number of bytes processed */
31 unsigned long state[5]; /*!< intermediate digest state */
32 unsigned char buffer[64]; /*!< data block being processed */
33
34 unsigned char ipad[64]; /*!< HMAC: inner padding */
35 unsigned char opad[64]; /*!< HMAC: outer padding */
36}
37sha1_context;
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/**
44 * \brief SHA-1 context setup
45 *
46 * \param ctx context to be initialized
47 */
48void sha1_starts( sha1_context *ctx );
49
50/**
51 * \brief SHA-1 process buffer
52 *
53 * \param ctx SHA-1 context
54 * \param input buffer holding the data
55 * \param ilen length of the input data
56 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000057void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000058
59/**
60 * \brief SHA-1 final digest
61 *
62 * \param ctx SHA-1 context
63 * \param output SHA-1 checksum result
64 */
65void sha1_finish( sha1_context *ctx, unsigned char output[20] );
66
67/**
68 * \brief Output = SHA-1( input buffer )
69 *
70 * \param input buffer holding the data
71 * \param ilen length of the input data
72 * \param output SHA-1 checksum result
73 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000074void sha1( const unsigned char *input, int ilen, unsigned char output[20] );
Paul Bakker5121ce52009-01-03 21:22:43 +000075
76/**
77 * \brief Output = SHA-1( file contents )
78 *
79 * \param path input file name
80 * \param output SHA-1 checksum result
81 *
82 * \return 0 if successful, 1 if fopen failed,
83 * or 2 if fread failed
84 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000085int sha1_file( const char *path, unsigned char output[20] );
Paul Bakker5121ce52009-01-03 21:22:43 +000086
87/**
88 * \brief SHA-1 HMAC context setup
89 *
90 * \param ctx HMAC context to be initialized
91 * \param key HMAC secret key
92 * \param keylen length of the HMAC key
93 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000094void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, int keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +000095
96/**
97 * \brief SHA-1 HMAC process buffer
98 *
99 * \param ctx HMAC context
100 * \param input buffer holding the data
101 * \param ilen length of the input data
102 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000103void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000104
105/**
106 * \brief SHA-1 HMAC final digest
107 *
108 * \param ctx HMAC context
109 * \param output SHA-1 HMAC checksum result
110 */
111void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] );
112
113/**
Paul Bakker7d3b6612010-03-21 16:23:13 +0000114 * \brief SHA-1 HMAC context reset
115 *
116 * \param ctx HMAC context to be reset
117 */
118void sha1_hmac_reset( sha1_context *ctx );
119
120/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000121 * \brief Output = HMAC-SHA-1( hmac key, input buffer )
122 *
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
128 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000129void sha1_hmac( const unsigned char *key, int keylen,
130 const unsigned char *input, int ilen,
Paul Bakker5121ce52009-01-03 21:22:43 +0000131 unsigned char output[20] );
132
133/**
134 * \brief Checkup routine
135 *
136 * \return 0 if successful, or 1 if the test failed
137 */
138int sha1_self_test( int verbose );
139
140#ifdef __cplusplus
141}
142#endif
143
144#endif /* sha1.h */