10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51937Sizick * Common Development and Distribution License (the "License"). 61937Sizick * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*9127SDina.Nimeh@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SOFTKEYSTORE_H 270Sstevel@tonic-gate #define _SOFTKEYSTORE_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #ifdef __cplusplus 300Sstevel@tonic-gate extern "C" { 310Sstevel@tonic-gate #endif 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <sys/types.h> 340Sstevel@tonic-gate #include <security/pkcs11t.h> 350Sstevel@tonic-gate 360Sstevel@tonic-gate #define PBKD2_SALT_SIZE 16 370Sstevel@tonic-gate #define PBKD2_ITERATIONS (1000) 381309Sizick #define PWD_BUFFER_SIZE 1024 390Sstevel@tonic-gate 400Sstevel@tonic-gate /* 410Sstevel@tonic-gate * The following structure is the object header 420Sstevel@tonic-gate * in the keystore. 430Sstevel@tonic-gate */ 440Sstevel@tonic-gate typedef struct ks_obj_hdr { 450Sstevel@tonic-gate uint64_t class; 460Sstevel@tonic-gate uint64_t key_type; 470Sstevel@tonic-gate uint64_t cert_type; 480Sstevel@tonic-gate uint64_t bool_attr_mask; 490Sstevel@tonic-gate uint64_t mechanism; 500Sstevel@tonic-gate uchar_t object_type; 510Sstevel@tonic-gate 520Sstevel@tonic-gate /* Extra non-boolean attribute list */ 530Sstevel@tonic-gate int num_attrs; 540Sstevel@tonic-gate } ks_obj_hdr_t; 550Sstevel@tonic-gate 560Sstevel@tonic-gate /* 570Sstevel@tonic-gate * This structure contains the individual attribute 580Sstevel@tonic-gate * (from extra_attrlistp) in the keystore. 590Sstevel@tonic-gate */ 600Sstevel@tonic-gate typedef struct ks_attr_hdr { 610Sstevel@tonic-gate uint64_t type; 620Sstevel@tonic-gate uint64_t ulValueLen; 630Sstevel@tonic-gate } ks_attr_hdr_t; 640Sstevel@tonic-gate 650Sstevel@tonic-gate #define ROUNDUP(x, y) roundup(x, y) /* defined in sys/sysmacros.h */ 660Sstevel@tonic-gate 670Sstevel@tonic-gate #ifdef _LITTLE_ENDIAN 680Sstevel@tonic-gate #define SWAP16(value) \ 690Sstevel@tonic-gate ((((value) & 0xff) << 8) | ((value) >> 8)) 700Sstevel@tonic-gate 710Sstevel@tonic-gate #define SWAP32(value) \ 720Sstevel@tonic-gate (((uint32_t)SWAP16((uint16_t)((value) & 0xffff)) << 16) | \ 730Sstevel@tonic-gate (uint32_t)SWAP16((uint16_t)((value) >> 16))) 740Sstevel@tonic-gate 750Sstevel@tonic-gate #define SWAP64(value) \ 760Sstevel@tonic-gate (((uint64_t)SWAP32((uint32_t)((value) & 0xffffffff)) \ 770Sstevel@tonic-gate << 32) | \ 780Sstevel@tonic-gate (uint64_t)SWAP32((uint32_t)((value) >> 32))) 790Sstevel@tonic-gate #else /* !_LITTLE_ENDIAN */ 800Sstevel@tonic-gate #define SWAP16(value) (value) 810Sstevel@tonic-gate #define SWAP32(value) (value) 820Sstevel@tonic-gate #define SWAP64(value) (value) 830Sstevel@tonic-gate #endif 840Sstevel@tonic-gate 850Sstevel@tonic-gate /* 860Sstevel@tonic-gate * Function Prototypes 870Sstevel@tonic-gate */ 880Sstevel@tonic-gate int soft_gen_hashed_pin(CK_UTF8CHAR_PTR pPin, char **result, char **salt); 890Sstevel@tonic-gate 900Sstevel@tonic-gate CK_RV soft_verify_pin(CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen); 910Sstevel@tonic-gate 920Sstevel@tonic-gate CK_RV soft_gen_crypt_key(uchar_t *pPIN, soft_object_t **key, 930Sstevel@tonic-gate CK_BYTE **saltdata); 940Sstevel@tonic-gate 950Sstevel@tonic-gate CK_RV soft_gen_hmac_key(uchar_t *pPIN, soft_object_t **key, CK_BYTE **saltdata); 960Sstevel@tonic-gate 970Sstevel@tonic-gate CK_RV soft_keystore_pack_obj(struct object *obj, uchar_t **ks_buf, size_t *len); 980Sstevel@tonic-gate 990Sstevel@tonic-gate CK_RV soft_keystore_unpack_obj(struct object *obj, ks_obj_t *ks_obj); 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate CK_RV soft_unpack_obj_attribute(uchar_t *buf, biginteger_t *key_dest, 1020Sstevel@tonic-gate cert_attr_t **cert_dest, ulong_t *offset, boolean_t cert); 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate ulong_t soft_pack_object_size(struct object *objp); 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate CK_RV soft_pack_object(struct object *objp, uchar_t *buf); 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate CK_RV soft_unpack_object(struct object *objp, uchar_t *buf); 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate CK_RV soft_setpin(CK_UTF8CHAR_PTR pOldPin, CK_ULONG ulOldPinLen, 1110Sstevel@tonic-gate CK_UTF8CHAR_PTR pNewPin, CK_ULONG ulNewPinLen); 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate CK_RV soft_put_object_to_keystore(struct object *objp); 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate CK_RV soft_modify_object_to_keystore(struct object *objp); 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate CK_RV soft_get_token_objects_from_keystore(ks_search_type_t type); 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate CK_RV soft_init_token_session(void); 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate void soft_destroy_token_session(void); 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate CK_RV soft_keystore_crypt(soft_object_t *key_p, uchar_t *ivec, 1240Sstevel@tonic-gate boolean_t encrypt, CK_BYTE_PTR in, CK_ULONG in_len, CK_BYTE_PTR out, 1250Sstevel@tonic-gate CK_ULONG_PTR out_len); 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate CK_RV soft_keystore_hmac(soft_object_t *key_p, boolean_t sign, 1280Sstevel@tonic-gate CK_BYTE_PTR in, CK_ULONG in_len, CK_BYTE_PTR out, CK_ULONG_PTR out_len); 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate #ifdef __cplusplus 1320Sstevel@tonic-gate } 1330Sstevel@tonic-gate #endif 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate #endif /* _SOFTKEYSTORE_H */ 136