11849Swollman/*-
21849Swollman * Copyright (c) 2005 Doug Rabson
31849Swollman * All rights reserved.
41849Swollman *
51849Swollman * Redistribution and use in source and binary forms, with or without
61849Swollman * modification, are permitted provided that the following conditions
71849Swollman * are met:
81849Swollman * 1. Redistributions of source code must retain the above copyright
91849Swollman *    notice, this list of conditions and the following disclaimer.
101849Swollman * 2. Redistributions in binary form must reproduce the above copyright
111849Swollman *    notice, this list of conditions and the following disclaimer in the
121849Swollman *    documentation and/or other materials provided with the distribution.
131849Swollman *
141849Swollman * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
151849Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
161849Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
171849Swollman * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
181849Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
191849Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
201849Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
211849Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
221849Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
231849Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
241849Swollman * SUCH DAMAGE.
251849Swollman *
261849Swollman *	$FreeBSD: src/lib/libgssapi/gss_wrap.c,v 1.1 2005/12/29 14:40:20 dfr Exp $
271849Swollman */
281849Swollman
291849Swollman#include "mech_locl.h"
301849Swollman
311849Swollman/**
321849Swollman * Wrap a message using either confidentiality (encryption +
331849Swollman * signature) or sealing (signature).
341849Swollman *
351849Swollman * @param minor_status minor status code.
361849Swollman * @param context_handle context handle.
371849Swollman * @param conf_req_flag if non zero, confidentiality is requestd.
381849Swollman * @param qop_req type of protection needed, in most cases it GSS_C_QOP_DEFAULT should be passed in.
391849Swollman * @param input_message_buffer messages to wrap
401849Swollman * @param conf_state returns non zero if confidentiality was honoured.
411849Swollman * @param output_message_buffer the resulting buffer, release with gss_release_buffer().
421849Swollman *
431849Swollman * @ingroup gssapi
441849Swollman */
451849Swollman
461849SwollmanGSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
471849Swollmangss_wrap(OM_uint32 *minor_status,
481849Swollman    const gss_ctx_id_t context_handle,
491849Swollman    int conf_req_flag,
501849Swollman    gss_qop_t qop_req,
511849Swollman    const gss_buffer_t input_message_buffer,
521849Swollman    int *conf_state,
531849Swollman    gss_buffer_t output_message_buffer)
541849Swollman{
55	struct _gss_context *ctx = (struct _gss_context *) context_handle;
56	gssapi_mech_interface m;
57
58	if (conf_state)
59	    *conf_state = 0;
60	_mg_buffer_zero(output_message_buffer);
61	if (ctx == NULL) {
62	    *minor_status = 0;
63	    return GSS_S_NO_CONTEXT;
64	}
65
66	m = ctx->gc_mech;
67
68	return (m->gm_wrap(minor_status, ctx->gc_ctx,
69		    conf_req_flag, qop_req, input_message_buffer,
70		    conf_state, output_message_buffer));
71}
72