summaryrefslogtreecommitdiff
path: root/mpi
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>1999-11-19 16:11:34 +0000
committerWerner Koch <wk@gnupg.org>1999-11-19 16:11:34 +0000
commit5d68aaccefcb3e9c7ff515096a240712962b72c9 (patch)
treee5181cfd801c41018f720217870ce229198abd13 /mpi
parent004b4b2bbd984c5efb4ecfa0b1fb3151e3b066bf (diff)
downloadlibgcrypt-5d68aaccefcb3e9c7ff515096a240712962b72c9.tar.gz
See ChangeLog: Fri Nov 19 17:15:20 CET 1999 Werner Koch
Diffstat (limited to 'mpi')
-rw-r--r--mpi/ChangeLog20
-rw-r--r--mpi/mpicoder.c14
-rw-r--r--mpi/mpih-mul.c11
-rw-r--r--mpi/mpiutil.c173
4 files changed, 58 insertions, 160 deletions
diff --git a/mpi/ChangeLog b/mpi/ChangeLog
index d6cf6e3e..3a0fca1a 100644
--- a/mpi/ChangeLog
+++ b/mpi/ChangeLog
@@ -1,3 +1,23 @@
+Fri Nov 19 17:15:20 CET 1999 Werner Koch <wk@gnupg.de>
+
+ * mpicoder.c (g10_log_mpidump): Add a temporary workaround
+
+ * mpih-mul.c (mpihelp_mul_n): s/m_is_ecure/g10_is_secure/
+
+ * mpiutil.c (mpi_alloc): Remved the debug mode because it has turned
+ out, that this feature was not very useful in the past. Use the
+ new alloc functions.
+ (mpi_alloc_secure): Ditto.
+ (mpi_alloc_limb_space): Ditto.
+ (mpi_free_limb_space): Ditto.
+ (mpi_resize): Ditto.
+ (mpi_free): Ditto.
+ (mpi_set_secure): Removed the debug stuff.
+ (mpi_set_opaque): Ditto.
+ (mpi_copy): Ditto.
+ (mpi_alloc_set_ui): Ditto.
+ (mpi_m_check): Use g10_ wrapper.
+
Mon Aug 30 20:38:33 CEST 1999 Werner Koch <wk@isil.d.shuttle.de>
diff --git a/mpi/mpicoder.c b/mpi/mpicoder.c
index dae6eb4e..25d37ec4 100644
--- a/mpi/mpicoder.c
+++ b/mpi/mpicoder.c
@@ -42,6 +42,9 @@
int
mpi_write( IOBUF out, MPI a )
{
+ return -1;
+ #warning Function is disabled
+ #if 0
int rc;
unsigned nbits = mpi_get_nbits(a);
byte *p, *buf;
@@ -57,6 +60,7 @@ mpi_write( IOBUF out, MPI a )
rc = iobuf_write( out, p, n );
m_free(buf);
return rc;
+ #endif
}
@@ -73,6 +77,9 @@ mpi_debug_read(IOBUF inp, unsigned *ret_nread, int secure, const char *info)
mpi_read(IOBUF inp, unsigned *ret_nread, int secure)
#endif
{
+ return NULL;
+ #warning Function is disabled
+ #if 0
int c, i, j;
unsigned nbits, nbytes, nlimbs, nread=0;
mpi_limb_t a;
@@ -120,6 +127,7 @@ mpi_read(IOBUF inp, unsigned *ret_nread, int secure)
else
*ret_nread = nread;
return val;
+ #endif
}
@@ -246,6 +254,7 @@ mpi_fromstr(MPI val, const char *str)
/****************
* print an MPI to the given stream and return the number of characters
* printed.
+ * FIXME: Replace this by the more generic gcry_mpi_print()
*/
int
mpi_print( FILE *fp, MPI a, int mode )
@@ -289,9 +298,10 @@ mpi_print( FILE *fp, MPI a, int mode )
void
g10_log_mpidump( const char *text, MPI a )
{
- FILE *fp = log_stream();
+ FILE *fp = stderr; /* used to be log_stream() */
- g10_log_print_prefix(text);
+ /* FIXME: Replace this function by a g10_log_xxx one */
+ fprintf(fp,"%s: ",text);
mpi_print(fp, a, 1 );
fputc('\n', fp);
}
diff --git a/mpi/mpih-mul.c b/mpi/mpih-mul.c
index 7707c0e3..67749f4c 100644
--- a/mpi/mpih-mul.c
+++ b/mpi/mpih-mul.c
@@ -31,6 +31,7 @@
#include <stdlib.h>
#include "mpi-internal.h"
#include "longlong.h"
+#include "g10lib.h" /* for g10_is_secure() */
@@ -352,7 +353,7 @@ mpihelp_mul_n( mpi_ptr_t prodp, mpi_ptr_t up, mpi_ptr_t vp, mpi_size_t size)
mpih_sqr_n_basecase( prodp, up, size );
else {
mpi_ptr_t tspace;
- secure = m_is_secure( up );
+ secure = g10_is_secure( up );
tspace = mpi_alloc_limb_space( 2 * size, secure );
mpih_sqr_n( prodp, up, size, tspace );
mpi_free_limb_space( tspace );
@@ -363,7 +364,7 @@ mpihelp_mul_n( mpi_ptr_t prodp, mpi_ptr_t up, mpi_ptr_t vp, mpi_size_t size)
mul_n_basecase( prodp, up, vp, size );
else {
mpi_ptr_t tspace;
- secure = m_is_secure( up ) || m_is_secure( vp );
+ secure = g10_is_secure( up ) || g10_is_secure( vp );
tspace = mpi_alloc_limb_space( 2 * size, secure );
mul_n (prodp, up, vp, size, tspace);
mpi_free_limb_space( tspace );
@@ -438,15 +439,15 @@ mpihelp_mul( mpi_ptr_t prodp, mpi_ptr_t up, mpi_size_t usize,
}
tspace = mpi_alloc_limb_space( 2 * vsize,
- m_is_secure( up ) || m_is_secure( vp ) );
+ g10_is_secure( up ) || g10_is_secure( vp ) );
MPN_MUL_N_RECURSE( prodp, up, vp, vsize, tspace );
prodp += vsize;
up += vsize;
usize -= vsize;
if( usize >= vsize ) {
- mpi_ptr_t tp = mpi_alloc_limb_space( 2 * vsize, m_is_secure( up )
- || m_is_secure( vp ) );
+ mpi_ptr_t tp = mpi_alloc_limb_space( 2 * vsize, g10_is_secure( up )
+ || g10_is_secure( vp ) );
do {
MPN_MUL_N_RECURSE( tp, up, vp, vsize, tspace );
cy = mpihelp_add_n( prodp, prodp, tp, vsize );
diff --git a/mpi/mpiutil.c b/mpi/mpiutil.c
index 62cb882d..317940b5 100644
--- a/mpi/mpiutil.c
+++ b/mpi/mpiutil.c
@@ -27,14 +27,7 @@
#include "mpi.h"
#include "mpi-internal.h"
#include "memory.h"
-#include "util.h"
-
-
-#ifdef M_DEBUG
- #undef mpi_alloc
- #undef mpi_alloc_secure
- #undef mpi_free
-#endif
+#include "g10lib.h"
/****************
* Note: It was a bad idea to use the number of limbs to allocate
@@ -44,23 +37,14 @@
* But mpi_alloc is used in a lot of places :-)
*/
MPI
-#ifdef M_DEBUG
-mpi_debug_alloc( unsigned nlimbs, const char *info )
-#else
mpi_alloc( unsigned nlimbs )
-#endif
{
MPI a;
if( DBG_MEMORY )
log_debug("mpi_alloc(%u)\n", nlimbs*BITS_PER_MPI_LIMB );
- #ifdef M_DEBUG
- a = m_debug_alloc( sizeof *a, info );
- a->d = nlimbs? mpi_debug_alloc_limb_space( nlimbs, 0, info ) : NULL;
- #else
- a = m_alloc( sizeof *a );
+ a = g10_xmalloc( sizeof *a );
a->d = nlimbs? mpi_alloc_limb_space( nlimbs, 0 ) : NULL;
- #endif
a->alloced = nlimbs;
a->nlimbs = 0;
a->sign = 0;
@@ -72,28 +56,19 @@ mpi_alloc( unsigned nlimbs )
void
mpi_m_check( MPI a )
{
- m_check(a);
- m_check(a->d);
+ g10_check_heap(a);
+ g10_check_heap(a->d);
}
MPI
-#ifdef M_DEBUG
-mpi_debug_alloc_secure( unsigned nlimbs, const char *info )
-#else
mpi_alloc_secure( unsigned nlimbs )
-#endif
{
MPI a;
if( DBG_MEMORY )
log_debug("mpi_alloc_secure(%u)\n", nlimbs*BITS_PER_MPI_LIMB );
- #ifdef M_DEBUG
- a = m_debug_alloc( sizeof *a, info );
- a->d = nlimbs? mpi_debug_alloc_limb_space( nlimbs, 1, info ) : NULL;
- #else
- a = m_alloc( sizeof *a );
+ a = g10_xmalloc( sizeof *a );
a->d = nlimbs? mpi_alloc_limb_space( nlimbs, 1 ) : NULL;
- #endif
a->alloced = nlimbs;
a->flags = 1;
a->nlimbs = 0;
@@ -103,90 +78,30 @@ mpi_alloc_secure( unsigned nlimbs )
}
-#if 0
-static void *unused_limbs_5;
-static void *unused_limbs_32;
-static void *unused_limbs_64;
-#endif
mpi_ptr_t
-#ifdef M_DEBUG
-mpi_debug_alloc_limb_space( unsigned nlimbs, int secure, const char *info )
-#else
mpi_alloc_limb_space( unsigned nlimbs, int secure )
-#endif
{
size_t len = nlimbs * sizeof(mpi_limb_t);
mpi_ptr_t p;
if( DBG_MEMORY )
log_debug("mpi_alloc_limb_space(%u)\n", (unsigned)len*8 );
- #if 0
- if( !secure ) {
- if( nlimbs == 5 && unused_limbs_5 ) { /* DSA 160 bits */
- p = unused_limbs_5;
- unused_limbs_5 = *p;
- return p;
- }
- else if( nlimbs == 32 && unused_limbs_32 ) { /* DSA 1024 bits */
- p = unused_limbs_32;
- unused_limbs_32 = *p;
- return p;
- }
- else if( nlimbs == 64 && unused_limbs_64 ) { /* DSA 2*1024 bits */
- p = unused_limbs_64;
- unused_limbs_64 = *p;
- return p;
- }
- }
- #endif
- #ifdef M_DEBUG
- p = secure? m_debug_alloc_secure(len, info):m_debug_alloc( len, info );
- #else
- p = secure? m_alloc_secure( len ):m_alloc( len );
- #endif
+ p = secure? g10_xmalloc_secure( len ) : g10_xmalloc( len );
return p;
}
void
-#ifdef M_DEBUG
-mpi_debug_free_limb_space( mpi_ptr_t a, const char *info )
-#else
mpi_free_limb_space( mpi_ptr_t a )
-#endif
{
if( !a )
return;
if( DBG_MEMORY )
- log_debug("mpi_free_limb_space of size %lu\n", (ulong)m_size(a)*8 );
-
- #if 0
- if( !m_is_secure(a) ) {
- size_t nlimbs = m_size(a) / 4 ;
- void *p = a;
-
- if( nlimbs == 5 ) { /* DSA 160 bits */
- *a = unused_limbs_5;
- unused_limbs_5 = a;
- return;
- }
- else if( nlimbs == 32 ) { /* DSA 1024 bits */
- *a = unused_limbs_32;
- unused_limbs_32 = a;
- return;
- }
- else if( nlimbs == 64 ) { /* DSA 2*1024 bits */
- *a = unused_limbs_64;
- unused_limbs_64 = a;
- return;
- }
- }
- #endif
+ log_debug("mpi_free_limb_space\n" );
-
- m_free(a);
+ g10_free(a);
}
@@ -202,33 +117,22 @@ mpi_assign_limb_space( MPI a, mpi_ptr_t ap, unsigned nlimbs )
/****************
* Resize the array of A to NLIMBS. the additional space is cleared
- * (set to 0) [done by m_realloc()]
+ * (set to 0) [done by g10_realloc()]
*/
void
-#ifdef M_DEBUG
-mpi_debug_resize( MPI a, unsigned nlimbs, const char *info )
-#else
mpi_resize( MPI a, unsigned nlimbs )
-#endif
{
if( nlimbs <= a->alloced )
return; /* no need to do it */
/* Note: a->secure is not used - instead the realloc functions
* take care of it. Maybe we should drop a->secure completely
* and rely on a mpi_is_secure function, which would be
- * a wrapper around m_is_secure
+ * a wrapper around g10_is_secure
*/
- #ifdef M_DEBUG
- if( a->d )
- a->d = m_debug_realloc(a->d, nlimbs * sizeof(mpi_limb_t), info );
- else
- a->d = m_debug_alloc_clear( nlimbs * sizeof(mpi_limb_t), info );
- #else
if( a->d )
- a->d = m_realloc(a->d, nlimbs * sizeof(mpi_limb_t) );
- else
- a->d = m_alloc_clear( nlimbs * sizeof(mpi_limb_t) );
- #endif
+ a->d = g10_xrealloc(a->d, nlimbs * sizeof(mpi_limb_t) );
+ else /* FIXME: It may not be allocted in secure memory */
+ a->d = g10_xcalloc( nlimbs , sizeof(mpi_limb_t) );
a->alloced = nlimbs;
}
@@ -242,28 +146,20 @@ mpi_clear( MPI a )
void
-#ifdef M_DEBUG
-mpi_debug_free( MPI a, const char *info )
-#else
mpi_free( MPI a )
-#endif
{
if( !a )
return;
if( DBG_MEMORY )
log_debug("mpi_free\n" );
if( a->flags & 4 )
- m_free( a->d );
+ g10_free( a->d );
else {
- #ifdef M_DEBUG
- mpi_debug_free_limb_space(a->d, info);
- #else
mpi_free_limb_space(a->d);
- #endif
}
if( a->flags & ~7 )
log_bug("invalid flag value in mpi\n");
- m_free(a);
+ g10_free(a);
}
@@ -280,18 +176,10 @@ mpi_set_secure( MPI a )
assert(!ap);
return;
}
- #ifdef M_DEBUG
- bp = mpi_debug_alloc_limb_space( a->nlimbs, 1, "set_secure" );
- #else
bp = mpi_alloc_limb_space( a->nlimbs, 1 );
- #endif
MPN_COPY( bp, ap, a->nlimbs );
a->d = bp;
- #ifdef M_DEBUG
- mpi_debug_free_limb_space(ap, "set_secure");
- #else
mpi_free_limb_space(ap);
- #endif
}
@@ -299,21 +187,13 @@ MPI
mpi_set_opaque( MPI a, void *p, int len )
{
if( !a ) {
- #ifdef M_DEBUG
- a = mpi_debug_alloc(0,"alloc_opaque");
- #else
a = mpi_alloc(0);
- #endif
}
if( a->flags & 4 )
- m_free( a->d );
+ g10_free( a->d );
else {
- #ifdef M_DEBUG
- mpi_debug_free_limb_space(a->d, "alloc_opaque");
- #else
mpi_free_limb_space(a->d);
- #endif
}
a->d = p;
@@ -341,29 +221,20 @@ mpi_get_opaque( MPI a, int *len )
* but copy it transparently.
*/
MPI
-#ifdef M_DEBUG
-mpi_debug_copy( MPI a, const char *info )
-#else
mpi_copy( MPI a )
-#endif
{
int i;
MPI b;
if( a && (a->flags & 4) ) {
- void *p = m_is_secure(a->d)? m_alloc_secure( a->nbits )
- : m_alloc( a->nbits );
+ void *p = g10_is_secure(a->d)? g10_xmalloc_secure( a->nbits )
+ : g10_xmalloc( a->nbits );
memcpy( p, a->d, a->nbits );
b = mpi_set_opaque( NULL, p, a->nbits );
}
else if( a ) {
- #ifdef M_DEBUG
- b = mpi_is_secure(a)? mpi_debug_alloc_secure( a->nlimbs, info )
- : mpi_debug_alloc( a->nlimbs, info );
- #else
b = mpi_is_secure(a)? mpi_alloc_secure( a->nlimbs )
: mpi_alloc( a->nlimbs );
- #endif
b->nlimbs = a->nlimbs;
b->sign = a->sign;
b->flags = a->flags;
@@ -388,8 +259,8 @@ mpi_alloc_like( MPI a )
MPI b;
if( a && (a->flags & 4) ) {
- void *p = m_is_secure(a->d)? m_alloc_secure( a->nbits )
- : m_alloc( a->nbits );
+ void *p = g10_is_secure(a->d)? g10_malloc_secure( a->nbits )
+ : g10_malloc( a->nbits );
memcpy( p, a->d, a->nbits );
b = mpi_set_opaque( NULL, p, a->nbits );
}
@@ -440,11 +311,7 @@ mpi_set_ui( MPI w, unsigned long u)
MPI
mpi_alloc_set_ui( unsigned long u)
{
- #ifdef M_DEBUG
- MPI w = mpi_debug_alloc(1,"alloc_set_ui");
- #else
MPI w = mpi_alloc(1);
- #endif
w->d[0] = u;
w->nlimbs = u? 1:0;
w->sign = 0;