softKeystore.h revision 90e0e8c47a01eef8d256571579d8acabd7cf681c
1N/A/*
1N/A * CDDL HEADER START
1N/A *
1N/A * The contents of this file are subject to the terms of the
1N/A * Common Development and Distribution License (the "License").
1N/A * You may not use this file except in compliance with the License.
1N/A *
1N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1N/A * or http://www.opensolaris.org/os/licensing.
1N/A * See the License for the specific language governing permissions
1N/A * and limitations under the License.
1N/A *
1N/A * When distributing Covered Code, include this CDDL HEADER in each
1N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1N/A * If applicable, add the following below this CDDL HEADER, with the
1N/A * fields enclosed by brackets "[]" replaced with your own identifying
1N/A * information: Portions Copyright [yyyy] [name of copyright owner]
1N/A *
1N/A * CDDL HEADER END
1N/A */
1N/A/*
1N/A * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
1N/A * Use is subject to license terms.
1N/A */
1N/A
1N/A#ifndef _SOFTKEYSTORE_H
1N/A#define _SOFTKEYSTORE_H
1N/A
1N/A#pragma ident "%Z%%M% %I% %E% SMI"
1N/A
1N/A#ifdef __cplusplus
1N/Aextern "C" {
1N/A#endif
1N/A
1N/A#include <sys/types.h>
1N/A#include <security/pkcs11t.h>
1N/A
1N/A#define PBKD2_SALT_SIZE 16
1N/A#define PBKD2_ITERATIONS (1000)
1N/A#define PWD_BUFFER_SIZE 1024
1N/A
1N/A/*
1N/A * The following structure is the object header
1N/A * in the keystore.
1N/A */
1N/Atypedef struct ks_obj_hdr {
1N/A uint64_t class;
1N/A uint64_t key_type;
1N/A uint64_t cert_type;
1N/A uint64_t bool_attr_mask;
1N/A uint64_t mechanism;
1N/A uchar_t object_type;
1N/A
1N/A /* Extra non-boolean attribute list */
1N/A int num_attrs;
1N/A} ks_obj_hdr_t;
1N/A
1N/A/*
1N/A * This structure contains the individual attribute
1N/A * (from extra_attrlistp) in the keystore.
1N/A */
1N/Atypedef struct ks_attr_hdr {
1N/A uint64_t type;
1N/A uint64_t ulValueLen;
1N/A} ks_attr_hdr_t;
1N/A
1N/A#define ROUNDUP(x, y) roundup(x, y) /* defined in sys/sysmacros.h */
1N/A
1N/A#ifdef _LITTLE_ENDIAN
1N/A#define SWAP16(value) \
1N/A ((((value) & 0xff) << 8) | ((value) >> 8))
1N/A
1N/A#define SWAP32(value) \
1N/A (((uint32_t)SWAP16((uint16_t)((value) & 0xffff)) << 16) | \
1N/A (uint32_t)SWAP16((uint16_t)((value) >> 16)))
1N/A
1N/A#define SWAP64(value) \
1N/A (((uint64_t)SWAP32((uint32_t)((value) & 0xffffffff)) \
1N/A << 32) | \
1N/A (uint64_t)SWAP32((uint32_t)((value) >> 32)))
1N/A#else /* !_LITTLE_ENDIAN */
1N/A#define SWAP16(value) (value)
1N/A#define SWAP32(value) (value)
1N/A#define SWAP64(value) (value)
1N/A#endif
1N/A
1N/A/*
1N/A * Function Prototypes
1N/A */
1N/ACK_RV soft_gen_iv(CK_BYTE *iv);
1N/A
1N/Aint soft_gen_hashed_pin(CK_UTF8CHAR_PTR pPin, char **result, char **salt);
1N/A
1N/ACK_RV soft_verify_pin(CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen);
1N/A
1N/ACK_RV soft_gen_crypt_key(uchar_t *pPIN, soft_object_t **key,
1N/A CK_BYTE **saltdata);
1N/A
1N/ACK_RV soft_gen_hmac_key(uchar_t *pPIN, soft_object_t **key, CK_BYTE **saltdata);
1N/A
1N/ACK_RV soft_keystore_pack_obj(struct object *obj, uchar_t **ks_buf, size_t *len);
1N/A
1N/ACK_RV soft_keystore_unpack_obj(struct object *obj, ks_obj_t *ks_obj);
1N/A
1N/ACK_RV soft_unpack_obj_attribute(uchar_t *buf, biginteger_t *key_dest,
1N/A cert_attr_t **cert_dest, ulong_t *offset, boolean_t cert);
1N/A
1N/Aulong_t soft_pack_object_size(struct object *objp);
1N/A
1N/ACK_RV soft_pack_object(struct object *objp, uchar_t *buf);
1N/A
1N/ACK_RV soft_unpack_object(struct object *objp, uchar_t *buf);
1N/A
1N/ACK_RV soft_setpin(CK_UTF8CHAR_PTR pOldPin, CK_ULONG ulOldPinLen,
1N/A CK_UTF8CHAR_PTR pNewPin, CK_ULONG ulNewPinLen);
1N/A
1N/ACK_RV soft_put_object_to_keystore(struct object *objp);
1N/A
1N/ACK_RV soft_modify_object_to_keystore(struct object *objp);
1N/A
1N/ACK_RV soft_get_token_objects_from_keystore(ks_search_type_t type);
1N/A
1N/ACK_RV soft_init_token_session(void);
1N/A
1N/Avoid soft_destroy_token_session(void);
1N/A
1N/ACK_RV soft_keystore_crypt(soft_object_t *key_p, uchar_t *ivec,
1N/A boolean_t encrypt, CK_BYTE_PTR in, CK_ULONG in_len, CK_BYTE_PTR out,
1N/A CK_ULONG_PTR out_len);
1N/A
1N/ACK_RV soft_keystore_hmac(soft_object_t *key_p, boolean_t sign,
1N/A CK_BYTE_PTR in, CK_ULONG in_len, CK_BYTE_PTR out, CK_ULONG_PTR out_len);
1N/A
1N/A
1N/A#ifdef __cplusplus
1N/A}
1N/A#endif
1N/A
1N/A#endif /* _SOFTKEYSTORE_H */
1N/A