xref: /onnv-gate/usr/src/cmd/mdb/common/modules/crypto/common.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate /*
30*0Sstevel@tonic-gate  * mdb dcmds for selected structures from
31*0Sstevel@tonic-gate  * usr/src/uts/common/sys/crypto/common.h
32*0Sstevel@tonic-gate  */
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate #include <sys/mdb_modapi.h>
35*0Sstevel@tonic-gate #include <sys/modctl.h>
36*0Sstevel@tonic-gate #include <sys/types.h>
37*0Sstevel@tonic-gate #include <sys/crypto/api.h>
38*0Sstevel@tonic-gate #include <sys/crypto/common.h>
39*0Sstevel@tonic-gate #include <sys/crypto/spi.h>
40*0Sstevel@tonic-gate #include <sys/crypto/impl.h>
41*0Sstevel@tonic-gate #include "crypto_cmds.h"
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate /*ARGSUSED*/
44*0Sstevel@tonic-gate int
crypto_mechanism(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)45*0Sstevel@tonic-gate crypto_mechanism(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
46*0Sstevel@tonic-gate {
47*0Sstevel@tonic-gate 	crypto_mechanism_t mch;
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
50*0Sstevel@tonic-gate 		return (DCMD_USAGE);
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate 	if (mdb_vread(&mch, sizeof (crypto_mechanism_t), addr) == -1) {
53*0Sstevel@tonic-gate 		mdb_warn("cannot read %p", addr);
54*0Sstevel@tonic-gate 		return (DCMD_ERR);
55*0Sstevel@tonic-gate 	}
56*0Sstevel@tonic-gate 	/* XXX a future RFE will interpret cm_type */
57*0Sstevel@tonic-gate 	mdb_printf("cm_type\t%ll#x\n", mch.cm_type);
58*0Sstevel@tonic-gate 	mdb_printf("cm_param\t%p\n", mch.cm_param);
59*0Sstevel@tonic-gate 	mdb_printf("cm_param_len\t%u\n", mch.cm_param_len);
60*0Sstevel@tonic-gate 	return (DCMD_OK);
61*0Sstevel@tonic-gate }
62*0Sstevel@tonic-gate 
63*0Sstevel@tonic-gate /*ARGSUSED*/
64*0Sstevel@tonic-gate static void
iovec_prt(iovec_t * addr)65*0Sstevel@tonic-gate iovec_prt(iovec_t *addr)
66*0Sstevel@tonic-gate {
67*0Sstevel@tonic-gate 	mdb_printf("iov_base\t%p\n", addr->iov_base);
68*0Sstevel@tonic-gate 	mdb_printf("iov_len\t\t%d\n", addr->iov_len);
69*0Sstevel@tonic-gate }
70*0Sstevel@tonic-gate 
71*0Sstevel@tonic-gate /*ARGSUSED*/
72*0Sstevel@tonic-gate static void
uio_prt(uio_t * addr)73*0Sstevel@tonic-gate uio_prt(uio_t *addr)
74*0Sstevel@tonic-gate {
75*0Sstevel@tonic-gate 	char *segstrings[] = {
76*0Sstevel@tonic-gate 		"UIO_USERSPACE",
77*0Sstevel@tonic-gate 		"UIO_SYSSPACE",
78*0Sstevel@tonic-gate 		"UIO_USERISPACE"
79*0Sstevel@tonic-gate 	};
80*0Sstevel@tonic-gate 	iovec_t iov;
81*0Sstevel@tonic-gate 	uio_t uio;
82*0Sstevel@tonic-gate 	int i;
83*0Sstevel@tonic-gate 
84*0Sstevel@tonic-gate 	mdb_printf("uio\t%p\n", addr);
85*0Sstevel@tonic-gate 	if (mdb_vread(&uio, sizeof (uio_t), (uintptr_t)addr)
86*0Sstevel@tonic-gate 		== -1) {
87*0Sstevel@tonic-gate 		mdb_warn("uio_prt: could not read uio");
88*0Sstevel@tonic-gate 	}
89*0Sstevel@tonic-gate 	mdb_inc_indent(4);
90*0Sstevel@tonic-gate 	for (i = 0; i < uio.uio_iovcnt; i++) {
91*0Sstevel@tonic-gate 		if (mdb_vread(&iov, sizeof (iovec_t),
92*0Sstevel@tonic-gate 		    (uintptr_t)(uio.uio_iov +i))
93*0Sstevel@tonic-gate 			== -1) {
94*0Sstevel@tonic-gate 			mdb_printf("uio_iov\t?????");
95*0Sstevel@tonic-gate 			mdb_warn("uio_prt: could not read uio_iov[%s]", i);
96*0Sstevel@tonic-gate 		} else
97*0Sstevel@tonic-gate 		    iovec_prt(&iov);
98*0Sstevel@tonic-gate 	}
99*0Sstevel@tonic-gate 	mdb_dec_indent(4);
100*0Sstevel@tonic-gate 	mdb_printf("uio_iovcnt\t%d\n", uio.uio_iovcnt);
101*0Sstevel@tonic-gate 	mdb_printf("uio_offset\t%lld\n", uio.uio_offset);
102*0Sstevel@tonic-gate 	mdb_printf("uio_segflg\t%s", segstrings[uio.uio_segflg]);
103*0Sstevel@tonic-gate 	mdb_printf("uio_fmode\t0%o", (int)uio.uio_fmode);
104*0Sstevel@tonic-gate 	mdb_printf("uio_limit\t%lld", uio.uio_limit);
105*0Sstevel@tonic-gate 	mdb_printf("uio_resid\t%ld", uio.uio_resid);
106*0Sstevel@tonic-gate }
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate static char *cdstrings[] = {
109*0Sstevel@tonic-gate 	"INVALID FORMAT",
110*0Sstevel@tonic-gate 	"CRYPTO_DATA_RAW",
111*0Sstevel@tonic-gate 	"CRYPTO_DATA_UIO",
112*0Sstevel@tonic-gate 	"CRYPTO_DATA_MBLK"
113*0Sstevel@tonic-gate };
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate /*
116*0Sstevel@tonic-gate  * Routine to print either of two structrually identical sub-structures --
117*0Sstevel@tonic-gate  * with different naming conventions.  Might be changed if we decide
118*0Sstevel@tonic-gate  * to merge the two.  They are the cdu union from crypto_data_t and
119*0Sstevel@tonic-gate  * the one from crypto_dual_data_t.
120*0Sstevel@tonic-gate  */
121*0Sstevel@tonic-gate 
122*0Sstevel@tonic-gate typedef union crypto_data_union {
123*0Sstevel@tonic-gate 	iovec_t	cdu_raw;		/* Raw format */
124*0Sstevel@tonic-gate 	uio_t	*cdu_uio;		/* uio scatter-gather format */
125*0Sstevel@tonic-gate 	mblk_t	*cdu_mp;		/* The mblk chain */
126*0Sstevel@tonic-gate } crypto_data_union_t;
127*0Sstevel@tonic-gate 
128*0Sstevel@tonic-gate /*ARGSUSED*/
129*0Sstevel@tonic-gate static void
prt_cdu(crypto_data_union_t * cdu,int format,const char * prefix)130*0Sstevel@tonic-gate prt_cdu(crypto_data_union_t *cdu, int format, const char *prefix)
131*0Sstevel@tonic-gate {
132*0Sstevel@tonic-gate 
133*0Sstevel@tonic-gate 	switch (format) {
134*0Sstevel@tonic-gate 		case CRYPTO_DATA_RAW:
135*0Sstevel@tonic-gate 		    mdb_printf("%s_raw:\n", prefix);
136*0Sstevel@tonic-gate 		    mdb_inc_indent(4);
137*0Sstevel@tonic-gate 		    iovec_prt(&cdu->cdu_raw);
138*0Sstevel@tonic-gate 		    mdb_dec_indent(4);
139*0Sstevel@tonic-gate 		    break;
140*0Sstevel@tonic-gate 
141*0Sstevel@tonic-gate 		case CRYPTO_DATA_UIO:
142*0Sstevel@tonic-gate 		    mdb_printf("%s_uio:\n", prefix);
143*0Sstevel@tonic-gate 		    mdb_inc_indent(4);
144*0Sstevel@tonic-gate 		    uio_prt(cdu->cdu_uio);
145*0Sstevel@tonic-gate 		    mdb_dec_indent(4);
146*0Sstevel@tonic-gate 		    break;
147*0Sstevel@tonic-gate 
148*0Sstevel@tonic-gate 		case CRYPTO_DATA_MBLK:
149*0Sstevel@tonic-gate 		    mdb_printf("%s_mp:\t\t%p\n", prefix, cdu->cdu_mp);
150*0Sstevel@tonic-gate 		    break;
151*0Sstevel@tonic-gate 
152*0Sstevel@tonic-gate 		default:
153*0Sstevel@tonic-gate 		    mdb_printf("cm_format\t??????\n");
154*0Sstevel@tonic-gate 		    break;
155*0Sstevel@tonic-gate 	}
156*0Sstevel@tonic-gate }
157*0Sstevel@tonic-gate 
158*0Sstevel@tonic-gate /*ARGSUSED*/
159*0Sstevel@tonic-gate int
crypto_data(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)160*0Sstevel@tonic-gate crypto_data(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
161*0Sstevel@tonic-gate {
162*0Sstevel@tonic-gate 	crypto_data_t data;
163*0Sstevel@tonic-gate 
164*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
165*0Sstevel@tonic-gate 		return (DCMD_USAGE);
166*0Sstevel@tonic-gate 
167*0Sstevel@tonic-gate 	if (mdb_vread(&data, sizeof (crypto_data_t), addr) == -1) {
168*0Sstevel@tonic-gate 		mdb_warn("cannot read %p", addr);
169*0Sstevel@tonic-gate 		return (DCMD_ERR);
170*0Sstevel@tonic-gate 	}
171*0Sstevel@tonic-gate 	if ((data.cd_format >= CRYPTO_DATA_RAW) &&
172*0Sstevel@tonic-gate 	    (data.cd_format <= CRYPTO_DATA_MBLK))
173*0Sstevel@tonic-gate 		mdb_printf("cm_format\t%s\n", cdstrings[data.cd_format]);
174*0Sstevel@tonic-gate 	else
175*0Sstevel@tonic-gate 		mdb_printf("bad cm_format\t%d\n", data.cd_format);
176*0Sstevel@tonic-gate 	mdb_printf("cm_offset\t%ld\n", data.cd_offset);
177*0Sstevel@tonic-gate 	mdb_printf("cm_length\t%ld\n", data.cd_length);
178*0Sstevel@tonic-gate 	mdb_printf("cm_miscdata\t%p\n", data.cd_miscdata);
179*0Sstevel@tonic-gate 	mdb_inc_indent(4);
180*0Sstevel@tonic-gate 	prt_cdu((crypto_data_union_t *)&data.cdu, data.cd_format, "cdu");
181*0Sstevel@tonic-gate 	mdb_dec_indent(4);
182*0Sstevel@tonic-gate 	return (DCMD_OK);
183*0Sstevel@tonic-gate }
184*0Sstevel@tonic-gate 
185*0Sstevel@tonic-gate /*ARGSUSED*/
186*0Sstevel@tonic-gate int
crypto_dual_data(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)187*0Sstevel@tonic-gate crypto_dual_data(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
188*0Sstevel@tonic-gate {
189*0Sstevel@tonic-gate 	crypto_dual_data_t ddata;
190*0Sstevel@tonic-gate 
191*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
192*0Sstevel@tonic-gate 		return (DCMD_USAGE);
193*0Sstevel@tonic-gate 
194*0Sstevel@tonic-gate 	if (mdb_vread(&ddata, sizeof (crypto_dual_data_t), addr) == -1) {
195*0Sstevel@tonic-gate 		mdb_warn("cannot read %p", addr);
196*0Sstevel@tonic-gate 		return (DCMD_ERR);
197*0Sstevel@tonic-gate 	}
198*0Sstevel@tonic-gate 	if ((ddata.dd_format > CRYPTO_DATA_RAW) &&
199*0Sstevel@tonic-gate 	    (ddata.dd_format <= CRYPTO_DATA_MBLK))
200*0Sstevel@tonic-gate 		mdb_printf("dd_format\t%s\n", cdstrings[ddata.dd_format]);
201*0Sstevel@tonic-gate 	else
202*0Sstevel@tonic-gate 		mdb_printf("bad dd_format\t%d\n", ddata.dd_format);
203*0Sstevel@tonic-gate 	mdb_printf("dd_offset1\t%ld\n", ddata.dd_offset1);
204*0Sstevel@tonic-gate 	mdb_printf("dd_len1\t%ld\n", ddata.dd_len1);
205*0Sstevel@tonic-gate 	mdb_printf("dd_offset2\t%ld\n", ddata.dd_offset2);
206*0Sstevel@tonic-gate 	mdb_printf("dd_len2\t%ld\n", ddata.dd_len2);
207*0Sstevel@tonic-gate 	mdb_printf("dd_miscdata\t%p\n", ddata.dd_miscdata);
208*0Sstevel@tonic-gate 	mdb_printf("cdu:\n");
209*0Sstevel@tonic-gate 	mdb_inc_indent(4);
210*0Sstevel@tonic-gate 	prt_cdu((crypto_data_union_t *)&ddata.dd_data.cdu, ddata.dd_format,
211*0Sstevel@tonic-gate 	    "ddu");
212*0Sstevel@tonic-gate 	mdb_dec_indent(4);
213*0Sstevel@tonic-gate 	return (DCMD_OK);
214*0Sstevel@tonic-gate }
215*0Sstevel@tonic-gate 
216*0Sstevel@tonic-gate 
217*0Sstevel@tonic-gate /*ARGSUSED*/
218*0Sstevel@tonic-gate int
crypto_key(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)219*0Sstevel@tonic-gate crypto_key(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
220*0Sstevel@tonic-gate {
221*0Sstevel@tonic-gate 	crypto_key_t key;
222*0Sstevel@tonic-gate 
223*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
224*0Sstevel@tonic-gate 		return (DCMD_USAGE);
225*0Sstevel@tonic-gate 
226*0Sstevel@tonic-gate 	if (mdb_vread(&key, sizeof (crypto_key_t), addr) == -1) {
227*0Sstevel@tonic-gate 		mdb_warn("cannot read %p", addr);
228*0Sstevel@tonic-gate 		return (DCMD_ERR);
229*0Sstevel@tonic-gate 	}
230*0Sstevel@tonic-gate 	switch (key.ck_format) {
231*0Sstevel@tonic-gate 		case CRYPTO_KEY_RAW:
232*0Sstevel@tonic-gate 		    mdb_printf("ck_format:\tCRYPTO_KEY_RAW\n");
233*0Sstevel@tonic-gate 		    mdb_printf(
234*0Sstevel@tonic-gate 			"cku_data.cku_key_value.cku_data.cku_v_length:\t%d\n",
235*0Sstevel@tonic-gate 			    key.cku_data.cku_key_value.cku_v_length);
236*0Sstevel@tonic-gate 		    mdb_printf("cku_data.cku_key_value.cku_v_data:\t%p\n",
237*0Sstevel@tonic-gate 			key.cku_data.cku_key_value.cku_v_data);
238*0Sstevel@tonic-gate 		    break;
239*0Sstevel@tonic-gate 		case CRYPTO_KEY_REFERENCE:
240*0Sstevel@tonic-gate 		    mdb_printf("ck_format:\tCRYPTO_KEY_REFERENCE\n");
241*0Sstevel@tonic-gate 		    mdb_printf("cku_data.cku_key_id:\t%u\n",
242*0Sstevel@tonic-gate 			key.cku_data.cku_key_id);
243*0Sstevel@tonic-gate 		    break;
244*0Sstevel@tonic-gate 		case CRYPTO_KEY_ATTR_LIST:
245*0Sstevel@tonic-gate 			mdb_printf("ck_format:\tCRYPTO_KEY_ATTR_LIST\n");
246*0Sstevel@tonic-gate 			mdb_printf("cku_data.cku_key_attrs.cku_a_count:\t%u\n",
247*0Sstevel@tonic-gate 				key.cku_data.cku_key_attrs.cku_a_count);
248*0Sstevel@tonic-gate 			mdb_printf("cku_data.cku_key_attrs.cku_o_oattr:\t%p\n",
249*0Sstevel@tonic-gate 				key.cku_data.cku_key_attrs.cku_a_oattr);
250*0Sstevel@tonic-gate 			break;
251*0Sstevel@tonic-gate 		default:
252*0Sstevel@tonic-gate 			mdb_printf("ck_format:\t\t?????\n");
253*0Sstevel@tonic-gate 			break;
254*0Sstevel@tonic-gate 	}
255*0Sstevel@tonic-gate 	return (DCMD_OK);
256*0Sstevel@tonic-gate }
257