cryptlib  3.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros
osconfig.h
Go to the documentation of this file.
1 #ifndef _OSCONFIG_DEFINED
2 #define _OSCONFIG_DEFINED
3 
4 /* Pull in cryptlib-wide configuration options */
5 
6 #include "misc/config.h"
7 
8 /* OpenSSL-specific defines */
9 
10 #define OPENSSL_EXTERN extern
11 #define OPENSSL_GLOBAL
12 #if defined( _WINDOWS ) && !defined( WINDOWS ) /* Windows */
13  #define WINDOWS /* Old format */
14  #define OPENSSL_SYS_WINDOWS /* New fomat */
15 #endif /* OpenSSL Windows not defined */
16 #if defined( _WIN32 ) /* Win32 and WinCE */
17  #ifndef WIN32
18  #define WIN32 /* Old format OpenSSL Win32 identifier */
19  #endif /* WIN32 */
20  #define OPENSSL_SYS_WIN32 /* New format OpenSSL Win32 identifier */
21  /* Note that the following asm defines are duplicated in misc/os_spec.h,
22  because the OpenSSL headers are non-orthogonal to the cryptlib ones.
23  Any changes made here need to be reflected in os_spec.h */
24  #if !( defined( _WIN32_WCE ) || defined( _M_X64 ) || \
25  defined( __BORLANDC__ ) || defined( NO_ASM ) )
26  #define USE_ASM /* Always enabled for x86 Win32 */
27  #endif /* WinCE || x86-64 || Borland compilers */
28 #endif /* OpenSSL Win32 not defined */
29 #include <stdlib.h> /* For malloc() */
30 #include <string.h> /* For memset() */
31 #ifdef USE_ASM /* Defined via makefile for Unix systems */
32  #define BN_ASM
33  #define MD5_ASM
34  #define RMD160_ASM
35  #define SHA1_ASM
36 #endif /* USE_ASM */
37 #if defined( USE_ASM ) && defined( __WATCOMC__ )
38  #define ASM_EXPORT __cdecl
39 #else
40  #define ASM_EXPORT
41 #endif /* System-specific interface to ASM files */
42 
43 /* General defines. A generic config from the original OpenSSL version can
44  be found at http://lists.alioth.debian.org/pipermail/pkg-openssl-changes/-
45  2005-October/000012.html */
46 
47 #include <limits.h>
48 #if ULONG_MAX > 0xFFFFFFFFUL
49  #define SIXTY_FOUR_BIT
50 #else
51  #define THIRTY_TWO_BIT
52 #endif /* Machine word size */
53 
54 #if defined( _MSC_VER )
55  /* cryptlib is built with the highest warning level, disable some of the
56  more irritating warnings produced by the OpenSSL code */
57  #pragma warning( disable: 4244 ) /* int <-> unsigned char/short */
58  #pragma warning( disable: 4100 ) /* Unreferenced parameter */
59  #pragma warning( disable: 4127 ) /* Conditional is constant: while( TRUE ) */
60 #endif /* Visual C++ */
61 
62 /* Aches */
63 #ifdef _AIX
64  #define B_ENDIAN
65  #define BN_LLONG
66  #define RC4_CHAR
67 #endif /* AIX */
68 
69 /* Alpha */
70 #if defined( __osf__ ) || defined( __alpha__ )
71  #define L_ENDIAN
72  #define SIXTY_FOUR_BIT_LONG
73  #define DES_INT
74  #define DES_UNROLL
75  #define DES_RISC1
76  #define RC4_CHUNK
77 #endif /* Alpha */
78 
79 /* BeOS */
80 #ifdef __BEOS__
81  #if defined( __i386__ )
82  #define L_ENDIAN
83  #define BN_LLONG
84  #define DES_PTR
85  #define DES_RISC1
86  #define DES_UNROLL
87  #define RC4_INDEX
88  #elif defined( __ppc__ )
89  #define B_ENDIAN
90  #define BN_LLONG
91  #define BF_PTR
92  #define DES_RISC1
93  #define DES_UNROLL
94  #define RC4_CHAR
95  #define RC4_CHUNK
96  #else
97  #error Need to define CPU type for non-x86/non-PPC BeOS
98  #endif /* BeoS variants */
99 #endif /* BeOS */
100 
101 /* The BSDs and Linux. For low-level code-generation purposes these are
102  identical, even if they differ at a higher level */
103 #if defined( __FreeBSD__ ) || defined( __bsdi__ ) || \
104  defined( __OpenBSD__ ) || defined( __NetBSD__ ) || \
105  defined( __linux__ )
106  #if defined( __x86_64__ ) || defined( __amd64__ )
107  /* 64-bit x86 has both 'long' and 'long long' as 64 bits. In addition
108  we use DES_INT since int's are 64-bit. We have to check for the
109  64-bit x86 variants before the generic ones because they're a
110  variation on the generics (e.g. AMD64 defines both __athlon__ and
111  __x86_64__, so if we checked for __athlon__ first we'd identify it
112  as a generic rather than 64-bit build) */
113  #define L_ENDIAN
114  #undef SIXTY_FOUR_BIT
115  #define SIXTY_FOUR_BIT_LONG
116  #define DES_INT
117  #define DES_RISC1
118  #define DES_UNROLL
119  #define RC4_INDEX
120  #elif defined( __i386__ )
121  #define L_ENDIAN
122  #define BN_LLONG
123  #define DES_PTR
124  #define DES_RISC1
125  #define DES_UNROLL
126  #define RC4_INDEX
127  #elif defined( __arm ) || defined( __arm__ )
128  #define L_ENDIAN
129  #define BN_LLONG
130  #define DES_RISC1
131  #elif defined( __mips__ )
132  #define L_ENDIAN
133  #define BN_LLONG
134  #define BF_PTR
135  #define DES_RISC2
136  #define DES_PTR
137  #define DES_UNROLL
138  #define RC4_INDEX
139  #define RC4_CHAR
140  #define RC4_CHUNK
141  #elif defined( __ppc__ ) || defined( __powerpc__ )
142  #define B_ENDIAN
143  #define BN_LLONG
144  #define BF_PTR
145  #define DES_RISC1
146  #define DES_UNROLL
147  #define RC4_CHAR
148  #define RC4_CHUNK
149  #elif defined( __hppa__ )
150  #define B_ENDIAN
151  #define BN_DIV2W
152  #define BN_LLONG
153  #define DES_PTR
154  #define DES_UNROLL
155  #define DES_RISC1
156  #define MD32_XARRAY
157  #elif defined( __sparc__ )
158  #define B_ENDIAN
159  #define BN_DIV2W
160  #define BN_LLONG
161  #define BF_PTR
162  #define DES_UNROLL
163  #define RC4_CHAR
164  #define RC4_CHUNK
165  #else
166  #error Need to define CPU type for non-x86/Arm/MIPS/PA-Risc/PPC/Sparc Linux
167  #endif /* *BSD/Linux variants */
168 #endif /* *BSD/Linux */
169 #if defined( __LINUX__ ) && defined( __WATCOMC__ )
170  #define L_ENDIAN
171  #define BN_LLONG
172  #define RC4_INDEX
173 #endif /* Linux */
174 
175 /* Cray Unicos */
176 #ifdef _CRAY
177  /* Crays are big-endian, but if B_ENDIAN is defined the code implicitly
178  assumes 32-bit ints whereas Crays have 64-bit ints and longs. However,
179  the non-B/L_ENDIAN code happens to work, so we don't define either */
180  #undef SIXTY_FOUR_BIT
181  #define SIXTY_FOUR_BIT_LONG
182  #define DES_INT
183 #endif /* Cray Unicos */
184 
185 /* DGUX */
186 #ifdef __dgux
187  #define L_ENDIAN
188  #define RC4_INDEX
189  #define DES_UNROLL
190 #endif /* DGUX */
191 
192 /* DOS */
193 #if defined( MSDOS ) || defined( __MSDOS__ )
194  #if defined(__WATCOMC__)
195  /* 32-bit DOS */
196  #define L_ENDIAN
197  #define BN_LLONG
198  #define RC4_INDEX
199  #else
200  /* 16-bit DOS */
201  #define L_ENDIAN
202  #define BN_LLONG
203  #define MD2_CHAR
204  #define DES_UNROLL
205  #define DES_PTR
206  #define RC4_INDEX
207  #undef THIRTY_TWO_BIT
208  #define SIXTEEN_BIT
209  #endif /* 16- vs.32-bit DOS */
210 #endif /* DOS */
211 
212 /* Irix */
213 #ifdef __sgi
214 
215  /* Irix 5.x and lower */
216  #if ( OSVERSION <= 5 )
217  #define B_ENDIAN
218  #define BN_LLONG
219  #define BF_PTR
220  #define DES_RISC2
221  #define DES_PTR
222  #define DES_UNROLL
223  #define RC4_INDEX
224  #define RC4_CHAR
225  #define RC4_CHUNK
226  #define MD2_CHAR
227 
228  /* Irix 6.x and higher */
229  #else
230  #define B_ENDIAN
231  #define BN_DIV3W
232  #define MD2_CHAR
233  #define RC4_INDEX
234  #define RC4_CHAR
235  #define RC4_CHUNK_LL
236  #define DES_UNROLL
237  #define DES_RISC2
238  #define DES_PTR
239  #define BF_PTR
240  #define SIXTY_FOUR_BIT
241  /* Pure 64-bit should also define SIXTY_FOUR_BIT_LONG */
242  #endif /* Irix versions */
243 #endif /* Irix */
244 
245 /* Mac */
246 #if defined( __MWERKS__ ) || defined( SYMANTEC_C ) || defined( __MRC__ )
247  #define B_ENDIAN
248  #define BN_LLONG
249  #define BF_PTR
250  #define DES_UNROLL
251  #define RC4_CHAR
252  #define RC4_CHUNK
253 #endif /* Mac */
254 
255 /* Darwin PPC / Mac OS X */
256 #if defined( __APPLE__ ) && !defined( __MAC__ )
257  #if defined( __ppc__ )
258  #define B_ENDIAN
259  #else
260  #define L_ENDIAN
261  #endif
262  #define BN_LLONG
263  #define BF_PTR
264  #define DES_RISC1
265  #define DES_UNROLL
266  #define RC4_CHAR
267  #define RC4_CHUNK
268 #endif /* Mac OS X */
269 
270 /* MSDOS */
271 #ifdef __MSDOS__
272  #define L_ENDIAN
273  #define BN_LLONG
274  #define MD2_CHAR
275  #define DES_UNROLL
276  #define DES_PTR
277  #define RC4_INDEX
278  #undef THIRTY_TWO_BIT
279  #define SIXTEEN_BIT
280 #endif /* __MSDOS__ */
281 
282 /* MVS */
283 #ifdef __MVS__
284  #define B_ENDIAN
285 #endif /* MVS */
286 
287 /* NCR MP-RAS */
288 #ifdef __UNIX_SV__
289  #define L_ENDIAN
290  #define BN_LLONG
291  #define DES_PTR
292  #define DES_RISC1
293  #define DES_UNROLL
294  #define RC4_INDEX
295 #endif /* UNIX_SV */
296 
297 /* Palm OS: ARM */
298 #if defined( __PALMSOURCE__ )
299  #if defined( __arm ) || defined( __arm__ )
300  #define L_ENDIAN
301  #define BN_LLONG
302  #define DES_RISC1
303  #else
304  #error Need to define architecture-specific values for crypto code
305  #endif /* Palm OS variants */
306 #endif /* Palm OS */
307 
308 /* PHUX */
309 #ifdef __hpux
310 
311  /* PHUX 9.x (some versions report it as 09 so we also check for 0) */
312  #if ( OSVERSION == 0 || OSVERSION == 9 )
313  #define B_ENDIAN
314  #define BN_DIV2W
315  #define BN_LLONG
316  #define DES_PTR
317  #define DES_UNROLL
318  #define DES_RISC1
319  #define MD32_XARRAY
320 
321  /* PHUX 10.x, 11.x */
322  #else
323  #define B_ENDIAN
324  #define BN_DIV2W
325  #define BN_LLONG
326  #define DES_PTR
327  #define DES_UNROLL
328  #define DES_RISC1
329  #define MD32_XARRAY
330  /* Pure 64-bit should also define SIXTY_FOUR_BIT_LONG MD2_CHAR RC4_INDEX
331  RC4_CHAR DES_INT */
332  #endif /* PHUX versions */
333 #endif /* PHUX */
334 
335 /* QNX */
336 #ifdef __QNX__
337  #define L_ENDIAN
338  #define BN_LLONG
339  #define DES_PTR
340  #define DES_RISC1
341  #define DES_UNROLL
342  #define RC4_INDEX
343  #if OSVERSION <= 4
344  /* The Watcom compiler can't handle 64-bit ints even though the hardware
345  can, so we have to build it as 16-bit code with 16x16 -> 32 multiplies
346  rather than 32x32 -> 64 */
347  #undef THIRTY_TWO_BIT
348  #define SIXTEEN_BIT
349  #endif /* QNX 4.x */
350 #endif /* QNX */
351 
352 /* SCO/UnixWare */
353 #ifdef __SCO_VERSION__
354 
355  /* SCO gcc */
356  #if defined( __GNUC__ )
357  #define L_ENDIAN
358  #define BN_LLONG
359  #define DES_PTR
360  #define DES_RISC1
361  #define DES_UNROLL
362  #define RC4_INDEX
363 
364  /* SCO cc */
365  #else
366  #define L_ENDIAN
367  #define BN_LLONG
368  #define DES_PTR
369  #define DES_RISC1
370  #define DES_UNROLL
371  #define RC4_INDEX
372  #define MD2_CHAR
373  #endif /* SCO gcc/cc */
374 #endif /* SCO */
375 
376 /* Solaris */
377 #ifdef sun
378 
379  /* Solaris Sparc */
380  #ifdef sparc
381 
382  /* Solaris Sparc gcc */
383  #if defined( __GNUC__ )
384  #define B_ENDIAN
385  #define BN_DIV2W
386  #define BN_LLONG
387  #define BF_PTR
388  #define DES_UNROLL
389  #define RC4_CHAR
390  #define RC4_CHUNK
391 
392  /* Solaris Sparc Sun C */
393  #else
394  #define B_ENDIAN
395  #define BN_DIV2W
396  #define BN_LLONG
397  #define BF_PTR
398  #define DES_PTR
399  #define DES_RISC1
400  #define DES_UNROLL
401  #define RC4_CHAR
402  #define RC4_CHUNK
403  /* Pure 64-bit should also define SIXTY_FOUR_BIT_LONG and DES_INT */
404  #endif /* Solaris Sparc */
405 
406  /* Solaris x86 */
407  #else
408 
409  /* Solaris x86 gcc */
410  #if defined( __GNUC__ )
411  #define L_ENDIAN
412  #define BN_LLONG
413  #define DES_PTR
414  #define DES_RISC1
415  #define DES_UNROLL
416  #define RC4_INDEX
417 
418  /* Solaris x86 Sun C */
419  #else
420  #define L_ENDIAN
421  #define BN_LLONG
422  #define BF_PTR
423  #define DES_PTR
424  #define DES_UNROLL
425  #define RC4_CHAR
426  #define RC4_CHUNK
427  #endif /* Solaris x86 */
428  #endif /* Solaris Sparc vs x86 */
429 #endif /* Slowaris */
430 
431 /* Symbian OS: Usually ARM, but we may be running under the x86 emulator */
432 #if defined( __SYMBIAN32__ )
433  #if defined( __MARM__ )
434  #define L_ENDIAN
435  #define BN_LLONG
436  #define DES_RISC1
437  #elif defined( __EMU_SYMBIAN_OS__ )
438  #define L_ENDIAN
439  #define BN_LLONG
440  #define BF_PTR
441  #define DES_PTR
442  #define DES_UNROLL
443  #define RC4_INDEX
444  #else
445  #error Need to define architecture-specific values for crypto code
446  #endif /* Symbian OS variants */
447 #endif /* Symbian OS */
448 
449 /* Tandem NSK/OSS */
450 #ifdef __TANDEM
451  #define B_ENDIAN
452  #define BF_PTR
453  #define DES_RISC2
454  #define DES_PTR
455  #define DES_UNROLL
456  #define RC4_INDEX
457  #define RC4_CHAR
458  #define RC4_CHUNK
459  #define MD2_CHAR
460 #endif /* Tandem */
461 
462 /* Ultrix */
463 #ifdef __ultrix__
464  #define L_ENDIAN
465  #define DES_PTR
466  #define DES_RISC2
467  #define DES_UNROLL
468 #endif /* Ultrix */
469 
470 /* VM/CMS */
471 #ifdef __VMCMS__
472  #define B_ENDIAN
473 #endif /* VM/CMS */
474 
475 /* Windows */
476 #if ( defined( _WINDOWS ) || defined( WIN32 ) || defined( _WIN32 ) )
477  #define L_ENDIAN
478 
479  /* VC++ */
480  #if defined( _MSC_VER )
481 
482  /* VS 64-bit */
483  #if defined( _M_X64 )
484  /* Win64's ULONG_MAX (via limits.h) is 32 bits so the system isn't
485  detected as a 64-bit one, to fix this we manually override the
486  detected machine word size here */
487  #undef THIRTY_TWO_BIT
488  #define SIXTY_FOUR_BIT
489  #define RC4_CHUNK_LL
490  #define DES_INT
491 
492  /* VC++ 32-bit */
493  #elif ( _MSC_VER >= 1000 )
494  #define BN_LLONG
495  #define RC4_INDEX
496 
497  /* VC++ 16-bit */
498  #else
499  #define BN_LLONG
500  #define MD2_CHAR
501  #define DES_UNROLL
502  #define DES_PTR
503  #define RC4_INDEX
504  #undef THIRTY_TWO_BIT
505  #define SIXTEEN_BIT
506  #endif /* VC++ 32 vs 16-bit */
507 
508  /* BC++ */
509  #elif defined( __BORLANDC__ )
510  #define BN_LLONG
511  #define DES_PTR
512  #define RC4_INDEX
513 
514  /* gcc */
515  #else
516  #define BN_LLONG
517  #define DES_PTR
518  #define DES_RISC1
519  #define DES_UNROLL
520  #define RC4_INDEX
521  #endif /* Assorted Windows compilers */
522 #endif /* Windows */
523 #ifdef __CYGWIN__
524  #define L_ENDIAN
525  #define BN_LLONG
526  #define DES_PTR
527  #define DES_RISC1
528  #define DES_UNROLL
529  #define RC4_INDEX
530 #endif /* gcc native under Cygwin (i.e. not a Cygwin-hosted
531  cross-development toolchain */
532 
533 /* Embeded OSes get a bit complicated because they're usually cross-
534  compiled, first we try for OS-specific options, then we try for the most
535  obvious generic options like the GNU toolchain, and finally if we can't
536  find anything we bail out with an error message */
537 
538 #if defined( USE_EMBEDDED_OS )
539 
540  /* Xilinx XMK */
541  #if defined ( _XMK ) || defined( __XMK__ )
542  #if defined( __mb__ )
543  #define B_ENDIAN
544  /* Not sure what other options the MicroBlaze build should enable... */
545  #elif defined( __ppc__ )
546  #define B_ENDIAN
547  #define BN_LLONG
548  #define BF_PTR
549  #define DES_RISC1
550  #define DES_UNROLL
551  #define RC4_CHAR
552  #define RC4_CHUNK
553  #else
554  #error Need to define CPU type for non-MicroBlaze/non-PPC XMK.
555  #endif /* XMK target variants */
556 
557  /* Generic gcc */
558  #elif defined( __i386__ )
559  #define L_ENDIAN
560  #define BN_LLONG
561  #define DES_PTR
562  #define DES_RISC1
563  #define DES_UNROLL
564  #define RC4_INDEX
565  #elif defined( __ppc__ ) || defined( __powerpc__ )
566  #define B_ENDIAN
567  #define BN_LLONG
568  #define BF_PTR
569  #define DES_RISC1
570  #define DES_UNROLL
571  #define RC4_CHAR
572  #define RC4_CHUNK
573  #elif defined( __arm ) || defined( __arm__ )
574  #define L_ENDIAN
575  #define BN_LLONG
576  #define DES_RISC1
577 
578  /* Generic 68K */
579  #elif defined( __m68k__ )
580  /* This one is CISC-y enough that any of the (mostly) RISC-specific
581  optimisations won't have much effect, so the generic code is as good
582  as any */
583  #define B_ENDIAN
584 
585  /* We need the developer's help to sort it out */
586  #else
587  #error Need to configure the crypto build options for your toolchain.
588  #endif /* Embedded OS variants */
589 #endif /* Embedded OSes */
590 
591 /* RC4_CHUNK is actually a data type rather than a straight define so we
592  redefine it as a data type if it's been defined */
593 
594 #ifdef RC4_CHUNK
595  #undef RC4_CHUNK
596  #define RC4_CHUNK unsigned long
597 #endif /* RC4_CHUNK */
598 
599 /* Make sure that we weren't missed out. See the comment in the Cray
600  section for the exception for Crays */
601 
602 #if !defined( _CRAY ) && !defined( L_ENDIAN ) && !defined( B_ENDIAN )
603  #error You need to add system-specific configuration settings to osconfig.h
604 #endif /* Endianness not defined */
605 #if defined( CHECK_ENDIANNESS ) && !defined( OSX_UNIVERSAL_BINARY )
606  /* One-off check in des_enc.c, however for OS X universal (fat) binaries
607  we're effectively cross-compiling for multiple targets so we don't
608  perform the check, which would yield false positives */
609  #undef _CONFIG_DEFINED
610  /* Including crypt.h at this point violates the normal include order
611  because we've already included config.h which normally depends on
612  settings in crypt.h, however for this one-off check it isn't a
613  problem so we fake out the include-order check in config.h */
614  #include "crypt.h"
615  #if ( defined( L_ENDIAN ) && !defined( DATA_LITTLEENDIAN ) ) || \
616  ( defined( B_ENDIAN ) && !defined( DATA_BIGENDIAN ) )
617  #error You need to synchronise the endianness configuration settings in osconfig.h and crypt.h
618  #endif /* Endianness conflict */
619 #endif /* One-off check */
620 
621 #endif /* _OSCONFIG_DEFINED */