libtommath/bn_mp_init_copy.c
ramkumarkoppu 76fe0008a2 Update bn_mp_init_copy.c
In mp_init_copy(), mp_init() is used to assign the memory with default block size, mp_copy() is used to grow the target mp_int size if it is required and copy the content.

My suggestion is to use mp_init_size() instead of mp_init() inside the mp_init_copy to assign required memory depending on the source mp_int size and then use mp_copy to copy the content. This will avoid the subsequent mp_grow() inside the mp_copy(). 

The associated issue number is 11 in GitHub.
2013-11-24 15:28:50 +01:00

33 lines
809 B
C

#include <tommath.h>
#ifdef BN_MP_INIT_COPY_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
* LibTomMath is a library that provides multiple-precision
* integer arithmetic as well as number theoretic functionality.
*
* The library was designed directly after the MPI library by
* Michael Fromberger but has been written from scratch with
* additional optimizations in place.
*
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/
/* creates "a" then copies b into it */
int mp_init_copy (mp_int * a, mp_int * b)
{
int res;
if ((res = mp_init_size (a, b->used)) != MP_OKAY) {
return res;
}
return mp_copy (b, a);
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */