xref: /netbsd-src/crypto/external/bsd/openssl/lib/libdes/orpc_enc.c (revision 49d46fa3c871a76b2e79b95237192a7724d66dc3)
1*49d46fa3Schristos /* crypto/des/rpc_enc.c */
2*49d46fa3Schristos /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3*49d46fa3Schristos  * All rights reserved.
4*49d46fa3Schristos  *
5*49d46fa3Schristos  * This package is an SSL implementation written
6*49d46fa3Schristos  * by Eric Young (eay@cryptsoft.com).
7*49d46fa3Schristos  * The implementation was written so as to conform with Netscapes SSL.
8*49d46fa3Schristos  *
9*49d46fa3Schristos  * This library is free for commercial and non-commercial use as long as
10*49d46fa3Schristos  * the following conditions are aheared to.  The following conditions
11*49d46fa3Schristos  * apply to all code found in this distribution, be it the RC4, RSA,
12*49d46fa3Schristos  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13*49d46fa3Schristos  * included with this distribution is covered by the same copyright terms
14*49d46fa3Schristos  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15*49d46fa3Schristos  *
16*49d46fa3Schristos  * Copyright remains Eric Young's, and as such any Copyright notices in
17*49d46fa3Schristos  * the code are not to be removed.
18*49d46fa3Schristos  * If this package is used in a product, Eric Young should be given attribution
19*49d46fa3Schristos  * as the author of the parts of the library used.
20*49d46fa3Schristos  * This can be in the form of a textual message at program startup or
21*49d46fa3Schristos  * in documentation (online or textual) provided with the package.
22*49d46fa3Schristos  *
23*49d46fa3Schristos  * Redistribution and use in source and binary forms, with or without
24*49d46fa3Schristos  * modification, are permitted provided that the following conditions
25*49d46fa3Schristos  * are met:
26*49d46fa3Schristos  * 1. Redistributions of source code must retain the copyright
27*49d46fa3Schristos  *    notice, this list of conditions and the following disclaimer.
28*49d46fa3Schristos  * 2. Redistributions in binary form must reproduce the above copyright
29*49d46fa3Schristos  *    notice, this list of conditions and the following disclaimer in the
30*49d46fa3Schristos  *    documentation and/or other materials provided with the distribution.
31*49d46fa3Schristos  * 3. All advertising materials mentioning features or use of this software
32*49d46fa3Schristos  *    must display the following acknowledgement:
33*49d46fa3Schristos  *    "This product includes cryptographic software written by
34*49d46fa3Schristos  *     Eric Young (eay@cryptsoft.com)"
35*49d46fa3Schristos  *    The word 'cryptographic' can be left out if the rouines from the library
36*49d46fa3Schristos  *    being used are not cryptographic related :-).
37*49d46fa3Schristos  * 4. If you include any Windows specific code (or a derivative thereof) from
38*49d46fa3Schristos  *    the apps directory (application code) you must include an acknowledgement:
39*49d46fa3Schristos  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40*49d46fa3Schristos  *
41*49d46fa3Schristos  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42*49d46fa3Schristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43*49d46fa3Schristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44*49d46fa3Schristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45*49d46fa3Schristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46*49d46fa3Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47*49d46fa3Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48*49d46fa3Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49*49d46fa3Schristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50*49d46fa3Schristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51*49d46fa3Schristos  * SUCH DAMAGE.
52*49d46fa3Schristos  *
53*49d46fa3Schristos  * The licence and distribution terms for any publically available version or
54*49d46fa3Schristos  * derivative of this code cannot be changed.  i.e. this code cannot simply be
55*49d46fa3Schristos  * copied and put under another distribution licence
56*49d46fa3Schristos  * [including the GNU Public Licence.]
57*49d46fa3Schristos  */
58*49d46fa3Schristos 
59*49d46fa3Schristos #include "rpc_des.h"
60*49d46fa3Schristos #include "des_locl.h"
61*49d46fa3Schristos 
62*49d46fa3Schristos int _des_crypt(char *buf,int len,struct desparams *desp);
_des_crypt(char * buf,int len,struct desparams * desp)63*49d46fa3Schristos int _des_crypt(char *buf, int len, struct desparams *desp)
64*49d46fa3Schristos 	{
65*49d46fa3Schristos 	des_key_schedule ks;
66*49d46fa3Schristos 	int enc;
67*49d46fa3Schristos 
68*49d46fa3Schristos 	des_set_key_unchecked(&desp->des_key,ks);
69*49d46fa3Schristos 	enc=(desp->des_dir == ENCRYPT)?DES_ENCRYPT:DES_DECRYPT;
70*49d46fa3Schristos 
71*49d46fa3Schristos 	if (desp->des_mode == CBC)
72*49d46fa3Schristos 		des_ecb_encrypt((const_des_cblock *)desp->UDES.UDES_buf,
73*49d46fa3Schristos 				(des_cblock *)desp->UDES.UDES_buf,ks,
74*49d46fa3Schristos 				enc);
75*49d46fa3Schristos 	else
76*49d46fa3Schristos 		{
77*49d46fa3Schristos 		des_ncbc_encrypt(desp->UDES.UDES_buf,desp->UDES.UDES_buf,
78*49d46fa3Schristos 				len,ks,&desp->des_ivec,enc);
79*49d46fa3Schristos #ifdef undef
80*49d46fa3Schristos 		/* len will always be %8 if called from common_crypt
81*49d46fa3Schristos 		 * in secure_rpc.
82*49d46fa3Schristos 		 * Libdes's cbc encrypt does not copy back the iv,
83*49d46fa3Schristos 		 * so we have to do it here. */
84*49d46fa3Schristos 		/* It does now :-) eay 20/09/95 */
85*49d46fa3Schristos 
86*49d46fa3Schristos 		a=(char *)&(desp->UDES.UDES_buf[len-8]);
87*49d46fa3Schristos 		b=(char *)&(desp->des_ivec[0]);
88*49d46fa3Schristos 
89*49d46fa3Schristos 		*(a++)= *(b++); *(a++)= *(b++);
90*49d46fa3Schristos 		*(a++)= *(b++); *(a++)= *(b++);
91*49d46fa3Schristos 		*(a++)= *(b++); *(a++)= *(b++);
92*49d46fa3Schristos 		*(a++)= *(b++); *(a++)= *(b++);
93*49d46fa3Schristos #endif
94*49d46fa3Schristos 		}
95*49d46fa3Schristos 	return(1);
96*49d46fa3Schristos 	}
97*49d46fa3Schristos 
98