1/*	$KAME: sha2.h,v 1.2 2001/08/08 22:09:27 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
42extern "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/*
64 * Most BSD systems already define u_intXX_t types, as does Linux.
65 * Some systems, however, like Compaq's Tru64 Unix instead can use
66 * uintXX_t types defined by very recent ANSI C standards and included
67 * in the file:
68 *
69 *   #include <inttypes.h>
70 *
71 * If you choose to use <inttypes.h> then please define:
72 *
73 *   #define SHA2_USE_INTTYPES_H
74 *
75 * Or on the command line during compile:
76 *
77 *   cc -DSHA2_USE_INTTYPES_H ...
78 */
79
80typedef struct _SHA256_CTX {
81	u_int32_t	state[8];
82	u_int64_t	bitcount;
83	u_int8_t	buffer[SHA256_BLOCK_LENGTH];
84} SHA256_CTX;
85typedef struct _SHA512_CTX {
86	u_int64_t	state[8];
87	u_int64_t	bitcount[2];
88	u_int8_t	buffer[SHA512_BLOCK_LENGTH];
89} SHA512_CTX;
90
91typedef SHA512_CTX SHA384_CTX;
92
93
94/*** SHA-256/384/512 Function Prototypes ******************************/
95
96void SHA256_Init __P((SHA256_CTX *));
97void SHA256_Update __P((SHA256_CTX*, const u_int8_t*, size_t));
98void SHA256_Final __P((u_int8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*));
99char* SHA256_End __P((SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]));
100char* SHA256_Data __P((const u_int8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]));
101
102void SHA384_Init __P((SHA384_CTX*));
103void SHA384_Update __P((SHA384_CTX*, const u_int8_t*, size_t));
104void SHA384_Final __P((u_int8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*));
105char* SHA384_End __P((SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]));
106char* SHA384_Data __P((const u_int8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]));
107
108void SHA512_Init __P((SHA512_CTX*));
109void SHA512_Update __P((SHA512_CTX*, const u_int8_t*, size_t));
110void SHA512_Final __P((u_int8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*));
111char* SHA512_End __P((SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]));
112char* SHA512_Data __P((const u_int8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]));
113
114struct env_md_st *EVP_sha2_256 __P((void));
115struct env_md_st *EVP_sha2_384 __P((void));
116struct env_md_st *EVP_sha2_512 __P((void));
117
118#ifdef	__cplusplus
119}
120#endif /* __cplusplus */
121
122#endif /* __SHA2_H__ */
123