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 #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #ifdef __cplusplus 327c478bd9Sstevel@tonic-gate extern "C" { 337c478bd9Sstevel@tonic-gate #endif 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #ifndef CK_PTR 367c478bd9Sstevel@tonic-gate #define CK_PTR * 377c478bd9Sstevel@tonic-gate #endif 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #ifndef CK_DEFINE_FUNCTION 407c478bd9Sstevel@tonic-gate #define CK_DEFINE_FUNCTION(returnType, name) returnType name 417c478bd9Sstevel@tonic-gate #endif 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #ifndef CK_DECLARE_FUNCTION 447c478bd9Sstevel@tonic-gate #define CK_DECLARE_FUNCTION(returnType, name) returnType name 457c478bd9Sstevel@tonic-gate #endif 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #ifndef CK_DECLARE_FUNCTION_POINTER 487c478bd9Sstevel@tonic-gate #define CK_DECLARE_FUNCTION_POINTER(returnType, name) returnType (* name) 497c478bd9Sstevel@tonic-gate #endif 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #ifndef CK_CALLBACK_FUNCTION 527c478bd9Sstevel@tonic-gate #define CK_CALLBACK_FUNCTION(returnType, name) returnType (* name) 537c478bd9Sstevel@tonic-gate #endif 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate #ifndef NULL_PTR 567c478bd9Sstevel@tonic-gate #include <unistd.h> /* For NULL */ 577c478bd9Sstevel@tonic-gate #define NULL_PTR NULL 587c478bd9Sstevel@tonic-gate #endif 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate /* 617c478bd9Sstevel@tonic-gate * pkcs11t.h defines TRUE and FALSE in a way that upsets lint 627c478bd9Sstevel@tonic-gate */ 637c478bd9Sstevel@tonic-gate #ifndef CK_DISABLE_TRUE_FALSE 647c478bd9Sstevel@tonic-gate #define CK_DISABLE_TRUE_FALSE 657c478bd9Sstevel@tonic-gate #ifndef TRUE 667c478bd9Sstevel@tonic-gate #define TRUE 1 677c478bd9Sstevel@tonic-gate #endif /* TRUE */ 687c478bd9Sstevel@tonic-gate #ifndef FALSE 697c478bd9Sstevel@tonic-gate #define FALSE 0 707c478bd9Sstevel@tonic-gate #endif /* FALSE */ 717c478bd9Sstevel@tonic-gate #endif /* CK_DISABLE_TRUE_FALSE */ 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate #undef CK_PKCS11_FUNCTION_INFO 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate #include <security/pkcs11.h> 767c478bd9Sstevel@tonic-gate 771c9bd843Sdinak /* Default salt len to generate PKCS#5 key */ 781c9bd843Sdinak #define CK_PKCS5_PBKD2_SALT_SIZE (16UL) 791c9bd843Sdinak 801c9bd843Sdinak /* Default number of iterations to generate PKCS#5 key */ 811c9bd843Sdinak #define CK_PKCS5_PBKD2_ITERATIONS (1000UL) 821c9bd843Sdinak 837c478bd9Sstevel@tonic-gate /* Solaris specific functions */ 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate #include <stdlib.h> 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate /* 88*17e2ff97Sdinak * pkcs11_GetCriteriaSession will initialize the framework and do all 89*17e2ff97Sdinak * the necessary work of calling C_GetSlotList(), C_GetMechanismInfo() 90*17e2ff97Sdinak * C_OpenSession() to create a session that meets all the criteria in 91*17e2ff97Sdinak * the given function pointer. 92*17e2ff97Sdinak */ 93*17e2ff97Sdinak CK_RV pkcs11_GetCriteriaSession( 94*17e2ff97Sdinak boolean_t (*criteria)(CK_SLOT_ID slot_id, void *args, CK_RV *rv), 95*17e2ff97Sdinak void *args, CK_SESSION_HANDLE_PTR hSession); 96*17e2ff97Sdinak 97*17e2ff97Sdinak /* 987c478bd9Sstevel@tonic-gate * SUNW_C_GetMechSession will initialize the framework and do all 997c478bd9Sstevel@tonic-gate * the necessary PKCS#11 calls to create a session capable of 1007c478bd9Sstevel@tonic-gate * providing operations on the requested mechanism 1017c478bd9Sstevel@tonic-gate */ 1027c478bd9Sstevel@tonic-gate CK_RV SUNW_C_GetMechSession(CK_MECHANISM_TYPE mech, 1037c478bd9Sstevel@tonic-gate CK_SESSION_HANDLE_PTR hSession); 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate /* 1067c478bd9Sstevel@tonic-gate * SUNW_C_KeyToObject will create a secret key object for the given 1077c478bd9Sstevel@tonic-gate * mechanism from the rawkey data. 1087c478bd9Sstevel@tonic-gate */ 1097c478bd9Sstevel@tonic-gate CK_RV SUNW_C_KeyToObject(CK_SESSION_HANDLE hSession, 1107c478bd9Sstevel@tonic-gate CK_MECHANISM_TYPE mech, const void *rawkey, size_t rawkey_len, 1117c478bd9Sstevel@tonic-gate CK_OBJECT_HANDLE_PTR obj); 1127c478bd9Sstevel@tonic-gate 1131c9bd843Sdinak /* 1141c9bd843Sdinak * pkcs11_PasswdToPBKD2Object will create a secret key from the given string 1151c9bd843Sdinak * (e.g. passphrase) using PKCS#5 Password-Based Key Derivation Function 2 1161c9bd843Sdinak * (PBKD2). 1171c9bd843Sdinak */ 1181c9bd843Sdinak CK_RV 1191c9bd843Sdinak pkcs11_PasswdToPBKD2Object(CK_SESSION_HANDLE hSession, char *passphrase, 1201c9bd843Sdinak size_t passphrase_len, void *salt, size_t salt_len, CK_ULONG iterations, 1211c9bd843Sdinak CK_KEY_TYPE key_type, CK_ULONG key_len, CK_FLAGS key_flags, 1221c9bd843Sdinak CK_OBJECT_HANDLE_PTR obj); 1231c9bd843Sdinak 1241c9bd843Sdinak /* 1251c9bd843Sdinak * pkcs11_ObjectToKey gets the rawkey data from a secret key object. 1261c9bd843Sdinak * The caller is responsible to free the allocated rawkey data. 1271c9bd843Sdinak */ 1281c9bd843Sdinak CK_RV 1291c9bd843Sdinak pkcs11_ObjectToKey(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE obj, 1301c9bd843Sdinak void **rawkey, size_t *rawkey_len, boolean_t destroy_obj); 1311c9bd843Sdinak 1321c9bd843Sdinak /* 1331c9bd843Sdinak * pkcs11_PasswdToKey will create PKCS#5 PBKD2 rawkey data from the 1341c9bd843Sdinak * given passphrase. The caller is responsible to free the allocated 1351c9bd843Sdinak * rawkey data. 1361c9bd843Sdinak */ 1371c9bd843Sdinak CK_RV 1381c9bd843Sdinak pkcs11_PasswdToKey(CK_SESSION_HANDLE hSession, char *passphrase, 1391c9bd843Sdinak size_t passphrase_len, void *salt, size_t salt_len, CK_KEY_TYPE key_type, 1401c9bd843Sdinak CK_ULONG key_len, void **rawkey, size_t *rawkey_len); 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1437c478bd9Sstevel@tonic-gate } 1447c478bd9Sstevel@tonic-gate #endif 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate #endif /* _CRYPTOKI_H */ 147