Codebase list libcryptx-perl / b295b31
support for older compilers - gcc3 + vc6 Karel Miko 8 years ago
6 changed file(s) with 27 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
1010
1111 /* use configuration data */
1212 #include <tomcrypt_custom.h>
13
14 /* Define inline for MSVC<2015 */
15 # if defined(_MSC_VER) && _MSC_VER < 1900
16 # define inline __inline
17 # endif
1318
1419 #ifdef __cplusplus
1520 extern "C" {
9999 typedef unsigned long ulong32;
100100 #endif
101101
102 #ifdef LTC_FAST
103 #if __GNUC__ < 4 /* if the compiler does not support gnu extensions, i.e. its neither clang nor gcc nor icc */
104 #error the LTC_FAST hack is only available on compilers that support __attribute__((may_alias)) - disable it for your compiler, and dont worry, it won`t buy you much anyway
105 #else
106 #ifdef ENDIAN_64BITWORD
107 typedef ulong64 __attribute__((__may_alias__)) LTC_FAST_TYPE;
108 #else
109 typedef ulong32 __attribute__((__may_alias__)) LTC_FAST_TYPE;
110 #endif
111 #endif
112 #endif /* LTC_FAST */
113
114102 /* detect sparc and sparc64 */
115103 #if defined(__sparc__)
116104 #define ENDIAN_BIG
131119 #ifdef LTC_FAST
132120 #undef LTC_FAST
133121 #endif
122 #endif
123
124 /* if the compiler does not support __attribute__((__may_alias__)) */
125 /* MSVC: http://stackoverflow.com/questions/70013/how-to-detect-if-im-compiling-code-with-visual-studio-2008 */
126 #if (defined(__GNUC__) && __GNUC__ < 4) || (defined(_MSC_VER) && _MSC_VER < 1300)
127 #undef LTC_FAST
134128 #endif
135129
136130 /* No asm is a quick way to disable anything "not portable" */
163157 #error Can not be 32 and 64 bit words...
164158 #endif
165159
160 #ifdef LTC_FAST
161 #ifdef ENDIAN_64BITWORD
162 typedef ulong64 __attribute__((__may_alias__)) LTC_FAST_TYPE;
163 #else
164 typedef ulong32 __attribute__((__may_alias__)) LTC_FAST_TYPE;
165 #endif
166 #endif /* LTC_FAST */
167
166168 /* gcc 4.3 and up has a bswap builtin; detect it by gcc version.
167169 * clang also supports the bswap builtin, and although clang pretends
168170 * to be gcc (macro-wise, anyway), clang pretends to be a version
2020 static unsigned long rng_nix(unsigned char *buf, unsigned long len,
2121 void (*callback)(void))
2222 {
23 LTC_UNUSED_PARAM(callback);
23 /* LTC_UNUSED_PARAM(callback); */
2424 #ifdef LTC_NO_FILE
2525 LTC_UNUSED_PARAM(buf);
2626 LTC_UNUSED_PARAM(len);
106106 static unsigned long rng_win32(unsigned char *buf, unsigned long len,
107107 void (*callback)(void))
108108 {
109 LTC_UNUSED_PARAM(callback);
109 /* LTC_UNUSED_PARAM(callback); */
110110 HCRYPTPROV hProv = 0;
111111 if (!CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL,
112112 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET)) &&
1515 */
1616
1717 /* get the lower unsigned long long of an mp_int, platform dependent */
18 unsigned long long mp_get_long_long (mp_int * a)
18 ulong64 mp_get_long_long (mp_int * a)
1919 {
2020 int i;
21 unsigned long long res;
21 ulong64 res;
2222
2323 if (a->used == 0) {
2424 return 0;
2525 }
2626
2727 /* get number of digits of the lsb we have to read */
28 i = MIN(a->used,(int)((sizeof(unsigned long long)*CHAR_BIT+DIGIT_BIT-1)/DIGIT_BIT))-1;
28 i = MIN(a->used,(int)((sizeof(ulong64)*CHAR_BIT+DIGIT_BIT-1)/DIGIT_BIT))-1;
2929
3030 /* get most significant digit of result */
3131 res = DIGIT(a,i);
1515 */
1616
1717 /* set a platform dependent unsigned long long int */
18 MP_SET_XLONG(mp_set_long_long, unsigned long long)
18 MP_SET_XLONG(mp_set_long_long, ulong64)
1919 #endif
2020
2121 /* $Source$ */
258258 int mp_set_long(mp_int *a, unsigned long b);
259259
260260 /* set a platform dependent unsigned long long value */
261 int mp_set_long_long(mp_int *a, unsigned long long b);
261 int mp_set_long_long(mp_int *a, ulong64 b);
262262
263263 /* get a 32-bit value */
264264 unsigned long mp_get_int(mp_int * a);
267267 unsigned long mp_get_long(mp_int * a);
268268
269269 /* get a platform dependent unsigned long long value */
270 unsigned long long mp_get_long_long(mp_int * a);
270 ulong64 mp_get_long_long(mp_int * a);
271271
272272 /* initialize and set a digit */
273273 int mp_init_set (mp_int * a, mp_digit b);