summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mpi/mpiutil.c16
-rw-r--r--src/mpi.h1
2 files changed, 17 insertions, 0 deletions
diff --git a/mpi/mpiutil.c b/mpi/mpiutil.c
index 433dda6b..57fe72a7 100644
--- a/mpi/mpiutil.c
+++ b/mpi/mpiutil.c
@@ -291,6 +291,22 @@ gcry_mpi_get_opaque( gcry_mpi_t a, unsigned int *nbits )
}
+void *
+_gcry_mpi_get_opaque_copy (gcry_mpi_t a, unsigned int *nbits)
+{
+ const void *s;
+ void *d;
+ unsigned int n;
+
+ s = gcry_mpi_get_opaque (a, nbits);
+ if (!s && nbits)
+ return NULL;
+ n = (*nbits+7)/8;
+ d = gcry_is_secure (s)? gcry_malloc_secure (n) : gcry_malloc (n);
+ memcpy (d, s, n);
+ return d;
+}
+
/****************
* Note: This copy function should not interpret the MPI
* but copy it transparently.
diff --git a/src/mpi.h b/src/mpi.h
index 52341fb7..bf731a3b 100644
--- a/src/mpi.h
+++ b/src/mpi.h
@@ -134,6 +134,7 @@ void _gcry_mpi_m_check( gcry_mpi_t a );
void _gcry_mpi_swap( gcry_mpi_t a, gcry_mpi_t b);
gcry_mpi_t _gcry_mpi_new (unsigned int nbits);
gcry_mpi_t _gcry_mpi_snew (unsigned int nbits);
+void *_gcry_mpi_get_opaque_copy (gcry_mpi_t a, unsigned int *nbits);
int _gcry_mpi_is_neg (gcry_mpi_t a);
void _gcry_mpi_neg (gcry_mpi_t w, gcry_mpi_t u);
void _gcry_mpi_abs (gcry_mpi_t w);