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 2006 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SOFTKEYSTORE_H 27 #define _SOFTKEYSTORE_H 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 #include <sys/types.h> 36 #include <security/pkcs11t.h> 37 38 #define PBKD2_SALT_SIZE 16 39 #define PBKD2_ITERATIONS (1000) 40 #define PWD_BUFFER_SIZE 1024 41 42 /* 43 * The following structure is the object header 44 * in the keystore. 45 */ 46 typedef struct ks_obj_hdr { 47 uint64_t class; 48 uint64_t key_type; 49 uint64_t cert_type; 50 uint64_t bool_attr_mask; 51 uint64_t mechanism; 52 uchar_t object_type; 53 54 /* Extra non-boolean attribute list */ 55 int num_attrs; 56 } ks_obj_hdr_t; 57 58 /* 59 * This structure contains the individual attribute 60 * (from extra_attrlistp) in the keystore. 61 */ 62 typedef struct ks_attr_hdr { 63 uint64_t type; 64 uint64_t ulValueLen; 65 } ks_attr_hdr_t; 66 67 #define ROUNDUP(x, y) roundup(x, y) /* defined in sys/sysmacros.h */ 68 69 #ifdef _LITTLE_ENDIAN 70 #define SWAP16(value) \ 71 ((((value) & 0xff) << 8) | ((value) >> 8)) 72 73 #define SWAP32(value) \ 74 (((uint32_t)SWAP16((uint16_t)((value) & 0xffff)) << 16) | \ 75 (uint32_t)SWAP16((uint16_t)((value) >> 16))) 76 77 #define SWAP64(value) \ 78 (((uint64_t)SWAP32((uint32_t)((value) & 0xffffffff)) \ 79 << 32) | \ 80 (uint64_t)SWAP32((uint32_t)((value) >> 32))) 81 #else /* !_LITTLE_ENDIAN */ 82 #define SWAP16(value) (value) 83 #define SWAP32(value) (value) 84 #define SWAP64(value) (value) 85 #endif 86 87 /* 88 * Function Prototypes 89 */ 90 CK_RV soft_gen_iv(CK_BYTE *iv); 91 92 int soft_gen_hashed_pin(CK_UTF8CHAR_PTR pPin, char **result, char **salt); 93 94 CK_RV soft_verify_pin(CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen); 95 96 CK_RV soft_gen_crypt_key(uchar_t *pPIN, soft_object_t **key, 97 CK_BYTE **saltdata); 98 99 CK_RV soft_gen_hmac_key(uchar_t *pPIN, soft_object_t **key, CK_BYTE **saltdata); 100 101 CK_RV soft_keystore_pack_obj(struct object *obj, uchar_t **ks_buf, size_t *len); 102 103 CK_RV soft_keystore_unpack_obj(struct object *obj, ks_obj_t *ks_obj); 104 105 CK_RV soft_unpack_obj_attribute(uchar_t *buf, biginteger_t *key_dest, 106 cert_attr_t **cert_dest, ulong_t *offset, boolean_t cert); 107 108 ulong_t soft_pack_object_size(struct object *objp); 109 110 CK_RV soft_pack_object(struct object *objp, uchar_t *buf); 111 112 CK_RV soft_unpack_object(struct object *objp, uchar_t *buf); 113 114 CK_RV soft_setpin(CK_UTF8CHAR_PTR pOldPin, CK_ULONG ulOldPinLen, 115 CK_UTF8CHAR_PTR pNewPin, CK_ULONG ulNewPinLen); 116 117 CK_RV soft_put_object_to_keystore(struct object *objp); 118 119 CK_RV soft_modify_object_to_keystore(struct object *objp); 120 121 CK_RV soft_get_token_objects_from_keystore(ks_search_type_t type); 122 123 CK_RV soft_init_token_session(void); 124 125 void soft_destroy_token_session(void); 126 127 CK_RV soft_keystore_crypt(soft_object_t *key_p, uchar_t *ivec, 128 boolean_t encrypt, CK_BYTE_PTR in, CK_ULONG in_len, CK_BYTE_PTR out, 129 CK_ULONG_PTR out_len); 130 131 CK_RV soft_keystore_hmac(soft_object_t *key_p, boolean_t sign, 132 CK_BYTE_PTR in, CK_ULONG in_len, CK_BYTE_PTR out, CK_ULONG_PTR out_len); 133 134 135 #ifdef __cplusplus 136 } 137 #endif 138 139 #endif /* _SOFTKEYSTORE_H */ 140