1 /* $KAME: sha2.h,v 1.1.1.1 2001/08/08 09:56:28 sakane Exp $ */
8 * Written by Aaron D. Gifford <me@aarongifford.com>
10 * Copyright 2000 Aaron D. Gifford. All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
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.
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
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)
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
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) */
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
74 * #include <inttypes.h>
76 * If you choose to use <inttypes.h> then please define:
78 * #define SHA2_USE_INTTYPES_H
80 * Or on the command line during compile:
82 * cc -DSHA2_USE_INTTYPES_H ...
84 #if 0 /*def SHA2_USE_INTTYPES_H*/
86 typedef struct _SHA256_CTX
{
89 uint8_t buffer
[SHA256_BLOCK_LENGTH
];
91 typedef struct _SHA512_CTX
{
94 uint8_t buffer
[SHA512_BLOCK_LENGTH
];
97 #else /* SHA2_USE_INTTYPES_H */
99 typedef struct _SHA256_CTX
{
102 u_int8_t buffer
[SHA256_BLOCK_LENGTH
];
104 typedef struct _SHA512_CTX
{
106 u_int64_t bitcount
[2];
107 u_int8_t buffer
[SHA512_BLOCK_LENGTH
];
110 #endif /* SHA2_USE_INTTYPES_H */
112 typedef SHA512_CTX SHA384_CTX
;
115 /*** SHA-256/384/512 Function Prototypes ******************************/
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
]));
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
]));
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
]));
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));
141 #endif /* __cplusplus */
143 #endif /* __SHA2_H__ */