source: project/release/5/sha2/trunk/sha2.h @ 35856

Last change on this file since 35856 was 35856, checked in by Kon Lovett, 2 years ago

C5 initial

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