17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51c9bd843Sdinak  * Common Development and Distribution License (the "License").
61c9bd843Sdinak  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*17e2ff97Sdinak  * Copyright 2008 Sun Microsystems, Inc.   All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_CRYPTOKI_H
277c478bd9Sstevel@tonic-gate #define	_CRYPTOKI_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifndef	CK_PTR
347c478bd9Sstevel@tonic-gate #define	CK_PTR *
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifndef CK_DEFINE_FUNCTION
387c478bd9Sstevel@tonic-gate #define	CK_DEFINE_FUNCTION(returnType, name) returnType name
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #ifndef CK_DECLARE_FUNCTION
427c478bd9Sstevel@tonic-gate #define	CK_DECLARE_FUNCTION(returnType, name) returnType name
437c478bd9Sstevel@tonic-gate #endif
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #ifndef CK_DECLARE_FUNCTION_POINTER
467c478bd9Sstevel@tonic-gate #define	CK_DECLARE_FUNCTION_POINTER(returnType, name) returnType (* name)
477c478bd9Sstevel@tonic-gate #endif
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #ifndef CK_CALLBACK_FUNCTION
507c478bd9Sstevel@tonic-gate #define	CK_CALLBACK_FUNCTION(returnType, name) returnType (* name)
517c478bd9Sstevel@tonic-gate #endif
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate #ifndef NULL_PTR
547c478bd9Sstevel@tonic-gate #include <unistd.h>	/* For NULL */
557c478bd9Sstevel@tonic-gate #define	NULL_PTR NULL
567c478bd9Sstevel@tonic-gate #endif
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate /*
597c478bd9Sstevel@tonic-gate  * pkcs11t.h defines TRUE and FALSE in a way that upsets lint
607c478bd9Sstevel@tonic-gate  */
617c478bd9Sstevel@tonic-gate #ifndef	CK_DISABLE_TRUE_FALSE
627c478bd9Sstevel@tonic-gate #define	CK_DISABLE_TRUE_FALSE
637c478bd9Sstevel@tonic-gate #ifndef	TRUE
647c478bd9Sstevel@tonic-gate #define	TRUE	1
657c478bd9Sstevel@tonic-gate #endif /* TRUE */
667c478bd9Sstevel@tonic-gate #ifndef	FALSE
677c478bd9Sstevel@tonic-gate #define	FALSE	0
687c478bd9Sstevel@tonic-gate #endif /* FALSE */
697c478bd9Sstevel@tonic-gate #endif /* CK_DISABLE_TRUE_FALSE */
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate #undef CK_PKCS11_FUNCTION_INFO
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #include <security/pkcs11.h>
747c478bd9Sstevel@tonic-gate 
751c9bd843Sdinak /* Default salt len to generate PKCS#5 key */
761c9bd843Sdinak #define	CK_PKCS5_PBKD2_SALT_SIZE	(16UL)
771c9bd843Sdinak 
781c9bd843Sdinak /* Default number of iterations to generate PKCS#5 key */
791c9bd843Sdinak #define	CK_PKCS5_PBKD2_ITERATIONS	(1000UL)
801c9bd843Sdinak 
817c478bd9Sstevel@tonic-gate /* Solaris specific functions */
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate #include <stdlib.h>
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate /*
86*17e2ff97Sdinak  * pkcs11_GetCriteriaSession will initialize the framework and do all
87*17e2ff97Sdinak  * the necessary work of calling C_GetSlotList(), C_GetMechanismInfo()
88*17e2ff97Sdinak  * C_OpenSession() to create a session that meets all the criteria in
89*17e2ff97Sdinak  * the given function pointer.
90*17e2ff97Sdinak  */
91*17e2ff97Sdinak CK_RV pkcs11_GetCriteriaSession(
92*17e2ff97Sdinak     boolean_t (*criteria)(CK_SLOT_ID slot_id, void *args, CK_RV *rv),
93*17e2ff97Sdinak     void *args, CK_SESSION_HANDLE_PTR hSession);
94*17e2ff97Sdinak 
95*17e2ff97Sdinak /*
967c478bd9Sstevel@tonic-gate  * SUNW_C_GetMechSession will initialize the framework and do all
977c478bd9Sstevel@tonic-gate  * the necessary PKCS#11 calls to create a session capable of
987c478bd9Sstevel@tonic-gate  * providing operations on the requested mechanism
997c478bd9Sstevel@tonic-gate  */
1007c478bd9Sstevel@tonic-gate CK_RV SUNW_C_GetMechSession(CK_MECHANISM_TYPE mech,
1017c478bd9Sstevel@tonic-gate     CK_SESSION_HANDLE_PTR hSession);
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate /*
1047c478bd9Sstevel@tonic-gate  * SUNW_C_KeyToObject will create a secret key object for the given
1057c478bd9Sstevel@tonic-gate  * mechanism from the rawkey data.
1067c478bd9Sstevel@tonic-gate  */
1077c478bd9Sstevel@tonic-gate CK_RV SUNW_C_KeyToObject(CK_SESSION_HANDLE hSession,
1087c478bd9Sstevel@tonic-gate     CK_MECHANISM_TYPE mech, const void *rawkey, size_t rawkey_len,
1097c478bd9Sstevel@tonic-gate     CK_OBJECT_HANDLE_PTR obj);
1107c478bd9Sstevel@tonic-gate 
1111c9bd843Sdinak /*
1121c9bd843Sdinak  * pkcs11_PasswdToPBKD2Object will create a secret key from the given string
1131c9bd843Sdinak  * (e.g. passphrase) using PKCS#5 Password-Based Key Derivation Function 2
1141c9bd843Sdinak  * (PBKD2).
1151c9bd843Sdinak  */
1161c9bd843Sdinak CK_RV
1171c9bd843Sdinak pkcs11_PasswdToPBKD2Object(CK_SESSION_HANDLE hSession, char *passphrase,
1181c9bd843Sdinak     size_t passphrase_len, void *salt, size_t salt_len, CK_ULONG iterations,
1191c9bd843Sdinak     CK_KEY_TYPE key_type, CK_ULONG key_len, CK_FLAGS key_flags,
1201c9bd843Sdinak     CK_OBJECT_HANDLE_PTR obj);
1211c9bd843Sdinak 
1221c9bd843Sdinak /*
1231c9bd843Sdinak  * pkcs11_ObjectToKey gets the rawkey data from a secret key object.
1241c9bd843Sdinak  * The caller is responsible to free the allocated rawkey data.
1251c9bd843Sdinak  */
1261c9bd843Sdinak CK_RV
1271c9bd843Sdinak pkcs11_ObjectToKey(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE obj,
1281c9bd843Sdinak     void **rawkey, size_t *rawkey_len, boolean_t destroy_obj);
1291c9bd843Sdinak 
1301c9bd843Sdinak /*
1311c9bd843Sdinak  * pkcs11_PasswdToKey will create PKCS#5 PBKD2 rawkey data from the
1321c9bd843Sdinak  * given passphrase.  The caller is responsible to free the allocated
1331c9bd843Sdinak  * rawkey data.
1341c9bd843Sdinak  */
1351c9bd843Sdinak CK_RV
1361c9bd843Sdinak pkcs11_PasswdToKey(CK_SESSION_HANDLE hSession, char *passphrase,
1371c9bd843Sdinak     size_t passphrase_len, void *salt, size_t salt_len, CK_KEY_TYPE key_type,
1381c9bd843Sdinak     CK_ULONG key_len, void **rawkey, size_t *rawkey_len);
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1417c478bd9Sstevel@tonic-gate }
1427c478bd9Sstevel@tonic-gate #endif
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate #endif	/* _CRYPTOKI_H */
145