summaryrefslogtreecommitdiffstats
path: root/mpi-patches
diff options
context:
space:
mode:
Diffstat (limited to 'mpi-patches')
-rw-r--r--mpi-patches/add-mp-hash48
-rw-r--r--mpi-patches/add-mp-set-intptr77
-rw-r--r--mpi-patches/add-mpi-toradix-with-case54
-rw-r--r--mpi-patches/config-types120
-rw-r--r--mpi-patches/export-mp-eq34
-rw-r--r--mpi-patches/fix-mult-bug13
-rw-r--r--mpi-patches/fix-warnings61
-rw-r--r--mpi-patches/series8
-rw-r--r--mpi-patches/use-txr-allocator70
9 files changed, 485 insertions, 0 deletions
diff --git a/mpi-patches/add-mp-hash b/mpi-patches/add-mp-hash
new file mode 100644
index 00000000..8a2cd585
--- /dev/null
+++ b/mpi-patches/add-mp-hash
@@ -0,0 +1,48 @@
+Index: mpi-1.8.6/mpi.c
+===================================================================
+--- mpi-1.8.6.orig/mpi.c 2011-12-09 14:10:41.000000000 -0800
++++ mpi-1.8.6/mpi.c 2011-12-09 14:26:02.000000000 -0800
+@@ -1960,6 +1960,30 @@
+
+ /* }}} */
+
++unsigned long mp_hash(mp_int *a)
++{
++ unsigned long hash = 0;
++ int ix;
++ for (ix = 0; ix < USED(a); ix++) {
++ mp_digit d = DIGIT(a, ix);
++#if SIZEOF_LONG < MP_DIGIT_SIZE
++ int j;
++ for (j = 0; j < MP_DIGIT_SIZE / SIZEOF_LONG; j++) {
++ hash ^= d;
++ d >> (SIZEOF_LONG * CHAR_BIT);
++ }
++#elif SIZEOF_LONG == MP_DIGIT_SIZE
++ hash ^= d;
++#else
++ hash <<= MP_DIGIT_BITS;
++ hash ^= d;
++#endif
++ }
++ if (SIGN(a) == MP_NEG)
++ hash = (hash << 16 | hash >> (SIZEOF_LONG * CHAR_BIT - 16));
++ return hash;
++}
++
+ /*------------------------------------------------------------------------*/
+ /* {{{ Number theoretic functions */
+
+Index: mpi-1.8.6/mpi.h
+===================================================================
+--- mpi-1.8.6.orig/mpi.h 2011-12-09 14:10:41.000000000 -0800
++++ mpi-1.8.6/mpi.h 2011-12-09 14:10:41.000000000 -0800
+@@ -165,6 +165,8 @@
+ int mp_isodd(mp_int *a);
+ int mp_iseven(mp_int *a);
+
++unsigned long mp_hash(mp_int *a);
++
+ /*------------------------------------------------------------------------*/
+ /* Number theoretic */
+
diff --git a/mpi-patches/add-mp-set-intptr b/mpi-patches/add-mp-set-intptr
new file mode 100644
index 00000000..a5d50a33
--- /dev/null
+++ b/mpi-patches/add-mp-set-intptr
@@ -0,0 +1,77 @@
+Index: mpi-1.8.6/mpi.c
+===================================================================
+--- mpi-1.8.6.orig/mpi.c 2011-12-09 13:52:26.000000000 -0800
++++ mpi-1.8.6/mpi.c 2011-12-09 13:56:19.000000000 -0800
+@@ -528,6 +528,59 @@
+
+ /* }}} */
+
++mp_err mp_set_intptr(mp_int *mp, int_ptr_t z)
++{
++ if (sizeof z > sizeof (mp_digit)) {
++ int ix, shift;
++ unsigned long v = z > 0 ? z : -z;
++ const int nd = (sizeof v + sizeof (mp_digit) - 1) / sizeof (mp_digit);
++
++ ARGCHK(mp != NULL, MP_BADARG);
++
++ mp_zero(mp);
++
++ if(z == 0)
++ return MP_OKAY; /* shortcut for zero */
++
++ s_mp_grow(mp, nd);
++
++ USED(mp) = nd;
++
++ for (ix = 0, shift = 0; ix < nd; ix++, shift += MP_DIGIT_BIT)
++ {
++ DIGIT(mp, ix) = (v >> shift) & MP_DIGIT_MAX;
++ }
++
++ if(z < 0)
++ SIGN(mp) = MP_NEG;
++
++ return MP_OKAY;
++ }
++
++ mp_set(mp, z);
++ return MP_OKAY;
++}
++
++/*
++ * No checks here: assumes that the mp is in range!
++ */
++mp_err mp_get_intptr(mp_int *mp, int_ptr_t *z)
++{
++ int_ptr_t out = 0;
++
++#if MP_DIGIT_SIZE < SIZEOF_PTR
++ int ix;
++ int nd = USED(mp);
++ for (ix = 0; ix < nd; ix++, out <<= MP_DIGIT_BIT)
++ out = DIGIT(mp, ix);
++#else
++ out = DIGIT(mp, 0);
++#endif
++
++ *z = (SIGN(mp) == MP_NEG) ? -out : out;
++ return MP_OKAY;
++}
++
+ /*------------------------------------------------------------------------*/
+ /* {{{ Digit arithmetic */
+
+Index: mpi-1.8.6/mpi.h
+===================================================================
+--- mpi-1.8.6.orig/mpi.h 2011-12-09 13:49:20.000000000 -0800
++++ mpi-1.8.6/mpi.h 2011-12-09 13:56:19.000000000 -0800
+@@ -94,6 +94,8 @@
+ void mp_zero(mp_int *mp);
+ void mp_set(mp_int *mp, mp_digit d);
+ mp_err mp_set_int(mp_int *mp, long z);
++mp_err mp_set_intptr(mp_int *mp, int_ptr_t z);
++mp_err mp_get_intptr(mp_int *mp, int_ptr_t *z);
+
+ /*------------------------------------------------------------------------*/
+ /* Single digit arithmetic */
diff --git a/mpi-patches/add-mpi-toradix-with-case b/mpi-patches/add-mpi-toradix-with-case
new file mode 100644
index 00000000..6fe9c191
--- /dev/null
+++ b/mpi-patches/add-mpi-toradix-with-case
@@ -0,0 +1,54 @@
+Index: mpi-1.8.6/mpi.c
+===================================================================
+--- mpi-1.8.6.orig/mpi.c 2011-12-09 19:16:58.000000000 -0800
++++ mpi-1.8.6/mpi.c 2011-12-09 19:19:23.000000000 -0800
+@@ -2624,9 +2624,9 @@
+
+ /* }}} */
+
+-/* {{{ mp_toradix(mp, str, radix) */
++/* {{{ mp_toradix_case(mp, str, radix, low) */
+
+-mp_err mp_toradix(mp_int *mp, unsigned char *str, int radix)
++mp_err mp_toradix_case(mp_int *mp, unsigned char *str, int radix, int low)
+ {
+ int ix, pos = 0;
+
+@@ -2657,7 +2657,7 @@
+ }
+
+ /* Generate digits, use capital letters */
+- ch = s_mp_todigit(rem, radix, 0);
++ ch = s_mp_todigit(rem, radix, low);
+
+ str[pos++] = ch;
+ }
+@@ -2685,10 +2685,15 @@
+
+ return MP_OKAY;
+
+-} /* end mp_toradix() */
++} /* end mp_toradix_case() */
+
+ /* }}} */
+
++mp_err mp_toradix(mp_int *mp, unsigned char *str, int radix)
++{
++ return mp_toradix_case(mp, str, radix, 0);
++}
++
+ /* {{{ mp_char2value(ch, r) */
+
+ int mp_char2value(char ch, int r)
+Index: mpi-1.8.6/mpi.h
+===================================================================
+--- mpi-1.8.6.orig/mpi.h 2011-12-09 19:16:58.000000000 -0800
++++ mpi-1.8.6/mpi.h 2011-12-09 19:28:38.000000000 -0800
+@@ -213,6 +213,7 @@
+ int mp_radix_size(mp_int *mp, int radix);
+ int mp_value_radix_size(int num, int qty, int radix);
+ mp_err mp_toradix(mp_int *mp, unsigned char *str, int radix);
++mp_err mp_toradix_case(mp_int *mp, unsigned char *str, int radix, int low);
+
+ int mp_char2value(char ch, int r);
+
diff --git a/mpi-patches/config-types b/mpi-patches/config-types
new file mode 100644
index 00000000..78b672b8
--- /dev/null
+++ b/mpi-patches/config-types
@@ -0,0 +1,120 @@
+Index: mpi-1.8.6/mpi-types.h
+===================================================================
+--- mpi-1.8.6.orig/mpi-types.h 2011-12-09 09:00:59.000000000 -0800
++++ mpi-1.8.6/mpi-types.h 2011-12-09 14:09:59.000000000 -0800
+@@ -1,17 +1,54 @@
+-/* 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_T
++ #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 DIGIT_FMT "%" #SIZEOF_INT "x"
++#elif SIZEOF_SHORT == 2
++ typedef unsigned char mp_digit;
++ typedef unsigned short mp_word;
++ #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 2011-12-09 09:00:59.000000000 -0800
++++ mpi-1.8.6/mpi.c 2011-12-09 14:10:29.000000000 -0800
+@@ -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 2011-12-09 09:00:59.000000000 -0800
++++ mpi-1.8.6/mplogic.c 2011-12-09 14:10:29.000000000 -0800
+@@ -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 2011-12-09 09:00:59.000000000 -0800
++++ mpi-1.8.6/mpprime.c 2011-12-09 09:01:01.000000000 -0800
+@@ -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 2011-12-09 09:00:59.000000000 -0800
++++ mpi-1.8.6/mprsa.c 2011-12-09 09:01:01.000000000 -0800
+@@ -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>
diff --git a/mpi-patches/export-mp-eq b/mpi-patches/export-mp-eq
new file mode 100644
index 00000000..e9ea7a49
--- /dev/null
+++ b/mpi-patches/export-mp-eq
@@ -0,0 +1,34 @@
+Index: mpi-1.8.6/mpi.c
+===================================================================
+--- mpi-1.8.6.orig/mpi.c 2011-12-09 13:56:19.000000000 -0800
++++ mpi-1.8.6/mpi.c 2011-12-09 13:56:23.000000000 -0800
+@@ -86,14 +86,6 @@
+
+ /* }}} */
+
+-/* {{{ Comparison constants */
+-
+-#define MP_LT -1
+-#define MP_EQ 0
+-#define MP_GT 1
+-
+-/* }}} */
+-
+ /* {{{ Constant strings */
+
+ /* Constant strings returned by mp_strerror() */
+Index: mpi-1.8.6/mpi.h
+===================================================================
+--- mpi-1.8.6.orig/mpi.h 2011-12-09 13:56:19.000000000 -0800
++++ mpi-1.8.6/mpi.h 2011-12-09 13:56:23.000000000 -0800
+@@ -42,6 +42,10 @@
+ #define MP_UNDEF -5 /* answer is undefined */
+ #define MP_LAST_CODE MP_UNDEF
+
++#define MP_LT -1
++#define MP_EQ 0
++#define MP_GT 1
++
+ #include "mpi-types.h"
+
+ /* Included for compatibility... */
diff --git a/mpi-patches/fix-mult-bug b/mpi-patches/fix-mult-bug
new file mode 100644
index 00000000..691f3334
--- /dev/null
+++ b/mpi-patches/fix-mult-bug
@@ -0,0 +1,13 @@
+Index: mpi-1.8.6/mpi.c
+===================================================================
+--- mpi-1.8.6.orig/mpi.c 2011-12-09 21:11:31.000000000 -0800
++++ mpi-1.8.6/mpi.c 2011-12-09 21:12:09.000000000 -0800
+@@ -3272,7 +3272,7 @@
+ }
+
+ for(ix = 0; ix < max; ix++) {
+- w = (dp[ix] * d) + k;
++ w = (dp[ix] * (mp_word) d) + k;
+ dp[ix] = ACCUM(w);
+ k = CARRYOUT(w);
+ }
diff --git a/mpi-patches/fix-warnings b/mpi-patches/fix-warnings
new file mode 100644
index 00000000..c35e4ead
--- /dev/null
+++ b/mpi-patches/fix-warnings
@@ -0,0 +1,61 @@
+Index: mpi-1.8.6/mpi.c
+===================================================================
+--- mpi-1.8.6.orig/mpi.c 2011-12-08 21:03:20.000000000 -0800
++++ mpi-1.8.6/mpi.c 2011-12-08 21:05:04.000000000 -0800
+@@ -2401,7 +2401,7 @@
+ int ix;
+
+ d = *dp;
+- for(ix = 0; ix < sizeof(mp_digit); ++ix) {
++ for(ix = 0; ix < (int) sizeof(mp_digit); ++ix) {
+ *spos = d & UCHAR_MAX;
+ d >>= CHAR_BIT;
+ ++spos;
+@@ -2598,10 +2598,10 @@
+ /* Reverse the digits and sign indicator */
+ ix = 0;
+ while(ix < pos) {
+- char tmp = str[ix];
++ char tmp2 = str[ix];
+
+ str[ix] = str[pos];
+- str[pos] = tmp;
++ str[pos] = tmp2;
+ ++ix;
+ --pos;
+ }
+@@ -2952,10 +2952,10 @@
+ void s_mp_mod_2d(mp_int *mp, mp_digit d)
+ {
+ unsigned int ndig = (d / DIGIT_BIT), nbit = (d % DIGIT_BIT);
+- unsigned int ix;
++ int ix;
+ mp_digit dmask, *dp = DIGITS(mp);
+
+- if(ndig >= USED(mp))
++ if((int) ndig >= USED(mp))
+ return;
+
+ /* Flush all the bits above 2^d in its digit */
+Index: mpi-1.8.6/mplogic.c
+===================================================================
+--- mpi-1.8.6.orig/mplogic.c 2011-12-08 21:03:20.000000000 -0800
++++ mpi-1.8.6/mplogic.c 2011-12-08 21:05:16.000000000 -0800
+@@ -290,7 +290,7 @@
+ for(ix = 0; ix < USED(a); ix++) {
+ cur = DIGIT(a, ix);
+
+- for(db = 0; db < sizeof(mp_digit); db++) {
++ for(db = 0; db < (int) sizeof(mp_digit); db++) {
+ reg = (cur >> (CHAR_BIT * db)) & UCHAR_MAX;
+
+ nset += bitc[reg];
+@@ -319,7 +319,7 @@
+ for(ix = 0; ix < USED(a); ix++) {
+ cur = DIGIT(a, ix);
+
+- for(db = 0; db < sizeof(mp_digit); db++) {
++ for(db = 0; db < (int) sizeof(mp_digit); db++) {
+ reg = (cur >> (CHAR_BIT * db)) & UCHAR_MAX;
+
+ nset += bitc[UCHAR_MAX - reg];
diff --git a/mpi-patches/series b/mpi-patches/series
new file mode 100644
index 00000000..71aa73ba
--- /dev/null
+++ b/mpi-patches/series
@@ -0,0 +1,8 @@
+config-types
+fix-warnings
+use-txr-allocator
+add-mp-set-intptr
+export-mp-eq
+add-mp-hash
+add-mpi-toradix-with-case
+fix-mult-bug
diff --git a/mpi-patches/use-txr-allocator b/mpi-patches/use-txr-allocator
new file mode 100644
index 00000000..2f85a574
--- /dev/null
+++ b/mpi-patches/use-txr-allocator
@@ -0,0 +1,70 @@
+Index: mpi-1.8.6/mpi.c
+===================================================================
+--- mpi-1.8.6.orig/mpi.c 2011-12-08 22:17:15.000000000 -0800
++++ mpi-1.8.6/mpi.c 2011-12-08 22:27:07.000000000 -0800
+@@ -15,6 +15,11 @@
+ #include <string.h>
+ #include <ctype.h>
+
++typedef unsigned char mem_t;
++extern mem_t *chk_malloc(size_t size);
++extern mem_t *chk_calloc(size_t n, size_t size);
++extern mem_t *chk_realloc(mem_t *, size_t size);
++
+ #if MP_DEBUG
+ #include <stdio.h>
+
+@@ -154,7 +159,7 @@
+ #define s_mp_copy(sp, dp, count) memcpy(dp, sp, (count) * sizeof(mp_digit))
+ #endif /* MP_MEMCPY */
+
+- #define s_mp_alloc(nb, ni) calloc(nb, ni)
++ #define s_mp_alloc(nb, ni) chk_calloc(nb, ni)
+ #define s_mp_free(ptr) {if(ptr) free(ptr);}
+ #endif /* MP_MACRO */
+
+@@ -282,7 +287,7 @@
+ {
+ ARGCHK(mp != NULL && prec > 0, MP_BADARG);
+
+- if((DIGITS(mp) = s_mp_alloc(prec, sizeof(mp_digit))) == NULL)
++ if((DIGITS(mp) = (mp_digit *) s_mp_alloc(prec, sizeof(mp_digit))) == NULL)
+ return MP_MEM;
+
+ SIGN(mp) = MP_ZPOS;
+@@ -312,7 +317,7 @@
+ if(mp == from)
+ return MP_OKAY;
+
+- if((DIGITS(mp) = s_mp_alloc(USED(from), sizeof(mp_digit))) == NULL)
++ if((DIGITS(mp) = (mp_digit *) s_mp_alloc(USED(from), sizeof(mp_digit))) == NULL)
+ return MP_MEM;
+
+ s_mp_copy(DIGITS(from), DIGITS(mp), USED(from));
+@@ -358,7 +363,7 @@
+ s_mp_copy(DIGITS(from), DIGITS(to), USED(from));
+
+ } else {
+- if((tmp = s_mp_alloc(USED(from), sizeof(mp_digit))) == NULL)
++ if((tmp = (mp_digit *) s_mp_alloc(USED(from), sizeof(mp_digit))) == NULL)
+ return MP_MEM;
+
+ s_mp_copy(DIGITS(from), tmp, USED(from));
+@@ -2670,7 +2675,7 @@
+ /* Set min to next nearest default precision block size */
+ min = ((min + (s_mp_defprec - 1)) / s_mp_defprec) * s_mp_defprec;
+
+- if((tmp = s_mp_alloc(min, sizeof(mp_digit))) == NULL)
++ if((tmp = (mp_digit *) s_mp_alloc(min, sizeof(mp_digit))) == NULL)
+ return MP_MEM;
+
+ s_mp_copy(DIGITS(mp), tmp, USED(mp));
+@@ -2757,7 +2762,7 @@
+ /* Allocate ni records of nb bytes each, and return a pointer to that */
+ void *s_mp_alloc(size_t nb, size_t ni)
+ {
+- return calloc(nb, ni);
++ return chk_calloc(nb, ni);
+
+ } /* end s_mp_alloc() */
+ #endif