xref: /freebsd/sys/contrib/openzfs/module/icp/include/sha2/sha2_impl.h (revision 22649d4dba730d46244fd2dff4fd174903c8379f)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * This file and its contents are supplied under the terms of the
4  * Common Development and Distribution License ("CDDL"), version 1.0.
5  * You may only use this file in accordance with the terms of version
6  * 1.0 of the CDDL.
7  *
8  * A full copy of the text of the CDDL should have accompanied this
9  * source.  A copy of the CDDL is also available via the Internet at
10  * https://opensource.org/license/CDDL-1.0.
11  */
12 
13 /*
14  * Copyright (c) 2009 Sun Microsystems, Inc.  All rights reserved.
15  * Copyright (c) 2022 Tino Reichardt <milky-zfs@mcmilk.de>
16  */
17 
18 #ifndef	_SHA2_IMPL_H
19 #define	_SHA2_IMPL_H
20 
21 #include <sys/sha2.h>
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* transform function definition */
28 typedef void (*sha256_f)(uint32_t state[8], const void *data, size_t blks);
29 typedef void (*sha512_f)(uint64_t state[8], const void *data, size_t blks);
30 
31 /* needed for checking valid implementations */
32 typedef boolean_t (*sha2_is_supported_f)(void);
33 
34 typedef struct {
35 	const char *name;
36 	sha256_f transform;
37 	sha2_is_supported_f is_supported;
38 } sha256_ops_t;
39 
40 typedef struct {
41 	const char *name;
42 	sha512_f transform;
43 	sha2_is_supported_f is_supported;
44 } sha512_ops_t;
45 
46 extern const sha256_ops_t *sha256_get_ops(void);
47 extern const sha512_ops_t *sha512_get_ops(void);
48 
49 typedef enum {
50 	SHA1_TYPE,
51 	SHA256_TYPE,
52 	SHA384_TYPE,
53 	SHA512_TYPE
54 } sha2_mech_t;
55 
56 /*
57  * Context for SHA2 mechanism.
58  */
59 typedef struct sha2_ctx {
60 	sha2_mech_type_t	sc_mech_type;	/* type of context */
61 	SHA2_CTX		sc_sha2_ctx;	/* SHA2 context */
62 } sha2_ctx_t;
63 
64 /*
65  * Context for SHA2 HMAC and HMAC GENERAL mechanisms.
66  */
67 typedef struct sha2_hmac_ctx {
68 	sha2_mech_type_t	hc_mech_type;	/* type of context */
69 	uint32_t		hc_digest_len;	/* digest len in bytes */
70 	SHA2_CTX		hc_icontext;	/* inner SHA2 context */
71 	SHA2_CTX		hc_ocontext;	/* outer SHA2 context */
72 } sha2_hmac_ctx_t;
73 
74 #ifdef	__cplusplus
75 }
76 #endif
77 
78 #endif /* _SHA2_IMPL_H */
79