]>
git.saurik.com Git - apple/xnu.git/blob - bsd/crypto/des/des_ecb.c
1 /* crypto/des/ecb_enc.c */
2 /* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au)
5 * This file is part of an SSL implementation written
6 * by Eric Young (eay@mincom.oz.au).
7 * The implementation was written so as to conform with Netscapes SSL
8 * specification. This library and applications are
9 * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
10 * as long as the following conditions are aheared to.
12 * Copyright remains Eric Young's, and as such any Copyright notices in
13 * the code are not to be removed. If this code is used in a product,
14 * Eric Young should be given attribution as the author of the parts used.
15 * This can be in the form of a textual message at program startup or
16 * in documentation (online or textual) provided with the package.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
21 * 1. Redistributions of source code must retain the copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
26 * 3. All advertising materials mentioning features or use of this software
27 * must display the following acknowledgement:
28 * This product includes software developed by Eric Young (eay@mincom.oz.au)
30 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * The licence and distribution terms for any publically available version or
43 * derivative of this code cannot be changed. i.e. this code cannot simply be
44 * copied and put under another distribution licence
45 * [including the GNU Public Licence.]
48 #include <crypto/des/des_locl.h>
49 #include <crypto/des/spr.h>
51 char *libdes_version
="libdes v 3.24 - 20-Apr-1996 - eay";
52 char *DES_version
="DES part of SSLeay 0.6.4 30-Aug-1996";
57 if (sizeof(DES_LONG
) != sizeof(long))
58 return("des(ptr,int)");
60 return("des(ptr,long)");
62 if (sizeof(DES_LONG
) != sizeof(long))
63 return("des(idx,int)");
65 return("des(idx,long)");
70 void des_ecb_encrypt(input
, output
, ks
, encrypt
)
77 register unsigned char *in
,*out
;
80 in
=(unsigned char *)input
;
81 out
=(unsigned char *)output
;
84 des_encrypt(ll
,ks
,encrypt
);
90 void des_encrypt(data
, ks
, encrypt
)
95 register DES_LONG l
,r
,t
,u
;
97 register unsigned char *des_SP
=(unsigned char *)des_SPtrans
;
107 register DES_LONG
*s
;
113 /* Things have been modified so that the initial rotate is
114 * done outside the loop. This required the
115 * des_SPtrans values in sp.h to be rotated 1 bit to the right.
116 * One perl script later and things have a 5% speed up on a sparc2.
117 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
118 * for pointing this out. */
122 /* clear the top bits on machines with 8byte longs */
127 /* I don't know if it is worth the effort of loop unrolling the
132 for (i
=0; i
<32; i
+=8)
134 D_ENCRYPT(l
,r
,i
+0); /* 1 */
135 D_ENCRYPT(r
,l
,i
+2); /* 2 */
136 D_ENCRYPT(l
,r
,i
+4); /* 3 */
137 D_ENCRYPT(r
,l
,i
+6); /* 4 */
142 for (i
=30; i
>0; i
-=8)
144 D_ENCRYPT(l
,r
,i
-0); /* 16 */
145 D_ENCRYPT(r
,l
,i
-2); /* 15 */
146 D_ENCRYPT(l
,r
,i
-4); /* 14 */
147 D_ENCRYPT(r
,l
,i
-6); /* 13 */
152 /* clear the top bits on machines with 8byte longs */
162 void des_encrypt2(data
, ks
, encrypt
)
167 register DES_LONG l
,r
,t
,u
;
169 register unsigned char *des_SP
=(unsigned char *)des_SPtrans
;
179 register DES_LONG
*s
;
184 /* Things have been modified so that the initial rotate is
185 * done outside the loop. This required the
186 * des_SPtrans values in sp.h to be rotated 1 bit to the right.
187 * One perl script later and things have a 5% speed up on a sparc2.
188 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
189 * for pointing this out. */
193 /* clear the top bits on machines with 8byte longs */
198 /* I don't know if it is worth the effort of loop unrolling the
202 for (i
=0; i
<32; i
+=8)
204 D_ENCRYPT(l
,r
,i
+0); /* 1 */
205 D_ENCRYPT(r
,l
,i
+2); /* 2 */
206 D_ENCRYPT(l
,r
,i
+4); /* 3 */
207 D_ENCRYPT(r
,l
,i
+6); /* 4 */
212 for (i
=30; i
>0; i
-=8)
214 D_ENCRYPT(l
,r
,i
-0); /* 16 */
215 D_ENCRYPT(r
,l
,i
-2); /* 15 */
216 D_ENCRYPT(l
,r
,i
-4); /* 14 */
217 D_ENCRYPT(r
,l
,i
-6); /* 13 */
222 /* clear the top bits on machines with 8byte longs */