4
* \brief SHA-384 and SHA-512 cryptographic hash function
6
* Copyright (C) 2006-2013, Brainspark B.V.
8
* This file is part of PolarSSL (http://www.polarssl.org)
9
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
11
* All rights reserved.
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.
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.
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.
27
#ifndef POLARSSL_SHA4_H
28
#define POLARSSL_SHA4_H
34
#if defined(_MSC_VER) || defined(__WATCOMC__)
35
#define UL64(x) x##ui64
36
typedef unsigned __int64 uint64_t;
39
#define UL64(x) x##ULL
42
#define POLARSSL_ERR_SHA4_FILE_IO_ERROR -0x007A /**< Read/write error in file. */
44
#if !defined(POLARSSL_SHA1_ALT)
45
// Regular implementation
49
* \brief SHA-512 context structure
53
uint64_t total[2]; /*!< number of bytes processed */
54
uint64_t state[8]; /*!< intermediate digest state */
55
unsigned char buffer[128]; /*!< data block being processed */
57
unsigned char ipad[128]; /*!< HMAC: inner padding */
58
unsigned char opad[128]; /*!< HMAC: outer padding */
59
int is384; /*!< 0 => SHA-512, else SHA-384 */
68
* \brief SHA-512 context setup
70
* \param ctx context to be initialized
71
* \param is384 0 = use SHA512, 1 = use SHA384
73
void sha4_starts( sha4_context *ctx, int is384 );
76
* \brief SHA-512 process buffer
78
* \param ctx SHA-512 context
79
* \param input buffer holding the data
80
* \param ilen length of the input data
82
void sha4_update( sha4_context *ctx, const unsigned char *input, size_t ilen );
85
* \brief SHA-512 final digest
87
* \param ctx SHA-512 context
88
* \param output SHA-384/512 checksum result
90
void sha4_finish( sha4_context *ctx, unsigned char output[64] );
96
#else /* POLARSSL_SHA4_ALT */
98
#endif /* POLARSSL_SHA4_ALT */
105
* \brief Output = SHA-512( input buffer )
107
* \param input buffer holding the data
108
* \param ilen length of the input data
109
* \param output SHA-384/512 checksum result
110
* \param is384 0 = use SHA512, 1 = use SHA384
112
void sha4( const unsigned char *input, size_t ilen,
113
unsigned char output[64], int is384 );
116
* \brief Output = SHA-512( file contents )
118
* \param path input file name
119
* \param output SHA-384/512 checksum result
120
* \param is384 0 = use SHA512, 1 = use SHA384
122
* \return 0 if successful, or POLARSSL_ERR_SHA4_FILE_IO_ERROR
124
int sha4_file( const char *path, unsigned char output[64], int is384 );
127
* \brief SHA-512 HMAC context setup
129
* \param ctx HMAC context to be initialized
130
* \param is384 0 = use SHA512, 1 = use SHA384
131
* \param key HMAC secret key
132
* \param keylen length of the HMAC key
134
void sha4_hmac_starts( sha4_context *ctx, const unsigned char *key, size_t keylen,
138
* \brief SHA-512 HMAC process buffer
140
* \param ctx HMAC context
141
* \param input buffer holding the data
142
* \param ilen length of the input data
144
void sha4_hmac_update( sha4_context *ctx, const unsigned char *input, size_t ilen );
147
* \brief SHA-512 HMAC final digest
149
* \param ctx HMAC context
150
* \param output SHA-384/512 HMAC checksum result
152
void sha4_hmac_finish( sha4_context *ctx, unsigned char output[64] );
155
* \brief SHA-512 HMAC context reset
157
* \param ctx HMAC context to be reset
159
void sha4_hmac_reset( sha4_context *ctx );
162
* \brief Output = HMAC-SHA-512( hmac key, input buffer )
164
* \param key HMAC secret key
165
* \param keylen length of the HMAC key
166
* \param input buffer holding the data
167
* \param ilen length of the input data
168
* \param output HMAC-SHA-384/512 result
169
* \param is384 0 = use SHA512, 1 = use SHA384
171
void sha4_hmac( const unsigned char *key, size_t keylen,
172
const unsigned char *input, size_t ilen,
173
unsigned char output[64], int is384 );
176
* \brief Checkup routine
178
* \return 0 if successful, or 1 if the test failed
180
int sha4_self_test( int verbose );