xref: /freebsd-src/lib/libgssapi/gss_pseudo_random.c (revision 2a63c3be158216222d89a073dcbd6a72ee4aab5a)
1bf3f9db6SUlrich Spörlein /*-
2*8a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3*8a16b7a1SPedro F. Giffuni  *
4bf3f9db6SUlrich Spörlein  * Copyright (c) 2007 Kungliga Tekniska Högskolan
533f12199SDoug Rabson  * (Royal Institute of Technology, Stockholm, Sweden).
633f12199SDoug Rabson  * All rights reserved.
733f12199SDoug Rabson  *
833f12199SDoug Rabson  * Redistribution and use in source and binary forms, with or without
933f12199SDoug Rabson  * modification, are permitted provided that the following conditions
1033f12199SDoug Rabson  * are met:
1133f12199SDoug Rabson  *
1233f12199SDoug Rabson  * 1. Redistributions of source code must retain the above copyright
1333f12199SDoug Rabson  *    notice, this list of conditions and the following disclaimer.
1433f12199SDoug Rabson  *
1533f12199SDoug Rabson  * 2. Redistributions in binary form must reproduce the above copyright
1633f12199SDoug Rabson  *    notice, this list of conditions and the following disclaimer in the
1733f12199SDoug Rabson  *    documentation and/or other materials provided with the distribution.
1833f12199SDoug Rabson  *
1933f12199SDoug Rabson  * 3. Neither the name of the Institute nor the names of its contributors
2033f12199SDoug Rabson  *    may be used to endorse or promote products derived from this software
2133f12199SDoug Rabson  *    without specific prior written permission.
2233f12199SDoug Rabson  *
2333f12199SDoug Rabson  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
2433f12199SDoug Rabson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2533f12199SDoug Rabson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2633f12199SDoug Rabson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
2733f12199SDoug Rabson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2833f12199SDoug Rabson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2933f12199SDoug Rabson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3033f12199SDoug Rabson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3133f12199SDoug Rabson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3233f12199SDoug Rabson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3333f12199SDoug Rabson  * SUCH DAMAGE.
3433f12199SDoug Rabson  */
3533f12199SDoug Rabson /* $Id: gss_pseudo_random.c 20053 2007-01-24 01:31:35Z lha $ */
3633f12199SDoug Rabson 
3733f12199SDoug Rabson #include <gssapi/gssapi.h>
3833f12199SDoug Rabson 
3933f12199SDoug Rabson #include "mech_switch.h"
4033f12199SDoug Rabson #include "context.h"
4133f12199SDoug Rabson #include "utils.h"
4233f12199SDoug Rabson 
4333f12199SDoug Rabson OM_uint32
gss_pseudo_random(OM_uint32 * minor_status,gss_ctx_id_t context,int prf_key,const gss_buffer_t prf_in,ssize_t desired_output_len,gss_buffer_t prf_out)4433f12199SDoug Rabson gss_pseudo_random(OM_uint32 *minor_status,
4533f12199SDoug Rabson 		  gss_ctx_id_t context,
4633f12199SDoug Rabson 		  int prf_key,
4733f12199SDoug Rabson 		  const gss_buffer_t prf_in,
4833f12199SDoug Rabson 		  ssize_t desired_output_len,
4933f12199SDoug Rabson 		  gss_buffer_t prf_out)
5033f12199SDoug Rabson {
5133f12199SDoug Rabson     struct _gss_context *ctx = (struct _gss_context *) context;
526baf7cc8SPedro F. Giffuni     struct _gss_mech_switch *m;
5333f12199SDoug Rabson     OM_uint32 major_status;
5433f12199SDoug Rabson 
5533f12199SDoug Rabson     _gss_buffer_zero(prf_out);
5633f12199SDoug Rabson     *minor_status = 0;
5733f12199SDoug Rabson 
5833f12199SDoug Rabson     if (ctx == NULL) {
5933f12199SDoug Rabson 	*minor_status = 0;
6033f12199SDoug Rabson 	return GSS_S_NO_CONTEXT;
6133f12199SDoug Rabson     }
626baf7cc8SPedro F. Giffuni     m = ctx->gc_mech;
6333f12199SDoug Rabson 
6433f12199SDoug Rabson     if (m->gm_pseudo_random == NULL)
6533f12199SDoug Rabson 	return GSS_S_UNAVAILABLE;
6633f12199SDoug Rabson 
6733f12199SDoug Rabson     major_status = (*m->gm_pseudo_random)(minor_status, ctx->gc_ctx,
6833f12199SDoug Rabson 					  prf_key, prf_in, desired_output_len,
6933f12199SDoug Rabson 					  prf_out);
7033f12199SDoug Rabson     if (major_status != GSS_S_COMPLETE)
7133f12199SDoug Rabson 	    _gss_mg_error(m, major_status, *minor_status);
7233f12199SDoug Rabson 
7333f12199SDoug Rabson     return major_status;
7433f12199SDoug Rabson }
75