blob: 4eb5f704fa3100356fd89ceb5e13ff152348f741 [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.
Paul Bakkerb96f1542010-07-18 20:36:00 +00005 *
6 * This file is part of PolarSSL (http://www.polarssl.org)
Paul Bakker84f12b72010-07-18 10:13:04 +00007 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakkerb96f1542010-07-18 20:36:00 +00008 *
Paul Bakker77b385e2009-07-28 17:23:11 +00009 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000010 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000011 * 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.
15 *
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.
20 *
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.
Paul Bakker5121ce52009-01-03 21:22:43 +000024 */
Paul Bakker40e46942009-01-03 21:51:57 +000025#ifndef POLARSSL_SHA1_H
26#define POLARSSL_SHA1_H
Paul Bakker5121ce52009-01-03 21:22:43 +000027
28/**
29 * \brief SHA-1 context structure
30 */
31typedef struct
32{
33 unsigned long total[2]; /*!< number of bytes processed */
34 unsigned long state[5]; /*!< intermediate digest state */
35 unsigned char buffer[64]; /*!< data block being processed */
36
37 unsigned char ipad[64]; /*!< HMAC: inner padding */
38 unsigned char opad[64]; /*!< HMAC: outer padding */
39}
40sha1_context;
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46/**
47 * \brief SHA-1 context setup
48 *
49 * \param ctx context to be initialized
50 */
51void sha1_starts( sha1_context *ctx );
52
53/**
54 * \brief SHA-1 process buffer
55 *
56 * \param ctx SHA-1 context
57 * \param input buffer holding the data
58 * \param ilen length of the input data
59 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000060void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000061
62/**
63 * \brief SHA-1 final digest
64 *
65 * \param ctx SHA-1 context
66 * \param output SHA-1 checksum result
67 */
68void sha1_finish( sha1_context *ctx, unsigned char output[20] );
69
70/**
71 * \brief Output = SHA-1( input buffer )
72 *
73 * \param input buffer holding the data
74 * \param ilen length of the input data
75 * \param output SHA-1 checksum result
76 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000077void sha1( const unsigned char *input, int ilen, unsigned char output[20] );
Paul Bakker5121ce52009-01-03 21:22:43 +000078
79/**
80 * \brief Output = SHA-1( file contents )
81 *
82 * \param path input file name
83 * \param output SHA-1 checksum result
84 *
85 * \return 0 if successful, 1 if fopen failed,
86 * or 2 if fread failed
87 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000088int sha1_file( const char *path, unsigned char output[20] );
Paul Bakker5121ce52009-01-03 21:22:43 +000089
90/**
91 * \brief SHA-1 HMAC context setup
92 *
93 * \param ctx HMAC context to be initialized
94 * \param key HMAC secret key
95 * \param keylen length of the HMAC key
96 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000097void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, int keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +000098
99/**
100 * \brief SHA-1 HMAC process buffer
101 *
102 * \param ctx HMAC context
103 * \param input buffer holding the data
104 * \param ilen length of the input data
105 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000106void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000107
108/**
109 * \brief SHA-1 HMAC final digest
110 *
111 * \param ctx HMAC context
112 * \param output SHA-1 HMAC checksum result
113 */
114void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] );
115
116/**
Paul Bakker7d3b6612010-03-21 16:23:13 +0000117 * \brief SHA-1 HMAC context reset
118 *
119 * \param ctx HMAC context to be reset
120 */
121void sha1_hmac_reset( sha1_context *ctx );
122
123/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000124 * \brief Output = HMAC-SHA-1( hmac key, input buffer )
125 *
126 * \param key HMAC secret key
127 * \param keylen length of the HMAC key
128 * \param input buffer holding the data
129 * \param ilen length of the input data
130 * \param output HMAC-SHA-1 result
131 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000132void sha1_hmac( const unsigned char *key, int keylen,
133 const unsigned char *input, int ilen,
Paul Bakker5121ce52009-01-03 21:22:43 +0000134 unsigned char output[20] );
135
136/**
137 * \brief Checkup routine
138 *
139 * \return 0 if successful, or 1 if the test failed
140 */
141int sha1_self_test( int verbose );
142
143#ifdef __cplusplus
144}
145#endif
146
147#endif /* sha1.h */