xref: /titanic_52/usr/src/lib/libgss/g_seal.c (revision 10db1377dafab8ba3feedef26db9c5d8539a5cd1)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1996,1997, by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  *  glue routine for gss_seal
31  */
32 
33 #include <mechglueP.h>
34 
35 /*ARGSUSED*/
36 OM_uint32
37 gss_seal(minor_status,
38 		context_handle,
39 		conf_req_flag,
40 		qop_req,
41 		input_message_buffer,
42 		conf_state,
43 		output_message_buffer)
44 
45 OM_uint32 *			minor_status;
46 gss_ctx_id_t			context_handle;
47 int				conf_req_flag;
48 int				qop_req;
49 gss_buffer_t			input_message_buffer;
50 int *				conf_state;
51 gss_buffer_t			output_message_buffer;
52 {
53 /* EXPORT DELETE START */
54 
55 	OM_uint32		status;
56 	gss_union_ctx_id_t	ctx;
57 	gss_mechanism		mech;
58 
59 
60 	if (minor_status == NULL)
61 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
62 	*minor_status = 0;
63 
64 	if (context_handle == GSS_C_NO_CONTEXT)
65 		return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CONTEXT);
66 
67 	if (input_message_buffer == NULL)
68 		return (GSS_S_CALL_INACCESSIBLE_READ);
69 
70 	if (output_message_buffer == NULL)
71 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
72 
73 	/*
74 	 * select the approprate underlying mechanism routine and
75 	 * call it.
76 	 */
77 
78 	ctx = (gss_union_ctx_id_t) context_handle;
79 	mech = __gss_get_mechanism(ctx->mech_type);
80 
81 	if (mech) {
82 		if (mech->gss_seal)
83 			status = mech->gss_seal(
84 						mech->context,
85 						minor_status,
86 						ctx->internal_ctx_id,
87 						conf_req_flag,
88 						qop_req,
89 						input_message_buffer,
90 						conf_state,
91 						output_message_buffer);
92 		else
93 			status = GSS_S_UNAVAILABLE;
94 
95 		return (status);
96 	}
97 /* EXPORT DELETE END */
98 
99 	return (GSS_S_BAD_MECH);
100 }
101 
102 OM_uint32
103 gss_wrap(minor_status,
104 		context_handle,
105 		conf_req_flag,
106 		qop_req,
107 		input_message_buffer,
108 		conf_state,
109 		output_message_buffer)
110 
111 OM_uint32 *			minor_status;
112 const gss_ctx_id_t		context_handle;
113 int				conf_req_flag;
114 gss_qop_t			qop_req;
115 const gss_buffer_t		input_message_buffer;
116 int *				conf_state;
117 gss_buffer_t			output_message_buffer;
118 
119 {
120 	return gss_seal(minor_status, (gss_ctx_id_t)context_handle,
121 			conf_req_flag, (int) qop_req,
122 			(gss_buffer_t)input_message_buffer, conf_state,
123 			output_message_buffer);
124 }
125 
126 /*
127  * New for V2
128  */
129 OM_uint32
130 gss_wrap_size_limit(minor_status, context_handle, conf_req_flag,
131 				qop_req, req_output_size, max_input_size)
132 	OM_uint32		*minor_status;
133 	const gss_ctx_id_t	context_handle;
134 	int			conf_req_flag;
135 	gss_qop_t		qop_req;
136 	OM_uint32		req_output_size;
137 	OM_uint32		*max_input_size;
138 {
139 	gss_union_ctx_id_t	ctx;
140 	gss_mechanism		mech;
141 
142 	if (minor_status == NULL)
143 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
144 	*minor_status = 0;
145 
146 	if (context_handle == GSS_C_NO_CONTEXT)
147 		return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CONTEXT);
148 
149 	if (max_input_size == NULL)
150 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
151 
152 	/*
153 	 * select the approprate underlying mechanism routine and
154 	 * call it.
155 	 */
156 
157 	ctx = (gss_union_ctx_id_t) context_handle;
158 	mech = __gss_get_mechanism(ctx->mech_type);
159 
160 	if (!mech)
161 		return (GSS_S_BAD_MECH);
162 
163 	if (!mech->gss_wrap_size_limit)
164 		return (GSS_S_UNAVAILABLE);
165 
166 	return (mech->gss_wrap_size_limit(mech->context, minor_status,
167 				ctx->internal_ctx_id, conf_req_flag, qop_req,
168 				req_output_size, max_input_size));
169 }
170