bn_mp_init_size.c

Go to the documentation of this file.
00001 #include <tommath.h>
00002 #ifdef BN_MP_INIT_SIZE_C
00003 /* LibTomMath, multiple-precision integer library -- Tom St Denis
00004  *
00005  * LibTomMath is a library that provides multiple-precision
00006  * integer arithmetic as well as number theoretic functionality.
00007  *
00008  * The library was designed directly after the MPI library by
00009  * Michael Fromberger but has been written from scratch with
00010  * additional optimizations in place.
00011  *
00012  * The library is free for all purposes without any express
00013  * guarantee it works.
00014  *
00015  * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
00016  */
00017 
00018 /* init an mp_init for a given size */
00019 int mp_init_size (mp_int * a, int size)
00020 {
00021   int x;
00022 
00023   /* pad size so there are always extra digits */
00024   size += (MP_PREC * 2) - (size % MP_PREC);     
00025   
00026   /* alloc mem */
00027   a->dp = OPT_CAST(mp_digit) XMALLOC (sizeof (mp_digit) * size);
00028   if (a->dp == NULL) {
00029     return MP_MEM;
00030   }
00031 
00032   /* set the members */
00033   a->used  = 0;
00034   a->alloc = size;
00035   a->sign  = MP_ZPOS;
00036 
00037   /* zero the digits */
00038   for (x = 0; x < size; x++) {
00039       a->dp[x] = 0;
00040   }
00041 
00042   return MP_OKAY;
00043 }
00044 #endif
00045 
00046 /* $Source: /cvsroot/tcl/libtommath/bn_mp_init_size.c,v $ */
00047 /* $Revision: 1.1.1.3 $ */
00048 /* $Date: 2006/12/01 00:08:11 $ */



Generated on Wed Mar 12 12:18:24 2008 by  doxygen 1.5.1