summaryrefslogtreecommitdiff
path: root/mpi/mpiutil.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>1999-06-01 14:08:55 +0000
committerWerner Koch <wk@gnupg.org>1999-06-01 14:08:55 +0000
commitf6655edfbebef7eabe3d754d971576156e0634d9 (patch)
tree6c511034fe1573882e59e2303a346b4a0cf9f22a /mpi/mpiutil.c
parent5502d85b627d7e4dc91e6726b782ae00d542535c (diff)
downloadlibgcrypt-f6655edfbebef7eabe3d754d971576156e0634d9.tar.gz
See ChangeLog: Tue Jun 1 16:01:46 CEST 1999 Werner Koch
Diffstat (limited to 'mpi/mpiutil.c')
-rw-r--r--mpi/mpiutil.c58
1 files changed, 56 insertions, 2 deletions
diff --git a/mpi/mpiutil.c b/mpi/mpiutil.c
index cbbe10d2..62cb882d 100644
--- a/mpi/mpiutil.c
+++ b/mpi/mpiutil.c
@@ -103,6 +103,12 @@ 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 )
@@ -111,14 +117,37 @@ 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
- return secure? m_debug_alloc_secure(len, info):m_debug_alloc( len, info );
+ p = secure? m_debug_alloc_secure(len, info):m_debug_alloc( len, info );
#else
- return secure? m_alloc_secure( len ):m_alloc( len );
+ p = secure? m_alloc_secure( len ):m_alloc( len );
#endif
+
+ return p;
}
void
@@ -132,6 +161,31 @@ mpi_free_limb_space( mpi_ptr_t 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
+
+
m_free(a);
}