summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/des/des_locl.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/des/des_locl.h')
-rw-r--r--src/lib/libcrypto/des/des_locl.h89
1 files changed, 49 insertions, 40 deletions
diff --git a/src/lib/libcrypto/des/des_locl.h b/src/lib/libcrypto/des/des_locl.h
index d6ea17cb68..70e833be3f 100644
--- a/src/lib/libcrypto/des/des_locl.h
+++ b/src/lib/libcrypto/des/des_locl.h
@@ -59,36 +59,45 @@
59#ifndef HEADER_DES_LOCL_H 59#ifndef HEADER_DES_LOCL_H
60#define HEADER_DES_LOCL_H 60#define HEADER_DES_LOCL_H
61 61
62#if defined(WIN32) || defined(WIN16) 62#include <openssl/e_os2.h>
63#ifndef MSDOS 63
64#define MSDOS 64#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
65#ifndef OPENSSL_SYS_MSDOS
66#define OPENSSL_SYS_MSDOS
65#endif 67#endif
66#endif 68#endif
67 69
68#include <stdio.h> 70#include <stdio.h>
69#include <stdlib.h> 71#include <stdlib.h>
70 72
71#include <openssl/opensslconf.h> 73#ifndef OPENSSL_SYS_MSDOS
72 74#if !defined(OPENSSL_SYS_VMS) || defined(__DECC)
73#ifndef MSDOS 75#ifdef OPENSSL_UNISTD
74#if !defined(VMS) || defined(__DECC) 76# include OPENSSL_UNISTD
75#include OPENSSL_UNISTD 77#else
78# include <unistd.h>
79#endif
76#include <math.h> 80#include <math.h>
77#endif 81#endif
78#endif 82#endif
79#include <openssl/des.h> 83#include <openssl/des.h>
80 84
81#ifdef MSDOS /* Visual C++ 2.1 (Windows NT/95) */ 85#ifdef OPENSSL_SYS_MSDOS /* Visual C++ 2.1 (Windows NT/95) */
82#include <stdlib.h> 86#include <stdlib.h>
83#include <errno.h> 87#include <errno.h>
84#include <time.h> 88#include <time.h>
85#include <io.h> 89#include <io.h>
86#endif 90#endif
87 91
88#if defined(__STDC__) || defined(VMS) || defined(M_XENIX) || defined(MSDOS) 92#if defined(__STDC__) || defined(OPENSSL_SYS_VMS) || defined(M_XENIX) || defined(OPENSSL_SYS_MSDOS)
89#include <string.h> 93#include <string.h>
90#endif 94#endif
91 95
96#ifdef OPENSSL_BUILD_SHLIBCRYPTO
97# undef OPENSSL_EXTERN
98# define OPENSSL_EXTERN OPENSSL_EXPORT
99#endif
100
92#define ITERATIONS 16 101#define ITERATIONS 16
93#define HALF_ITERATIONS 8 102#define HALF_ITERATIONS 8
94 103
@@ -151,7 +160,7 @@
151 } \ 160 } \
152 } 161 }
153 162
154#if defined(WIN32) 163#if defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER)
155#define ROTATE(a,n) (_lrotr(a,n)) 164#define ROTATE(a,n) (_lrotr(a,n))
156#else 165#else
157#define ROTATE(a,n) (((a)>>(n))+((a)<<(32-(n)))) 166#define ROTATE(a,n) (((a)>>(n))+((a)<<(32-(n))))
@@ -178,14 +187,14 @@
178#endif 187#endif
179 188
180/* The changes to this macro may help or hinder, depending on the 189/* The changes to this macro may help or hinder, depending on the
181 * compiler and the achitecture. gcc2 always seems to do well :-). 190 * compiler and the architecture. gcc2 always seems to do well :-).
182 * Inspired by Dana How <how@isl.stanford.edu> 191 * Inspired by Dana How <how@isl.stanford.edu>
183 * DO NOT use the alternative version on machines with 8 byte longs. 192 * DO NOT use the alternative version on machines with 8 byte longs.
184 * It does not seem to work on the Alpha, even when DES_LONG is 4 193 * It does not seem to work on the Alpha, even when DES_LONG is 4
185 * bytes, probably an issue of accessing non-word aligned objects :-( */ 194 * bytes, probably an issue of accessing non-word aligned objects :-( */
186#ifdef DES_PTR 195#ifdef DES_PTR
187 196
188/* It recently occured to me that 0^0^0^0^0^0^0 == 0, so there 197/* It recently occurred to me that 0^0^0^0^0^0^0 == 0, so there
189 * is no reason to not xor all the sub items together. This potentially 198 * is no reason to not xor all the sub items together. This potentially
190 * saves a register since things can be xored directly into L */ 199 * saves a register since things can be xored directly into L */
191 200
@@ -274,24 +283,24 @@
274 u1=(int)u&0x3f; \ 283 u1=(int)u&0x3f; \
275 u2&=0x3f; \ 284 u2&=0x3f; \
276 u>>=16L; \ 285 u>>=16L; \
277 LL^=des_SPtrans[0][u1]; \ 286 LL^=DES_SPtrans[0][u1]; \
278 LL^=des_SPtrans[2][u2]; \ 287 LL^=DES_SPtrans[2][u2]; \
279 u3=(int)u>>8L; \ 288 u3=(int)u>>8L; \
280 u1=(int)u&0x3f; \ 289 u1=(int)u&0x3f; \
281 u3&=0x3f; \ 290 u3&=0x3f; \
282 LL^=des_SPtrans[4][u1]; \ 291 LL^=DES_SPtrans[4][u1]; \
283 LL^=des_SPtrans[6][u3]; \ 292 LL^=DES_SPtrans[6][u3]; \
284 u2=(int)t>>8L; \ 293 u2=(int)t>>8L; \
285 u1=(int)t&0x3f; \ 294 u1=(int)t&0x3f; \
286 u2&=0x3f; \ 295 u2&=0x3f; \
287 t>>=16L; \ 296 t>>=16L; \
288 LL^=des_SPtrans[1][u1]; \ 297 LL^=DES_SPtrans[1][u1]; \
289 LL^=des_SPtrans[3][u2]; \ 298 LL^=DES_SPtrans[3][u2]; \
290 u3=(int)t>>8L; \ 299 u3=(int)t>>8L; \
291 u1=(int)t&0x3f; \ 300 u1=(int)t&0x3f; \
292 u3&=0x3f; \ 301 u3&=0x3f; \
293 LL^=des_SPtrans[5][u1]; \ 302 LL^=DES_SPtrans[5][u1]; \
294 LL^=des_SPtrans[7][u3]; } 303 LL^=DES_SPtrans[7][u3]; }
295#endif 304#endif
296#ifdef DES_RISC2 305#ifdef DES_RISC2
297#define D_ENCRYPT(LL,R,S) {\ 306#define D_ENCRYPT(LL,R,S) {\
@@ -302,25 +311,25 @@
302 u2=(int)u>>8L; \ 311 u2=(int)u>>8L; \
303 u1=(int)u&0x3f; \ 312 u1=(int)u&0x3f; \
304 u2&=0x3f; \ 313 u2&=0x3f; \
305 LL^=des_SPtrans[0][u1]; \ 314 LL^=DES_SPtrans[0][u1]; \
306 LL^=des_SPtrans[2][u2]; \ 315 LL^=DES_SPtrans[2][u2]; \
307 s1=(int)u>>16L; \ 316 s1=(int)u>>16L; \
308 s2=(int)u>>24L; \ 317 s2=(int)u>>24L; \
309 s1&=0x3f; \ 318 s1&=0x3f; \
310 s2&=0x3f; \ 319 s2&=0x3f; \
311 LL^=des_SPtrans[4][s1]; \ 320 LL^=DES_SPtrans[4][s1]; \
312 LL^=des_SPtrans[6][s2]; \ 321 LL^=DES_SPtrans[6][s2]; \
313 u2=(int)t>>8L; \ 322 u2=(int)t>>8L; \
314 u1=(int)t&0x3f; \ 323 u1=(int)t&0x3f; \
315 u2&=0x3f; \ 324 u2&=0x3f; \
316 LL^=des_SPtrans[1][u1]; \ 325 LL^=DES_SPtrans[1][u1]; \
317 LL^=des_SPtrans[3][u2]; \ 326 LL^=DES_SPtrans[3][u2]; \
318 s1=(int)t>>16; \ 327 s1=(int)t>>16; \
319 s2=(int)t>>24L; \ 328 s2=(int)t>>24L; \
320 s1&=0x3f; \ 329 s1&=0x3f; \
321 s2&=0x3f; \ 330 s2&=0x3f; \
322 LL^=des_SPtrans[5][s1]; \ 331 LL^=DES_SPtrans[5][s1]; \
323 LL^=des_SPtrans[7][s2]; } 332 LL^=DES_SPtrans[7][s2]; }
324#endif 333#endif
325 334
326#else 335#else
@@ -329,14 +338,14 @@
329 LOAD_DATA_tmp(R,S,u,t,E0,E1); \ 338 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
330 t=ROTATE(t,4); \ 339 t=ROTATE(t,4); \
331 LL^=\ 340 LL^=\
332 des_SPtrans[0][(u>> 2L)&0x3f]^ \ 341 DES_SPtrans[0][(u>> 2L)&0x3f]^ \
333 des_SPtrans[2][(u>>10L)&0x3f]^ \ 342 DES_SPtrans[2][(u>>10L)&0x3f]^ \
334 des_SPtrans[4][(u>>18L)&0x3f]^ \ 343 DES_SPtrans[4][(u>>18L)&0x3f]^ \
335 des_SPtrans[6][(u>>26L)&0x3f]^ \ 344 DES_SPtrans[6][(u>>26L)&0x3f]^ \
336 des_SPtrans[1][(t>> 2L)&0x3f]^ \ 345 DES_SPtrans[1][(t>> 2L)&0x3f]^ \
337 des_SPtrans[3][(t>>10L)&0x3f]^ \ 346 DES_SPtrans[3][(t>>10L)&0x3f]^ \
338 des_SPtrans[5][(t>>18L)&0x3f]^ \ 347 DES_SPtrans[5][(t>>18L)&0x3f]^ \
339 des_SPtrans[7][(t>>26L)&0x3f]; } 348 DES_SPtrans[7][(t>>26L)&0x3f]; }
340#endif 349#endif
341#endif 350#endif
342 351
@@ -401,8 +410,8 @@
401 PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \ 410 PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \
402 } 411 }
403 412
404OPENSSL_EXTERN const DES_LONG des_SPtrans[8][64]; 413OPENSSL_EXTERN const DES_LONG DES_SPtrans[8][64];
405 414
406void fcrypt_body(DES_LONG *out,des_key_schedule ks, 415void fcrypt_body(DES_LONG *out,DES_key_schedule *ks,
407 DES_LONG Eswap0, DES_LONG Eswap1); 416 DES_LONG Eswap0, DES_LONG Eswap1);
408#endif 417#endif