7 #if defined(_MSC_VER) || defined(__WATCOMC__)
8 #define UL64(x) x##ui64
11 #define UL64(x) x##ULL
12 #define int64 long long
16 * \brief SHA-512 context structure
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 */
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 */
35 * \brief SHA-512 context setup
37 * \param ctx context to be initialized
38 * \param is384 0 = use SHA512, 1 = use SHA384
40 void sha4_starts( sha4_context
*ctx
, int is384
);
43 * \brief SHA-512 process buffer
45 * \param ctx SHA-512 context
46 * \param input buffer holding the data
47 * \param ilen length of the input data
49 void sha4_update( sha4_context
*ctx
, unsigned char *input
, int ilen
);
52 * \brief SHA-512 final digest
54 * \param ctx SHA-512 context
55 * \param output SHA-384/512 checksum result
57 void sha4_finish( sha4_context
*ctx
, unsigned char output
[64] );
60 * \brief Output = SHA-512( input buffer )
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
67 void sha4( unsigned char *input
, int ilen
,
68 unsigned char output
[64], int is384
);
71 * \brief Output = SHA-512( file contents )
73 * \param path input file name
74 * \param output SHA-384/512 checksum result
75 * \param is384 0 = use SHA512, 1 = use SHA384
77 * \return 0 if successful, 1 if fopen failed,
78 * or 2 if fread failed
80 int sha4_file( char *path
, unsigned char output
[64], int is384
);
83 * \brief SHA-512 HMAC context setup
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
90 void sha4_hmac_starts( sha4_context
*ctx
, unsigned char *key
, int keylen
,
94 * \brief SHA-512 HMAC process buffer
96 * \param ctx HMAC context
97 * \param input buffer holding the data
98 * \param ilen length of the input data
100 void sha4_hmac_update( sha4_context
*ctx
, unsigned char *input
, int ilen
);
103 * \brief SHA-512 HMAC final digest
105 * \param ctx HMAC context
106 * \param output SHA-384/512 HMAC checksum result
108 void sha4_hmac_finish( sha4_context
*ctx
, unsigned char output
[64] );
111 * \brief Output = HMAC-SHA-512( hmac key, input buffer )
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
120 void sha4_hmac( unsigned char *key
, int keylen
,
121 unsigned char *input
, int ilen
,
122 unsigned char output
[64], int is384
);
125 * \brief Checkup routine
127 * \return 0 if successful, or 1 if the test failed
129 int sha4_self_test( int verbose
);