8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / pkcs11 / pkcs11_softtoken / common / softKeystore.h
blobaab64ac40516d83681f77b0e700dabccf43d42c8
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #ifndef _SOFTKEYSTORE_H
27 #define _SOFTKEYSTORE_H
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
33 #include <sys/types.h>
34 #include <security/pkcs11t.h>
36 #define PBKD2_SALT_SIZE 16
37 #define PBKD2_ITERATIONS (1000)
38 #define PWD_BUFFER_SIZE 1024
41 * The following structure is the object header
42 * in the keystore.
44 typedef struct ks_obj_hdr {
45 uint64_t class;
46 uint64_t key_type;
47 uint64_t cert_type;
48 uint64_t bool_attr_mask;
49 uint64_t mechanism;
50 uchar_t object_type;
52 /* Extra non-boolean attribute list */
53 int num_attrs;
54 } ks_obj_hdr_t;
57 * This structure contains the individual attribute
58 * (from extra_attrlistp) in the keystore.
60 typedef struct ks_attr_hdr {
61 uint64_t type;
62 uint64_t ulValueLen;
63 } ks_attr_hdr_t;
65 #define ROUNDUP(x, y) roundup(x, y) /* defined in sys/sysmacros.h */
67 #ifdef _LITTLE_ENDIAN
68 #define SWAP16(value) \
69 ((((value) & 0xff) << 8) | ((value) >> 8))
71 #define SWAP32(value) \
72 (((uint32_t)SWAP16((uint16_t)((value) & 0xffff)) << 16) | \
73 (uint32_t)SWAP16((uint16_t)((value) >> 16)))
75 #define SWAP64(value) \
76 (((uint64_t)SWAP32((uint32_t)((value) & 0xffffffff)) \
77 << 32) | \
78 (uint64_t)SWAP32((uint32_t)((value) >> 32)))
79 #else /* !_LITTLE_ENDIAN */
80 #define SWAP16(value) (value)
81 #define SWAP32(value) (value)
82 #define SWAP64(value) (value)
83 #endif
86 * Function Prototypes
88 int soft_gen_hashed_pin(CK_UTF8CHAR_PTR pPin, char **result, char **salt);
90 CK_RV soft_verify_pin(CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen);
92 CK_RV soft_gen_crypt_key(uchar_t *pPIN, soft_object_t **key,
93 CK_BYTE **saltdata);
95 CK_RV soft_gen_hmac_key(uchar_t *pPIN, soft_object_t **key, CK_BYTE **saltdata);
97 CK_RV soft_keystore_pack_obj(struct object *obj, uchar_t **ks_buf, size_t *len);
99 CK_RV soft_keystore_unpack_obj(struct object *obj, ks_obj_t *ks_obj);
101 CK_RV soft_unpack_obj_attribute(uchar_t *buf, biginteger_t *key_dest,
102 cert_attr_t **cert_dest, ulong_t *offset, boolean_t cert);
104 ulong_t soft_pack_object_size(struct object *objp);
106 CK_RV soft_pack_object(struct object *objp, uchar_t *buf);
108 CK_RV soft_unpack_object(struct object *objp, uchar_t *buf);
110 CK_RV soft_setpin(CK_UTF8CHAR_PTR pOldPin, CK_ULONG ulOldPinLen,
111 CK_UTF8CHAR_PTR pNewPin, CK_ULONG ulNewPinLen);
113 CK_RV soft_put_object_to_keystore(struct object *objp);
115 CK_RV soft_modify_object_to_keystore(struct object *objp);
117 CK_RV soft_get_token_objects_from_keystore(ks_search_type_t type);
119 CK_RV soft_init_token_session(void);
121 void soft_destroy_token_session(void);
123 CK_RV soft_keystore_crypt(soft_object_t *key_p, uchar_t *ivec,
124 boolean_t encrypt, CK_BYTE_PTR in, CK_ULONG in_len, CK_BYTE_PTR out,
125 CK_ULONG_PTR out_len);
127 CK_RV soft_keystore_hmac(soft_object_t *key_p, boolean_t sign,
128 CK_BYTE_PTR in, CK_ULONG in_len, CK_BYTE_PTR out, CK_ULONG_PTR out_len);
131 #ifdef __cplusplus
133 #endif
135 #endif /* _SOFTKEYSTORE_H */