xref: /titanic_44/usr/src/common/crypto/sha2/sha2_impl.h (revision 02d09e03eb27f3a2dc299de704e45dae5173f43f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SHA2_IMPL_H
27 #define	_SHA2_IMPL_H
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <fips/fips_post.h>
34 
35 typedef enum {
36 	SHA1_TYPE,
37 	SHA256_TYPE,
38 	SHA384_TYPE,
39 	SHA512_TYPE
40 } sha2_mech_t;
41 
42 #ifdef _KERNEL
43 
44 /*
45  * Context for SHA2 mechanism.
46  */
47 typedef struct sha2_ctx {
48 	sha2_mech_type_t	sc_mech_type;	/* type of context */
49 	SHA2_CTX		sc_sha2_ctx;	/* SHA2 context */
50 } sha2_ctx_t;
51 
52 /*
53  * Context for SHA2 HMAC and HMAC GENERAL mechanisms.
54  */
55 typedef struct sha2_hmac_ctx {
56 	sha2_mech_type_t	hc_mech_type;	/* type of context */
57 	uint32_t		hc_digest_len;	/* digest len in bytes */
58 	SHA2_CTX		hc_icontext;	/* inner SHA2 context */
59 	SHA2_CTX		hc_ocontext;	/* outer SHA2 context */
60 } sha2_hmac_ctx_t;
61 
62 #endif
63 
64 extern int fips_sha2_post(void);
65 extern int fips_sha2_hash(SHA2_CTX *, uchar_t *, ulong_t, uchar_t *);
66 
67 #ifndef _KERNEL
68 /* SHA2 funtions */
69 extern SHA2_CTX *fips_sha2_build_context(CK_MECHANISM_TYPE);
70 
71 /* SHA2 HMAC functions */
72 extern soft_hmac_ctx_t *fips_sha2_hmac_build_context(CK_MECHANISM_TYPE,
73 	uint8_t *, unsigned int);
74 extern CK_RV fips_hmac_sha2_hash(unsigned char *, uint8_t *,
75 	unsigned int, uint8_t *, unsigned int, CK_MECHANISM_TYPE);
76 #else
77 
78 extern SHA2_CTX *fips_sha2_build_context(sha2_mech_t);
79 extern sha2_hmac_ctx_t *fips_sha2_hmac_build_context(sha2_mech_t,
80 	uint8_t *, unsigned int);
81 extern void fips_hmac_sha2_hash(sha2_hmac_ctx_t *, uint8_t *, uint32_t,
82 	uint8_t *, sha2_mech_t);
83 #endif
84 
85 #ifdef	__cplusplus
86 }
87 #endif
88 
89 #endif /* _SHA2_IMPL_H */
90