bn_mp_init_multi.cGo to the documentation of this file.00001 #include <tommath.h> 00002 #ifdef BN_MP_INIT_MULTI_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 #include <stdarg.h> 00018 00019 int mp_init_multi(mp_int *mp, ...) 00020 { 00021 mp_err res = MP_OKAY; /* Assume ok until proven otherwise */ 00022 int n = 0; /* Number of ok inits */ 00023 mp_int* cur_arg = mp; 00024 va_list args; 00025 00026 va_start(args, mp); /* init args to next argument from caller */ 00027 while (cur_arg != NULL) { 00028 if (mp_init(cur_arg) != MP_OKAY) { 00029 /* Oops - error! Back-track and mp_clear what we already 00030 succeeded in init-ing, then return error. 00031 */ 00032 va_list clean_args; 00033 00034 /* end the current list */ 00035 va_end(args); 00036 00037 /* now start cleaning up */ 00038 cur_arg = mp; 00039 va_start(clean_args, mp); 00040 while (n--) { 00041 mp_clear(cur_arg); 00042 cur_arg = va_arg(clean_args, mp_int*); 00043 } 00044 va_end(clean_args); 00045 res = MP_MEM; 00046 break; 00047 } 00048 n++; 00049 cur_arg = va_arg(args, mp_int*); 00050 } 00051 va_end(args); 00052 return res; /* Assumed ok, if error flagged above. */ 00053 } 00054 00055 #endif 00056 00057 /* $Source: /cvsroot/tcl/libtommath/bn_mp_init_multi.c,v $ */ 00058 /* $Revision: 1.1.1.3 $ */ 00059 /* $Date: 2006/12/01 00:08:11 $ */
Generated on Wed Mar 12 12:18:24 2008 by 1.5.1 |