xref: /titanic_50/usr/src/lib/pkcs11/pkcs11_kernel/common/kernelEmulate.h (revision 2eeaed14a5e2ed9bd811643ad5bffc3510ca0310)
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 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_KERNEL_EMULATE_H
28 #define	_KERNEL_EMULATE_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <strings.h>
37 #include <sys/crypto/ioctl.h>
38 #include <security/cryptoki.h>
39 #include "kernelGlobal.h"
40 #include "kernelSession.h"
41 #include "kernelSoftCommon.h"
42 
43 #define	SLOT_THRESHOLD(sp) (slot_table[sp->ses_slotid]->sl_threshold)
44 #define	SLOT_MAX_INDATA_LEN(sp)	(slot_table[sp->ses_slotid]->sl_max_inlen)
45 #define	SLOT_HAS_LIMITED_HASH(sp) (slot_table[sp->ses_slotid]->sl_flags & \
46 	CRYPTO_LIMITED_HASH_SUPPORT)
47 #define	get_sp(opp)	(((digest_buf_t *)((opp)->context))->soft_sp)
48 #define	get_spp(opp)	(&(((digest_buf_t *)((opp)->context))->soft_sp))
49 
50 /* reinit buffer so that we can reuse it */
51 #define	REINIT_OPBUF(opp) {			 		\
52 	if ((opp)->flags & CRYPTO_EMULATE) {			\
53 		digest_buf_t *bufp = (opp)->context;		\
54 		if (bufp != NULL) {				\
55 			bzero(bufp->buf, bufp->indata_len);	\
56 			bufp->indata_len = 0;			\
57 		}						\
58 	}							\
59 }
60 
61 boolean_t is_hmac(CK_MECHANISM_TYPE mechanism);
62 CK_RV emulate_buf_init(kernel_session_t *session_p, int buflen, int opflag);
63 CK_RV emulate_init(kernel_session_t *session_p, CK_MECHANISM_PTR pMechanism,
64     crypto_key_t *keyp, int opflag);
65 CK_RV emulate_update(kernel_session_t *session_p, CK_BYTE_PTR pPart,
66     CK_ULONG ulPartLen, int opflag);
67 
68 #ifdef __cplusplus
69 }
70 #endif
71 
72 #endif /* _KERNEL_EMULATE_H */
73