diff options
author | Moritz Schulte <mo@g10code.com> | 2003-04-27 19:28:28 +0000 |
---|---|---|
committer | Moritz Schulte <mo@g10code.com> | 2003-04-27 19:28:28 +0000 |
commit | f206bde542e50fab3e60482dfb44e878ab1c2aa6 (patch) | |
tree | 277fba1dbcc35149ed3d808b0d4dd8395fafa573 /mpi/mpiutil.c | |
parent | 53189fb2a0594de16bd33a095677d703981ae1f5 (diff) | |
download | libgcrypt-f206bde542e50fab3e60482dfb44e878ab1c2aa6.tar.gz |
2003-04-27 Moritz Schulte <moritz@g10code.com>
* mpiutil.c (_gcry_mpi_resize): Allocate secure memory, in case
bit zero of `flags' is set.
* mpi-add.c (gcry_mpi_sub): Simplify function; always use a
temporary variable now.
Diffstat (limited to 'mpi/mpiutil.c')
-rw-r--r-- | mpi/mpiutil.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/mpi/mpiutil.c b/mpi/mpiutil.c index b1b9a97d..caa48a39 100644 --- a/mpi/mpiutil.c +++ b/mpi/mpiutil.c @@ -1,5 +1,5 @@ /* mpiutil.ac - Utility functions for MPI - * Copyright (C) 1998, 2000, 2001, 2002 Free Software Foundation, Inc. + * Copyright (C) 1998, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * @@ -107,20 +107,23 @@ _gcry_mpi_assign_limb_space( MPI a, mpi_ptr_t ap, unsigned nlimbs ) * (set to 0) [done by gcry_realloc()] */ void -_gcry_mpi_resize( MPI a, unsigned nlimbs ) +_gcry_mpi_resize (MPI a, unsigned nlimbs) { - 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 gcry_is_secure - */ - if( a->d ) - a->d = gcry_xrealloc(a->d, nlimbs * sizeof(mpi_limb_t) ); - else /* FIXME: It may not be allocted in secure memory */ - a->d = gcry_xcalloc( nlimbs , sizeof(mpi_limb_t) ); - a->alloced = nlimbs; + if (nlimbs <= a->alloced) + return; /* no need to do it */ + + if (a->d) + a->d = gcry_xrealloc (a->d, nlimbs * sizeof (mpi_limb_t)); + else + { + if (a->flags & 1) + /* Secure memory is wanted. */ + a->d = gcry_xcalloc_secure (nlimbs , sizeof (mpi_limb_t)); + else + /* Standard memory. */ + a->d = gcry_xcalloc (nlimbs , sizeof (mpi_limb_t)); + } + a->alloced = nlimbs; } void |