libtommath sync
Karel Miko
7 years ago
37 | 37 | #endif |
38 | 38 | |
39 | 39 | /* detect 64-bit mode if possible */ |
40 | #if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT)) | |
41 | #if defined(__x86_64__) | |
40 | #if defined(__x86_64__) | |
41 | #if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT)) | |
42 | 42 | #if defined(__GNUC__) |
43 | 43 | typedef unsigned long mp_uint128 __attribute__ ((mode(TI))); |
44 | 44 | #define MP_64BIT |
58 | 58 | * [any size beyond that is ok provided it doesn't overflow the data type] |
59 | 59 | */ |
60 | 60 | #ifdef MP_8BIT |
61 | typedef mp_uint8 mp_digit; | |
62 | typedef mp_uint16 mp_word; | |
63 | #define DIGIT_BIT 7 | |
61 | typedef mp_uint8 mp_digit; | |
62 | typedef mp_uint16 mp_word; | |
63 | #define MP_SIZEOF_MP_DIGIT 1 | |
64 | #ifdef DIGIT_BIT | |
65 | #error You must not define DIGIT_BIT when using MP_8BIT | |
66 | #endif | |
64 | 67 | #elif defined(MP_16BIT) |
65 | typedef mp_uint16 mp_digit; | |
66 | typedef mp_uint32 mp_word; | |
67 | #define DIGIT_BIT 15 | |
68 | typedef mp_uint16 mp_digit; | |
69 | typedef mp_uint32 mp_word; | |
70 | #define MP_SIZEOF_MP_DIGIT 2 | |
71 | #ifdef DIGIT_BIT | |
72 | #error You must not define DIGIT_BIT when using MP_16BIT | |
73 | #endif | |
68 | 74 | #elif defined(MP_64BIT) |
69 | typedef mp_uint64 mp_digit; | |
70 | typedef mp_uint128 mp_word; | |
71 | #define DIGIT_BIT 60 | |
72 | #elif defined(MP_32BIT) | |
73 | typedef mp_uint32 mp_digit; | |
74 | typedef mp_uint64 mp_word; | |
75 | #define DIGIT_BIT 31 | |
75 | typedef mp_uint64 mp_digit; | |
76 | typedef mp_uint128 mp_word; | |
77 | #define DIGIT_BIT 60 | |
76 | 78 | #else |
77 | typedef mp_uint32 mp_digit; | |
78 | typedef mp_uint64 mp_word; | |
79 | #define DIGIT_BIT 28 | |
79 | /* this is the default case, 28-bit digits */ | |
80 | ||
81 | /* this is to make porting into LibTomCrypt easier :-) */ | |
82 | typedef mp_uint32 mp_digit; | |
83 | typedef mp_uint64 mp_word; | |
84 | ||
85 | #ifdef MP_31BIT | |
86 | /* this is an extension that uses 31-bit digits */ | |
87 | #define DIGIT_BIT 31 | |
88 | #else | |
89 | /* default case is 28-bit digits, defines MP_28BIT as a handy macro to test */ | |
90 | #define DIGIT_BIT 28 | |
80 | 91 | #define MP_28BIT |
92 | #endif | |
93 | #endif | |
94 | ||
95 | /* otherwise the bits per digit is calculated automatically from the size of a mp_digit */ | |
96 | #ifndef DIGIT_BIT | |
97 | #define DIGIT_BIT (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1)) /* bits per digit */ | |
98 | typedef mp_uint32 mp_min_u32; | |
99 | #else | |
100 | typedef mp_digit mp_min_u32; | |
81 | 101 | #endif |
82 | 102 | |
83 | 103 | /* platforms that can use a better rand function */ |