xref: /freebsd/lib/libgssapi/gss_wrap.c (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
1c0b9f4feSDoug Rabson /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
35e53a4f9SPedro F. Giffuni  *
4c0b9f4feSDoug Rabson  * Copyright (c) 2005 Doug Rabson
5c0b9f4feSDoug Rabson  * All rights reserved.
6c0b9f4feSDoug Rabson  *
7c0b9f4feSDoug Rabson  * Redistribution and use in source and binary forms, with or without
8c0b9f4feSDoug Rabson  * modification, are permitted provided that the following conditions
9c0b9f4feSDoug Rabson  * are met:
10c0b9f4feSDoug Rabson  * 1. Redistributions of source code must retain the above copyright
11c0b9f4feSDoug Rabson  *    notice, this list of conditions and the following disclaimer.
12c0b9f4feSDoug Rabson  * 2. Redistributions in binary form must reproduce the above copyright
13c0b9f4feSDoug Rabson  *    notice, this list of conditions and the following disclaimer in the
14c0b9f4feSDoug Rabson  *    documentation and/or other materials provided with the distribution.
15c0b9f4feSDoug Rabson  *
16c0b9f4feSDoug Rabson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17c0b9f4feSDoug Rabson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18c0b9f4feSDoug Rabson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19c0b9f4feSDoug Rabson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20c0b9f4feSDoug Rabson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21c0b9f4feSDoug Rabson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22c0b9f4feSDoug Rabson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23c0b9f4feSDoug Rabson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24c0b9f4feSDoug Rabson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25c0b9f4feSDoug Rabson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26c0b9f4feSDoug Rabson  * SUCH DAMAGE.
27c0b9f4feSDoug Rabson  */
28c0b9f4feSDoug Rabson 
29c0b9f4feSDoug Rabson #include <gssapi/gssapi.h>
30c0b9f4feSDoug Rabson 
31c0b9f4feSDoug Rabson #include "mech_switch.h"
32c0b9f4feSDoug Rabson #include "context.h"
3333f12199SDoug Rabson #include "utils.h"
34c0b9f4feSDoug Rabson 
35c0b9f4feSDoug Rabson OM_uint32
gss_wrap(OM_uint32 * minor_status,const gss_ctx_id_t context_handle,int conf_req_flag,gss_qop_t qop_req,const gss_buffer_t input_message_buffer,int * conf_state,gss_buffer_t output_message_buffer)36c0b9f4feSDoug Rabson gss_wrap(OM_uint32 *minor_status,
37c0b9f4feSDoug Rabson     const gss_ctx_id_t context_handle,
38c0b9f4feSDoug Rabson     int conf_req_flag,
39c0b9f4feSDoug Rabson     gss_qop_t qop_req,
40c0b9f4feSDoug Rabson     const gss_buffer_t input_message_buffer,
41c0b9f4feSDoug Rabson     int *conf_state,
42c0b9f4feSDoug Rabson     gss_buffer_t output_message_buffer)
43c0b9f4feSDoug Rabson {
44c0b9f4feSDoug Rabson 	struct _gss_context *ctx = (struct _gss_context *) context_handle;
456baf7cc8SPedro F. Giffuni 	struct _gss_mech_switch *m;
46c0b9f4feSDoug Rabson 
4733f12199SDoug Rabson 	if (conf_state)
4833f12199SDoug Rabson 		*conf_state = 0;
4933f12199SDoug Rabson 	_gss_buffer_zero(output_message_buffer);
5033f12199SDoug Rabson 	if (ctx == NULL) {
5133f12199SDoug Rabson 		*minor_status = 0;
5233f12199SDoug Rabson 		return (GSS_S_NO_CONTEXT);
5333f12199SDoug Rabson 	}
546baf7cc8SPedro F. Giffuni 	m = ctx->gc_mech;
5533f12199SDoug Rabson 
56c0b9f4feSDoug Rabson 	return (m->gm_wrap(minor_status, ctx->gc_ctx,
57c0b9f4feSDoug Rabson 		    conf_req_flag, qop_req, input_message_buffer,
58c0b9f4feSDoug Rabson 		    conf_state, output_message_buffer));
59c0b9f4feSDoug Rabson }
60