use stdint.h for mp_digit and mp_word typedefs
This commit is contained in:
parent
25480d57b7
commit
7ab90a48ee
30
tommath.h
30
tommath.h
@ -18,6 +18,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
@ -61,15 +62,15 @@ extern "C" {
|
|||||||
* [any size beyond that is ok provided it doesn't overflow the data type]
|
* [any size beyond that is ok provided it doesn't overflow the data type]
|
||||||
*/
|
*/
|
||||||
#ifdef MP_8BIT
|
#ifdef MP_8BIT
|
||||||
typedef unsigned char mp_digit;
|
typedef uint8_t mp_digit;
|
||||||
typedef unsigned short mp_word;
|
typedef uint16_t mp_word;
|
||||||
#define MP_SIZEOF_MP_DIGIT 1
|
#define MP_SIZEOF_MP_DIGIT 1
|
||||||
#ifdef DIGIT_BIT
|
#ifdef DIGIT_BIT
|
||||||
#error You must not define DIGIT_BIT when using MP_8BIT
|
#error You must not define DIGIT_BIT when using MP_8BIT
|
||||||
#endif
|
#endif
|
||||||
#elif defined(MP_16BIT)
|
#elif defined(MP_16BIT)
|
||||||
typedef unsigned short mp_digit;
|
typedef uint16_t mp_digit;
|
||||||
typedef unsigned int mp_word;
|
typedef uint32_t mp_word;
|
||||||
#define MP_SIZEOF_MP_DIGIT 2
|
#define MP_SIZEOF_MP_DIGIT 2
|
||||||
#ifdef DIGIT_BIT
|
#ifdef DIGIT_BIT
|
||||||
#error You must not define DIGIT_BIT when using MP_16BIT
|
#error You must not define DIGIT_BIT when using MP_16BIT
|
||||||
@ -81,8 +82,16 @@ extern "C" {
|
|||||||
typedef signed long long long64;
|
typedef signed long long long64;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef unsigned long long mp_digit;
|
typedef uint64_t mp_digit;
|
||||||
|
#if defined(_WIN32)
|
||||||
|
typedef unsigned __int128 mp_word;
|
||||||
|
#elif defined(__GNUC__)
|
||||||
typedef unsigned long mp_word __attribute__ ((mode(TI)));
|
typedef unsigned long mp_word __attribute__ ((mode(TI)));
|
||||||
|
#else
|
||||||
|
/* it seems you have a problem
|
||||||
|
* but we assume you can somewhere define your own uint128_t */
|
||||||
|
typedef uint128_t mp_word;
|
||||||
|
#endif
|
||||||
|
|
||||||
#define DIGIT_BIT 60
|
#define DIGIT_BIT 60
|
||||||
#else
|
#else
|
||||||
@ -90,17 +99,12 @@ extern "C" {
|
|||||||
|
|
||||||
/* this is to make porting into LibTomCrypt easier :-) */
|
/* this is to make porting into LibTomCrypt easier :-) */
|
||||||
#ifndef CRYPT
|
#ifndef CRYPT
|
||||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
|
||||||
typedef unsigned __int64 ulong64;
|
|
||||||
typedef signed __int64 long64;
|
|
||||||
#else
|
|
||||||
typedef unsigned long long ulong64;
|
typedef unsigned long long ulong64;
|
||||||
typedef signed long long long64;
|
typedef signed long long long64;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef unsigned long mp_digit;
|
typedef uint32_t mp_digit;
|
||||||
typedef ulong64 mp_word;
|
typedef uint64_t mp_word;
|
||||||
|
|
||||||
#ifdef MP_31BIT
|
#ifdef MP_31BIT
|
||||||
/* this is an extension that uses 31-bit digits */
|
/* this is an extension that uses 31-bit digits */
|
||||||
@ -133,7 +137,7 @@ extern "C" {
|
|||||||
/* otherwise the bits per digit is calculated automatically from the size of a mp_digit */
|
/* otherwise the bits per digit is calculated automatically from the size of a mp_digit */
|
||||||
#ifndef DIGIT_BIT
|
#ifndef DIGIT_BIT
|
||||||
#define DIGIT_BIT (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1)) /* bits per digit */
|
#define DIGIT_BIT (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1)) /* bits per digit */
|
||||||
typedef unsigned long mp_min_u32;
|
typedef uint_least32_t mp_min_u32;
|
||||||
#else
|
#else
|
||||||
typedef mp_digit mp_min_u32;
|
typedef mp_digit mp_min_u32;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user