xref: /titanic_44/usr/src/lib/pkcs11/pkcs11_kernel/common/kernelGlobal.h (revision 2ec7cc7fc084163eaed884efee9bbd322cc8951b)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _KERNELGLOBAL_H
27 #define	_KERNELGLOBAL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/crypto/common.h>
36 #include <security/cryptoki.h>
37 #include <security/pkcs11t.h>
38 #include "kernelObject.h"
39 
40 typedef struct kmh_elem {
41 	CK_MECHANISM_TYPE type;
42 	crypto_mech_type_t kmech;	/* kCF mech number */
43 	struct kmh_elem *knext;		/* Next in hash chain */
44 } kmh_elem_t;
45 
46 extern kmh_elem_t **kernel_mechhash;
47 extern boolean_t kernel_initialized;
48 extern int kernel_fd;
49 
50 #define	KMECH_HASHTABLE_SIZE	67
51 
52 #define	CRYPTO_DEVICE		"/dev/crypto"
53 
54 /* CK_INFO: Information about cryptoki */
55 #define	CRYPTOKI_VERSION_MAJOR	2
56 #define	CRYPTOKI_VERSION_MINOR	20
57 #define	MANUFACTURER_ID		"Sun Microsystems, Inc.          "
58 #define	LIBRARY_DESCRIPTION	"Sun Crypto pkcs11_kernel        "
59 #define	LIBRARY_VERSION_MAJOR	1
60 #define	LIBRARY_VERSION_MINOR	1
61 
62 
63 /* CK_SLOT_INFO: Information about our slot */
64 #define	SLOT_DESCRIPTION	"Sun Crypto pkcs11_kernel        " \
65 				"                                "
66 #define	HARDWARE_VERSION_MAJOR	0
67 #define	HARDWARE_VERSION_MINOR	0
68 #define	FIRMWARE_VERSION_MAJOR	0
69 #define	FIRMWARE_VERSION_MINOR	0
70 
71 #define	INPLACE_MECHANISM(m)	((m) == CKM_DES_ECB || (m) == CKM_DES_CBC || \
72 	(m) == CKM_DES3_ECB || (m) == CKM_DES3_CBC || (m) == CKM_AES_ECB || \
73 	(m) == CKM_AES_CBC || (m) == CKM_RC4 || (m) == CKM_BLOWFISH_CBC)
74 
75 CK_RV crypto2pkcs11_error_number(uint_t);
76 CK_RV kernel_mech(CK_MECHANISM_TYPE, crypto_mech_type_t *);
77 unsigned char *get_symmetric_key_value(kernel_object_t *);
78 CK_RV get_rsa_public_key(kernel_object_t *, crypto_key_t *);
79 CK_RV get_rsa_private_key(kernel_object_t *, crypto_key_t *);
80 CK_RV get_dsa_public_key(kernel_object_t *, crypto_key_t *);
81 CK_RV get_dsa_private_key(kernel_object_t *, crypto_key_t *);
82 CK_RV get_ec_public_key(kernel_object_t *, crypto_key_t *);
83 CK_RV get_ec_private_key(kernel_object_t *, crypto_key_t *);
84 void free_key_attributes(crypto_key_t *);
85 void get_ulong_attr_from_template(CK_ULONG *, CK_ATTRIBUTE_PTR);
86 CK_RV process_object_attributes(CK_ATTRIBUTE_PTR, CK_ULONG, caddr_t *,
87     CK_BBOOL *);
88 CK_RV get_object_attributes(CK_ATTRIBUTE_PTR, CK_ULONG, caddr_t);
89 void free_object_attributes(caddr_t, CK_ULONG);
90 CK_RV get_cka_private_value(kernel_session_t *, crypto_object_id_t,
91     CK_BBOOL *);
92 CK_RV process_found_objects(kernel_session_t *, CK_OBJECT_HANDLE *,
93     CK_ULONG *, crypto_object_find_update_t);
94 CK_RV get_mechanism_info(kernel_slot_t *, CK_MECHANISM_TYPE,
95     CK_MECHANISM_INFO_PTR, uint32_t *);
96 CK_RV kernel_decrypt_init(kernel_session_t *, kernel_object_t *,
97     CK_MECHANISM_PTR);
98 CK_RV kernel_decrypt(kernel_session_t *, CK_BYTE_PTR, CK_ULONG, CK_BYTE_PTR,
99     CK_ULONG_PTR);
100 CK_RV kernel_add_extra_attr(CK_ATTRIBUTE_PTR, kernel_object_t *);
101 
102 #ifdef	__cplusplus
103 }
104 #endif
105 
106 #endif /* _KERNELGLOBAL_H */
107