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 2009 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#ifndef	_CRYPTO_UTIL_H
27#define	_CRYPTO_UTIL_H
28
29
30#ifdef	__cplusplus
31extern "C" {
32#endif
33
34#include <limits.h>
35#include <security/cryptoki.h>
36#include <security/pkcs11.h>
37#include <kmfapi.h>
38
39#include <sys/usb/usba/wusba_io.h>
40
41
42#define	WUSB_DEV_MAC_LENGTH		6
43#define	WUSB_CC_LABEL_LENGTH		(WUSB_DEV_MAC_LENGTH * 2 + 1)
44#define	WUSB_TYPE_LEN			16
45
46/*
47 * wusb_cc_info.
48 * Record the association information and it is
49 * saved at /etc/usb/wusbcc
50 */
51typedef	struct wusb_cc_info {
52	uint8_t			mac[WUSB_DEV_MAC_LENGTH];
53	wusb_cc_t		cc;   /* cc info */
54	char			type[WUSB_TYPE_LEN]; /* device/host path */
55	uint8_t			host; /* Host id */
56	uint16_t		dev;  /* Device id */
57	char			flag; /* Onetime/Always */
58} wusb_cc_info_t;
59
60
61/* Device state definition */
62#define	DEV_STAT_DISCONN	0x00
63#define	DEV_STAT_CONNECT	0x01
64
65/* wusbadm list structure */
66typedef	struct wusb_cc_list {
67	struct wusb_cc_list	*next;
68	wusb_cc_info_t		info;   /* cc info */
69	uint8_t			stat;	/* host or device state */
70} wusb_cc_list_t;
71
72typedef	struct wusb_device_info {
73	char			type[WUSB_TYPE_LEN];
74	uint8_t			host; /* host id */
75	uint16_t		dev;  /* device id */
76	uint8_t			stat; /* state */
77} wusb_device_info_t;
78
79/* cc generation functions */
80int	wusb_crypto_init(KMF_HANDLE_T *, CK_SESSION_HANDLE *,
81		const char *, const char *);
82void	wusb_crypto_fini(KMF_HANDLE_T);
83
84int	wusb_random(CK_SESSION_HANDLE, CK_BYTE *, size_t, CK_BYTE *, size_t);
85
86
87void	mac_to_label(uint8_t *, char *);
88
89void	print_array(const char *, CK_BYTE *, size_t);
90
91int	chk_auths(uid_t, const char *);
92#ifdef __cplusplus
93}
94#endif
95
96#endif	/* _CRYPTO_UTIL_H */
97