1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
Index: mpi-1.8.6/mpi-types.h
===================================================================
--- mpi-1.8.6.orig/mpi-types.h
+++ mpi-1.8.6/mpi-types.h
@@ -1,17 +1,56 @@
-/* Type definitions generated by 'types.pl' */
+/*
+ * Universal. We can further tweak these by making them
+ * bitfields inside the mp_int struct.
+ */
+typedef int mp_sign;
+typedef int mp_size;
-typedef char mp_sign;
-typedef unsigned short mp_digit; /* 2 byte type */
-typedef unsigned int mp_word; /* 4 byte type */
-typedef unsigned int mp_size;
-typedef int mp_err;
+/*
+ * Universal. Does not need platform configuration.
+ */
+typedef int mp_err;
-#define MP_DIGIT_BIT (CHAR_BIT*sizeof(mp_digit))
-#define MP_DIGIT_MAX USHRT_MAX
-#define MP_WORD_BIT (CHAR_BIT*sizeof(mp_word))
-#define MP_WORD_MAX UINT_MAX
+#if HAVE_USUPERLONG_T && HAVE_ULONGLONG_T && \
+ SIZEOF_SUPERLONG_T / 2 == SIZEOF_LONGLONG_T && \
+ SIZEOF_PTR >= SIZEOF_LONGLONG_T
+ typedef ulonglong_t mp_digit;
+ typedef usuperlong_t mp_word;
+ #define MP_DIGIT_SIZE SIZEOF_LONGLONG_T
+ #define DIGIT_FMT "%" #SIZEOF_SUPERLONG_T "llx"
+#elif HAVE_ULONGLONG_T && SIZEOF_LONGLONG_T / 2 == SIZEOF_LONG && \
+ SIZEOF_PTR >= SIZEOF_LONG
+ typedef unsigned long mp_digit;
+ typedef ulonglong_t mp_word;
+ #define MP_DIGIT_SIZE SIZEOF_LONG
+ #define DIGIT_FMT "%" #SIZEOF_LONGLONG_T "lx"
+#elif HAVE_ULONGLONG_T && SIZEOF_LONGLONG_T / 2 == SIZEOF_INT && \
+ SIZEOF_PTR >= SIZEOF_INT
+ typedef unsigned int mp_digit;
+ typedef ulonglong_t mp_word;
+ #define MP_DIGIT_SIZE SIZEOF_INT
+ #define DIGIT_FMT "%" #SIZEOF_LONGLONG_T "lx"
+#elif SIZEOF_LONG / 2 == SIZEOF_INT && SIZEOF_PTR >= SIZEOF_INT
+ typedef unsigned int mp_digit;
+ typedef unsigned long mp_word;
+ #define MP_DIGIT_SIZE SIZEOF_INT
+ #define DIGIT_FMT "%" #SIZEOF_LONG "x"
+#elif SIZEOF_INT / 2 == SIZEOF_SHORT
+ typedef unsigned short mp_digit;
+ typedef unsigned int mp_word;
+ #define MP_DIGIT_SIZE SIZEOF_SHORT
+ #define DIGIT_FMT "%" #SIZEOF_INT "x"
+#elif SIZEOF_SHORT == 2
+ typedef unsigned char mp_digit;
+ typedef unsigned short mp_word;
+ #define MP_DIGIT_SIZE 1
+ #define DIGIT_FMT "%" #SIZEOF_SHORT "x"
+#else
+ #error Failure to configure MPI types on this target platform
+#endif
-#define RADIX (MP_DIGIT_MAX+1)
+#define MP_DIGIT_BIT ((int) (CHAR_BIT*sizeof(mp_digit)))
+#define MP_DIGIT_MAX ((mp_digit) -1)
+#define MP_WORD_BIT ((int) (CHAR_BIT*sizeof(mp_word)))
+#define MP_WORD_MAX ((mp_word) -1)
-#define MP_DIGIT_SIZE 2
-#define DIGIT_FMT "%04X"
+#define RADIX (((mp_word) MP_DIGIT_MAX) + 1)
Index: mpi-1.8.6/mpi.c
===================================================================
--- mpi-1.8.6.orig/mpi.c
+++ mpi-1.8.6/mpi.c
@@ -9,6 +9,7 @@
$Id: mpi.c,v 1.1 2004/02/08 04:29:29 sting Exp $
*/
+#include "../config.h"
#include "mpi.h"
#include <stdlib.h>
#include <string.h>
Index: mpi-1.8.6/mplogic.c
===================================================================
--- mpi-1.8.6.orig/mplogic.c
+++ mpi-1.8.6/mplogic.c
@@ -9,6 +9,7 @@
$Id: mplogic.c,v 1.1 2004/02/08 04:29:29 sting Exp $
*/
+#include "../config.h"
#include "mplogic.h"
#include <stdlib.h>
Index: mpi-1.8.6/mpprime.c
===================================================================
--- mpi-1.8.6.orig/mpprime.c
+++ mpi-1.8.6/mpprime.c
@@ -10,6 +10,7 @@
$Id: mpprime.c,v 1.1 2004/02/08 04:29:29 sting Exp $
*/
+#include "../config.h"
#include "mpprime.h"
#include <stdlib.h>
Index: mpi-1.8.6/mprsa.c
===================================================================
--- mpi-1.8.6.orig/mprsa.c
+++ mpi-1.8.6/mprsa.c
@@ -11,6 +11,7 @@
$Id: mprsa.c,v 1.1 2004/02/08 04:29:29 sting Exp $
*/
+#include "../config.h"
#include "mprsa.h"
#include <stdlib.h>
#include <string.h>
|