blob: 6c7a41f38f0990b0f40da6ae64331975895378be [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file sha1.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker83ded912010-03-21 17:46:26 +00004 * Copyright (C) 2006-2010, Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakker77b385e2009-07-28 17:23:11 +00005 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00006 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00007 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Paul Bakker5121ce52009-01-03 21:22:43 +000020 */
Paul Bakker40e46942009-01-03 21:51:57 +000021#ifndef POLARSSL_SHA1_H
22#define POLARSSL_SHA1_H
Paul Bakker5121ce52009-01-03 21:22:43 +000023
24/**
25 * \brief SHA-1 context structure
26 */
27typedef struct
28{
29 unsigned long total[2]; /*!< number of bytes processed */
30 unsigned long state[5]; /*!< intermediate digest state */
31 unsigned char buffer[64]; /*!< data block being processed */
32
33 unsigned char ipad[64]; /*!< HMAC: inner padding */
34 unsigned char opad[64]; /*!< HMAC: outer padding */
35}
36sha1_context;
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42/**
43 * \brief SHA-1 context setup
44 *
45 * \param ctx context to be initialized
46 */
47void sha1_starts( sha1_context *ctx );
48
49/**
50 * \brief SHA-1 process buffer
51 *
52 * \param ctx SHA-1 context
53 * \param input buffer holding the data
54 * \param ilen length of the input data
55 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000056void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000057
58/**
59 * \brief SHA-1 final digest
60 *
61 * \param ctx SHA-1 context
62 * \param output SHA-1 checksum result
63 */
64void sha1_finish( sha1_context *ctx, unsigned char output[20] );
65
66/**
67 * \brief Output = SHA-1( input buffer )
68 *
69 * \param input buffer holding the data
70 * \param ilen length of the input data
71 * \param output SHA-1 checksum result
72 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000073void sha1( const unsigned char *input, int ilen, unsigned char output[20] );
Paul Bakker5121ce52009-01-03 21:22:43 +000074
75/**
76 * \brief Output = SHA-1( file contents )
77 *
78 * \param path input file name
79 * \param output SHA-1 checksum result
80 *
81 * \return 0 if successful, 1 if fopen failed,
82 * or 2 if fread failed
83 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000084int sha1_file( const char *path, unsigned char output[20] );
Paul Bakker5121ce52009-01-03 21:22:43 +000085
86/**
87 * \brief SHA-1 HMAC context setup
88 *
89 * \param ctx HMAC context to be initialized
90 * \param key HMAC secret key
91 * \param keylen length of the HMAC key
92 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000093void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, int keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +000094
95/**
96 * \brief SHA-1 HMAC process buffer
97 *
98 * \param ctx HMAC context
99 * \param input buffer holding the data
100 * \param ilen length of the input data
101 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000102void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000103
104/**
105 * \brief SHA-1 HMAC final digest
106 *
107 * \param ctx HMAC context
108 * \param output SHA-1 HMAC checksum result
109 */
110void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] );
111
112/**
Paul Bakker7d3b6612010-03-21 16:23:13 +0000113 * \brief SHA-1 HMAC context reset
114 *
115 * \param ctx HMAC context to be reset
116 */
117void sha1_hmac_reset( sha1_context *ctx );
118
119/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000120 * \brief Output = HMAC-SHA-1( hmac key, input buffer )
121 *
122 * \param key HMAC secret key
123 * \param keylen length of the HMAC key
124 * \param input buffer holding the data
125 * \param ilen length of the input data
126 * \param output HMAC-SHA-1 result
127 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000128void sha1_hmac( const unsigned char *key, int keylen,
129 const unsigned char *input, int ilen,
Paul Bakker5121ce52009-01-03 21:22:43 +0000130 unsigned char output[20] );
131
132/**
133 * \brief Checkup routine
134 *
135 * \return 0 if successful, or 1 if the test failed
136 */
137int sha1_self_test( int verbose );
138
139#ifdef __cplusplus
140}
141#endif
142
143#endif /* sha1.h */