]> git.saurik.com Git - apple/network_cmds.git/blob - eaytest.tproj/sha2.h
network_cmds-245.19.tar.gz
[apple/network_cmds.git] / eaytest.tproj / sha2.h
1 /* $KAME: sha2.h,v 1.1.1.1 2001/08/08 09:56:28 sakane Exp $ */
2
3 /*
4 * sha2.h
5 *
6 * Version 1.0.0beta1
7 *
8 * Written by Aaron D. Gifford <me@aarongifford.com>
9 *
10 * Copyright 2000 Aaron D. Gifford. All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the copyright holder nor the names of contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTOR(S) ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 */
37
38 #ifndef __SHA2_H__
39 #define __SHA2_H__
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45
46 /*** SHA-256/384/512 Various Length Definitions ***********************/
47 #define SHA256_BLOCK_LENGTH 64
48 #define SHA256_DIGEST_LENGTH 32
49 #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
50 #define SHA384_BLOCK_LENGTH 128
51 #define SHA384_DIGEST_LENGTH 48
52 #define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1)
53 #define SHA512_BLOCK_LENGTH 128
54 #define SHA512_DIGEST_LENGTH 64
55 #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
56
57
58 /*** SHA-256/384/512 Context Structures *******************************/
59 /* NOTE: If your architecture does not define either u_intXX_t types or
60 * uintXX_t (from inttypes.h), you may need to define things by hand
61 * for your system:
62 */
63 #if 0
64 typedef unsigned char u_int8_t; /* 1-byte (8-bits) */
65 typedef unsigned int u_int32_t; /* 4-bytes (32-bits) */
66 typedef unsigned long long u_int64_t; /* 8-bytes (64-bits) */
67 #endif
68 /*
69 * Most BSD systems already define u_intXX_t types, as does Linux.
70 * Some systems, however, like Compaq's Tru64 Unix instead can use
71 * uintXX_t types defined by very recent ANSI C standards and included
72 * in the file:
73 *
74 * #include <inttypes.h>
75 *
76 * If you choose to use <inttypes.h> then please define:
77 *
78 * #define SHA2_USE_INTTYPES_H
79 *
80 * Or on the command line during compile:
81 *
82 * cc -DSHA2_USE_INTTYPES_H ...
83 */
84 #if 0 /*def SHA2_USE_INTTYPES_H*/
85
86 typedef struct _SHA256_CTX {
87 uint32_t state[8];
88 uint64_t bitcount;
89 uint8_t buffer[SHA256_BLOCK_LENGTH];
90 } SHA256_CTX;
91 typedef struct _SHA512_CTX {
92 uint64_t state[8];
93 uint64_t bitcount[2];
94 uint8_t buffer[SHA512_BLOCK_LENGTH];
95 } SHA512_CTX;
96
97 #else /* SHA2_USE_INTTYPES_H */
98
99 typedef struct _SHA256_CTX {
100 u_int32_t state[8];
101 u_int64_t bitcount;
102 u_int8_t buffer[SHA256_BLOCK_LENGTH];
103 } SHA256_CTX;
104 typedef struct _SHA512_CTX {
105 u_int64_t state[8];
106 u_int64_t bitcount[2];
107 u_int8_t buffer[SHA512_BLOCK_LENGTH];
108 } SHA512_CTX;
109
110 #endif /* SHA2_USE_INTTYPES_H */
111
112 typedef SHA512_CTX SHA384_CTX;
113
114
115 /*** SHA-256/384/512 Function Prototypes ******************************/
116
117 void SHA256_Init __P((SHA256_CTX *));
118 void SHA256_Update __P((SHA256_CTX*, const u_int8_t*, size_t));
119 void SHA256_Final __P((u_int8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*));
120 char* SHA256_End __P((SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]));
121 char* SHA256_Data __P((const u_int8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]));
122
123 void SHA384_Init __P((SHA384_CTX*));
124 void SHA384_Update __P((SHA384_CTX*, const u_int8_t*, size_t));
125 void SHA384_Final __P((u_int8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*));
126 char* SHA384_End __P((SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]));
127 char* SHA384_Data __P((const u_int8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]));
128
129 void SHA512_Init __P((SHA512_CTX*));
130 void SHA512_Update __P((SHA512_CTX*, const u_int8_t*, size_t));
131 void SHA512_Final __P((u_int8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*));
132 char* SHA512_End __P((SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]));
133 char* SHA512_Data __P((const u_int8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]));
134
135 struct env_md_st *EVP_sha2_256 __P((void));
136 struct env_md_st *EVP_sha2_384 __P((void));
137 struct env_md_st *EVP_sha2_512 __P((void));
138
139 #ifdef __cplusplus
140 }
141 #endif /* __cplusplus */
142
143 #endif /* __SHA2_H__ */
144