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 8d2e954c 2024-04-27 thomas.ad #if !defined(HAVE_SHA256UPDATE)
43 b1ec8cee 2023-02-25 thomas
44 b1ec8cee 2023-02-25 thomas /*** SHA-256/384/512 Various Length Definitions ***********************/
45 b1ec8cee 2023-02-25 thomas #define SHA224_BLOCK_LENGTH 64
46 b1ec8cee 2023-02-25 thomas #define SHA224_DIGEST_LENGTH 28
47 b1ec8cee 2023-02-25 thomas #define SHA224_DIGEST_STRING_LENGTH (SHA224_DIGEST_LENGTH * 2 + 1)
48 b1ec8cee 2023-02-25 thomas #define SHA256_BLOCK_LENGTH 64
49 b1ec8cee 2023-02-25 thomas #define SHA256_DIGEST_LENGTH 32
50 b1ec8cee 2023-02-25 thomas #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
51 b1ec8cee 2023-02-25 thomas #define SHA384_BLOCK_LENGTH 128
52 b1ec8cee 2023-02-25 thomas #define SHA384_DIGEST_LENGTH 48
53 b1ec8cee 2023-02-25 thomas #define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1)
54 b1ec8cee 2023-02-25 thomas #define SHA512_BLOCK_LENGTH 128
55 b1ec8cee 2023-02-25 thomas #define SHA512_DIGEST_LENGTH 64
56 b1ec8cee 2023-02-25 thomas #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
57 b1ec8cee 2023-02-25 thomas #define SHA512_256_BLOCK_LENGTH 128
58 b1ec8cee 2023-02-25 thomas #define SHA512_256_DIGEST_LENGTH 32
59 b1ec8cee 2023-02-25 thomas #define SHA512_256_DIGEST_STRING_LENGTH (SHA512_256_DIGEST_LENGTH * 2 + 1)
60 b1ec8cee 2023-02-25 thomas
61 b1ec8cee 2023-02-25 thomas
62 b1ec8cee 2023-02-25 thomas /*** SHA-224/256/384/512 Context Structure *******************************/
63 b1ec8cee 2023-02-25 thomas typedef struct _SHA2_CTX {
64 b1ec8cee 2023-02-25 thomas union {
65 b1ec8cee 2023-02-25 thomas u_int32_t st32[8];
66 b1ec8cee 2023-02-25 thomas u_int64_t st64[8];
67 b1ec8cee 2023-02-25 thomas } state;
68 b1ec8cee 2023-02-25 thomas u_int64_t bitcount[2];
69 b1ec8cee 2023-02-25 thomas u_int8_t buffer[SHA512_BLOCK_LENGTH];
70 b1ec8cee 2023-02-25 thomas } SHA2_CTX;
71 b1ec8cee 2023-02-25 thomas
72 b1ec8cee 2023-02-25 thomas #if 0
73 b1ec8cee 2023-02-25 thomas __BEGIN_DECLS
74 b1ec8cee 2023-02-25 thomas void SHA224Init(SHA2_CTX *);
75 b1ec8cee 2023-02-25 thomas void SHA224Transform(u_int32_t state[8], const u_int8_t [SHA224_BLOCK_LENGTH]);
76 b1ec8cee 2023-02-25 thomas void SHA224Update(SHA2_CTX *, const u_int8_t *, size_t)
77 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__string__,2,3)));
78 b1ec8cee 2023-02-25 thomas void SHA224Pad(SHA2_CTX *);
79 b1ec8cee 2023-02-25 thomas void SHA224Final(u_int8_t [SHA224_DIGEST_LENGTH], SHA2_CTX *)
80 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,1,SHA224_DIGEST_LENGTH)));
81 b1ec8cee 2023-02-25 thomas char *SHA224End(SHA2_CTX *, char *)
82 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA224_DIGEST_STRING_LENGTH)));
83 b1ec8cee 2023-02-25 thomas char *SHA224File(const char *, char *)
84 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA224_DIGEST_STRING_LENGTH)));
85 b1ec8cee 2023-02-25 thomas char *SHA224FileChunk(const char *, char *, off_t, off_t)
86 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA224_DIGEST_STRING_LENGTH)));
87 b1ec8cee 2023-02-25 thomas char *SHA224Data(const u_int8_t *, size_t, char *)
88 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__string__,1,2)))
89 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,3,SHA224_DIGEST_STRING_LENGTH)));
90 b1ec8cee 2023-02-25 thomas #endif /* 0 */
91 b1ec8cee 2023-02-25 thomas
92 b1ec8cee 2023-02-25 thomas #ifndef HAVE_SHA256UPDATE
93 b1ec8cee 2023-02-25 thomas void SHA256Init(SHA2_CTX *);
94 b1ec8cee 2023-02-25 thomas void SHA256Transform(u_int32_t state[8], const u_int8_t [SHA256_BLOCK_LENGTH]);
95 b1ec8cee 2023-02-25 thomas void SHA256Update(SHA2_CTX *, const u_int8_t *, size_t)
96 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__string__,2,3)));
97 b1ec8cee 2023-02-25 thomas void SHA256Pad(SHA2_CTX *);
98 b1ec8cee 2023-02-25 thomas void SHA256Final(u_int8_t [SHA256_DIGEST_LENGTH], SHA2_CTX *)
99 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,1,SHA256_DIGEST_LENGTH)));
100 b1ec8cee 2023-02-25 thomas char *SHA256End(SHA2_CTX *, char *)
101 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH)));
102 b1ec8cee 2023-02-25 thomas char *SHA256File(const char *, char *)
103 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH)));
104 b1ec8cee 2023-02-25 thomas char *SHA256FileChunk(const char *, char *, off_t, off_t)
105 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH)));
106 b1ec8cee 2023-02-25 thomas char *SHA256Data(const u_int8_t *, size_t, char *)
107 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__string__,1,2)))
108 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,3,SHA256_DIGEST_STRING_LENGTH)));
109 b1ec8cee 2023-02-25 thomas #endif /* HAVE_SHA256UPDATE */
110 b1ec8cee 2023-02-25 thomas
111 8d2e954c 2024-04-27 thomas.ad #if 0
112 b1ec8cee 2023-02-25 thomas void SHA384Init(SHA2_CTX *);
113 b1ec8cee 2023-02-25 thomas void SHA384Transform(u_int64_t state[8], const u_int8_t [SHA384_BLOCK_LENGTH]);
114 b1ec8cee 2023-02-25 thomas void SHA384Update(SHA2_CTX *, const u_int8_t *, size_t)
115 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__string__,2,3)));
116 b1ec8cee 2023-02-25 thomas void SHA384Pad(SHA2_CTX *);
117 b1ec8cee 2023-02-25 thomas void SHA384Final(u_int8_t [SHA384_DIGEST_LENGTH], SHA2_CTX *)
118 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,1,SHA384_DIGEST_LENGTH)));
119 b1ec8cee 2023-02-25 thomas char *SHA384End(SHA2_CTX *, char *)
120 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH)));
121 b1ec8cee 2023-02-25 thomas char *SHA384File(const char *, char *)
122 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH)));
123 b1ec8cee 2023-02-25 thomas char *SHA384FileChunk(const char *, char *, off_t, off_t)
124 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH)));
125 b1ec8cee 2023-02-25 thomas char *SHA384Data(const u_int8_t *, size_t, char *)
126 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__string__,1,2)))
127 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,3,SHA384_DIGEST_STRING_LENGTH)));
128 b1ec8cee 2023-02-25 thomas
129 b1ec8cee 2023-02-25 thomas void SHA512Init(SHA2_CTX *);
130 b1ec8cee 2023-02-25 thomas void SHA512Transform(u_int64_t state[8], const u_int8_t [SHA512_BLOCK_LENGTH]);
131 b1ec8cee 2023-02-25 thomas void SHA512Update(SHA2_CTX *, const u_int8_t *, size_t)
132 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__string__,2,3)));
133 b1ec8cee 2023-02-25 thomas void SHA512Pad(SHA2_CTX *);
134 b1ec8cee 2023-02-25 thomas void SHA512Final(u_int8_t [SHA512_DIGEST_LENGTH], SHA2_CTX *)
135 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,1,SHA512_DIGEST_LENGTH)));
136 b1ec8cee 2023-02-25 thomas char *SHA512End(SHA2_CTX *, char *)
137 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH)));
138 b1ec8cee 2023-02-25 thomas char *SHA512File(const char *, char *)
139 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH)));
140 b1ec8cee 2023-02-25 thomas char *SHA512FileChunk(const char *, char *, off_t, off_t)
141 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH)));
142 b1ec8cee 2023-02-25 thomas char *SHA512Data(const u_int8_t *, size_t, char *)
143 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__string__,1,2)))
144 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,3,SHA512_DIGEST_STRING_LENGTH)));
145 b1ec8cee 2023-02-25 thomas
146 b1ec8cee 2023-02-25 thomas void SHA512_256Init(SHA2_CTX *);
147 b1ec8cee 2023-02-25 thomas void SHA512_256Transform(u_int64_t state[8], const u_int8_t [SHA512_256_BLOCK_LENGTH]);
148 b1ec8cee 2023-02-25 thomas void SHA512_256Update(SHA2_CTX *, const u_int8_t *, size_t)
149 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__string__,2,3)));
150 b1ec8cee 2023-02-25 thomas void SHA512_256Pad(SHA2_CTX *);
151 b1ec8cee 2023-02-25 thomas void SHA512_256Final(u_int8_t [SHA512_256_DIGEST_LENGTH], SHA2_CTX *)
152 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,1,SHA512_256_DIGEST_LENGTH)));
153 b1ec8cee 2023-02-25 thomas char *SHA512_256End(SHA2_CTX *, char *)
154 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA512_256_DIGEST_STRING_LENGTH)));
155 b1ec8cee 2023-02-25 thomas char *SHA512_256File(const char *, char *)
156 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA512_256_DIGEST_STRING_LENGTH)));
157 b1ec8cee 2023-02-25 thomas char *SHA512_256FileChunk(const char *, char *, off_t, off_t)
158 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,2,SHA512_256_DIGEST_STRING_LENGTH)));
159 b1ec8cee 2023-02-25 thomas char *SHA512_256Data(const u_int8_t *, size_t, char *)
160 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__string__,1,2)))
161 b1ec8cee 2023-02-25 thomas __attribute__((__bounded__(__minbytes__,3,SHA512_256_DIGEST_STRING_LENGTH)));
162 b1ec8cee 2023-02-25 thomas __END_DECLS
163 b1ec8cee 2023-02-25 thomas #endif /* 0 */
164 b1ec8cee 2023-02-25 thomas
165 8d2e954c 2024-04-27 thomas.ad #endif /* HAVE_SHA256UPDATE */
166 b1ec8cee 2023-02-25 thomas
167 b1ec8cee 2023-02-25 thomas #endif /* _SSHSHA2_H */