xref: /openssh-portable/openbsd-compat/sha2.h (revision fd0684b3)
109159594SDarren Tucker /*	$OpenBSD: sha2.h,v 1.10 2016/09/03 17:00:29 tedu Exp $	*/
2af87af16SDamien Miller 
3af87af16SDamien Miller /*
4af87af16SDamien Miller  * FILE:	sha2.h
5af87af16SDamien Miller  * AUTHOR:	Aaron D. Gifford <me@aarongifford.com>
6af87af16SDamien Miller  *
7af87af16SDamien Miller  * Copyright (c) 2000-2001, Aaron D. Gifford
8af87af16SDamien Miller  * All rights reserved.
9af87af16SDamien Miller  *
10af87af16SDamien Miller  * Redistribution and use in source and binary forms, with or without
11af87af16SDamien Miller  * modification, are permitted provided that the following conditions
12af87af16SDamien Miller  * are met:
13af87af16SDamien Miller  * 1. Redistributions of source code must retain the above copyright
14af87af16SDamien Miller  *    notice, this list of conditions and the following disclaimer.
15af87af16SDamien Miller  * 2. Redistributions in binary form must reproduce the above copyright
16af87af16SDamien Miller  *    notice, this list of conditions and the following disclaimer in the
17af87af16SDamien Miller  *    documentation and/or other materials provided with the distribution.
18af87af16SDamien Miller  * 3. Neither the name of the copyright holder nor the names of contributors
19af87af16SDamien Miller  *    may be used to endorse or promote products derived from this software
20af87af16SDamien Miller  *    without specific prior written permission.
21af87af16SDamien Miller  *
22af87af16SDamien Miller  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND
23af87af16SDamien Miller  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24af87af16SDamien Miller  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25af87af16SDamien Miller  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE
26af87af16SDamien Miller  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27af87af16SDamien Miller  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28af87af16SDamien Miller  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29af87af16SDamien Miller  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30af87af16SDamien Miller  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31af87af16SDamien Miller  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32af87af16SDamien Miller  * SUCH DAMAGE.
33af87af16SDamien Miller  *
34af87af16SDamien Miller  * $From: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $
35af87af16SDamien Miller  */
36af87af16SDamien Miller 
37*11cba2a4SDarren Tucker /* OPENBSD ORIGINAL: include/sha2.h */
38af87af16SDamien Miller 
39*11cba2a4SDarren Tucker #ifndef _SSHSHA2_H
40*11cba2a4SDarren Tucker #define _SSHSHA2_H
41*11cba2a4SDarren Tucker 
42*11cba2a4SDarren Tucker #include "includes.h"
43*11cba2a4SDarren Tucker 
44*11cba2a4SDarren Tucker #if !defined(HAVE_SHA256UPDATE) || !defined(HAVE_SHA384UPDATE) || \
45*11cba2a4SDarren Tucker     !defined(HAVE_SHA512UPDATE)
46af87af16SDamien Miller 
47af87af16SDamien Miller /*** SHA-256/384/512 Various Length Definitions ***********************/
4809159594SDarren Tucker #define SHA224_BLOCK_LENGTH		64
4909159594SDarren Tucker #define SHA224_DIGEST_LENGTH		28
5009159594SDarren Tucker #define SHA224_DIGEST_STRING_LENGTH	(SHA224_DIGEST_LENGTH * 2 + 1)
51af87af16SDamien Miller #define SHA256_BLOCK_LENGTH		64
52af87af16SDamien Miller #define SHA256_DIGEST_LENGTH		32
53af87af16SDamien Miller #define SHA256_DIGEST_STRING_LENGTH	(SHA256_DIGEST_LENGTH * 2 + 1)
54af87af16SDamien Miller #define SHA384_BLOCK_LENGTH		128
55af87af16SDamien Miller #define SHA384_DIGEST_LENGTH		48
56af87af16SDamien Miller #define SHA384_DIGEST_STRING_LENGTH	(SHA384_DIGEST_LENGTH * 2 + 1)
57af87af16SDamien Miller #define SHA512_BLOCK_LENGTH		128
58af87af16SDamien Miller #define SHA512_DIGEST_LENGTH		64
59af87af16SDamien Miller #define SHA512_DIGEST_STRING_LENGTH	(SHA512_DIGEST_LENGTH * 2 + 1)
6009159594SDarren Tucker #define SHA512_256_BLOCK_LENGTH		128
6109159594SDarren Tucker #define SHA512_256_DIGEST_LENGTH	32
6209159594SDarren Tucker #define SHA512_256_DIGEST_STRING_LENGTH	(SHA512_256_DIGEST_LENGTH * 2 + 1)
63af87af16SDamien Miller 
64af87af16SDamien Miller 
6509159594SDarren Tucker /*** SHA-224/256/384/512 Context Structure *******************************/
6609159594SDarren Tucker typedef struct _SHA2_CTX {
6709159594SDarren Tucker 	union {
6809159594SDarren Tucker 		u_int32_t	st32[8];
6909159594SDarren Tucker 		u_int64_t	st64[8];
7009159594SDarren Tucker 	} state;
71af87af16SDamien Miller 	u_int64_t	bitcount[2];
72af87af16SDamien Miller 	u_int8_t	buffer[SHA512_BLOCK_LENGTH];
7309159594SDarren Tucker } SHA2_CTX;
74af87af16SDamien Miller 
75*11cba2a4SDarren Tucker #if 0
7609159594SDarren Tucker __BEGIN_DECLS
7709159594SDarren Tucker void SHA224Init(SHA2_CTX *);
7809159594SDarren Tucker void SHA224Transform(u_int32_t state[8], const u_int8_t [SHA224_BLOCK_LENGTH]);
7909159594SDarren Tucker void SHA224Update(SHA2_CTX *, const u_int8_t *, size_t)
80af87af16SDamien Miller 	__attribute__((__bounded__(__string__,2,3)));
8109159594SDarren Tucker void SHA224Pad(SHA2_CTX *);
8209159594SDarren Tucker void SHA224Final(u_int8_t [SHA224_DIGEST_LENGTH], SHA2_CTX *)
8309159594SDarren Tucker 	__attribute__((__bounded__(__minbytes__,1,SHA224_DIGEST_LENGTH)));
8409159594SDarren Tucker char *SHA224End(SHA2_CTX *, char *)
8509159594SDarren Tucker 	__attribute__((__bounded__(__minbytes__,2,SHA224_DIGEST_STRING_LENGTH)));
8609159594SDarren Tucker char *SHA224File(const char *, char *)
8709159594SDarren Tucker 	__attribute__((__bounded__(__minbytes__,2,SHA224_DIGEST_STRING_LENGTH)));
8809159594SDarren Tucker char *SHA224FileChunk(const char *, char *, off_t, off_t)
8909159594SDarren Tucker 	__attribute__((__bounded__(__minbytes__,2,SHA224_DIGEST_STRING_LENGTH)));
9009159594SDarren Tucker char *SHA224Data(const u_int8_t *, size_t, char *)
9109159594SDarren Tucker 	__attribute__((__bounded__(__string__,1,2)))
9209159594SDarren Tucker 	__attribute__((__bounded__(__minbytes__,3,SHA224_DIGEST_STRING_LENGTH)));
93*11cba2a4SDarren Tucker #endif /* 0 */
9409159594SDarren Tucker 
95*11cba2a4SDarren Tucker #ifndef HAVE_SHA256UPDATE
9609159594SDarren Tucker void SHA256Init(SHA2_CTX *);
9709159594SDarren Tucker void SHA256Transform(u_int32_t state[8], const u_int8_t [SHA256_BLOCK_LENGTH]);
9809159594SDarren Tucker void SHA256Update(SHA2_CTX *, const u_int8_t *, size_t)
9909159594SDarren Tucker 	__attribute__((__bounded__(__string__,2,3)));
10009159594SDarren Tucker void SHA256Pad(SHA2_CTX *);
10109159594SDarren Tucker void SHA256Final(u_int8_t [SHA256_DIGEST_LENGTH], SHA2_CTX *)
102af87af16SDamien Miller 	__attribute__((__bounded__(__minbytes__,1,SHA256_DIGEST_LENGTH)));
10309159594SDarren Tucker char *SHA256End(SHA2_CTX *, char *)
104af87af16SDamien Miller 	__attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH)));
10509159594SDarren Tucker char *SHA256File(const char *, char *)
106af87af16SDamien Miller 	__attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH)));
10709159594SDarren Tucker char *SHA256FileChunk(const char *, char *, off_t, off_t)
108af87af16SDamien Miller 	__attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH)));
10909159594SDarren Tucker char *SHA256Data(const u_int8_t *, size_t, char *)
110af87af16SDamien Miller 	__attribute__((__bounded__(__string__,1,2)))
111af87af16SDamien Miller 	__attribute__((__bounded__(__minbytes__,3,SHA256_DIGEST_STRING_LENGTH)));
112*11cba2a4SDarren Tucker #endif /* HAVE_SHA256UPDATE */
113af87af16SDamien Miller 
114*11cba2a4SDarren Tucker #ifndef HAVE_SHA384UPDATE
11509159594SDarren Tucker void SHA384Init(SHA2_CTX *);
11609159594SDarren Tucker void SHA384Transform(u_int64_t state[8], const u_int8_t [SHA384_BLOCK_LENGTH]);
11709159594SDarren Tucker void SHA384Update(SHA2_CTX *, const u_int8_t *, size_t)
118af87af16SDamien Miller 	__attribute__((__bounded__(__string__,2,3)));
11909159594SDarren Tucker void SHA384Pad(SHA2_CTX *);
12009159594SDarren Tucker void SHA384Final(u_int8_t [SHA384_DIGEST_LENGTH], SHA2_CTX *)
121af87af16SDamien Miller 	__attribute__((__bounded__(__minbytes__,1,SHA384_DIGEST_LENGTH)));
12209159594SDarren Tucker char *SHA384End(SHA2_CTX *, char *)
123af87af16SDamien Miller 	__attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH)));
12409159594SDarren Tucker char *SHA384File(const char *, char *)
125af87af16SDamien Miller 	__attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH)));
12609159594SDarren Tucker char *SHA384FileChunk(const char *, char *, off_t, off_t)
127af87af16SDamien Miller 	__attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH)));
12809159594SDarren Tucker char *SHA384Data(const u_int8_t *, size_t, char *)
129af87af16SDamien Miller 	__attribute__((__bounded__(__string__,1,2)))
130af87af16SDamien Miller 	__attribute__((__bounded__(__minbytes__,3,SHA384_DIGEST_STRING_LENGTH)));
131*11cba2a4SDarren Tucker #endif /* HAVE_SHA384UPDATE */
132af87af16SDamien Miller 
133*11cba2a4SDarren Tucker #ifndef HAVE_SHA512UPDATE
13409159594SDarren Tucker void SHA512Init(SHA2_CTX *);
13509159594SDarren Tucker void SHA512Transform(u_int64_t state[8], const u_int8_t [SHA512_BLOCK_LENGTH]);
13609159594SDarren Tucker void SHA512Update(SHA2_CTX *, const u_int8_t *, size_t)
137af87af16SDamien Miller 	__attribute__((__bounded__(__string__,2,3)));
13809159594SDarren Tucker void SHA512Pad(SHA2_CTX *);
13909159594SDarren Tucker void SHA512Final(u_int8_t [SHA512_DIGEST_LENGTH], SHA2_CTX *)
140af87af16SDamien Miller 	__attribute__((__bounded__(__minbytes__,1,SHA512_DIGEST_LENGTH)));
14109159594SDarren Tucker char *SHA512End(SHA2_CTX *, char *)
142af87af16SDamien Miller 	__attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH)));
14309159594SDarren Tucker char *SHA512File(const char *, char *)
144af87af16SDamien Miller 	__attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH)));
14509159594SDarren Tucker char *SHA512FileChunk(const char *, char *, off_t, off_t)
146af87af16SDamien Miller 	__attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH)));
14709159594SDarren Tucker char *SHA512Data(const u_int8_t *, size_t, char *)
148af87af16SDamien Miller 	__attribute__((__bounded__(__string__,1,2)))
149af87af16SDamien Miller 	__attribute__((__bounded__(__minbytes__,3,SHA512_DIGEST_STRING_LENGTH)));
150*11cba2a4SDarren Tucker #endif /* HAVE_SHA512UPDATE */
151af87af16SDamien Miller 
152*11cba2a4SDarren Tucker #if 0
15309159594SDarren Tucker void SHA512_256Init(SHA2_CTX *);
15409159594SDarren Tucker void SHA512_256Transform(u_int64_t state[8], const u_int8_t [SHA512_256_BLOCK_LENGTH]);
15509159594SDarren Tucker void SHA512_256Update(SHA2_CTX *, const u_int8_t *, size_t)
15609159594SDarren Tucker 	__attribute__((__bounded__(__string__,2,3)));
15709159594SDarren Tucker void SHA512_256Pad(SHA2_CTX *);
15809159594SDarren Tucker void SHA512_256Final(u_int8_t [SHA512_256_DIGEST_LENGTH], SHA2_CTX *)
15909159594SDarren Tucker 	__attribute__((__bounded__(__minbytes__,1,SHA512_256_DIGEST_LENGTH)));
16009159594SDarren Tucker char *SHA512_256End(SHA2_CTX *, char *)
16109159594SDarren Tucker 	__attribute__((__bounded__(__minbytes__,2,SHA512_256_DIGEST_STRING_LENGTH)));
16209159594SDarren Tucker char *SHA512_256File(const char *, char *)
16309159594SDarren Tucker 	__attribute__((__bounded__(__minbytes__,2,SHA512_256_DIGEST_STRING_LENGTH)));
16409159594SDarren Tucker char *SHA512_256FileChunk(const char *, char *, off_t, off_t)
16509159594SDarren Tucker 	__attribute__((__bounded__(__minbytes__,2,SHA512_256_DIGEST_STRING_LENGTH)));
16609159594SDarren Tucker char *SHA512_256Data(const u_int8_t *, size_t, char *)
16709159594SDarren Tucker 	__attribute__((__bounded__(__string__,1,2)))
16809159594SDarren Tucker 	__attribute__((__bounded__(__minbytes__,3,SHA512_256_DIGEST_STRING_LENGTH)));
16909159594SDarren Tucker __END_DECLS
170*11cba2a4SDarren Tucker #endif /* 0 */
171af87af16SDamien Miller 
172*11cba2a4SDarren Tucker #endif /* HAVE_SHA{256,384,512}UPDATE */
173*11cba2a4SDarren Tucker 
174*11cba2a4SDarren Tucker #endif /* _SSHSHA2_H */
175