BitPunch McEliece  v0.0.4
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
sha512.h
Go to the documentation of this file.
1 /*
2  * \file sha512.h
3  *
4  * \brief SHA-384 and SHA-512 cryptographic hash function
5  *
6  * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
7  * Copyright (C) 2015 Frantisek Uhrecky <frantisek.uhrecky[what here]gmail.com>
8  *
9  * This file is part of mbed TLS (https://polarssl.org)
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25 #ifndef POLARSSL_SHA512_H
26 #define POLARSSL_SHA512_H
27 
28 #include <string.h>
29 
30 #if defined(_MSC_VER) || defined(__WATCOMC__)
31  #define UL64(x) x##ui64
32  typedef unsigned __int64 uint64_t;
33 #else
34  #include <inttypes.h>
35  #define UL64(x) x##ULL
36 #endif
37 
38 #define POLARSSL_ERR_SHA512_FILE_IO_ERROR -0x007A
40 #if !defined(POLARSSL_SHA512_ALT)
41 // Regular implementation
42 //
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
51 typedef struct
52 {
53  uint64_t total[2];
54  uint64_t state[8];
55  unsigned char buffer[128];
57  unsigned char ipad[128];
58  unsigned char opad[128];
59  int is384;
60 }
62 
68 void sha512_init( sha512_context *ctx );
69 
75 void sha512_free( sha512_context *ctx );
76 
83 void sha512_starts( sha512_context *ctx, int is384 );
84 
92 void sha512_update( sha512_context *ctx, const unsigned char *input,
93  size_t ilen );
94 
101 void sha512_finish( sha512_context *ctx, unsigned char output[64] );
102 
103 #ifdef __cplusplus
104 }
105 #endif
106 
107 #else /* POLARSSL_SHA512_ALT */
108 #include "sha512_alt.h"
109 #endif /* POLARSSL_SHA512_ALT */
110 
111 #ifdef __cplusplus
112 extern "C" {
113 #endif
114 
123 void sha512( const unsigned char *input, size_t ilen,
124  unsigned char output[64], int is384 );
125 
135 int sha512_file( const char *path, unsigned char output[64], int is384 );
136 
137 #ifdef POLARSSL_SHA512_HMAC
138 
146 void sha512_hmac_starts( sha512_context *ctx, const unsigned char *key,
147  size_t keylen, int is384 );
148 
156 void sha512_hmac_update( sha512_context *ctx, const unsigned char *input,
157  size_t ilen );
158 
165 void sha512_hmac_finish( sha512_context *ctx, unsigned char output[64] );
166 
172 void sha512_hmac_reset( sha512_context *ctx );
173 
184 void sha512_hmac( const unsigned char *key, size_t keylen,
185  const unsigned char *input, size_t ilen,
186  unsigned char output[64], int is384 );
187 #endif // POLARSSL_SHA512_HMAC
188 
189 #ifdef POLLARSSL_SHA512_TEST
190 
195 int sha512_self_test( int verbose );
196 #endif
197 /* Internal use */
198 void sha512_process( sha512_context *ctx, const unsigned char data[128] );
199 
200 #ifdef __cplusplus
201 }
202 #endif
203 
204 #endif /* sha512.h */
void sha512_update(sha512_context *ctx, const unsigned char *input, size_t ilen)
SHA-512 process buffer.
Definition: sha512.c:246
void sha512_init(sha512_context *ctx)
Initialize SHA-512 context.
Definition: sha512.c:125
void sha512_finish(sha512_context *ctx, unsigned char output[64])
SHA-512 final digest.
Definition: sha512.c:298
void sha512_process(sha512_context *ctx, const unsigned char data[128])
Definition: sha512.c:174
SHA-512 context structure.
Definition: sha512.h:51
int sha512_file(const char *path, unsigned char output[64], int is384)
Output = SHA-512( file contents )
void sha512(const unsigned char *input, size_t ilen, unsigned char output[64], int is384)
Output = SHA-512( input buffer )
Definition: sha512.c:336
void sha512_free(sha512_context *ctx)
Clear SHA-512 context.
Definition: sha512.c:130
void sha512_starts(sha512_context *ctx, int is384)
SHA-512 context setup.
Definition: sha512.c:141