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 5*1c9bd843Sdinak * Common Development and Distribution License (the "License"). 6*1c9bd843Sdinak * 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*1c9bd843Sdinak * Copyright 2007 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 77*1c9bd843Sdinak /* Default salt len to generate PKCS#5 key */ 78*1c9bd843Sdinak #define CK_PKCS5_PBKD2_SALT_SIZE (16UL) 79*1c9bd843Sdinak 80*1c9bd843Sdinak /* Default number of iterations to generate PKCS#5 key */ 81*1c9bd843Sdinak #define CK_PKCS5_PBKD2_ITERATIONS (1000UL) 82*1c9bd843Sdinak 837c478bd9Sstevel@tonic-gate /* Solaris specific functions */ 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate #include <stdlib.h> 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate /* 887c478bd9Sstevel@tonic-gate * SUNW_C_GetMechSession will initialize the framework and do all 897c478bd9Sstevel@tonic-gate * the necessary PKCS#11 calls to create a session capable of 907c478bd9Sstevel@tonic-gate * providing operations on the requested mechanism 917c478bd9Sstevel@tonic-gate */ 927c478bd9Sstevel@tonic-gate CK_RV SUNW_C_GetMechSession(CK_MECHANISM_TYPE mech, 937c478bd9Sstevel@tonic-gate CK_SESSION_HANDLE_PTR hSession); 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate /* 967c478bd9Sstevel@tonic-gate * SUNW_C_KeyToObject will create a secret key object for the given 977c478bd9Sstevel@tonic-gate * mechanism from the rawkey data. 987c478bd9Sstevel@tonic-gate */ 997c478bd9Sstevel@tonic-gate CK_RV SUNW_C_KeyToObject(CK_SESSION_HANDLE hSession, 1007c478bd9Sstevel@tonic-gate CK_MECHANISM_TYPE mech, const void *rawkey, size_t rawkey_len, 1017c478bd9Sstevel@tonic-gate CK_OBJECT_HANDLE_PTR obj); 1027c478bd9Sstevel@tonic-gate 103*1c9bd843Sdinak /* 104*1c9bd843Sdinak * pkcs11_PasswdToPBKD2Object will create a secret key from the given string 105*1c9bd843Sdinak * (e.g. passphrase) using PKCS#5 Password-Based Key Derivation Function 2 106*1c9bd843Sdinak * (PBKD2). 107*1c9bd843Sdinak */ 108*1c9bd843Sdinak CK_RV 109*1c9bd843Sdinak pkcs11_PasswdToPBKD2Object(CK_SESSION_HANDLE hSession, char *passphrase, 110*1c9bd843Sdinak size_t passphrase_len, void *salt, size_t salt_len, CK_ULONG iterations, 111*1c9bd843Sdinak CK_KEY_TYPE key_type, CK_ULONG key_len, CK_FLAGS key_flags, 112*1c9bd843Sdinak CK_OBJECT_HANDLE_PTR obj); 113*1c9bd843Sdinak 114*1c9bd843Sdinak /* 115*1c9bd843Sdinak * pkcs11_ObjectToKey gets the rawkey data from a secret key object. 116*1c9bd843Sdinak * The caller is responsible to free the allocated rawkey data. 117*1c9bd843Sdinak */ 118*1c9bd843Sdinak CK_RV 119*1c9bd843Sdinak pkcs11_ObjectToKey(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE obj, 120*1c9bd843Sdinak void **rawkey, size_t *rawkey_len, boolean_t destroy_obj); 121*1c9bd843Sdinak 122*1c9bd843Sdinak /* 123*1c9bd843Sdinak * pkcs11_PasswdToKey will create PKCS#5 PBKD2 rawkey data from the 124*1c9bd843Sdinak * given passphrase. The caller is responsible to free the allocated 125*1c9bd843Sdinak * rawkey data. 126*1c9bd843Sdinak */ 127*1c9bd843Sdinak CK_RV 128*1c9bd843Sdinak pkcs11_PasswdToKey(CK_SESSION_HANDLE hSession, char *passphrase, 129*1c9bd843Sdinak size_t passphrase_len, void *salt, size_t salt_len, CK_KEY_TYPE key_type, 130*1c9bd843Sdinak CK_ULONG key_len, void **rawkey, size_t *rawkey_len); 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1337c478bd9Sstevel@tonic-gate } 1347c478bd9Sstevel@tonic-gate #endif 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate #endif /* _CRYPTOKI_H */ 137