summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2002-06-25 11:12:58 +0000
committerWerner Koch <wk@gnupg.org>2002-06-25 11:12:58 +0000
commitf20ecd6bfafa3f2b06a0c33949dec1f2641b4bab (patch)
tree4706129d90f6ec73b1d705152d209c4e0a8a713b
parent6641cccfe5169df8e1d08836219244aebb94cf17 (diff)
downloadlibgcrypt-f20ecd6bfafa3f2b06a0c33949dec1f2641b4bab.tar.gz
* mpiutil.c (gcry_mpi_swap): New.
* mpi-div.c (gcry_mpi_div): New. (gcry_mpi_mod): New. * mpi-inv.c (gcry_mpi_invm): New. * mpicoder.c (do_get_buffer): Make sure that we allocate at least one byte.
-rw-r--r--mpi/ChangeLog11
-rw-r--r--mpi/mpi-div.c36
-rw-r--r--mpi/mpi-inv.c7
-rw-r--r--mpi/mpicoder.c6
-rw-r--r--mpi/mpiutil.c6
-rw-r--r--src/ChangeLog9
-rw-r--r--src/gcrypt.h28
-rw-r--r--src/missing-string.c1
8 files changed, 96 insertions, 8 deletions
diff --git a/mpi/ChangeLog b/mpi/ChangeLog
index 77fbccf0..b68af236 100644
--- a/mpi/ChangeLog
+++ b/mpi/ChangeLog
@@ -1,3 +1,14 @@
+2002-06-24 Werner Koch <wk@gnupg.org>
+
+ * mpiutil.c (gcry_mpi_swap): New.
+
+ * mpi-div.c (gcry_mpi_div): New.
+ (gcry_mpi_mod): New.
+ * mpi-inv.c (gcry_mpi_invm): New.
+
+ * mpicoder.c (do_get_buffer): Make sure that we allocate at least
+ one byte.
+
2002-06-12 Werner Koch <wk@gnupg.org>
* hppa1.1/udiv-qrnnd.S: Changes for PIC by Randolph Chung.
diff --git a/mpi/mpi-div.c b/mpi/mpi-div.c
index 32abe794..6ccc67cc 100644
--- a/mpi/mpi-div.c
+++ b/mpi/mpi-div.c
@@ -317,3 +317,39 @@ _gcry_mpi_divisible_ui(MPI dividend, ulong divisor )
return !_gcry_mpih_mod_1( dividend->d, dividend->nlimbs, divisor );
}
+
+void
+gcry_mpi_div (MPI quot, MPI rem, MPI dividend, MPI divisor, int round)
+{
+ if (!round)
+ {
+ if (!rem)
+ {
+ MPI tmp = mpi_alloc (mpi_get_nlimbs(quot));
+ _gcry_mpi_tdiv_qr (quot, tmp, dividend, divisor);
+ mpi_free (tmp);
+ }
+ else
+ _gcry_mpi_tdiv_qr (quot, rem, dividend, divisor);
+ }
+ else if (round < 0)
+ {
+ if (!rem)
+ _gcry_mpi_fdiv_q (quot, dividend, divisor);
+ else if (!quot)
+ _gcry_mpi_fdiv_r (rem, dividend, divisor);
+ else
+ _gcry_mpi_fdiv_qr (quot, rem, dividend, divisor);
+ }
+ else
+ log_bug ("mpi rounding to ceiling not yet implemented\n");
+}
+
+
+void
+gcry_mpi_mod (MPI rem, MPI dividend, MPI divisor)
+{
+ _gcry_mpi_fdiv_r (rem, dividend, divisor);
+ rem->sign = 0;
+}
+
diff --git a/mpi/mpi-inv.c b/mpi/mpi-inv.c
index 8760e941..80efd62d 100644
--- a/mpi/mpi-inv.c
+++ b/mpi/mpi-inv.c
@@ -267,4 +267,9 @@ _gcry_mpi_invm( MPI x, MPI a, MPI n )
}
-
+int
+gcry_mpi_invm (MPI x, MPI a, MPI n)
+{
+ _gcry_mpi_invm (x, a, n);
+ return 1;
+}
diff --git a/mpi/mpicoder.c b/mpi/mpicoder.c
index f005521d..3051b410 100644
--- a/mpi/mpicoder.c
+++ b/mpi/mpicoder.c
@@ -221,12 +221,14 @@ do_get_buffer( MPI a, unsigned *nbytes, int *sign, int force_secure )
byte *p, *buffer;
mpi_limb_t alimb;
int i;
+ size_t n;
if( sign )
*sign = a->sign;
*nbytes = a->nlimbs * BYTES_PER_MPI_LIMB;
- p = buffer = force_secure || mpi_is_secure(a) ? gcry_xmalloc_secure( *nbytes)
- : gcry_xmalloc( *nbytes );
+ n = *nbytes? *nbytes:1; /* allocate at least one byte */
+ p = buffer = force_secure || mpi_is_secure(a) ? gcry_xmalloc_secure(n)
+ : gcry_xmalloc(n);
for(i=a->nlimbs-1; i >= 0; i-- ) {
alimb = a->d[i];
diff --git a/mpi/mpiutil.c b/mpi/mpiutil.c
index a60ca000..b1b9a97d 100644
--- a/mpi/mpiutil.c
+++ b/mpi/mpiutil.c
@@ -307,6 +307,12 @@ _gcry_mpi_swap( MPI a, MPI b)
tmp = *a; *a = *b; *b = tmp;
}
+void
+gcry_mpi_swap( MPI a, MPI b)
+{
+ _gcry_mpi_swap (a, b);
+}
+
GCRY_MPI
gcry_mpi_new( unsigned int nbits )
diff --git a/src/ChangeLog b/src/ChangeLog
index d0bcd96d..4f8f0a68 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,6 +1,13 @@
+2002-06-24 Werner Koch <wk@gnupg.org>
+
+ * missing-string.c: Include ctype.h.
+
+ * gcrypt.h (gcry_mpi_invm, gcry_mpi_div, gcry_mpi_mod)
+ (gcry_mpi_swap): New.
+
2002-06-18 Werner Koch <wk@gnupg.org>
- * gcrypt.h: Added a bunch for brief function descriptions.
+ * gcrypt.h: Added a bunch of brief function descriptions.
2002-05-21 Werner Koch <wk@gnupg.org>
diff --git a/src/gcrypt.h b/src/gcrypt.h
index ea3da630..7f8e955b 100644
--- a/src/gcrypt.h
+++ b/src/gcrypt.h
@@ -36,7 +36,7 @@ extern "C" {
autoconf (using the AM_PATH_GCRYPT macro) check that this header
matches the installed library. Note: Do not edit the next line as
configure may fix the string here. */
-#define GCRYPT_VERSION "1.1.8-cvs"
+#define GCRYPT_VERSION "1.1.8"
/* Internal: We can't to use the convenience macros for the multi
precision integer functions when building this library. */
@@ -279,6 +279,9 @@ GcryMPI gcry_mpi_set (GcryMPI w, const GcryMPI u);
/* Store the unsigned integer value U in W. */
GcryMPI gcry_mpi_set_ui (GcryMPI w, unsigned long u);
+/* Swap the values of A and B. */
+void gcry_mpi_swap (GcryMPI a, GcryMPI b);
+
/* Compare the big integer number U and V returning 0 for equality, a
positive value for U > V and a negative for U < V. */
int gcry_mpi_cmp (const GcryMPI u, const GcryMPI v);
@@ -340,13 +343,26 @@ void gcry_mpi_mulm (GcryMPI w, GcryMPI u, GcryMPI v, GcryMPI m);
/* W = U * (2 ^ CNT). */
void gcry_mpi_mul_2exp (GcryMPI w, GcryMPI u, unsigned long cnt);
+/* Q = DIVIDEND / DIVISOR, R = DIVIDEND % DIVISOR,
+ Q or R may be passed as NULL. ROUND should be negative or 0. */
+void gcry_mpi_div (GcryMPI q, GcryMPI r,
+ GcryMPI dividend, GcryMPI divisor, int round);
+
+/* R = DIVIDEND % DIVISOR */
+void gcry_mpi_mod (GcryMPI r, GcryMPI dividend, GcryMPI divisor);
+
/* W = B ^ E mod M. */
void gcry_mpi_powm (GcryMPI w,
const GcryMPI b, const GcryMPI e, const GcryMPI m);
/* Set G to the greatest common divisor of A and B.
Return true if the G is 1. */
-int gcry_mpi_gcd (GcryMPI g, GcryMPI a, GcryMPI b);
+int gcry_mpi_gcd (GcryMPI g, GcryMPI a, GcryMPI b);
+
+/* Set X to the multiplicative inverse of A mod M.
+ Return true if the value exists. */
+int gcry_mpi_invm (GcryMPI x, GcryMPI a, GcryMPI m);
+
/* Return the number of bits required to represent A. */
unsigned int gcry_mpi_get_nbits (GcryMPI a);
@@ -414,8 +430,12 @@ int gcry_mpi_get_flag (GcryMPI a, enum gcry_mpi_flag flag);
#define mpi_mul_2exp(w,u,v) gcry_mpi_mul_2exp ((w),(u),(v))
#define mpi_mul(w,u,v) gcry_mpi_mul ((w),(u),(v))
#define mpi_mulm(w,u,v,m) gcry_mpi_mulm ((w),(u),(v),(m))
-#define mpi_powm(w,b,e,m) gcry_mpi_powm( (w), (b), (e), (m) )
-#define mpi_gcd(g,a,b) gcry_mpi_gcd( (g), (a), (b) )
+#define mpi_powm(w,b,e,m) gcry_mpi_powm ( (w), (b), (e), (m) )
+#define mpi_tdiv(q,r,a,m) gcry_mpi_div ( (q), (r), (a), (m), 0)
+#define mpi_fdiv(q,r,a,m) gcry_mpi_div ( (q), (r), (a), (m), -1)
+#define mpi_mod(r,a,m) gcry_mpi_mod ((r), (a), (m))
+#define mpi_gcd(g,a,b) gcry_mpi_gcd ( (g), (a), (b) )
+#define mpi_invm(g,a,b) gcry_mpi_invm ( (g), (a), (b) )
#define mpi_get_nbits(a) gcry_mpi_get_nbits ((a))
#define mpi_test_bit(a,b) gcry_mpi_test_bit ((a),(b))
diff --git a/src/missing-string.c b/src/missing-string.c
index 99789036..2efd3d6f 100644
--- a/src/missing-string.c
+++ b/src/missing-string.c
@@ -21,6 +21,7 @@
#include <config.h>
#include <stdlib.h>
#include <string.h>
+#include <ctype.h>
#include "g10lib.h"