Skip to content
Newer
Older
100644 210 lines (177 sloc) 6.63 KB
ca5f82c @mrash Removed legacy $Id$ tags from svn
authored Jun 18, 2011
1 /*
0f6ca00 Updated the GPL blurb at the top of the source files. Added some miss…
Damien Stuart authored Nov 13, 2010
2 *****************************************************************************
3 *
4 * File: sha2.h
5 *
6 * Purpose: Header for sha2.c - Implementation of the SHA 26/384/512 digests.
7 *
f011889 Forgot to add the files for the updated SHA digests (oops).
Damien Stuart authored Aug 2, 2009
8 * AUTHOR: Aaron D. Gifford - http://www.aarongifford.com/
9 *
10 * Copyright (c) 2000-2001, Aaron D. Gifford
11 * All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the copyright holder nor the names of contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
0f6ca00 Updated the GPL blurb at the top of the source files. Added some miss…
Damien Stuart authored Nov 13, 2010
37 *****************************************************************************
38 */
f011889 Forgot to add the files for the updated SHA digests (oops).
Damien Stuart authored Aug 2, 2009
39 #ifndef __SHA2_H__
40 #define __SHA2_H__
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 #include "fko_common.h"
47
48 /*
49 * Import u_intXX_t size_t type definitions from system headers. You
50 * may need to change this, or define these things yourself in this
51 * file.
52 */
53 #include <sys/types.h>
54
a07decf Added some more stuff to deal with byte order identification on Solar…
Damien Stuart authored Sep 9, 2009
55 #if HAVE_INTTYPES_H
56 #define SHA2_USE_INTTYPES_H
57 #endif
58
f011889 Forgot to add the files for the updated SHA digests (oops).
Damien Stuart authored Aug 2, 2009
59 #ifdef SHA2_USE_INTTYPES_H
60 #include <inttypes.h>
61 #endif /* SHA2_USE_INTTYPES_H */
62
63 /* Make sure we keep this below the check above.
64 */
65 #ifdef WIN32
66 #define SHA2_USE_INTTYPES_H 1
67 #endif
68
69 /*** SHA-256/384/512 Various Length Definitions ***********************/
70 #define SHA256_BLOCK_LENGTH 64
71 #define SHA256_DIGEST_LENGTH 32
72 #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
73 #define SHA384_BLOCK_LENGTH 128
74 #define SHA384_DIGEST_LENGTH 48
75 #define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1)
76 #define SHA512_BLOCK_LENGTH 128
77 #define SHA512_DIGEST_LENGTH 64
78 #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
79
80
81 /*** SHA-256/384/512 Context Structures *******************************/
82 /* NOTE: If your architecture does not define either u_intXX_t types or
83 * uintXX_t (from inttypes.h), you may need to define things by hand
84 * for your system:
85 */
86 #if 0
87 typedef unsigned char u_int8_t; /* 1-byte (8-bits) */
88 typedef unsigned int u_int32_t; /* 4-bytes (32-bits) */
89 typedef unsigned long long u_int64_t; /* 8-bytes (64-bits) */
90 #endif
91 /*
92 * Most BSD systems already define u_intXX_t types, as does Linux.
93 * Some systems, however, like Compaq's Tru64 Unix instead can use
94 * uintXX_t types defined by very recent ANSI C standards and included
95 * in the file:
96 *
97 * #include <inttypes.h>
98 *
99 * If you choose to use <inttypes.h> then please define:
100 *
101 * #define SHA2_USE_INTTYPES_H
102 *
103 * Or on the command line during compile:
104 *
105 * cc -DSHA2_USE_INTTYPES_H ...
106 */
107 #ifdef SHA2_USE_INTTYPES_H
108
109 typedef struct _SHA256_CTX {
110 uint32_t state[8];
111 uint64_t bitcount;
112 uint8_t buffer[SHA256_BLOCK_LENGTH];
113 } SHA256_CTX;
114 typedef struct _SHA512_CTX {
115 uint64_t state[8];
116 uint64_t bitcount[2];
117 uint8_t buffer[SHA512_BLOCK_LENGTH];
118 } SHA512_CTX;
119
120 #else /* SHA2_USE_INTTYPES_H */
121
122 typedef struct _SHA256_CTX {
123 u_int32_t state[8];
124 u_int64_t bitcount;
125 u_int8_t buffer[SHA256_BLOCK_LENGTH];
126 } SHA256_CTX;
127 typedef struct _SHA512_CTX {
128 u_int64_t state[8];
129 u_int64_t bitcount[2];
130 u_int8_t buffer[SHA512_BLOCK_LENGTH];
131 } SHA512_CTX;
132
133 #endif /* SHA2_USE_INTTYPES_H */
134
135 typedef SHA512_CTX SHA384_CTX;
136
137
138 /*** SHA-256/384/512 Function Prototypes ******************************/
139 #ifndef NOPROTO
140 #ifdef SHA2_USE_INTTYPES_H
141
142 void SHA256_Init(SHA256_CTX *);
143 void SHA256_Update(SHA256_CTX*, const uint8_t*, size_t);
144 void SHA256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*);
145 char* SHA256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
146 char* SHA256_Data(const uint8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
147
148 void SHA384_Init(SHA384_CTX*);
149 void SHA384_Update(SHA384_CTX*, const uint8_t*, size_t);
150 void SHA384_Final(uint8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*);
151 char* SHA384_End(SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]);
152 char* SHA384_Data(const uint8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]);
153
154 void SHA512_Init(SHA512_CTX*);
155 void SHA512_Update(SHA512_CTX*, const uint8_t*, size_t);
156 void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
157 char* SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
158 char* SHA512_Data(const uint8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
159
160 #else /* SHA2_USE_INTTYPES_H */
161
162 void SHA256_Init(SHA256_CTX *);
163 void SHA256_Update(SHA256_CTX*, const u_int8_t*, size_t);
164 void SHA256_Final(u_int8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*);
165 char* SHA256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
166 char* SHA256_Data(const u_int8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
167
168 void SHA384_Init(SHA384_CTX*);
169 void SHA384_Update(SHA384_CTX*, const u_int8_t*, size_t);
170 void SHA384_Final(u_int8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*);
171 char* SHA384_End(SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]);
172 char* SHA384_Data(const u_int8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]);
173
174 void SHA512_Init(SHA512_CTX*);
175 void SHA512_Update(SHA512_CTX*, const u_int8_t*, size_t);
176 void SHA512_Final(u_int8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
177 char* SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
178 char* SHA512_Data(const u_int8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
179
180 #endif /* SHA2_USE_INTTYPES_H */
181
182 #else /* NOPROTO */
183
184 void SHA256_Init();
185 void SHA256_Update();
186 void SHA256_Final();
187 char* SHA256_End();
188 char* SHA256_Data();
189
190 void SHA384_Init();
191 void SHA384_Update();
192 void SHA384_Final();
193 char* SHA384_End();
194 char* SHA384_Data();
195
196 void SHA512_Init();
197 void SHA512_Update();
198 void SHA512_Final();
199 char* SHA512_End();
200 char* SHA512_Data();
201
202 #endif /* NOPROTO */
203
204 #ifdef __cplusplus
205 }
206 #endif /* __cplusplus */
207
208 #endif /* __SHA2_H__ */
209
Something went wrong with that request. Please try again.