rpc_enc.c revision 296465
1213496Scognet/* crypto/des/rpc_enc.c */ 2213496Scognet/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3213496Scognet * All rights reserved. 4213496Scognet * 5213496Scognet * This package is an SSL implementation written 6213496Scognet * by Eric Young (eay@cryptsoft.com). 7213496Scognet * The implementation was written so as to conform with Netscapes SSL. 8213496Scognet * 9213496Scognet * This library is free for commercial and non-commercial use as long as 10213496Scognet * the following conditions are aheared to. The following conditions 11213496Scognet * apply to all code found in this distribution, be it the RC4, RSA, 12213496Scognet * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13213496Scognet * included with this distribution is covered by the same copyright terms 14213496Scognet * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15213496Scognet * 16213496Scognet * Copyright remains Eric Young's, and as such any Copyright notices in 17213496Scognet * the code are not to be removed. 18213496Scognet * If this package is used in a product, Eric Young should be given attribution 19213496Scognet * as the author of the parts of the library used. 20213496Scognet * This can be in the form of a textual message at program startup or 21213496Scognet * in documentation (online or textual) provided with the package. 22213496Scognet * 23213496Scognet * Redistribution and use in source and binary forms, with or without 24213496Scognet * modification, are permitted provided that the following conditions 25213496Scognet * are met: 26213496Scognet * 1. Redistributions of source code must retain the copyright 27213496Scognet * notice, this list of conditions and the following disclaimer. 28213496Scognet * 2. Redistributions in binary form must reproduce the above copyright 29213496Scognet * notice, this list of conditions and the following disclaimer in the 30213496Scognet * documentation and/or other materials provided with the distribution. 31213496Scognet * 3. All advertising materials mentioning features or use of this software 32213496Scognet * must display the following acknowledgement: 33213496Scognet * "This product includes cryptographic software written by 34213496Scognet * Eric Young (eay@cryptsoft.com)" 35213496Scognet * The word 'cryptographic' can be left out if the rouines from the library 36213496Scognet * being used are not cryptographic related :-). 37213496Scognet * 4. If you include any Windows specific code (or a derivative thereof) from 38213496Scognet * the apps directory (application code) you must include an acknowledgement: 39213496Scognet * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40213496Scognet * 41238331Simp * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42213496Scognet * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43213496Scognet * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44213496Scognet * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45238376Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46213496Scognet * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47238376Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48213496Scognet * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49213496Scognet * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50213496Scognet * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51213496Scognet * SUCH DAMAGE. 52213496Scognet * 53213496Scognet * The licence and distribution terms for any publically available version or 54213496Scognet * derivative of this code cannot be changed. i.e. this code cannot simply be 55213496Scognet * copied and put under another distribution licence 56213496Scognet * [including the GNU Public Licence.] 57213496Scognet */ 58213496Scognet 59213496Scognet#include "rpc_des.h" 60213496Scognet#include "des_locl.h" 61213496Scognet#include "des_ver.h" 62213496Scognet 63213496Scognetint _des_crypt(char *buf, int len, struct desparams *desp); 64213496Scognetint _des_crypt(char *buf, int len, struct desparams *desp) 65213496Scognet{ 66213496Scognet DES_key_schedule ks; 67213496Scognet int enc; 68213496Scognet 69213496Scognet DES_set_key_unchecked(&desp->des_key, &ks); 70213496Scognet enc = (desp->des_dir == ENCRYPT) ? DES_ENCRYPT : DES_DECRYPT; 71213496Scognet 72213496Scognet if (desp->des_mode == CBC) 73213496Scognet DES_ecb_encrypt((const_DES_cblock *)desp->UDES.UDES_buf, 74213496Scognet (DES_cblock *)desp->UDES.UDES_buf, &ks, enc); 75213496Scognet else { 76213496Scognet DES_ncbc_encrypt(desp->UDES.UDES_buf, desp->UDES.UDES_buf, 77213496Scognet len, &ks, &desp->des_ivec, enc); 78213496Scognet#ifdef undef 79213496Scognet /* 80213496Scognet * len will always be %8 if called from common_crypt in secure_rpc. 81213496Scognet * Libdes's cbc encrypt does not copy back the iv, so we have to do 82213496Scognet * it here. 83213496Scognet */ 84213496Scognet /* It does now :-) eay 20/09/95 */ 85213496Scognet 86213496Scognet a = (char *)&(desp->UDES.UDES_buf[len - 8]); 87213496Scognet b = (char *)&(desp->des_ivec[0]); 88213496Scognet 89213496Scognet *(a++) = *(b++); 90213496Scognet *(a++) = *(b++); 91260696Simp *(a++) = *(b++); 92260696Simp *(a++) = *(b++); 93260696Simp *(a++) = *(b++); 94260696Simp *(a++) = *(b++); 95260696Simp *(a++) = *(b++); 96260696Simp *(a++) = *(b++); 97260696Simp#endif 98213496Scognet } 99213496Scognet return (1); 100213496Scognet} 101213496Scognet