blob: 481aa874e01604028819ee3df0ad8448978366ec [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file sha1.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
4 * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
5 *
Paul Bakker27db1f52009-01-25 15:27:00 +00006 * Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00007 *
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.
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 */
57void sha1_update( sha1_context *ctx, unsigned char *input, int ilen );
58
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 */
74void sha1( unsigned char *input, int ilen, unsigned char output[20] );
75
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 */
85int sha1_file( char *path, unsigned char output[20] );
86
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 */
94void sha1_hmac_starts( sha1_context *ctx, unsigned char *key, int keylen );
95
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 */
103void sha1_hmac_update( sha1_context *ctx, unsigned char *input, int ilen );
104
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/**
114 * \brief Output = HMAC-SHA-1( hmac key, input buffer )
115 *
116 * \param key HMAC secret key
117 * \param keylen length of the HMAC key
118 * \param input buffer holding the data
119 * \param ilen length of the input data
120 * \param output HMAC-SHA-1 result
121 */
122void sha1_hmac( unsigned char *key, int keylen,
123 unsigned char *input, int ilen,
124 unsigned char output[20] );
125
126/**
127 * \brief Checkup routine
128 *
129 * \return 0 if successful, or 1 if the test failed
130 */
131int sha1_self_test( int verbose );
132
133#ifdef __cplusplus
134}
135#endif
136
137#endif /* sha1.h */