xref: /freebsd-src/sys/contrib/openzfs/module/icp/include/sha2/sha2_impl.h (revision 2a58b312b62f908ec92311d1bd8536dbaeb8e55b)
1eda14cbcSMatt Macy /*
2eda14cbcSMatt Macy  * CDDL HEADER START
3eda14cbcSMatt Macy  *
4eda14cbcSMatt Macy  * The contents of this file are subject to the terms of the
5eda14cbcSMatt Macy  * Common Development and Distribution License (the "License").
6eda14cbcSMatt Macy  * You may not use this file except in compliance with the License.
7eda14cbcSMatt Macy  *
8eda14cbcSMatt Macy  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9271171e0SMartin Matuska  * or https://opensource.org/licenses/CDDL-1.0.
10eda14cbcSMatt Macy  * See the License for the specific language governing permissions
11eda14cbcSMatt Macy  * and limitations under the License.
12eda14cbcSMatt Macy  *
13eda14cbcSMatt Macy  * When distributing Covered Code, include this CDDL HEADER in each
14eda14cbcSMatt Macy  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15eda14cbcSMatt Macy  * If applicable, add the following below this CDDL HEADER, with the
16eda14cbcSMatt Macy  * fields enclosed by brackets "[]" replaced with your own identifying
17eda14cbcSMatt Macy  * information: Portions Copyright [yyyy] [name of copyright owner]
18eda14cbcSMatt Macy  *
19eda14cbcSMatt Macy  * CDDL HEADER END
20eda14cbcSMatt Macy  */
21*2a58b312SMartin Matuska 
22eda14cbcSMatt Macy /*
23*2a58b312SMartin Matuska  * Copyright (c) 2009 Sun Microsystems, Inc.  All rights reserved.
24*2a58b312SMartin Matuska  * Copyright (c) 2022 Tino Reichardt <milky-zfs@mcmilk.de>
25eda14cbcSMatt Macy  */
26eda14cbcSMatt Macy 
27eda14cbcSMatt Macy #ifndef	_SHA2_IMPL_H
28eda14cbcSMatt Macy #define	_SHA2_IMPL_H
29eda14cbcSMatt Macy 
30eda14cbcSMatt Macy #include <sys/sha2.h>
31eda14cbcSMatt Macy 
32eda14cbcSMatt Macy #ifdef __cplusplus
33eda14cbcSMatt Macy extern "C" {
34eda14cbcSMatt Macy #endif
35eda14cbcSMatt Macy 
36*2a58b312SMartin Matuska /* transform function definition */
37*2a58b312SMartin Matuska typedef void (*sha256_f)(uint32_t state[8], const void *data, size_t blks);
38*2a58b312SMartin Matuska typedef void (*sha512_f)(uint64_t state[8], const void *data, size_t blks);
39*2a58b312SMartin Matuska 
40*2a58b312SMartin Matuska /* needed for checking valid implementations */
41*2a58b312SMartin Matuska typedef boolean_t (*sha2_is_supported_f)(void);
42*2a58b312SMartin Matuska 
43*2a58b312SMartin Matuska typedef struct {
44*2a58b312SMartin Matuska 	const char *name;
45*2a58b312SMartin Matuska 	sha256_f transform;
46*2a58b312SMartin Matuska 	sha2_is_supported_f is_supported;
47*2a58b312SMartin Matuska } sha256_ops_t;
48*2a58b312SMartin Matuska 
49*2a58b312SMartin Matuska typedef struct {
50*2a58b312SMartin Matuska 	const char *name;
51*2a58b312SMartin Matuska 	sha512_f transform;
52*2a58b312SMartin Matuska 	sha2_is_supported_f is_supported;
53*2a58b312SMartin Matuska } sha512_ops_t;
54*2a58b312SMartin Matuska 
55*2a58b312SMartin Matuska extern const sha256_ops_t *sha256_get_ops(void);
56*2a58b312SMartin Matuska extern const sha512_ops_t *sha512_get_ops(void);
57*2a58b312SMartin Matuska 
58eda14cbcSMatt Macy typedef enum {
59eda14cbcSMatt Macy 	SHA1_TYPE,
60eda14cbcSMatt Macy 	SHA256_TYPE,
61eda14cbcSMatt Macy 	SHA384_TYPE,
62eda14cbcSMatt Macy 	SHA512_TYPE
63eda14cbcSMatt Macy } sha2_mech_t;
64eda14cbcSMatt Macy 
65eda14cbcSMatt Macy /*
66eda14cbcSMatt Macy  * Context for SHA2 mechanism.
67eda14cbcSMatt Macy  */
68eda14cbcSMatt Macy typedef struct sha2_ctx {
69eda14cbcSMatt Macy 	sha2_mech_type_t	sc_mech_type;	/* type of context */
70eda14cbcSMatt Macy 	SHA2_CTX		sc_sha2_ctx;	/* SHA2 context */
71eda14cbcSMatt Macy } sha2_ctx_t;
72eda14cbcSMatt Macy 
73eda14cbcSMatt Macy /*
74eda14cbcSMatt Macy  * Context for SHA2 HMAC and HMAC GENERAL mechanisms.
75eda14cbcSMatt Macy  */
76eda14cbcSMatt Macy typedef struct sha2_hmac_ctx {
77eda14cbcSMatt Macy 	sha2_mech_type_t	hc_mech_type;	/* type of context */
78eda14cbcSMatt Macy 	uint32_t		hc_digest_len;	/* digest len in bytes */
79eda14cbcSMatt Macy 	SHA2_CTX		hc_icontext;	/* inner SHA2 context */
80eda14cbcSMatt Macy 	SHA2_CTX		hc_ocontext;	/* outer SHA2 context */
81eda14cbcSMatt Macy } sha2_hmac_ctx_t;
82eda14cbcSMatt Macy 
83eda14cbcSMatt Macy #ifdef	__cplusplus
84eda14cbcSMatt Macy }
85eda14cbcSMatt Macy #endif
86eda14cbcSMatt Macy 
87eda14cbcSMatt Macy #endif /* _SHA2_IMPL_H */
88