libtommath/bn_mp_init_multi.c

42 lines
1.1 KiB
C
Raw Normal View History

#include "tommath_private.h"
2004-10-29 22:07:18 +00:00
#ifdef BN_MP_INIT_MULTI_C
2019-04-07 13:29:11 +00:00
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
2017-12-18 22:37:01 +00:00
2003-05-17 12:33:54 +00:00
#include <stdarg.h>
mp_err mp_init_multi(mp_int *mp, ...)
2003-05-17 12:33:54 +00:00
{
2019-05-19 15:16:13 +00:00
mp_err err = MP_OKAY; /* Assume ok until proven otherwise */
2017-08-30 17:11:35 +00:00
int n = 0; /* Number of ok inits */
mp_int *cur_arg = mp;
va_list args;
2003-05-17 12:33:54 +00:00
2017-08-30 17:11:35 +00:00
va_start(args, mp); /* init args to next argument from caller */
while (cur_arg != NULL) {
if (mp_init(cur_arg) != MP_OKAY) {
/* Oops - error! Back-track and mp_clear what we already
succeeded in init-ing, then return error.
*/
va_list clean_args;
2017-08-30 03:51:11 +00:00
2017-08-30 17:11:35 +00:00
/* now start cleaning up */
cur_arg = mp;
va_start(clean_args, mp);
while (n-- != 0) {
mp_clear(cur_arg);
cur_arg = va_arg(clean_args, mp_int *);
}
va_end(clean_args);
2019-05-19 15:16:13 +00:00
err = MP_MEM;
2017-08-30 17:11:35 +00:00
break;
}
n++;
cur_arg = va_arg(args, mp_int *);
}
va_end(args);
2019-05-19 15:16:13 +00:00
return err; /* Assumed ok, if error flagged above. */
2003-08-29 14:06:56 +00:00
}
2004-10-29 22:07:18 +00:00
#endif