crypt_client.c revision 287341
1219140Srwatson/* 2219140Srwatson * Copyright (c) 1996 3247602Spjd * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 4219140Srwatson * 5219140Srwatson * Redistribution and use in source and binary forms, with or without 6219140Srwatson * modification, are permitted provided that the following conditions 7219140Srwatson * are met: 8219140Srwatson * 1. Redistributions of source code must retain the above copyright 9247602Spjd * notice, this list of conditions and the following disclaimer. 10247602Spjd * 2. Redistributions in binary form must reproduce the above copyright 11247602Spjd * notice, this list of conditions and the following disclaimer in the 12219140Srwatson * documentation and/or other materials provided with the distribution. 13219140Srwatson * 3. All advertising materials mentioning features or use of this software 14219140Srwatson * must display the following acknowledgement: 15219140Srwatson * This product includes software developed by Bill Paul. 16219140Srwatson * 4. Neither the name of the author nor the names of any co-contributors 17219140Srwatson * may be used to endorse or promote products derived from this software 18219140Srwatson * without specific prior written permission. 19219140Srwatson * 20219140Srwatson * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 21219140Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22219140Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23219140Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE 24219140Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25219140Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26219140Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27219140Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28219140Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29219140Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30219140Srwatson * SUCH DAMAGE. 31219140Srwatson */ 32219140Srwatson 33219140Srwatson#include <sys/cdefs.h> 34219140Srwatson__FBSDID("$FreeBSD: head/lib/libc/rpc/crypt_client.c 287341 2015-09-01 02:39:07Z rodrigc $"); 35219140Srwatson 36219140Srwatson#include "namespace.h" 37219140Srwatson#include <err.h> 38219140Srwatson#include <sys/types.h> 39280224Srwatson#include <rpc/des_crypt.h> 40280224Srwatson#include <rpc/des.h> 41219140Srwatson#include <string.h> 42219140Srwatson#include <rpcsvc/crypt.h> 43247602Spjd#include "un-namespace.h" 44219140Srwatson 45255219Spjdint 46223762Sjonathan_des_crypt_call(char *buf, int len, struct desparams *dparms) 47247602Spjd{ 48223762Sjonathan CLIENT *clnt; 49255219Spjd desresp *result_1; 50255219Spjd desargs des_crypt_1_arg; 51255219Spjd struct netconfig *nconf; 52255219Spjd void *localhandle; 53255219Spjd int stat; 54255219Spjd 55223762Sjonathan nconf = NULL; 56223762Sjonathan localhandle = setnetconfig(); 57223762Sjonathan while ((nconf = getnetconfig(localhandle)) != NULL) { 58223762Sjonathan if (nconf->nc_protofmly != NULL && 59223762Sjonathan strcmp(nconf->nc_protofmly, NC_LOOPBACK) == 0) 60223762Sjonathan break; 61223762Sjonathan } 62223762Sjonathan if (nconf == NULL) { 63223762Sjonathan warnx("getnetconfig: %s", nc_sperror()); 64223762Sjonathan endnetconfig(localhandle); 65223762Sjonathan return(DESERR_HWERROR); 66223762Sjonathan } 67223762Sjonathan clnt = clnt_tp_create(NULL, CRYPT_PROG, CRYPT_VERS, nconf); 68224255Sjonathan if (clnt == (CLIENT *) NULL) { 69255219Spjd endnetconfig(localhandle); 70247602Spjd return(DESERR_HWERROR); 71247602Spjd } 72247602Spjd endnetconfig(localhandle); 73247602Spjd 74247602Spjd des_crypt_1_arg.desbuf.desbuf_len = len; 75255219Spjd des_crypt_1_arg.desbuf.desbuf_val = buf; 76247602Spjd des_crypt_1_arg.des_dir = (dparms->des_dir == ENCRYPT) ? ENCRYPT_DES : DECRYPT_DES; 77255219Spjd des_crypt_1_arg.des_mode = (dparms->des_mode == CBC) ? CBC_DES : ECB_DES; 78255219Spjd bcopy(dparms->des_ivec, des_crypt_1_arg.des_ivec, 8); 79255219Spjd bcopy(dparms->des_key, des_crypt_1_arg.des_key, 8); 80247602Spjd 81255219Spjd result_1 = des_crypt_1(&des_crypt_1_arg, clnt); 82258324Spjd if (result_1 == (desresp *) NULL) { 83247602Spjd clnt_destroy(clnt); 84258324Spjd return(DESERR_HWERROR); 85258324Spjd } 86258324Spjd 87258324Spjd stat = result_1->stat; 88247602Spjd 89247602Spjd if (result_1->stat == DESERR_NONE || 90255219Spjd result_1->stat == DESERR_NOHWDEVICE) { 91247602Spjd bcopy(result_1->desbuf.desbuf_val, buf, len); 92247602Spjd bcopy(result_1->des_ivec, dparms->des_ivec, 8); 93247602Spjd } 94247602Spjd 95247602Spjd clnt_freeres(clnt, (xdrproc_t)xdr_desresp, result_1); 96255219Spjd clnt_destroy(clnt); 97247602Spjd 98247602Spjd return(stat); 99247602Spjd} 100247602Spjd