blob: e4cebf2f5fc97f9ff9d107bd1b5bef4f7f7be453 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file sha4.h
3 */
Paul Bakker40e46942009-01-03 21:51:57 +00004#ifndef POLARSSL_SHA4_H
5#define POLARSSL_SHA4_H
Paul Bakker5121ce52009-01-03 21:22:43 +00006
7#if defined(_MSC_VER) || defined(__WATCOMC__)
8 #define UL64(x) x##ui64
9 #define int64 __int64
10#else
11 #define UL64(x) x##ULL
12 #define int64 long long
13#endif
14
15/**
16 * \brief SHA-512 context structure
17 */
18typedef struct
19{
20 unsigned int64 total[2]; /*!< number of bytes processed */
21 unsigned int64 state[8]; /*!< intermediate digest state */
22 unsigned char buffer[128]; /*!< data block being processed */
23
24 unsigned char ipad[128]; /*!< HMAC: inner padding */
25 unsigned char opad[128]; /*!< HMAC: outer padding */
26 int is384; /*!< 0 => SHA-512, else SHA-384 */
27}
28sha4_context;
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/**
35 * \brief SHA-512 context setup
36 *
37 * \param ctx context to be initialized
38 * \param is384 0 = use SHA512, 1 = use SHA384
39 */
40void sha4_starts( sha4_context *ctx, int is384 );
41
42/**
43 * \brief SHA-512 process buffer
44 *
45 * \param ctx SHA-512 context
46 * \param input buffer holding the data
47 * \param ilen length of the input data
48 */
49void sha4_update( sha4_context *ctx, unsigned char *input, int ilen );
50
51/**
52 * \brief SHA-512 final digest
53 *
54 * \param ctx SHA-512 context
55 * \param output SHA-384/512 checksum result
56 */
57void sha4_finish( sha4_context *ctx, unsigned char output[64] );
58
59/**
60 * \brief Output = SHA-512( input buffer )
61 *
62 * \param input buffer holding the data
63 * \param ilen length of the input data
64 * \param output SHA-384/512 checksum result
65 * \param is384 0 = use SHA512, 1 = use SHA384
66 */
67void sha4( unsigned char *input, int ilen,
68 unsigned char output[64], int is384 );
69
70/**
71 * \brief Output = SHA-512( file contents )
72 *
73 * \param path input file name
74 * \param output SHA-384/512 checksum result
75 * \param is384 0 = use SHA512, 1 = use SHA384
76 *
77 * \return 0 if successful, 1 if fopen failed,
78 * or 2 if fread failed
79 */
80int sha4_file( char *path, unsigned char output[64], int is384 );
81
82/**
83 * \brief SHA-512 HMAC context setup
84 *
85 * \param ctx HMAC context to be initialized
86 * \param is384 0 = use SHA512, 1 = use SHA384
87 * \param key HMAC secret key
88 * \param keylen length of the HMAC key
89 */
90void sha4_hmac_starts( sha4_context *ctx, unsigned char *key, int keylen,
91 int is384 );
92
93/**
94 * \brief SHA-512 HMAC process buffer
95 *
96 * \param ctx HMAC context
97 * \param input buffer holding the data
98 * \param ilen length of the input data
99 */
100void sha4_hmac_update( sha4_context *ctx, unsigned char *input, int ilen );
101
102/**
103 * \brief SHA-512 HMAC final digest
104 *
105 * \param ctx HMAC context
106 * \param output SHA-384/512 HMAC checksum result
107 */
108void sha4_hmac_finish( sha4_context *ctx, unsigned char output[64] );
109
110/**
111 * \brief Output = HMAC-SHA-512( hmac key, input buffer )
112 *
113 * \param key HMAC secret key
114 * \param keylen length of the HMAC key
115 * \param input buffer holding the data
116 * \param ilen length of the input data
117 * \param output HMAC-SHA-384/512 result
118 * \param is384 0 = use SHA512, 1 = use SHA384
119 */
120void sha4_hmac( unsigned char *key, int keylen,
121 unsigned char *input, int ilen,
122 unsigned char output[64], int is384 );
123
124/**
125 * \brief Checkup routine
126 *
127 * \return 0 if successful, or 1 if the test failed
128 */
129int sha4_self_test( int verbose );
130
131#ifdef __cplusplus
132}
133#endif
134
135#endif /* sha4.h */