178064Sume/* 257922Sshin * Copyright (c) 1996 357922Sshin * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 457922Sshin * 562589Sitojun * Redistribution and use in source and binary forms, with or without 657922Sshin * modification, are permitted provided that the following conditions 757922Sshin * are met: 857922Sshin * 1. Redistributions of source code must retain the above copyright 957922Sshin * notice, this list of conditions and the following disclaimer. 1057922Sshin * 2. Redistributions in binary form must reproduce the above copyright 1157922Sshin * notice, this list of conditions and the following disclaimer in the 1257922Sshin * documentation and/or other materials provided with the distribution. 1357922Sshin * 3. All advertising materials mentioning features or use of this software 1457922Sshin * must display the following acknowledgement: 1557922Sshin * This product includes software developed by Bill Paul. 1657922Sshin * 4. Neither the name of the author nor the names of any co-contributors 1762589Sitojun * may be used to endorse or promote products derived from this software 1857922Sshin * without specific prior written permission. 1957922Sshin * 2057922Sshin * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 2157922Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2257922Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2357922Sshin * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE 2457922Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2557922Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2657922Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2757922Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2857922Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2957922Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30141580Sru * SUCH DAMAGE. 31141580Sru */ 32244750Sae 3357922Sshin#include <sys/cdefs.h> 3462589Sitojun__FBSDID("$FreeBSD: releng/10.3/lib/libc/rpc/crypt_client.c 228538 2011-12-15 20:27:36Z dim $"); 3557922Sshin 3657922Sshin#include "namespace.h" 3757922Sshin#include <err.h> 3875670Sru#include <sys/types.h> 3975670Sru#include <rpc/des_crypt.h> 4057922Sshin#include <rpc/des.h> 4176175Sschweikh#include <string.h> 4257922Sshin#include <rpcsvc/crypt.h> 4357922Sshin#include "un-namespace.h" 4457922Sshin 4557922Sshinint 4657922Sshin_des_crypt_call(buf, len, dparms) 4757922Sshin char *buf; 4857922Sshin int len; 4978064Sume struct desparams *dparms; 5057922Sshin{ 5162589Sitojun CLIENT *clnt; 5262589Sitojun desresp *result_1; 5362589Sitojun desargs des_crypt_1_arg; 5462589Sitojun struct netconfig *nconf; 5562589Sitojun void *localhandle; 5662589Sitojun int stat; 5781251Sru 5862589Sitojun nconf = NULL; 5981251Sru localhandle = setnetconfig(); 6062589Sitojun while ((nconf = getnetconfig(localhandle)) != NULL) { 6197451Sbrooks if (nconf->nc_protofmly != NULL && 6297451Sbrooks strcmp(nconf->nc_protofmly, NC_LOOPBACK) == 0) 6397451Sbrooks break; 6497451Sbrooks } 6597451Sbrooks if (nconf == NULL) { 6697451Sbrooks warnx("getnetconfig: %s", nc_sperror()); 6797451Sbrooks return(DESERR_HWERROR); 6897451Sbrooks } 6997451Sbrooks clnt = clnt_tp_create(NULL, CRYPT_PROG, CRYPT_VERS, nconf); 7097451Sbrooks if (clnt == (CLIENT *) NULL) { 7197451Sbrooks endnetconfig(localhandle); 7297451Sbrooks return(DESERR_HWERROR); 7357922Sshin } 7457922Sshin endnetconfig(localhandle); 7557922Sshin 7657922Sshin des_crypt_1_arg.desbuf.desbuf_len = len; 7781251Sru des_crypt_1_arg.desbuf.desbuf_val = buf; 7857922Sshin des_crypt_1_arg.des_dir = (dparms->des_dir == ENCRYPT) ? ENCRYPT_DES : DECRYPT_DES; 7957922Sshin des_crypt_1_arg.des_mode = (dparms->des_mode == CBC) ? CBC_DES : ECB_DES; 8057922Sshin bcopy(dparms->des_ivec, des_crypt_1_arg.des_ivec, 8); 8157922Sshin bcopy(dparms->des_key, des_crypt_1_arg.des_key, 8); 8268962Sru 8357922Sshin result_1 = des_crypt_1(&des_crypt_1_arg, clnt); 8457922Sshin if (result_1 == (desresp *) NULL) { 8557922Sshin clnt_destroy(clnt); 8657922Sshin return(DESERR_HWERROR); 8757922Sshin } 8857922Sshin 8957922Sshin stat = result_1->stat; 9057922Sshin 9157922Sshin if (result_1->stat == DESERR_NONE || 9262589Sitojun result_1->stat == DESERR_NOHWDEVICE) { 9362589Sitojun bcopy(result_1->desbuf.desbuf_val, buf, len); 9462589Sitojun bcopy(result_1->des_ivec, dparms->des_ivec, 8); 9557922Sshin } 9662589Sitojun 9781251Sru clnt_freeres(clnt, (xdrproc_t)xdr_desresp, result_1); 9862589Sitojun clnt_destroy(clnt); 9981251Sru 10062589Sitojun return(stat); 10157922Sshin} 10257922Sshin