Blame


1 b1ec8cee 2023-02-25 thomas /* $OpenBSD: sha2.h,v 1.10 2016/09/03 17:00:29 tedu Exp $ */
2 b1ec8cee 2023-02-25 thomas
3 b1ec8cee 2023-02-25 thomas /*
4 b1ec8cee 2023-02-25 thomas * FILE: sha2.h
5 b1ec8cee 2023-02-25 thomas * AUTHOR: Aaron D. Gifford <me@aarongifford.com>
6 b1ec8cee 2023-02-25 thomas *
7 b1ec8cee 2023-02-25 thomas * Copyright (c) 2000-2001, Aaron D. Gifford
8 b1ec8cee 2023-02-25 thomas * All rights reserved.
9 b1ec8cee 2023-02-25 thomas *
10 b1ec8cee 2023-02-25 thomas * Redistribution and use in source and binary forms, with or without
11 b1ec8cee 2023-02-25 thomas * modification, are permitted provided that the following conditions
12 b1ec8cee 2023-02-25 thomas * are met:
13 b1ec8cee 2023-02-25 thomas * 1. Redistributions of source code must retain the above copyright
14 b1ec8cee 2023-02-25 thomas * notice, this list of conditions and the following disclaimer.
15 b1ec8cee 2023-02-25 thomas * 2. Redistributions in binary form must reproduce the above copyright
16 b1ec8cee 2023-02-25 thomas * notice, this list of conditions and the following disclaimer in the
17 b1ec8cee 2023-02-25 thomas * documentation and/or other materials provided with the distribution.
18 b1ec8cee 2023-02-25 thomas * 3. Neither the name of the copyright holder nor the names of contributors
19 b1ec8cee 2023-02-25 thomas * may be used to endorse or promote products derived from this software
20 b1ec8cee 2023-02-25 thomas * without specific prior written permission.
21 b1ec8cee 2023-02-25 thomas *
22 b1ec8cee 2023-02-25 thomas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND
23 b1ec8cee 2023-02-25 thomas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 b1ec8cee 2023-02-25 thomas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 b1ec8cee 2023-02-25 thomas * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE
26 b1ec8cee 2023-02-25 thomas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 b1ec8cee 2023-02-25 thomas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 b1ec8cee 2023-02-25 thomas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 b1ec8cee 2023-02-25 thomas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 b1ec8cee 2023-02-25 thomas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 b1ec8cee 2023-02-25 thomas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 b1ec8cee 2023-02-25 thomas * SUCH DAMAGE.
33 b1ec8cee 2023-02-25 thomas *
34 b1ec8cee 2023-02-25 thomas * $From: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $
35 b1ec8cee 2023-02-25 thomas */
36 b1ec8cee 2023-02-25 thomas
37 b1ec8cee 2023-02-25 thomas /* OPENBSD ORIGINAL: include/sha2.h */
38 b1ec8cee 2023-02-25 thomas
39 b1ec8cee 2023-02-25 thomas #ifndef _SSHSHA2_H
40 b1ec8cee 2023-02-25 thomas #define _SSHSHA2_H
41 b1ec8cee 2023-02-25 thomas
42 b1ec8cee 2023-02-25 thomas #if !defined(HAVE_SHA256UPDATE) || !defined(HAVE_SHA384UPDATE) || \
43 b1ec8cee 2023-02-25 thomas !defined(HAVE_SHA512UPDATE)
44 b1ec8cee 2023-02-25 thomas
45 b1ec8cee 2023-02-25 thomas /*** SHA-256/384/512 Various Length Definitions ***********************/
46 b1ec8cee 2023-02-25 thomas #define SHA224_BLOCK_LENGTH 64
47 b1ec8cee 2023-02-25 thomas #define SHA224_DIGEST_LENGTH 28
48 b1ec8cee 2023-02-25 thomas #define SHA224_DIGEST_STRING_LENGTH (SHA224_DIGEST_LENGTH * 2 + 1)
49 b1ec8cee 2023-02-25 thomas #define SHA256_BLOCK_LENGTH 64
50 b1ec8cee 2023-02-25 thomas #define SHA256_DIGEST_LENGTH 32
51 b1ec8cee 2023-02-25 thomas #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
52 b1ec8cee 2023-02-25 thomas #define SHA384_BLOCK_LENGTH 128
53 b1ec8cee 2023-02-25 thomas #define SHA384_DIGEST_LENGTH 48
54 b1ec8cee 2023-02-25 thomas #define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1)
55 b1ec8cee 2023-02-25 thomas #define SHA512_BLOCK_LENGTH 128
56 b1ec8cee 2023-02-25 thomas #define SHA512_DIGEST_LENGTH 64
57 b1ec8cee 2023-02-25 thomas #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
58 b1ec8cee 2023-02-25 thomas #define SHA512_256_BLOCK_LENGTH 128
59 b1ec8cee 2023-02-25 thomas #define SHA512_256_DIGEST_LENGTH 32
60 b1ec8cee 2023-02-25 thomas #define SHA512_256_DIGEST_STRING_LENGTH (SHA512_256_DIGEST_LENGTH * 2 + 1)
61 b1ec8cee 2023-02-25 thomas
62 b1ec8cee 2023-02-25 thomas
63 b1ec8cee 2023-02-25 thomas /*** SHA-224/256/384/512 Context Structure *******************************/
64 b1ec8cee 2023-02-25 thomas typedef struct _SHA2_CTX {
65 b1ec8cee 2023-02-25 thomas union {
66 b1ec8cee 2023-02-25 thomas u_int32_t st32[8];
67 b1ec8cee 2023-02-25 thomas u_int64_t st64[8];
68 b1ec8cee 2023-02-25 thomas } state;
69 b1ec8cee 2023-02-25 thomas u_int64_t bitcount[2];
70 b1ec8cee 2023-02-25 thomas u_int8_t buffer[SHA512_BLOCK_LENGTH];
71 b1ec8cee 2023-02-25 thomas } SHA2_CTX;
72 b1ec8cee 2023-02-25 thomas
73 b1ec8cee 2023-02-25 thomas #if 0
74 b1ec8cee 2023-02-25 thomas __BEGIN_DECLS
75 b1ec8cee 2023-02-25 thomas void SHA224Init(SHA2_CTX *);
76 b1ec8cee 2023-02-25 thomas void SHA224Transform(u_int32_t state[8], const u_int8_t [SHA224_BLOCK_LENGTH]);
77 b1ec8cee 2023-02-25 thomas void SHA224Update(SHA2_CTX *, const u_int8_t *, size_t)
78 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__string__,2,3)));
79 b1ec8cee 2023-02-25 thomas void SHA224Pad(SHA2_CTX *);
80 b1ec8cee 2023-02-25 thomas void SHA224Final(u_int8_t [SHA224_DIGEST_LENGTH], SHA2_CTX *)
81 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,1,SHA224_DIGEST_LENGTH)));
82 b1ec8cee 2023-02-25 thomas char *SHA224End(SHA2_CTX *, char *)
83 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA224_DIGEST_STRING_LENGTH)));
84 b1ec8cee 2023-02-25 thomas char *SHA224File(const char *, char *)
85 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA224_DIGEST_STRING_LENGTH)));
86 b1ec8cee 2023-02-25 thomas char *SHA224FileChunk(const char *, char *, off_t, off_t)
87 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA224_DIGEST_STRING_LENGTH)));
88 b1ec8cee 2023-02-25 thomas char *SHA224Data(const u_int8_t *, size_t, char *)
89 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__string__,1,2)))
90 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,3,SHA224_DIGEST_STRING_LENGTH)));
91 b1ec8cee 2023-02-25 thomas #endif /* 0 */
92 b1ec8cee 2023-02-25 thomas
93 b1ec8cee 2023-02-25 thomas #ifndef HAVE_SHA256UPDATE
94 b1ec8cee 2023-02-25 thomas void SHA256Init(SHA2_CTX *);
95 b1ec8cee 2023-02-25 thomas void SHA256Transform(u_int32_t state[8], const u_int8_t [SHA256_BLOCK_LENGTH]);
96 b1ec8cee 2023-02-25 thomas void SHA256Update(SHA2_CTX *, const u_int8_t *, size_t)
97 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__string__,2,3)));
98 b1ec8cee 2023-02-25 thomas void SHA256Pad(SHA2_CTX *);
99 b1ec8cee 2023-02-25 thomas void SHA256Final(u_int8_t [SHA256_DIGEST_LENGTH], SHA2_CTX *)
100 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,1,SHA256_DIGEST_LENGTH)));
101 b1ec8cee 2023-02-25 thomas char *SHA256End(SHA2_CTX *, char *)
102 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH)));
103 b1ec8cee 2023-02-25 thomas char *SHA256File(const char *, char *)
104 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH)));
105 b1ec8cee 2023-02-25 thomas char *SHA256FileChunk(const char *, char *, off_t, off_t)
106 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH)));
107 b1ec8cee 2023-02-25 thomas char *SHA256Data(const u_int8_t *, size_t, char *)
108 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__string__,1,2)))
109 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,3,SHA256_DIGEST_STRING_LENGTH)));
110 b1ec8cee 2023-02-25 thomas #endif /* HAVE_SHA256UPDATE */
111 b1ec8cee 2023-02-25 thomas
112 b1ec8cee 2023-02-25 thomas #ifndef HAVE_SHA384UPDATE
113 b1ec8cee 2023-02-25 thomas void SHA384Init(SHA2_CTX *);
114 b1ec8cee 2023-02-25 thomas void SHA384Transform(u_int64_t state[8], const u_int8_t [SHA384_BLOCK_LENGTH]);
115 b1ec8cee 2023-02-25 thomas void SHA384Update(SHA2_CTX *, const u_int8_t *, size_t)
116 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__string__,2,3)));
117 b1ec8cee 2023-02-25 thomas void SHA384Pad(SHA2_CTX *);
118 b1ec8cee 2023-02-25 thomas void SHA384Final(u_int8_t [SHA384_DIGEST_LENGTH], SHA2_CTX *)
119 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,1,SHA384_DIGEST_LENGTH)));
120 b1ec8cee 2023-02-25 thomas char *SHA384End(SHA2_CTX *, char *)
121 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH)));
122 b1ec8cee 2023-02-25 thomas char *SHA384File(const char *, char *)
123 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH)));
124 b1ec8cee 2023-02-25 thomas char *SHA384FileChunk(const char *, char *, off_t, off_t)
125 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH)));
126 b1ec8cee 2023-02-25 thomas char *SHA384Data(const u_int8_t *, size_t, char *)
127 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__string__,1,2)))
128 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,3,SHA384_DIGEST_STRING_LENGTH)));
129 b1ec8cee 2023-02-25 thomas #endif /* HAVE_SHA384UPDATE */
130 b1ec8cee 2023-02-25 thomas
131 b1ec8cee 2023-02-25 thomas #ifndef HAVE_SHA512UPDATE
132 b1ec8cee 2023-02-25 thomas void SHA512Init(SHA2_CTX *);
133 b1ec8cee 2023-02-25 thomas void SHA512Transform(u_int64_t state[8], const u_int8_t [SHA512_BLOCK_LENGTH]);
134 b1ec8cee 2023-02-25 thomas void SHA512Update(SHA2_CTX *, const u_int8_t *, size_t)
135 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__string__,2,3)));
136 b1ec8cee 2023-02-25 thomas void SHA512Pad(SHA2_CTX *);
137 b1ec8cee 2023-02-25 thomas void SHA512Final(u_int8_t [SHA512_DIGEST_LENGTH], SHA2_CTX *)
138 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,1,SHA512_DIGEST_LENGTH)));
139 b1ec8cee 2023-02-25 thomas char *SHA512End(SHA2_CTX *, char *)
140 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH)));
141 b1ec8cee 2023-02-25 thomas char *SHA512File(const char *, char *)
142 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH)));
143 b1ec8cee 2023-02-25 thomas char *SHA512FileChunk(const char *, char *, off_t, off_t)
144 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH)));
145 b1ec8cee 2023-02-25 thomas char *SHA512Data(const u_int8_t *, size_t, char *)
146 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__string__,1,2)))
147 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,3,SHA512_DIGEST_STRING_LENGTH)));
148 b1ec8cee 2023-02-25 thomas #endif /* HAVE_SHA512UPDATE */
149 b1ec8cee 2023-02-25 thomas
150 b1ec8cee 2023-02-25 thomas #if 0
151 b1ec8cee 2023-02-25 thomas void SHA512_256Init(SHA2_CTX *);
152 b1ec8cee 2023-02-25 thomas void SHA512_256Transform(u_int64_t state[8], const u_int8_t [SHA512_256_BLOCK_LENGTH]);
153 b1ec8cee 2023-02-25 thomas void SHA512_256Update(SHA2_CTX *, const u_int8_t *, size_t)
154 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__string__,2,3)));
155 b1ec8cee 2023-02-25 thomas void SHA512_256Pad(SHA2_CTX *);
156 b1ec8cee 2023-02-25 thomas void SHA512_256Final(u_int8_t [SHA512_256_DIGEST_LENGTH], SHA2_CTX *)
157 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,1,SHA512_256_DIGEST_LENGTH)));
158 b1ec8cee 2023-02-25 thomas char *SHA512_256End(SHA2_CTX *, char *)
159 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA512_256_DIGEST_STRING_LENGTH)));
160 b1ec8cee 2023-02-25 thomas char *SHA512_256File(const char *, char *)
161 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA512_256_DIGEST_STRING_LENGTH)));
162 b1ec8cee 2023-02-25 thomas char *SHA512_256FileChunk(const char *, char *, off_t, off_t)
163 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA512_256_DIGEST_STRING_LENGTH)));
164 b1ec8cee 2023-02-25 thomas char *SHA512_256Data(const u_int8_t *, size_t, char *)
165 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__string__,1,2)))
166 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,3,SHA512_256_DIGEST_STRING_LENGTH)));
167 b1ec8cee 2023-02-25 thomas __END_DECLS
168 b1ec8cee 2023-02-25 thomas #endif /* 0 */
169 b1ec8cee 2023-02-25 thomas
170 b1ec8cee 2023-02-25 thomas #endif /* HAVE_SHA{256,384,512}UPDATE */
171 b1ec8cee 2023-02-25 thomas
172 b1ec8cee 2023-02-25 thomas #endif /* _SSHSHA2_H */