xref: /onnv-gate/usr/src/lib/pkcs11/pkcs11_kernel/common/kernelEmulate.h (revision 11304:3092d1e303d6)
14072Skrishna /*
24072Skrishna  * CDDL HEADER START
34072Skrishna  *
44072Skrishna  * The contents of this file are subject to the terms of the
54072Skrishna  * Common Development and Distribution License (the "License").
64072Skrishna  * You may not use this file except in compliance with the License.
74072Skrishna  *
84072Skrishna  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
94072Skrishna  * or http://www.opensolaris.org/os/licensing.
104072Skrishna  * See the License for the specific language governing permissions
114072Skrishna  * and limitations under the License.
124072Skrishna  *
134072Skrishna  * When distributing Covered Code, include this CDDL HEADER in each
144072Skrishna  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
154072Skrishna  * If applicable, add the following below this CDDL HEADER, with the
164072Skrishna  * fields enclosed by brackets "[]" replaced with your own identifying
174072Skrishna  * information: Portions Copyright [yyyy] [name of copyright owner]
184072Skrishna  *
194072Skrishna  * CDDL HEADER END
204072Skrishna  */
214072Skrishna 
224072Skrishna /*
23*11304SJanie.Lu@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
244072Skrishna  * Use is subject to license terms.
254072Skrishna  */
264072Skrishna 
274072Skrishna #ifndef	_KERNEL_EMULATE_H
284072Skrishna #define	_KERNEL_EMULATE_H
294072Skrishna 
304072Skrishna #ifdef __cplusplus
314072Skrishna extern "C" {
324072Skrishna #endif
334072Skrishna 
344072Skrishna #include <strings.h>
354072Skrishna #include <sys/crypto/ioctl.h>
364072Skrishna #include <security/cryptoki.h>
374072Skrishna #include "kernelGlobal.h"
384072Skrishna #include "kernelSession.h"
394072Skrishna #include "kernelSoftCommon.h"
404072Skrishna 
414072Skrishna #define	SLOT_THRESHOLD(sp) (slot_table[sp->ses_slotid]->sl_threshold)
42*11304SJanie.Lu@Sun.COM #define	SLOT_HASH_MAX_INDATA_LEN(sp) \
43*11304SJanie.Lu@Sun.COM 	(slot_table[sp->ses_slotid]->sl_hash_max_inlen)
44*11304SJanie.Lu@Sun.COM #define	SLOT_HMAC_MAX_INDATA_LEN(sp) \
45*11304SJanie.Lu@Sun.COM 	(slot_table[sp->ses_slotid]->sl_hmac_max_inlen)
464072Skrishna #define	SLOT_HAS_LIMITED_HASH(sp) (slot_table[sp->ses_slotid]->sl_flags & \
474072Skrishna 	CRYPTO_LIMITED_HASH_SUPPORT)
48*11304SJanie.Lu@Sun.COM #define	SLOT_HAS_LIMITED_HMAC(sp) (slot_table[sp->ses_slotid]->sl_flags & \
49*11304SJanie.Lu@Sun.COM 	CRYPTO_LIMITED_HMAC_SUPPORT)
504072Skrishna #define	get_sp(opp)	(((digest_buf_t *)((opp)->context))->soft_sp)
514072Skrishna #define	get_spp(opp)	(&(((digest_buf_t *)((opp)->context))->soft_sp))
524072Skrishna 
534072Skrishna /* reinit buffer so that we can reuse it */
544072Skrishna #define	REINIT_OPBUF(opp) {			 		\
554072Skrishna 	if ((opp)->flags & CRYPTO_EMULATE) {			\
564072Skrishna 		digest_buf_t *bufp = (opp)->context;		\
574072Skrishna 		if (bufp != NULL) {				\
584072Skrishna 			bzero(bufp->buf, bufp->indata_len);	\
594072Skrishna 			bufp->indata_len = 0;			\
604072Skrishna 		}						\
614072Skrishna 	}							\
624072Skrishna }
634072Skrishna 
644072Skrishna boolean_t is_hmac(CK_MECHANISM_TYPE mechanism);
655616Skrishna CK_RV emulate_buf_init(kernel_session_t *session_p, int buflen, int opflag);
664072Skrishna CK_RV emulate_init(kernel_session_t *session_p, CK_MECHANISM_PTR pMechanism,
674072Skrishna     crypto_key_t *keyp, int opflag);
684072Skrishna CK_RV emulate_update(kernel_session_t *session_p, CK_BYTE_PTR pPart,
694072Skrishna     CK_ULONG ulPartLen, int opflag);
704072Skrishna 
714072Skrishna #ifdef __cplusplus
724072Skrishna }
734072Skrishna #endif
744072Skrishna 
754072Skrishna #endif /* _KERNEL_EMULATE_H */
76