xref: /titanic_44/usr/src/lib/pkcs11/pkcs11_kernel/common/kernelEmulate.h (revision 4df55fde49134f9735f84011f23a767c75e393c7)
1ba5f469cSkrishna /*
2ba5f469cSkrishna  * CDDL HEADER START
3ba5f469cSkrishna  *
4ba5f469cSkrishna  * The contents of this file are subject to the terms of the
5ba5f469cSkrishna  * Common Development and Distribution License (the "License").
6ba5f469cSkrishna  * You may not use this file except in compliance with the License.
7ba5f469cSkrishna  *
8ba5f469cSkrishna  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9ba5f469cSkrishna  * or http://www.opensolaris.org/os/licensing.
10ba5f469cSkrishna  * See the License for the specific language governing permissions
11ba5f469cSkrishna  * and limitations under the License.
12ba5f469cSkrishna  *
13ba5f469cSkrishna  * When distributing Covered Code, include this CDDL HEADER in each
14ba5f469cSkrishna  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15ba5f469cSkrishna  * If applicable, add the following below this CDDL HEADER, with the
16ba5f469cSkrishna  * fields enclosed by brackets "[]" replaced with your own identifying
17ba5f469cSkrishna  * information: Portions Copyright [yyyy] [name of copyright owner]
18ba5f469cSkrishna  *
19ba5f469cSkrishna  * CDDL HEADER END
20ba5f469cSkrishna  */
21ba5f469cSkrishna 
22ba5f469cSkrishna /*
23*4df55fdeSJanie Lu  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24ba5f469cSkrishna  * Use is subject to license terms.
25ba5f469cSkrishna  */
26ba5f469cSkrishna 
27ba5f469cSkrishna #ifndef	_KERNEL_EMULATE_H
28ba5f469cSkrishna #define	_KERNEL_EMULATE_H
29ba5f469cSkrishna 
30ba5f469cSkrishna #ifdef __cplusplus
31ba5f469cSkrishna extern "C" {
32ba5f469cSkrishna #endif
33ba5f469cSkrishna 
34ba5f469cSkrishna #include <strings.h>
35ba5f469cSkrishna #include <sys/crypto/ioctl.h>
36ba5f469cSkrishna #include <security/cryptoki.h>
37ba5f469cSkrishna #include "kernelGlobal.h"
38ba5f469cSkrishna #include "kernelSession.h"
39ba5f469cSkrishna #include "kernelSoftCommon.h"
40ba5f469cSkrishna 
41ba5f469cSkrishna #define	SLOT_THRESHOLD(sp) (slot_table[sp->ses_slotid]->sl_threshold)
42*4df55fdeSJanie Lu #define	SLOT_HASH_MAX_INDATA_LEN(sp) \
43*4df55fdeSJanie Lu 	(slot_table[sp->ses_slotid]->sl_hash_max_inlen)
44*4df55fdeSJanie Lu #define	SLOT_HMAC_MAX_INDATA_LEN(sp) \
45*4df55fdeSJanie Lu 	(slot_table[sp->ses_slotid]->sl_hmac_max_inlen)
46ba5f469cSkrishna #define	SLOT_HAS_LIMITED_HASH(sp) (slot_table[sp->ses_slotid]->sl_flags & \
47ba5f469cSkrishna 	CRYPTO_LIMITED_HASH_SUPPORT)
48*4df55fdeSJanie Lu #define	SLOT_HAS_LIMITED_HMAC(sp) (slot_table[sp->ses_slotid]->sl_flags & \
49*4df55fdeSJanie Lu 	CRYPTO_LIMITED_HMAC_SUPPORT)
50ba5f469cSkrishna #define	get_sp(opp)	(((digest_buf_t *)((opp)->context))->soft_sp)
51ba5f469cSkrishna #define	get_spp(opp)	(&(((digest_buf_t *)((opp)->context))->soft_sp))
52ba5f469cSkrishna 
53ba5f469cSkrishna /* reinit buffer so that we can reuse it */
54ba5f469cSkrishna #define	REINIT_OPBUF(opp) {			 		\
55ba5f469cSkrishna 	if ((opp)->flags & CRYPTO_EMULATE) {			\
56ba5f469cSkrishna 		digest_buf_t *bufp = (opp)->context;		\
57ba5f469cSkrishna 		if (bufp != NULL) {				\
58ba5f469cSkrishna 			bzero(bufp->buf, bufp->indata_len);	\
59ba5f469cSkrishna 			bufp->indata_len = 0;			\
60ba5f469cSkrishna 		}						\
61ba5f469cSkrishna 	}							\
62ba5f469cSkrishna }
63ba5f469cSkrishna 
64ba5f469cSkrishna boolean_t is_hmac(CK_MECHANISM_TYPE mechanism);
65b2a96221Skrishna CK_RV emulate_buf_init(kernel_session_t *session_p, int buflen, int opflag);
66ba5f469cSkrishna CK_RV emulate_init(kernel_session_t *session_p, CK_MECHANISM_PTR pMechanism,
67ba5f469cSkrishna     crypto_key_t *keyp, int opflag);
68ba5f469cSkrishna CK_RV emulate_update(kernel_session_t *session_p, CK_BYTE_PTR pPart,
69ba5f469cSkrishna     CK_ULONG ulPartLen, int opflag);
70ba5f469cSkrishna 
71ba5f469cSkrishna #ifdef __cplusplus
72ba5f469cSkrishna }
73ba5f469cSkrishna #endif
74ba5f469cSkrishna 
75ba5f469cSkrishna #endif /* _KERNEL_EMULATE_H */
76