summaryrefslogtreecommitdiff
path: root/mpi
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2013-10-22 14:26:53 +0200
committerWerner Koch <wk@gnupg.org>2013-12-05 08:27:48 +0100
commit7bacf1812b55fa78db63abaa1f5a9220e9c6cccc (patch)
tree4141585ef24a83e22e411355585784f24b78f58f /mpi
parent85bb0a98ea5add0296cbcc415d557eaa1f6bd294 (diff)
downloadlibgcrypt-7bacf1812b55fa78db63abaa1f5a9220e9c6cccc.tar.gz
Remove macro hacks for internal vs. external functions. Part 1.
* src/visibility.h: Remove almost all define/undef hacks for symbol visibility. Add macros to detect the use of the public functions. Change all affected functions by prefixing them explicitly with an underscore and change all internal callers to call the underscore prefixed versions. Provide convenience macros from sexp and mpi functions. * src/visibility.c: Change all functions to use only gpg_err_code_t and translate to gpg_error_t only in visibility.c. -- The use of the macro magic made if hard to follow the function calls in the source. It was not easy to see if an internal or external function (as defined by visibility.c) was called. The change is quite large but hopefully makes Libgcrypt easier to maintain. Some function have not yet been fixed; this will be done soon. Because Libgcrypt does no make use of any other libgpg-error using libraries it is useless to always translate between gpg_error_t and gpg_err_code_t (i.e with and w/o error source identifier). This translation has no mostly be moved to the function wrappers in visibility.c. An additional advantage of using gpg_err_code_t is that comparison can be done without using gpg_err_code(). I am sorry for that large patch, but a series of patches would actually be more work to audit. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'mpi')
-rw-r--r--mpi/ec.c50
-rw-r--r--mpi/mpi-add.c22
-rw-r--r--mpi/mpi-bit.c18
-rw-r--r--mpi/mpi-cmp.c4
-rw-r--r--mpi/mpi-div.c9
-rw-r--r--mpi/mpi-gcd.c11
-rw-r--r--mpi/mpi-inv.c2
-rw-r--r--mpi/mpi-mod.c2
-rw-r--r--mpi/mpi-mpow.c2
-rw-r--r--mpi/mpi-mul.c10
-rw-r--r--mpi/mpi-pow.c8
-rw-r--r--mpi/mpicoder.c72
-rw-r--r--mpi/mpiutil.c53
13 files changed, 127 insertions, 136 deletions
diff --git a/mpi/ec.c b/mpi/ec.c
index 6fca95b5..6a968a57 100644
--- a/mpi/ec.c
+++ b/mpi/ec.c
@@ -53,8 +53,8 @@ _gcry_mpi_point_log (const char *name, mpi_point_t point, mpi_ec_t ctx)
if (ctx)
{
- x = gcry_mpi_new (0);
- y = gcry_mpi_new (0);
+ x = mpi_new (0);
+ y = mpi_new (0);
}
if (!ctx || _gcry_mpi_ec_get_affine (x, y, point, ctx))
{
@@ -74,8 +74,8 @@ _gcry_mpi_point_log (const char *name, mpi_point_t point, mpi_ec_t ctx)
}
if (ctx)
{
- gcry_mpi_release (x);
- gcry_mpi_release (y);
+ _gcry_mpi_release (x);
+ _gcry_mpi_release (y);
}
}
@@ -84,7 +84,7 @@ _gcry_mpi_point_log (const char *name, mpi_point_t point, mpi_ec_t ctx)
coordinate; it is only used to pre-allocate some resources and
might also be passed as 0 to use a default value. */
mpi_point_t
-gcry_mpi_point_new (unsigned int nbits)
+_gcry_mpi_point_new (unsigned int nbits)
{
mpi_point_t p;
@@ -98,7 +98,7 @@ gcry_mpi_point_new (unsigned int nbits)
/* Release the point object P. P may be NULL. */
void
-gcry_mpi_point_release (mpi_point_t p)
+_gcry_mpi_point_release (mpi_point_t p)
{
if (p)
{
@@ -142,8 +142,8 @@ point_set (mpi_point_t d, mpi_point_t s)
/* Set the projective coordinates from POINT into X, Y, and Z. If a
coordinate is not required, X, Y, or Z may be passed as NULL. */
void
-gcry_mpi_point_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z,
- mpi_point_t point)
+_gcry_mpi_point_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z,
+ mpi_point_t point)
{
if (x)
mpi_set (x, point->x);
@@ -158,8 +158,8 @@ gcry_mpi_point_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z,
release POINT. If a coordinate is not required, X, Y, or Z may be
passed as NULL. */
void
-gcry_mpi_point_snatch_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z,
- mpi_point_t point)
+_gcry_mpi_point_snatch_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z,
+ mpi_point_t point)
{
mpi_snatch (x, point->x);
mpi_snatch (y, point->y);
@@ -173,11 +173,11 @@ gcry_mpi_point_snatch_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z,
POINT is given as NULL a new point object is allocated. Returns
POINT or the newly allocated point object. */
mpi_point_t
-gcry_mpi_point_set (mpi_point_t point,
- gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z)
+_gcry_mpi_point_set (mpi_point_t point,
+ gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z)
{
if (!point)
- point = gcry_mpi_point_new (0);
+ point = mpi_point_new (0);
if (x)
mpi_set (point->x, x);
@@ -202,11 +202,11 @@ gcry_mpi_point_set (mpi_point_t point,
coordinates X, Y, and Z are released. Returns POINT or the newly
allocated point object. */
mpi_point_t
-gcry_mpi_point_snatch_set (mpi_point_t point,
- gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z)
+_gcry_mpi_point_snatch_set (mpi_point_t point,
+ gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z)
{
if (!point)
- point = gcry_mpi_point_new (0);
+ point = mpi_point_new (0);
if (x)
mpi_snatch (point->x, x);
@@ -240,7 +240,7 @@ ec_mod (gcry_mpi_t w, mpi_ec_t ec)
static void
ec_addm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, mpi_ec_t ctx)
{
- gcry_mpi_add (w, u, v);
+ mpi_add (w, u, v);
ec_mod (w, ctx);
}
@@ -248,7 +248,7 @@ static void
ec_subm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, mpi_ec_t ec)
{
(void)ec;
- gcry_mpi_sub (w, u, v);
+ mpi_sub (w, u, v);
/*ec_mod (w, ec);*/
}
@@ -427,11 +427,11 @@ ec_deinit (void *opaque)
mpi_free (ctx->p);
mpi_free (ctx->a);
mpi_free (ctx->b);
- gcry_mpi_point_release (ctx->G);
+ _gcry_mpi_point_release (ctx->G);
mpi_free (ctx->n);
/* The key. */
- gcry_mpi_point_release (ctx->Q);
+ _gcry_mpi_point_release (ctx->Q);
mpi_free (ctx->d);
/* Private data of ec.c. */
@@ -617,7 +617,7 @@ _gcry_mpi_ec_get_affine (gcry_mpi_t x, gcry_mpi_t y, mpi_point_t point,
if (y)
ec_mulm (y, point->y, z, ctx);
- gcry_mpi_release (z);
+ _gcry_mpi_release (z);
}
return 0;
@@ -1262,7 +1262,7 @@ _gcry_mpi_ec_curve_point (gcry_mpi_point_t point, mpi_ec_t ctx)
if (!mpi_cmp (y, w))
res = 1;
- gcry_mpi_release (xxx);
+ _gcry_mpi_release (xxx);
}
break;
case MPI_EC_MONTGOMERY:
@@ -1292,9 +1292,9 @@ _gcry_mpi_ec_curve_point (gcry_mpi_point_t point, mpi_ec_t ctx)
break;
}
- gcry_mpi_release (w);
- gcry_mpi_release (x);
- gcry_mpi_release (y);
+ _gcry_mpi_release (w);
+ _gcry_mpi_release (x);
+ _gcry_mpi_release (y);
return res;
}
diff --git a/mpi/mpi-add.c b/mpi/mpi-add.c
index 5f7ad3ff..53f476e0 100644
--- a/mpi/mpi-add.c
+++ b/mpi/mpi-add.c
@@ -36,7 +36,7 @@
* result in W. U and V may be the same.
*/
void
-gcry_mpi_add_ui(gcry_mpi_t w, gcry_mpi_t u, unsigned long v )
+_gcry_mpi_add_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v )
{
mpi_ptr_t wp, up;
mpi_size_t usize, wsize;
@@ -85,7 +85,7 @@ gcry_mpi_add_ui(gcry_mpi_t w, gcry_mpi_t u, unsigned long v )
void
-gcry_mpi_add(gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v)
+_gcry_mpi_add(gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v)
{
mpi_ptr_t wp, up, vp;
mpi_size_t usize, vsize, wsize;
@@ -162,7 +162,7 @@ gcry_mpi_add(gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v)
* result in W.
*/
void
-gcry_mpi_sub_ui(gcry_mpi_t w, gcry_mpi_t u, unsigned long v )
+_gcry_mpi_sub_ui(gcry_mpi_t w, gcry_mpi_t u, unsigned long v )
{
mpi_ptr_t wp, up;
mpi_size_t usize, wsize;
@@ -211,25 +211,25 @@ gcry_mpi_sub_ui(gcry_mpi_t w, gcry_mpi_t u, unsigned long v )
}
void
-gcry_mpi_sub(gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v)
+_gcry_mpi_sub(gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v)
{
gcry_mpi_t vv = mpi_copy (v);
vv->sign = ! vv->sign;
- gcry_mpi_add (w, u, vv);
+ mpi_add (w, u, vv);
mpi_free (vv);
}
void
-gcry_mpi_addm( gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m)
+_gcry_mpi_addm( gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m)
{
- gcry_mpi_add(w, u, v);
- _gcry_mpi_mod (w, w, m);
+ mpi_add (w, u, v);
+ mpi_mod (w, w, m);
}
void
-gcry_mpi_subm( gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m)
+_gcry_mpi_subm( gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m)
{
- gcry_mpi_sub(w, u, v);
- _gcry_mpi_mod (w, w, m);
+ mpi_sub (w, u, v);
+ mpi_mod (w, w, m);
}
diff --git a/mpi/mpi-bit.c b/mpi/mpi-bit.c
index 74042e89..fcafda04 100644
--- a/mpi/mpi-bit.c
+++ b/mpi/mpi-bit.c
@@ -68,7 +68,7 @@ _gcry_mpi_normalize( gcry_mpi_t a )
* Return the number of bits in A.
*/
unsigned int
-gcry_mpi_get_nbits( gcry_mpi_t a )
+_gcry_mpi_get_nbits (gcry_mpi_t a)
{
unsigned n;
@@ -95,7 +95,7 @@ gcry_mpi_get_nbits( gcry_mpi_t a )
* Test whether bit N is set.
*/
int
-gcry_mpi_test_bit( gcry_mpi_t a, unsigned int n )
+_gcry_mpi_test_bit( gcry_mpi_t a, unsigned int n )
{
unsigned int limbno, bitno;
mpi_limb_t limb;
@@ -114,7 +114,7 @@ gcry_mpi_test_bit( gcry_mpi_t a, unsigned int n )
* Set bit N of A.
*/
void
-gcry_mpi_set_bit( gcry_mpi_t a, unsigned int n )
+_gcry_mpi_set_bit( gcry_mpi_t a, unsigned int n )
{
unsigned int limbno, bitno;
@@ -139,7 +139,7 @@ gcry_mpi_set_bit( gcry_mpi_t a, unsigned int n )
* Set bit N of A. and clear all bits above
*/
void
-gcry_mpi_set_highbit( gcry_mpi_t a, unsigned int n )
+_gcry_mpi_set_highbit( gcry_mpi_t a, unsigned int n )
{
unsigned int limbno, bitno;
@@ -167,7 +167,7 @@ gcry_mpi_set_highbit( gcry_mpi_t a, unsigned int n )
* clear bit N of A and all bits above
*/
void
-gcry_mpi_clear_highbit( gcry_mpi_t a, unsigned int n )
+_gcry_mpi_clear_highbit( gcry_mpi_t a, unsigned int n )
{
unsigned int limbno, bitno;
@@ -192,7 +192,7 @@ gcry_mpi_clear_highbit( gcry_mpi_t a, unsigned int n )
* Clear bit N of A.
*/
void
-gcry_mpi_clear_bit( gcry_mpi_t a, unsigned int n )
+_gcry_mpi_clear_bit( gcry_mpi_t a, unsigned int n )
{
unsigned int limbno, bitno;
@@ -245,7 +245,7 @@ _gcry_mpi_rshift_limbs( gcry_mpi_t a, unsigned int count )
* Shift A by N bits to the right.
*/
void
-gcry_mpi_rshift ( gcry_mpi_t x, gcry_mpi_t a, unsigned int n )
+_gcry_mpi_rshift ( gcry_mpi_t x, gcry_mpi_t a, unsigned int n )
{
mpi_size_t xsize;
unsigned int i;
@@ -360,7 +360,7 @@ _gcry_mpi_lshift_limbs (gcry_mpi_t a, unsigned int count)
* Shift A by N bits to the left.
*/
void
-gcry_mpi_lshift ( gcry_mpi_t x, gcry_mpi_t a, unsigned int n )
+_gcry_mpi_lshift ( gcry_mpi_t x, gcry_mpi_t a, unsigned int n )
{
unsigned int nlimbs = (n/BITS_PER_MPI_LIMB);
unsigned int nbits = (n%BITS_PER_MPI_LIMB);
@@ -400,7 +400,7 @@ gcry_mpi_lshift ( gcry_mpi_t x, gcry_mpi_t a, unsigned int n )
/* We use a very dump approach: Shift left by the number of
limbs plus one and than fix it up by an rshift. */
_gcry_mpi_lshift_limbs (x, nlimbs+1);
- gcry_mpi_rshift (x, x, BITS_PER_MPI_LIMB - nbits);
+ mpi_rshift (x, x, BITS_PER_MPI_LIMB - nbits);
}
MPN_NORMALIZE (x->d, x->nlimbs);
diff --git a/mpi/mpi-cmp.c b/mpi/mpi-cmp.c
index 30e1fce9..838a7c92 100644
--- a/mpi/mpi-cmp.c
+++ b/mpi/mpi-cmp.c
@@ -24,7 +24,7 @@
#include "mpi-internal.h"
int
-gcry_mpi_cmp_ui (gcry_mpi_t u, unsigned long v)
+_gcry_mpi_cmp_ui (gcry_mpi_t u, unsigned long v)
{
mpi_limb_t limb = v;
@@ -55,7 +55,7 @@ gcry_mpi_cmp_ui (gcry_mpi_t u, unsigned long v)
int
-gcry_mpi_cmp (gcry_mpi_t u, gcry_mpi_t v)
+_gcry_mpi_cmp (gcry_mpi_t u, gcry_mpi_t v)
{
mpi_size_t usize;
mpi_size_t vsize;
diff --git a/mpi/mpi-div.c b/mpi/mpi-div.c
index a6ee3006..9ac99c31 100644
--- a/mpi/mpi-div.c
+++ b/mpi/mpi-div.c
@@ -50,7 +50,7 @@ _gcry_mpi_fdiv_r( gcry_mpi_t rem, gcry_mpi_t dividend, gcry_mpi_t divisor )
_gcry_mpi_tdiv_r( rem, dividend, divisor );
if( ((divisor_sign?1:0) ^ (dividend->sign?1:0)) && rem->nlimbs )
- gcry_mpi_add( rem, rem, divisor);
+ mpi_add (rem, rem, divisor);
if( temp_divisor )
mpi_free(temp_divisor);
@@ -103,8 +103,8 @@ _gcry_mpi_fdiv_qr( gcry_mpi_t quot, gcry_mpi_t rem, gcry_mpi_t dividend, gcry_mp
_gcry_mpi_tdiv_qr( quot, rem, dividend, divisor );
if( (divisor_sign ^ dividend->sign) && rem->nlimbs ) {
- gcry_mpi_sub_ui( quot, quot, 1 );
- gcry_mpi_add( rem, rem, divisor);
+ mpi_sub_ui( quot, quot, 1 );
+ mpi_add( rem, rem, divisor);
}
if( temp_divisor )
@@ -328,7 +328,8 @@ _gcry_mpi_divisible_ui(gcry_mpi_t dividend, ulong divisor )
void
-gcry_mpi_div (gcry_mpi_t quot, gcry_mpi_t rem, gcry_mpi_t dividend, gcry_mpi_t divisor, int round)
+_gcry_mpi_div (gcry_mpi_t quot, gcry_mpi_t rem, gcry_mpi_t dividend,
+ gcry_mpi_t divisor, int round)
{
if (!round)
{
diff --git a/mpi/mpi-gcd.c b/mpi/mpi-gcd.c
index 5cbefa12..77ca05a6 100644
--- a/mpi/mpi-gcd.c
+++ b/mpi/mpi-gcd.c
@@ -28,7 +28,7 @@
* Return: true if this 1, false in all other cases
*/
int
-gcry_mpi_gcd( gcry_mpi_t g, gcry_mpi_t xa, gcry_mpi_t xb )
+_gcry_mpi_gcd (gcry_mpi_t g, gcry_mpi_t xa, gcry_mpi_t xb)
{
gcry_mpi_t a, b;
@@ -38,14 +38,15 @@ gcry_mpi_gcd( gcry_mpi_t g, gcry_mpi_t xa, gcry_mpi_t xb )
/* TAOCP Vol II, 4.5.2, Algorithm A */
a->sign = 0;
b->sign = 0;
- while( gcry_mpi_cmp_ui( b, 0 ) ) {
- _gcry_mpi_fdiv_r( g, a, b ); /* g used as temorary variable */
+ while (mpi_cmp_ui (b, 0))
+ {
+ _gcry_mpi_fdiv_r( g, a, b ); /* G is used as temporary variable. */
mpi_set(a,b);
mpi_set(b,g);
- }
+ }
mpi_set(g, a);
mpi_free(a);
mpi_free(b);
- return !gcry_mpi_cmp_ui( g, 1);
+ return !mpi_cmp_ui( g, 1);
}
diff --git a/mpi/mpi-inv.c b/mpi/mpi-inv.c
index 15fa58ff..ee6813b1 100644
--- a/mpi/mpi-inv.c
+++ b/mpi/mpi-inv.c
@@ -29,7 +29,7 @@
* 1 = (a*x) mod n
*/
int
-gcry_mpi_invm( gcry_mpi_t x, gcry_mpi_t a, gcry_mpi_t n )
+_gcry_mpi_invm (gcry_mpi_t x, gcry_mpi_t a, gcry_mpi_t n)
{
#if 0
gcry_mpi_t u, v, u1, u2, u3, v1, v2, v3, q, t1, t2, t3;
diff --git a/mpi/mpi-mod.c b/mpi/mpi-mod.c
index d48d7f4f..0a8cfb67 100644
--- a/mpi/mpi-mod.c
+++ b/mpi/mpi-mod.c
@@ -183,6 +183,6 @@ void
_gcry_mpi_mul_barrett (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v,
mpi_barrett_t ctx)
{
- gcry_mpi_mul (w, u, v);
+ mpi_mul (w, u, v);
mpi_mod_barrett (w, w, ctx);
}
diff --git a/mpi/mpi-mpow.c b/mpi/mpi-mpow.c
index ec677fe9..2a9a86b0 100644
--- a/mpi/mpi-mpow.c
+++ b/mpi/mpi-mpow.c
@@ -39,7 +39,7 @@ static void barrett_mulm( gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m
static gcry_mpi_t init_barrett( gcry_mpi_t m, int *k, gcry_mpi_t *r1, gcry_mpi_t *r2 );
static int calc_barrett( gcry_mpi_t r, gcry_mpi_t x, gcry_mpi_t m, gcry_mpi_t y, int k, gcry_mpi_t r1, gcry_mpi_t r2 );
#else
-#define barrett_mulm( w, u, v, m, y, k, r1, r2 ) gcry_mpi_mulm( (w), (u), (v), (m) )
+#define barrett_mulm( w, u, v, m, y, k, r1, r2 ) _gcry_mpi_mulm( (w), (u), (v), (m) )
#endif
diff --git a/mpi/mpi-mul.c b/mpi/mpi-mul.c
index 0a687116..4f4d7096 100644
--- a/mpi/mpi-mul.c
+++ b/mpi/mpi-mul.c
@@ -31,7 +31,7 @@
void
-gcry_mpi_mul_ui( gcry_mpi_t prod, gcry_mpi_t mult, unsigned long small_mult )
+_gcry_mpi_mul_ui (gcry_mpi_t prod, gcry_mpi_t mult, unsigned long small_mult)
{
mpi_size_t size, prod_size;
mpi_ptr_t prod_ptr;
@@ -61,7 +61,7 @@ gcry_mpi_mul_ui( gcry_mpi_t prod, gcry_mpi_t mult, unsigned long small_mult )
void
-gcry_mpi_mul_2exp( gcry_mpi_t w, gcry_mpi_t u, unsigned long cnt)
+_gcry_mpi_mul_2exp (gcry_mpi_t w, gcry_mpi_t u, unsigned long cnt)
{
mpi_size_t usize, wsize, limb_cnt;
mpi_ptr_t wp;
@@ -107,7 +107,7 @@ gcry_mpi_mul_2exp( gcry_mpi_t w, gcry_mpi_t u, unsigned long cnt)
void
-gcry_mpi_mul( gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v)
+_gcry_mpi_mul (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v)
{
mpi_size_t usize, vsize, wsize;
mpi_ptr_t up, vp, wp;
@@ -205,8 +205,8 @@ gcry_mpi_mul( gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v)
void
-gcry_mpi_mulm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m)
+_gcry_mpi_mulm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m)
{
- gcry_mpi_mul (w, u, v);
+ mpi_mul (w, u, v);
_gcry_mpi_tdiv_r (w, w, m);
}
diff --git a/mpi/mpi-pow.c b/mpi/mpi-pow.c
index 4bf0233a..0f0947f4 100644
--- a/mpi/mpi-pow.c
+++ b/mpi/mpi-pow.c
@@ -46,8 +46,8 @@
* RES = BASE ^ EXPO mod MOD
*/
void
-gcry_mpi_powm (gcry_mpi_t res,
- gcry_mpi_t base, gcry_mpi_t expo, gcry_mpi_t mod)
+_gcry_mpi_powm (gcry_mpi_t res,
+ gcry_mpi_t base, gcry_mpi_t expo, gcry_mpi_t mod)
{
/* Pointer to the limbs of the arguments, their size and signs. */
mpi_ptr_t rp, ep, mp, bp;
@@ -395,8 +395,8 @@ mul_mod (mpi_ptr_t xp, mpi_size_t *xsize_p,
* Algorithm 14.83: Modified left-to-right k-ary exponentiation
*/
void
-gcry_mpi_powm (gcry_mpi_t res,
- gcry_mpi_t base, gcry_mpi_t expo, gcry_mpi_t mod)
+_gcry_mpi_powm (gcry_mpi_t res,
+ gcry_mpi_t base, gcry_mpi_t expo, gcry_mpi_t mod)
{
/* Pointer to the limbs of the arguments, their size and signs. */
mpi_ptr_t rp, ep, mp, bp;
diff --git a/mpi/mpicoder.c b/mpi/mpicoder.c
index 7c4f5cae..911ddcc3 100644
--- a/mpi/mpicoder.c
+++ b/mpi/mpicoder.c
@@ -416,9 +416,9 @@ twocompl (unsigned char *p, unsigned int n)
with a length of BUFLEN into a newly create MPI returned in
RET_MPI. If NBYTES is not NULL, it will receive the number of
bytes actually scanned after a successful operation. */
-gcry_error_t
-gcry_mpi_scan (struct gcry_mpi **ret_mpi, enum gcry_mpi_format format,
- const void *buffer_arg, size_t buflen, size_t *nscanned)
+gcry_err_code_t
+_gcry_mpi_scan (struct gcry_mpi **ret_mpi, enum gcry_mpi_format format,
+ const void *buffer_arg, size_t buflen, size_t *nscanned)
{
const unsigned char *buffer = (const unsigned char*)buffer_arg;
struct gcry_mpi *a = NULL;
@@ -493,7 +493,7 @@ gcry_mpi_scan (struct gcry_mpi **ret_mpi, enum gcry_mpi_format format,
mpi_free(a);
a = NULL;
}
- return a? 0 : gcry_error (GPG_ERR_INV_OBJ);
+ return a? 0 : GPG_ERR_INV_OBJ;
}
else if (format == GCRYMPI_FMT_SSH)
{
@@ -505,14 +505,14 @@ gcry_mpi_scan (struct gcry_mpi **ret_mpi, enum gcry_mpi_format format,
allow the BUFLEN argument to act as a sanitiy check. Same
below. */
if (len && len < 4)
- return gcry_error (GPG_ERR_TOO_SHORT);
+ return GPG_ERR_TOO_SHORT;
n = (s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]);
s += 4;
if (len)
len -= 4;
if (len && n > len)
- return gcry_error (GPG_ERR_TOO_LARGE);
+ return GPG_ERR_TOO_LARGE;
a = secure? mpi_alloc_secure ((n+BYTES_PER_MPI_LIMB-1)
/BYTES_PER_MPI_LIMB)
@@ -543,13 +543,13 @@ gcry_mpi_scan (struct gcry_mpi **ret_mpi, enum gcry_mpi_format format,
{
/* We can only handle C strings for now. */
if (buflen)
- return gcry_error (GPG_ERR_INV_ARG);
+ return GPG_ERR_INV_ARG;
a = secure? mpi_alloc_secure (0) : mpi_alloc(0);
if (mpi_fromstr (a, (const char *)buffer))
{
mpi_free (a);
- return gcry_error (GPG_ERR_INV_OBJ);
+ return GPG_ERR_INV_OBJ;
}
if (ret_mpi)
{
@@ -563,7 +563,7 @@ gcry_mpi_scan (struct gcry_mpi **ret_mpi, enum gcry_mpi_format format,
return 0;
}
else
- return gcry_error (GPG_ERR_INV_ARG);
+ return GPG_ERR_INV_ARG;
}
@@ -573,10 +573,10 @@ gcry_mpi_scan (struct gcry_mpi **ret_mpi, enum gcry_mpi_format format,
receives the actual length of the external representation unless it
has been passed as NULL. BUFFER may be NULL to query the required
length. */
-gcry_error_t
-gcry_mpi_print (enum gcry_mpi_format format,
- unsigned char *buffer, size_t buflen,
- size_t *nwritten, struct gcry_mpi *a)
+gcry_err_code_t
+_gcry_mpi_print (enum gcry_mpi_format format,
+ unsigned char *buffer, size_t buflen,
+ size_t *nwritten, struct gcry_mpi *a)
{
unsigned int nbits = mpi_get_nbits (a);
size_t len;
@@ -606,7 +606,7 @@ gcry_mpi_print (enum gcry_mpi_format format,
tmp = _gcry_mpi_get_buffer (a, 0, &n, NULL);
if (!tmp)
- return gpg_error_from_syserror ();
+ return gpg_err_code_from_syserror ();
if (negative)
{
@@ -631,7 +631,7 @@ gcry_mpi_print (enum gcry_mpi_format format,
{
/* The provided buffer is too short. */
gcry_free (tmp);
- return gcry_error (GPG_ERR_TOO_SHORT);
+ return GPG_ERR_TOO_SHORT;
}
if (buffer)
{
@@ -656,14 +656,14 @@ gcry_mpi_print (enum gcry_mpi_format format,
mpi_aprint because we can then use the buffer directly. */
if (buffer && n > len)
- return gcry_error (GPG_ERR_TOO_SHORT);
+ return GPG_ERR_TOO_SHORT;
if (buffer)
{
unsigned char *tmp;
tmp = _gcry_mpi_get_buffer (a, 0, &n, NULL);
if (!tmp)
- return gpg_error_from_syserror ();
+ return gpg_err_code_from_syserror ();
memcpy (buffer, tmp, n);
gcry_free (tmp);
}
@@ -676,10 +676,10 @@ gcry_mpi_print (enum gcry_mpi_format format,
/* The PGP format can only handle unsigned integers. */
if (negative)
- return gcry_error (GPG_ERR_INV_ARG);
+ return GPG_ERR_INV_ARG;
if (buffer && n+2 > len)
- return gcry_error (GPG_ERR_TOO_SHORT);
+ return GPG_ERR_TOO_SHORT;
if (buffer)
{
@@ -691,7 +691,7 @@ gcry_mpi_print (enum gcry_mpi_format format,
tmp = _gcry_mpi_get_buffer (a, 0, &n, NULL);
if (!tmp)
- return gpg_error_from_syserror ();
+ return gpg_err_code_from_syserror ();
memcpy (s+2, tmp, n);
gcry_free (tmp);
}
@@ -706,7 +706,7 @@ gcry_mpi_print (enum gcry_mpi_format format,
tmp = _gcry_mpi_get_buffer (a, 0, &n, NULL);
if (!tmp)
- return gpg_error_from_syserror ();
+ return gpg_err_code_from_syserror ();
if (negative)
{
@@ -727,7 +727,7 @@ gcry_mpi_print (enum gcry_mpi_format format,
if (buffer && n+4 > len)
{
gcry_free(tmp);
- return gcry_error (GPG_ERR_TOO_SHORT);
+ return GPG_ERR_TOO_SHORT;
}
if (buffer)
@@ -757,14 +757,14 @@ gcry_mpi_print (enum gcry_mpi_format format,
tmp = _gcry_mpi_get_buffer (a, 0, &n, NULL);
if (!tmp)
- return gpg_error_from_syserror ();
+ return gpg_err_code_from_syserror ();
if (!n || (*tmp & 0x80))
extra = 2;
if (buffer && 2*n + extra + negative + 1 > len)
{
gcry_free(tmp);
- return gcry_error (GPG_ERR_TOO_SHORT);
+ return GPG_ERR_TOO_SHORT;
}
if (buffer)
{
@@ -797,7 +797,7 @@ gcry_mpi_print (enum gcry_mpi_format format,
return 0;
}
else
- return gcry_error (GPG_ERR_INV_ARG);
+ return GPG_ERR_INV_ARG;
}
@@ -806,27 +806,27 @@ gcry_mpi_print (enum gcry_mpi_format format,
* The caller has to supply the address of a pointer. NWRITTEN may be
* NULL.
*/
-gcry_error_t
-gcry_mpi_aprint (enum gcry_mpi_format format,
- unsigned char **buffer, size_t *nwritten,
- struct gcry_mpi *a)
+gcry_err_code_t
+_gcry_mpi_aprint (enum gcry_mpi_format format,
+ unsigned char **buffer, size_t *nwritten,
+ struct gcry_mpi *a)
{
size_t n;
- gcry_error_t rc;
+ gcry_err_code_t rc;
*buffer = NULL;
- rc = gcry_mpi_print (format, NULL, 0, &n, a);
+ rc = _gcry_mpi_print (format, NULL, 0, &n, a);
if (rc)
return rc;
*buffer = mpi_is_secure(a) ? gcry_malloc_secure (n?n:1) : gcry_malloc (n?n:1);
if (!*buffer)
- return gpg_error_from_syserror ();
+ return gpg_err_code_from_syserror ();
/* If the returned buffer will have a length of 0, we nevertheless
allocated 1 byte (malloc needs it anyway) and store a 0. */
if (!n)
**buffer = 0;
- rc = gcry_mpi_print( format, *buffer, n, &n, a );
+ rc = _gcry_mpi_print( format, *buffer, n, &n, a );
if (rc)
{
gcry_free(*buffer);
@@ -859,8 +859,7 @@ _gcry_mpi_to_octet_string (unsigned char **r_frame, void *space,
if (r_frame)
*r_frame = NULL;
- rc = gcry_err_code (gcry_mpi_print (GCRYMPI_FMT_USG,
- NULL, 0, &nframe, value));
+ rc = _gcry_mpi_print (GCRYMPI_FMT_USG, NULL, 0, &nframe, value);
if (rc)
return rc;
if (nframe > nbytes)
@@ -882,8 +881,7 @@ _gcry_mpi_to_octet_string (unsigned char **r_frame, void *space,
if (noff)
memset (frame, 0, noff);
nframe += noff;
- rc = gcry_err_code (gcry_mpi_print (GCRYMPI_FMT_USG,
- frame+noff, nframe-noff, NULL, value));
+ rc = _gcry_mpi_print (GCRYMPI_FMT_USG, frame+noff, nframe-noff, NULL, value);
if (rc)
{
gcry_free (frame);
diff --git a/mpi/mpiutil.c b/mpi/mpiutil.c
index c4259ace..28a24f37 100644
--- a/mpi/mpiutil.c
+++ b/mpi/mpiutil.c
@@ -259,7 +259,7 @@ mpi_set_secure( gcry_mpi_t a )
gcry_mpi_t
-gcry_mpi_set_opaque( gcry_mpi_t a, void *p, unsigned int nbits )
+_gcry_mpi_set_opaque (gcry_mpi_t a, void *p, unsigned int nbits)
{
if (!a)
a = mpi_alloc(0);
@@ -298,12 +298,12 @@ _gcry_mpi_set_opaque_copy (gcry_mpi_t a, const void *p, unsigned int nbits)
if (!d)
return NULL;
memcpy (d, p, n);
- return gcry_mpi_set_opaque (a, d, nbits);
+ return mpi_set_opaque (a, d, nbits);
}
void *
-gcry_mpi_get_opaque( gcry_mpi_t a, unsigned int *nbits )
+_gcry_mpi_get_opaque (gcry_mpi_t a, unsigned int *nbits)
{
if( !(a->flags & 4) )
log_bug("mpi_get_opaque on normal mpi\n");
@@ -320,7 +320,7 @@ _gcry_mpi_get_opaque_copy (gcry_mpi_t a, unsigned int *nbits)
void *d;
unsigned int n;
- s = gcry_mpi_get_opaque (a, nbits);
+ s = mpi_get_opaque (a, nbits);
if (!s && nbits)
return NULL;
n = (*nbits+7)/8;
@@ -335,7 +335,7 @@ _gcry_mpi_get_opaque_copy (gcry_mpi_t a, unsigned int *nbits)
* but copy it transparently.
*/
gcry_mpi_t
-gcry_mpi_copy( gcry_mpi_t a )
+_gcry_mpi_copy (gcry_mpi_t a)
{
int i;
gcry_mpi_t b;
@@ -344,7 +344,7 @@ gcry_mpi_copy( gcry_mpi_t a )
void *p = gcry_is_secure(a->d)? gcry_xmalloc_secure( (a->sign+7)/8 )
: gcry_xmalloc( (a->sign+7)/8 );
memcpy( p, a->d, (a->sign+7)/8 );
- b = gcry_mpi_set_opaque( NULL, p, a->sign );
+ b = mpi_set_opaque( NULL, p, a->sign );
b->flags &= ~(16|32); /* Reset the immutable and constant flags. */
}
else if( a ) {
@@ -419,7 +419,7 @@ _gcry_mpi_alloc_like( gcry_mpi_t a )
void *p = gcry_is_secure(a->d)? gcry_malloc_secure( n )
: gcry_malloc( n );
memcpy( p, a->d, n );
- b = gcry_mpi_set_opaque( NULL, p, a->sign );
+ b = mpi_set_opaque( NULL, p, a->sign );
}
else if( a ) {
b = mpi_is_secure(a)? mpi_alloc_secure( a->nlimbs )
@@ -436,7 +436,7 @@ _gcry_mpi_alloc_like( gcry_mpi_t a )
/* Set U into W and release U. If W is NULL only U will be released. */
void
-gcry_mpi_snatch (gcry_mpi_t w, gcry_mpi_t u)
+_gcry_mpi_snatch (gcry_mpi_t w, gcry_mpi_t u)
{
if (w)
{
@@ -458,7 +458,7 @@ gcry_mpi_snatch (gcry_mpi_t w, gcry_mpi_t u)
gcry_mpi_t
-gcry_mpi_set( gcry_mpi_t w, gcry_mpi_t u)
+_gcry_mpi_set (gcry_mpi_t w, gcry_mpi_t u)
{
mpi_ptr_t wp, up;
mpi_size_t usize = u->nlimbs;
@@ -484,7 +484,7 @@ gcry_mpi_set( gcry_mpi_t w, gcry_mpi_t u)
gcry_mpi_t
-gcry_mpi_set_ui( gcry_mpi_t w, unsigned long u)
+_gcry_mpi_set_ui (gcry_mpi_t w, unsigned long u)
{
if (!w)
w = _gcry_mpi_alloc (1);
@@ -522,15 +522,6 @@ _gcry_mpi_get_ui (gcry_mpi_t w, unsigned long *u)
return err;
}
-gcry_error_t
-gcry_mpi_get_ui (gcry_mpi_t w, unsigned long *u)
-{
- gcry_err_code_t err = GPG_ERR_NO_ERROR;
-
- err = _gcry_mpi_get_ui (w, u);
-
- return gcry_error (err);
-}
gcry_mpi_t
_gcry_mpi_alloc_set_ui( unsigned long u)
@@ -543,7 +534,7 @@ _gcry_mpi_alloc_set_ui( unsigned long u)
}
void
-gcry_mpi_swap( gcry_mpi_t a, gcry_mpi_t b)
+_gcry_mpi_swap (gcry_mpi_t a, gcry_mpi_t b)
{
struct gcry_mpi tmp;
@@ -552,7 +543,7 @@ gcry_mpi_swap( gcry_mpi_t a, gcry_mpi_t b)
gcry_mpi_t
-gcry_mpi_new( unsigned int nbits )
+_gcry_mpi_new (unsigned int nbits)
{
return _gcry_mpi_alloc ( (nbits+BITS_PER_MPI_LIMB-1)
/ BITS_PER_MPI_LIMB );
@@ -560,21 +551,21 @@ gcry_mpi_new( unsigned int nbits )
gcry_mpi_t
-gcry_mpi_snew( unsigned int nbits )
+_gcry_mpi_snew (unsigned int nbits)
{
return _gcry_mpi_alloc_secure ( (nbits+BITS_PER_MPI_LIMB-1)
/ BITS_PER_MPI_LIMB );
}
void
-gcry_mpi_release( gcry_mpi_t a )
+_gcry_mpi_release( gcry_mpi_t a )
{
_gcry_mpi_free( a );
}
void
-gcry_mpi_randomize( gcry_mpi_t w,
- unsigned int nbits, enum gcry_random_level level )
+_gcry_mpi_randomize (gcry_mpi_t w,
+ unsigned int nbits, enum gcry_random_level level)
{
unsigned char *p;
size_t nbytes = (nbits+7)/8;
@@ -588,12 +579,12 @@ gcry_mpi_randomize( gcry_mpi_t w,
{
p = mpi_is_secure(w) ? gcry_xmalloc_secure (nbytes)
: gcry_xmalloc (nbytes);
- gcry_create_nonce (p, nbytes);
+ _gcry_create_nonce (p, nbytes);
}
else
{
- p = mpi_is_secure(w) ? gcry_random_bytes_secure (nbytes, level)
- : gcry_random_bytes (nbytes, level);
+ p = mpi_is_secure(w) ? _gcry_random_bytes_secure (nbytes, level)
+ : _gcry_random_bytes (nbytes, level);
}
_gcry_mpi_set_buffer( w, p, nbytes, 0 );
gcry_free (p);
@@ -601,7 +592,7 @@ gcry_mpi_randomize( gcry_mpi_t w,
void
-gcry_mpi_set_flag (gcry_mpi_t a, enum gcry_mpi_flag flag)
+_gcry_mpi_set_flag (gcry_mpi_t a, enum gcry_mpi_flag flag)
{
switch (flag)
{
@@ -620,7 +611,7 @@ gcry_mpi_set_flag (gcry_mpi_t a, enum gcry_mpi_flag flag)
}
void
-gcry_mpi_clear_flag (gcry_mpi_t a, enum gcry_mpi_flag flag)
+_gcry_mpi_clear_flag (gcry_mpi_t a, enum gcry_mpi_flag flag)
{
(void)a; /* Not yet used. */
@@ -646,7 +637,7 @@ gcry_mpi_clear_flag (gcry_mpi_t a, enum gcry_mpi_flag flag)
}
int
-gcry_mpi_get_flag (gcry_mpi_t a, enum gcry_mpi_flag flag)
+_gcry_mpi_get_flag (gcry_mpi_t a, enum gcry_mpi_flag flag)
{
switch (flag)
{