1 /**
2  * \file sha4.h
3  *
4  *  Copyright (C) 2011, Con Kolivas <kernel@kolivas.org>
5  *  Copyright (C) 2006-2010, Brainspark B.V.
6  *
7  *  This file is part of PolarSSL (http://www.polarssl.org)
8  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
9  *
10  *  All rights reserved.
11  *
12  *  This program is free software; you can redistribute it and/or modify
13  *  it under the terms of the GNU General Public License as published by
14  *  the Free Software Foundation; either version 2 of the License, or
15  *  (at your option) any later version.
16  *
17  *  This program is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *  GNU General Public License for more details.
21  *
22  *  You should have received a copy of the GNU General Public License along
23  *  with this program; if not, write to the Free Software Foundation, Inc.,
24  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  */
26 #ifndef POLARSSL_SHA4_H
27 #define POLARSSL_SHA4_H
28 
29 #if defined(_MSC_VER) || defined(__WATCOMC__)
30   #define UL64(x) x##ui64
31   #define int64 __int64
32 #else
33   #define UL64(x) x##ULL
34   #define int64 long long
35 #endif
36 
37 /**
38  * \brief          SHA-512 context structure
39  */
40 typedef struct
41 {
42     unsigned int64 total[2];    /*!< number of bytes processed  */
43     unsigned int64 state[8];    /*!< intermediate digest state  */
44     unsigned char buffer[128];  /*!< data block being processed */
45 
46     unsigned char ipad[128];    /*!< HMAC: inner padding        */
47     unsigned char opad[128];    /*!< HMAC: outer padding        */
48     int is384;                  /*!< 0 => SHA-512, else SHA-384 */
49 }
50 sha4_context;
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 /**
57  * \brief          SHA-512 context setup
58  *
59  * \param ctx      context to be initialized
60  * \param is384    0 = use SHA512, 1 = use SHA384
61  */
62 void sha4_starts( sha4_context *ctx, int is384 );
63 
64 /**
65  * \brief          SHA-512 process buffer
66  *
67  * \param ctx      SHA-512 context
68  * \param input    buffer holding the  data
69  * \param ilen     length of the input data
70  */
71 void sha4_update( sha4_context *ctx, const unsigned char *input, int ilen );
72 
73 /**
74  * \brief          SHA-512 final digest
75  *
76  * \param ctx      SHA-512 context
77  * \param output   SHA-384/512 checksum result
78  */
79 void sha4_finish( sha4_context *ctx, unsigned char output[64] );
80 
81 /**
82  * \brief          Output = SHA-512( input buffer )
83  *
84  * \param input    buffer holding the  data
85  * \param ilen     length of the input data
86  * \param output   SHA-384/512 checksum result
87  * \param is384    0 = use SHA512, 1 = use SHA384
88  */
89 void sha4( const unsigned char *input, int ilen,
90            unsigned char output[64], int is384 );
91 
92 #ifdef __cplusplus
93 }
94 #endif
95 
96 #endif /* sha4.h */
97