OLD | NEW |
1 /* crypto/des/des_enc.c */ | 1 /* crypto/des/des_enc.c */ |
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * This package is an SSL implementation written | 5 * This package is an SSL implementation written |
6 * by Eric Young (eay@cryptsoft.com). | 6 * by Eric Young (eay@cryptsoft.com). |
7 * The implementation was written so as to conform with Netscapes SSL. | 7 * The implementation was written so as to conform with Netscapes SSL. |
8 * | 8 * |
9 * This library is free for commercial and non-commercial use as long as | 9 * This library is free for commercial and non-commercial use as long as |
10 * the following conditions are aheared to. The following conditions | 10 * the following conditions are aheared to. The following conditions |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 * SUCH DAMAGE. | 51 * SUCH DAMAGE. |
52 * | 52 * |
53 * The licence and distribution terms for any publically available version or | 53 * The licence and distribution terms for any publically available version or |
54 * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 * copied and put under another distribution licence | 55 * copied and put under another distribution licence |
56 * [including the GNU Public Licence.] | 56 * [including the GNU Public Licence.] |
57 */ | 57 */ |
58 | 58 |
59 #include "des_locl.h" | 59 #include "des_locl.h" |
| 60 #include "spr.h" |
60 | 61 |
61 void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc) | 62 void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc) |
62 { | 63 { |
63 register DES_LONG l,r,t,u; | 64 register DES_LONG l,r,t,u; |
64 #ifdef DES_PTR | 65 #ifdef DES_PTR |
65 register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans; | 66 register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans; |
66 #endif | 67 #endif |
67 #ifndef DES_UNROLL | 68 #ifndef DES_UNROLL |
68 register int i; | 69 register int i; |
69 #endif | 70 #endif |
(...skipping 30 matching lines...) Expand all Loading... |
100 D_ENCRYPT(r,l,14); /* 8 */ | 101 D_ENCRYPT(r,l,14); /* 8 */ |
101 D_ENCRYPT(l,r,16); /* 9 */ | 102 D_ENCRYPT(l,r,16); /* 9 */ |
102 D_ENCRYPT(r,l,18); /* 10 */ | 103 D_ENCRYPT(r,l,18); /* 10 */ |
103 D_ENCRYPT(l,r,20); /* 11 */ | 104 D_ENCRYPT(l,r,20); /* 11 */ |
104 D_ENCRYPT(r,l,22); /* 12 */ | 105 D_ENCRYPT(r,l,22); /* 12 */ |
105 D_ENCRYPT(l,r,24); /* 13 */ | 106 D_ENCRYPT(l,r,24); /* 13 */ |
106 D_ENCRYPT(r,l,26); /* 14 */ | 107 D_ENCRYPT(r,l,26); /* 14 */ |
107 D_ENCRYPT(l,r,28); /* 15 */ | 108 D_ENCRYPT(l,r,28); /* 15 */ |
108 D_ENCRYPT(r,l,30); /* 16 */ | 109 D_ENCRYPT(r,l,30); /* 16 */ |
109 #else | 110 #else |
110 » » for (i=0; i<32; i+=8) | 111 » » for (i=0; i<32; i+=4) |
111 { | 112 { |
112 D_ENCRYPT(l,r,i+0); /* 1 */ | 113 D_ENCRYPT(l,r,i+0); /* 1 */ |
113 D_ENCRYPT(r,l,i+2); /* 2 */ | 114 D_ENCRYPT(r,l,i+2); /* 2 */ |
114 D_ENCRYPT(l,r,i+4); /* 3 */ | |
115 D_ENCRYPT(r,l,i+6); /* 4 */ | |
116 } | 115 } |
117 #endif | 116 #endif |
118 } | 117 } |
119 else | 118 else |
120 { | 119 { |
121 #ifdef DES_UNROLL | 120 #ifdef DES_UNROLL |
122 D_ENCRYPT(l,r,30); /* 16 */ | 121 D_ENCRYPT(l,r,30); /* 16 */ |
123 D_ENCRYPT(r,l,28); /* 15 */ | 122 D_ENCRYPT(r,l,28); /* 15 */ |
124 D_ENCRYPT(l,r,26); /* 14 */ | 123 D_ENCRYPT(l,r,26); /* 14 */ |
125 D_ENCRYPT(r,l,24); /* 13 */ | 124 D_ENCRYPT(r,l,24); /* 13 */ |
126 D_ENCRYPT(l,r,22); /* 12 */ | 125 D_ENCRYPT(l,r,22); /* 12 */ |
127 D_ENCRYPT(r,l,20); /* 11 */ | 126 D_ENCRYPT(r,l,20); /* 11 */ |
128 D_ENCRYPT(l,r,18); /* 10 */ | 127 D_ENCRYPT(l,r,18); /* 10 */ |
129 D_ENCRYPT(r,l,16); /* 9 */ | 128 D_ENCRYPT(r,l,16); /* 9 */ |
130 D_ENCRYPT(l,r,14); /* 8 */ | 129 D_ENCRYPT(l,r,14); /* 8 */ |
131 D_ENCRYPT(r,l,12); /* 7 */ | 130 D_ENCRYPT(r,l,12); /* 7 */ |
132 D_ENCRYPT(l,r,10); /* 6 */ | 131 D_ENCRYPT(l,r,10); /* 6 */ |
133 D_ENCRYPT(r,l, 8); /* 5 */ | 132 D_ENCRYPT(r,l, 8); /* 5 */ |
134 D_ENCRYPT(l,r, 6); /* 4 */ | 133 D_ENCRYPT(l,r, 6); /* 4 */ |
135 D_ENCRYPT(r,l, 4); /* 3 */ | 134 D_ENCRYPT(r,l, 4); /* 3 */ |
136 D_ENCRYPT(l,r, 2); /* 2 */ | 135 D_ENCRYPT(l,r, 2); /* 2 */ |
137 D_ENCRYPT(r,l, 0); /* 1 */ | 136 D_ENCRYPT(r,l, 0); /* 1 */ |
138 #else | 137 #else |
139 » » for (i=30; i>0; i-=8) | 138 » » for (i=30; i>0; i-=4) |
140 { | 139 { |
141 D_ENCRYPT(l,r,i-0); /* 16 */ | 140 D_ENCRYPT(l,r,i-0); /* 16 */ |
142 D_ENCRYPT(r,l,i-2); /* 15 */ | 141 D_ENCRYPT(r,l,i-2); /* 15 */ |
143 D_ENCRYPT(l,r,i-4); /* 14 */ | |
144 D_ENCRYPT(r,l,i-6); /* 13 */ | |
145 } | 142 } |
146 #endif | 143 #endif |
147 } | 144 } |
148 | 145 |
149 /* rotate and clear the top bits on machines with 8byte longs */ | 146 /* rotate and clear the top bits on machines with 8byte longs */ |
150 l=ROTATE(l,3)&0xffffffffL; | 147 l=ROTATE(l,3)&0xffffffffL; |
151 r=ROTATE(r,3)&0xffffffffL; | 148 r=ROTATE(r,3)&0xffffffffL; |
152 | 149 |
153 FP(r,l); | 150 FP(r,l); |
154 data[0]=l; | 151 data[0]=l; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 D_ENCRYPT(r,l,14); /* 8 */ | 193 D_ENCRYPT(r,l,14); /* 8 */ |
197 D_ENCRYPT(l,r,16); /* 9 */ | 194 D_ENCRYPT(l,r,16); /* 9 */ |
198 D_ENCRYPT(r,l,18); /* 10 */ | 195 D_ENCRYPT(r,l,18); /* 10 */ |
199 D_ENCRYPT(l,r,20); /* 11 */ | 196 D_ENCRYPT(l,r,20); /* 11 */ |
200 D_ENCRYPT(r,l,22); /* 12 */ | 197 D_ENCRYPT(r,l,22); /* 12 */ |
201 D_ENCRYPT(l,r,24); /* 13 */ | 198 D_ENCRYPT(l,r,24); /* 13 */ |
202 D_ENCRYPT(r,l,26); /* 14 */ | 199 D_ENCRYPT(r,l,26); /* 14 */ |
203 D_ENCRYPT(l,r,28); /* 15 */ | 200 D_ENCRYPT(l,r,28); /* 15 */ |
204 D_ENCRYPT(r,l,30); /* 16 */ | 201 D_ENCRYPT(r,l,30); /* 16 */ |
205 #else | 202 #else |
206 » » for (i=0; i<32; i+=8) | 203 » » for (i=0; i<32; i+=4) |
207 { | 204 { |
208 D_ENCRYPT(l,r,i+0); /* 1 */ | 205 D_ENCRYPT(l,r,i+0); /* 1 */ |
209 D_ENCRYPT(r,l,i+2); /* 2 */ | 206 D_ENCRYPT(r,l,i+2); /* 2 */ |
210 D_ENCRYPT(l,r,i+4); /* 3 */ | |
211 D_ENCRYPT(r,l,i+6); /* 4 */ | |
212 } | 207 } |
213 #endif | 208 #endif |
214 } | 209 } |
215 else | 210 else |
216 { | 211 { |
217 #ifdef DES_UNROLL | 212 #ifdef DES_UNROLL |
218 D_ENCRYPT(l,r,30); /* 16 */ | 213 D_ENCRYPT(l,r,30); /* 16 */ |
219 D_ENCRYPT(r,l,28); /* 15 */ | 214 D_ENCRYPT(r,l,28); /* 15 */ |
220 D_ENCRYPT(l,r,26); /* 14 */ | 215 D_ENCRYPT(l,r,26); /* 14 */ |
221 D_ENCRYPT(r,l,24); /* 13 */ | 216 D_ENCRYPT(r,l,24); /* 13 */ |
222 D_ENCRYPT(l,r,22); /* 12 */ | 217 D_ENCRYPT(l,r,22); /* 12 */ |
223 D_ENCRYPT(r,l,20); /* 11 */ | 218 D_ENCRYPT(r,l,20); /* 11 */ |
224 D_ENCRYPT(l,r,18); /* 10 */ | 219 D_ENCRYPT(l,r,18); /* 10 */ |
225 D_ENCRYPT(r,l,16); /* 9 */ | 220 D_ENCRYPT(r,l,16); /* 9 */ |
226 D_ENCRYPT(l,r,14); /* 8 */ | 221 D_ENCRYPT(l,r,14); /* 8 */ |
227 D_ENCRYPT(r,l,12); /* 7 */ | 222 D_ENCRYPT(r,l,12); /* 7 */ |
228 D_ENCRYPT(l,r,10); /* 6 */ | 223 D_ENCRYPT(l,r,10); /* 6 */ |
229 D_ENCRYPT(r,l, 8); /* 5 */ | 224 D_ENCRYPT(r,l, 8); /* 5 */ |
230 D_ENCRYPT(l,r, 6); /* 4 */ | 225 D_ENCRYPT(l,r, 6); /* 4 */ |
231 D_ENCRYPT(r,l, 4); /* 3 */ | 226 D_ENCRYPT(r,l, 4); /* 3 */ |
232 D_ENCRYPT(l,r, 2); /* 2 */ | 227 D_ENCRYPT(l,r, 2); /* 2 */ |
233 D_ENCRYPT(r,l, 0); /* 1 */ | 228 D_ENCRYPT(r,l, 0); /* 1 */ |
234 #else | 229 #else |
235 » » for (i=30; i>0; i-=8) | 230 » » for (i=30; i>0; i-=4) |
236 { | 231 { |
237 D_ENCRYPT(l,r,i-0); /* 16 */ | 232 D_ENCRYPT(l,r,i-0); /* 16 */ |
238 D_ENCRYPT(r,l,i-2); /* 15 */ | 233 D_ENCRYPT(r,l,i-2); /* 15 */ |
239 D_ENCRYPT(l,r,i-4); /* 14 */ | |
240 D_ENCRYPT(r,l,i-6); /* 13 */ | |
241 } | 234 } |
242 #endif | 235 #endif |
243 } | 236 } |
244 /* rotate and clear the top bits on machines with 8byte longs */ | 237 /* rotate and clear the top bits on machines with 8byte longs */ |
245 data[0]=ROTATE(l,3)&0xffffffffL; | 238 data[0]=ROTATE(l,3)&0xffffffffL; |
246 data[1]=ROTATE(r,3)&0xffffffffL; | 239 data[1]=ROTATE(r,3)&0xffffffffL; |
247 l=r=t=u=0; | 240 l=r=t=u=0; |
248 } | 241 } |
249 | 242 |
250 void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1, | 243 void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 DES_encrypt2((DES_LONG *)data,ks1,DES_DECRYPT); | 275 DES_encrypt2((DES_LONG *)data,ks1,DES_DECRYPT); |
283 l=data[0]; | 276 l=data[0]; |
284 r=data[1]; | 277 r=data[1]; |
285 FP(r,l); | 278 FP(r,l); |
286 data[0]=l; | 279 data[0]=l; |
287 data[1]=r; | 280 data[1]=r; |
288 } | 281 } |
289 | 282 |
290 #ifndef DES_DEFAULT_OPTIONS | 283 #ifndef DES_DEFAULT_OPTIONS |
291 | 284 |
292 #if !defined(OPENSSL_FIPS_DES_ASM) | |
293 | |
294 #undef CBC_ENC_C__DONT_UPDATE_IV | 285 #undef CBC_ENC_C__DONT_UPDATE_IV |
295 #include "ncbc_enc.c" /* DES_ncbc_encrypt */ | 286 #include "ncbc_enc.c" /* DES_ncbc_encrypt */ |
296 | 287 |
297 void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output, | 288 void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output, |
298 long length, DES_key_schedule *ks1, | 289 long length, DES_key_schedule *ks1, |
299 DES_key_schedule *ks2, DES_key_schedule *ks3, | 290 DES_key_schedule *ks2, DES_key_schedule *ks3, |
300 DES_cblock *ivec, int enc) | 291 DES_cblock *ivec, int enc) |
301 { | 292 { |
302 register DES_LONG tin0,tin1; | 293 register DES_LONG tin0,tin1; |
303 register DES_LONG tout0,tout1,xor0,xor1; | 294 register DES_LONG tout0,tout1,xor0,xor1; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 } | 390 } |
400 | 391 |
401 iv = &(*ivec)[0]; | 392 iv = &(*ivec)[0]; |
402 l2c(xor0,iv); | 393 l2c(xor0,iv); |
403 l2c(xor1,iv); | 394 l2c(xor1,iv); |
404 } | 395 } |
405 tin0=tin1=tout0=tout1=xor0=xor1=0; | 396 tin0=tin1=tout0=tout1=xor0=xor1=0; |
406 tin[0]=tin[1]=0; | 397 tin[0]=tin[1]=0; |
407 } | 398 } |
408 | 399 |
409 #endif | |
410 | |
411 #endif /* DES_DEFAULT_OPTIONS */ | 400 #endif /* DES_DEFAULT_OPTIONS */ |
OLD | NEW |