126219Swpaul/* 226219Swpaul * Copyright (c) 1996 326219Swpaul * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 426219Swpaul * 526219Swpaul * Redistribution and use in source and binary forms, with or without 626219Swpaul * modification, are permitted provided that the following conditions 726219Swpaul * are met: 826219Swpaul * 1. Redistributions of source code must retain the above copyright 926219Swpaul * notice, this list of conditions and the following disclaimer. 1026219Swpaul * 2. Redistributions in binary form must reproduce the above copyright 1126219Swpaul * notice, this list of conditions and the following disclaimer in the 1226219Swpaul * documentation and/or other materials provided with the distribution. 1326219Swpaul * 3. All advertising materials mentioning features or use of this software 1426219Swpaul * must display the following acknowledgement: 1526219Swpaul * This product includes software developed by Bill Paul. 1626219Swpaul * 4. Neither the name of the author nor the names of any co-contributors 1726219Swpaul * may be used to endorse or promote products derived from this software 1826219Swpaul * without specific prior written permission. 1926219Swpaul * 2026219Swpaul * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 2126219Swpaul * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2226219Swpaul * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2326219Swpaul * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE 2426219Swpaul * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2526219Swpaul * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2626219Swpaul * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2726219Swpaul * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2826219Swpaul * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2926219Swpaul * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3026219Swpaul * SUCH DAMAGE. 3126219Swpaul */ 3226219Swpaul 3392990Sobrien#include <sys/cdefs.h> 3492990Sobrien__FBSDID("$FreeBSD$"); 3592990Sobrien 3674462Salfred#include "namespace.h" 37111010Snectar#include <err.h> 3826219Swpaul#include <sys/types.h> 3926219Swpaul#include <rpc/des_crypt.h> 4026219Swpaul#include <rpc/des.h> 4126219Swpaul#include <string.h> 4226219Swpaul#include <rpcsvc/crypt.h> 4374462Salfred#include "un-namespace.h" 4426219Swpaul 4526219Swpaulint 4626219Swpaul_des_crypt_call(buf, len, dparms) 4726219Swpaul char *buf; 4826219Swpaul int len; 4926219Swpaul struct desparams *dparms; 5026219Swpaul{ 5126219Swpaul CLIENT *clnt; 5226219Swpaul desresp *result_1; 5326219Swpaul desargs des_crypt_1_arg; 5490256Salfred struct netconfig *nconf; 5590256Salfred void *localhandle; 5690256Salfred int stat; 5726219Swpaul 5890256Salfred nconf = NULL; 5990256Salfred localhandle = setnetconfig(); 6090256Salfred while ((nconf = getnetconfig(localhandle)) != NULL) { 6190256Salfred if (nconf->nc_protofmly != NULL && 6290256Salfred strcmp(nconf->nc_protofmly, NC_LOOPBACK) == 0) 6390256Salfred break; 6490256Salfred } 6590256Salfred if (nconf == NULL) { 6690256Salfred warnx("getnetconfig: %s", nc_sperror()); 6790256Salfred return(DESERR_HWERROR); 6890256Salfred } 6990256Salfred clnt = clnt_tp_create(NULL, CRYPT_PROG, CRYPT_VERS, nconf); 7026219Swpaul if (clnt == (CLIENT *) NULL) { 7190256Salfred endnetconfig(localhandle); 7226219Swpaul return(DESERR_HWERROR); 7326219Swpaul } 7490256Salfred endnetconfig(localhandle); 7526219Swpaul 7626219Swpaul des_crypt_1_arg.desbuf.desbuf_len = len; 7726219Swpaul des_crypt_1_arg.desbuf.desbuf_val = buf; 78229078Sdim des_crypt_1_arg.des_dir = (dparms->des_dir == ENCRYPT) ? ENCRYPT_DES : DECRYPT_DES; 79229078Sdim des_crypt_1_arg.des_mode = (dparms->des_mode == CBC) ? CBC_DES : ECB_DES; 8026219Swpaul bcopy(dparms->des_ivec, des_crypt_1_arg.des_ivec, 8); 8126219Swpaul bcopy(dparms->des_key, des_crypt_1_arg.des_key, 8); 8226219Swpaul 8326219Swpaul result_1 = des_crypt_1(&des_crypt_1_arg, clnt); 8426219Swpaul if (result_1 == (desresp *) NULL) { 8536816Swpaul clnt_destroy(clnt); 8626219Swpaul return(DESERR_HWERROR); 8726219Swpaul } 8826219Swpaul 8926219Swpaul stat = result_1->stat; 9026219Swpaul 9126219Swpaul if (result_1->stat == DESERR_NONE || 9226219Swpaul result_1->stat == DESERR_NOHWDEVICE) { 9326219Swpaul bcopy(result_1->desbuf.desbuf_val, buf, len); 9426219Swpaul bcopy(result_1->des_ivec, dparms->des_ivec, 8); 9526219Swpaul } 9626219Swpaul 9795658Sdes clnt_freeres(clnt, (xdrproc_t)xdr_desresp, result_1); 9826219Swpaul clnt_destroy(clnt); 9926219Swpaul 10026219Swpaul return(stat); 10126219Swpaul} 102