support for older compilers - gcc3 + vc6
Karel Miko
8 years ago
10 | 10 |
|
11 | 11 |
/* use configuration data */
|
12 | 12 |
#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
|
13 | 18 |
|
14 | 19 |
#ifdef __cplusplus
|
15 | 20 |
extern "C" {
|
99 | 99 |
typedef unsigned long ulong32;
|
100 | 100 |
#endif
|
101 | 101 |
|
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 | |
|
114 | 102 |
/* detect sparc and sparc64 */
|
115 | 103 |
#if defined(__sparc__)
|
116 | 104 |
#define ENDIAN_BIG
|
|
131 | 119 |
#ifdef LTC_FAST
|
132 | 120 |
#undef LTC_FAST
|
133 | 121 |
#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
|
134 | 128 |
#endif
|
135 | 129 |
|
136 | 130 |
/* No asm is a quick way to disable anything "not portable" */
|
|
163 | 157 |
#error Can not be 32 and 64 bit words...
|
164 | 158 |
#endif
|
165 | 159 |
|
|
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 |
|
166 | 168 |
/* gcc 4.3 and up has a bswap builtin; detect it by gcc version.
|
167 | 169 |
* clang also supports the bswap builtin, and although clang pretends
|
168 | 170 |
* to be gcc (macro-wise, anyway), clang pretends to be a version
|
20 | 20 |
static unsigned long rng_nix(unsigned char *buf, unsigned long len,
|
21 | 21 |
void (*callback)(void))
|
22 | 22 |
{
|
23 | |
LTC_UNUSED_PARAM(callback);
|
|
23 |
/* LTC_UNUSED_PARAM(callback); */
|
24 | 24 |
#ifdef LTC_NO_FILE
|
25 | 25 |
LTC_UNUSED_PARAM(buf);
|
26 | 26 |
LTC_UNUSED_PARAM(len);
|
|
106 | 106 |
static unsigned long rng_win32(unsigned char *buf, unsigned long len,
|
107 | 107 |
void (*callback)(void))
|
108 | 108 |
{
|
109 | |
LTC_UNUSED_PARAM(callback);
|
|
109 |
/* LTC_UNUSED_PARAM(callback); */
|
110 | 110 |
HCRYPTPROV hProv = 0;
|
111 | 111 |
if (!CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL,
|
112 | 112 |
(CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET)) &&
|
15 | 15 |
*/
|
16 | 16 |
|
17 | 17 |
/* 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)
|
19 | 19 |
{
|
20 | 20 |
int i;
|
21 | |
unsigned long long res;
|
|
21 |
ulong64 res;
|
22 | 22 |
|
23 | 23 |
if (a->used == 0) {
|
24 | 24 |
return 0;
|
25 | 25 |
}
|
26 | 26 |
|
27 | 27 |
/* 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;
|
29 | 29 |
|
30 | 30 |
/* get most significant digit of result */
|
31 | 31 |
res = DIGIT(a,i);
|
15 | 15 |
*/
|
16 | 16 |
|
17 | 17 |
/* 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)
|
19 | 19 |
#endif
|
20 | 20 |
|
21 | 21 |
/* $Source$ */
|
258 | 258 |
int mp_set_long(mp_int *a, unsigned long b);
|
259 | 259 |
|
260 | 260 |
/* 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);
|
262 | 262 |
|
263 | 263 |
/* get a 32-bit value */
|
264 | 264 |
unsigned long mp_get_int(mp_int * a);
|
|
267 | 267 |
unsigned long mp_get_long(mp_int * a);
|
268 | 268 |
|
269 | 269 |
/* 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);
|
271 | 271 |
|
272 | 272 |
/* initialize and set a digit */
|
273 | 273 |
int mp_init_set (mp_int * a, mp_digit b);
|