]> cvs.zerfleddert.de Git - proxmark3-svn/blame - common/polarssl/sha1.h
Merge branch 'master' into emv_argtable
[proxmark3-svn] / common / polarssl / sha1.h
CommitLineData
1c4c0b06 1/**
2 * \file sha1.h
3 *
4 * \brief SHA-1 cryptographic hash function
5 *
d03fb293 6 * Copyright (C) 2006-2013, Brainspark B.V.
1c4c0b06 7 *
d03fb293
OM
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.
1c4c0b06 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
d03fb293 30#include "polarssl_config.h"
1c4c0b06 31
d03fb293 32#include <string.h>
1c4c0b06 33
d03fb293 34#ifdef _MSC_VER
1c4c0b06 35#include <basetsd.h>
36typedef 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
1c4c0b06 47/**
48 * \brief SHA-1 context structure
49 */
50typedef 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}
59sha1_context;
60
d03fb293
OM
61#ifdef __cplusplus
62extern "C" {
63#endif
1c4c0b06 64
65/**
66 * \brief SHA-1 context setup
67 *
68 * \param ctx context to be initialized
69 */
70void 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 */
79void 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 */
87void sha1_finish( sha1_context *ctx, unsigned char output[20] );
88
89/* Internal use */
90void 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
101extern "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 */
111void 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 */
121int 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 */
d03fb293 130void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, size_t keylen );
1c4c0b06 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 */
d03fb293 139void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, size_t ilen );
1c4c0b06 140
141/**
142 * \brief SHA-1 HMAC final digest
143 *
144 * \param ctx HMAC context
145 * \param output SHA-1 HMAC checksum result
146 */
147void 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 */
154void 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 */
165void 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 */
174int sha1_self_test( int verbose );
175
176#ifdef __cplusplus
177}
178#endif
179
180#endif /* sha1.h */
Impressum, Datenschutz