blob: 1d5cc258d6f1e832e5df1751d83c901b2b3c8332 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file sha1.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker37ca75d2011-01-06 12:28:03 +00004 * \brief SHA-1 cryptographic hash function
5 *
Paul Bakker84f12b72010-07-18 10:13:04 +00006 * Copyright (C) 2006-2010, Brainspark B.V.
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
Paul Bakker84f12b72010-07-18 10:13:04 +00009 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakkerb96f1542010-07-18 20:36:00 +000010 *
Paul Bakker77b385e2009-07-28 17:23:11 +000011 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000012 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000013 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Paul Bakker5121ce52009-01-03 21:22:43 +000026 */
Paul Bakker40e46942009-01-03 21:51:57 +000027#ifndef POLARSSL_SHA1_H
28#define POLARSSL_SHA1_H
Paul Bakker5121ce52009-01-03 21:22:43 +000029
30/**
31 * \brief SHA-1 context structure
32 */
33typedef struct
34{
35 unsigned long total[2]; /*!< number of bytes processed */
36 unsigned long state[5]; /*!< intermediate digest state */
37 unsigned char buffer[64]; /*!< data block being processed */
38
39 unsigned char ipad[64]; /*!< HMAC: inner padding */
40 unsigned char opad[64]; /*!< HMAC: outer padding */
41}
42sha1_context;
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48/**
49 * \brief SHA-1 context setup
50 *
51 * \param ctx context to be initialized
52 */
53void sha1_starts( sha1_context *ctx );
54
55/**
56 * \brief SHA-1 process buffer
57 *
58 * \param ctx SHA-1 context
59 * \param input buffer holding the data
60 * \param ilen length of the input data
61 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000062void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000063
64/**
65 * \brief SHA-1 final digest
66 *
67 * \param ctx SHA-1 context
68 * \param output SHA-1 checksum result
69 */
70void sha1_finish( sha1_context *ctx, unsigned char output[20] );
71
72/**
73 * \brief Output = SHA-1( input buffer )
74 *
75 * \param input buffer holding the data
76 * \param ilen length of the input data
77 * \param output SHA-1 checksum result
78 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000079void sha1( const unsigned char *input, int ilen, unsigned char output[20] );
Paul Bakker5121ce52009-01-03 21:22:43 +000080
81/**
82 * \brief Output = SHA-1( file contents )
83 *
84 * \param path input file name
85 * \param output SHA-1 checksum result
86 *
87 * \return 0 if successful, 1 if fopen failed,
88 * or 2 if fread failed
89 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000090int sha1_file( const char *path, unsigned char output[20] );
Paul Bakker5121ce52009-01-03 21:22:43 +000091
92/**
93 * \brief SHA-1 HMAC context setup
94 *
95 * \param ctx HMAC context to be initialized
96 * \param key HMAC secret key
97 * \param keylen length of the HMAC key
98 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000099void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, int keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000100
101/**
102 * \brief SHA-1 HMAC process buffer
103 *
104 * \param ctx HMAC context
105 * \param input buffer holding the data
106 * \param ilen length of the input data
107 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000108void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000109
110/**
111 * \brief SHA-1 HMAC final digest
112 *
113 * \param ctx HMAC context
114 * \param output SHA-1 HMAC checksum result
115 */
116void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] );
117
118/**
Paul Bakker7d3b6612010-03-21 16:23:13 +0000119 * \brief SHA-1 HMAC context reset
120 *
121 * \param ctx HMAC context to be reset
122 */
123void sha1_hmac_reset( sha1_context *ctx );
124
125/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000126 * \brief Output = HMAC-SHA-1( hmac key, input buffer )
127 *
128 * \param key HMAC secret key
129 * \param keylen length of the HMAC key
130 * \param input buffer holding the data
131 * \param ilen length of the input data
132 * \param output HMAC-SHA-1 result
133 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000134void sha1_hmac( const unsigned char *key, int keylen,
135 const unsigned char *input, int ilen,
Paul Bakker5121ce52009-01-03 21:22:43 +0000136 unsigned char output[20] );
137
138/**
139 * \brief Checkup routine
140 *
141 * \return 0 if successful, or 1 if the test failed
142 */
143int sha1_self_test( int verbose );
144
145#ifdef __cplusplus
146}
147#endif
148
149#endif /* sha1.h */