]> git.zerfleddert.de Git - proxmark3-svn/blob - common/polarssl/sha1.h
Merge branch 'master' into emv_argtable
[proxmark3-svn] / common / polarssl / sha1.h
1 /**
2 * \file sha1.h
3 *
4 * \brief SHA-1 cryptographic hash function
5 *
6 * Copyright (C) 2006-2013, Brainspark B.V.
7 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
9 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
10 *
11 * All rights reserved.
12 *
13 * 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.
26 */
27 #ifndef POLARSSL_SHA1_H
28 #define POLARSSL_SHA1_H
29
30 #include "polarssl_config.h"
31
32 #include <string.h>
33
34 #ifdef _MSC_VER
35 #include <basetsd.h>
36 typedef UINT32 uint32_t;
37 #else
38 #include <inttypes.h>
39 #endif
40
41 #define POLARSSL_ERR_SHA1_FILE_IO_ERROR -0x0076 /**< Read/write error in file. */
42
43 #if !defined(POLARSSL_SHA1_ALT)
44 // Regular implementation
45 //
46
47 /**
48 * \brief SHA-1 context structure
49 */
50 typedef struct
51 {
52 uint32_t total[2]; /*!< number of bytes processed */
53 uint32_t state[5]; /*!< intermediate digest state */
54 unsigned char buffer[64]; /*!< data block being processed */
55
56 unsigned char ipad[64]; /*!< HMAC: inner padding */
57 unsigned char opad[64]; /*!< HMAC: outer padding */
58 }
59 sha1_context;
60
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64
65 /**
66 * \brief SHA-1 context setup
67 *
68 * \param ctx context to be initialized
69 */
70 void sha1_starts( sha1_context *ctx );
71
72 /**
73 * \brief SHA-1 process buffer
74 *
75 * \param ctx SHA-1 context
76 * \param input buffer holding the data
77 * \param ilen length of the input data
78 */
79 void sha1_update( sha1_context *ctx, const unsigned char *input, size_t ilen );
80
81 /**
82 * \brief SHA-1 final digest
83 *
84 * \param ctx SHA-1 context
85 * \param output SHA-1 checksum result
86 */
87 void sha1_finish( sha1_context *ctx, unsigned char output[20] );
88
89 /* Internal use */
90 void sha1_process( sha1_context *ctx, const unsigned char data[64] );
91
92 #ifdef __cplusplus
93 }
94 #endif
95
96 #else /* POLARSSL_SHA1_ALT */
97 #include "sha1_alt.h"
98 #endif /* POLARSSL_SHA1_ALT */
99
100 #ifdef __cplusplus
101 extern "C" {
102 #endif
103
104 /**
105 * \brief Output = SHA-1( input buffer )
106 *
107 * \param input buffer holding the data
108 * \param ilen length of the input data
109 * \param output SHA-1 checksum result
110 */
111 void sha1( const unsigned char *input, size_t ilen, unsigned char output[20] );
112
113 /**
114 * \brief Output = SHA-1( file contents )
115 *
116 * \param path input file name
117 * \param output SHA-1 checksum result
118 *
119 * \return 0 if successful, or POLARSSL_ERR_SHA1_FILE_IO_ERROR
120 */
121 int sha1_file( const char *path, unsigned char output[20] );
122
123 /**
124 * \brief SHA-1 HMAC context setup
125 *
126 * \param ctx HMAC context to be initialized
127 * \param key HMAC secret key
128 * \param keylen length of the HMAC key
129 */
130 void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, size_t keylen );
131
132 /**
133 * \brief SHA-1 HMAC process buffer
134 *
135 * \param ctx HMAC context
136 * \param input buffer holding the data
137 * \param ilen length of the input data
138 */
139 void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, size_t ilen );
140
141 /**
142 * \brief SHA-1 HMAC final digest
143 *
144 * \param ctx HMAC context
145 * \param output SHA-1 HMAC checksum result
146 */
147 void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] );
148
149 /**
150 * \brief SHA-1 HMAC context reset
151 *
152 * \param ctx HMAC context to be reset
153 */
154 void sha1_hmac_reset( sha1_context *ctx );
155
156 /**
157 * \brief Output = HMAC-SHA-1( hmac key, input buffer )
158 *
159 * \param key HMAC secret key
160 * \param keylen length of the HMAC key
161 * \param input buffer holding the data
162 * \param ilen length of the input data
163 * \param output HMAC-SHA-1 result
164 */
165 void sha1_hmac( const unsigned char *key, size_t keylen,
166 const unsigned char *input, size_t ilen,
167 unsigned char output[20] );
168
169 /**
170 * \brief Checkup routine
171 *
172 * \return 0 if successful, or 1 if the test failed
173 */
174 int sha1_self_test( int verbose );
175
176 #ifdef __cplusplus
177 }
178 #endif
179
180 #endif /* sha1.h */
Impressum, Datenschutz