Merge pull request #578 from PX4/fix_mp_prime_strong_lucas_lefridge_compilation
[libtommath.git] / mp_init_multi.c
blob908b4df45778766fb813b465a634d7de3b1f604e
1 #include "tommath_private.h"
2 #ifdef MP_INIT_MULTI_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
6 #include <stdarg.h>
8 mp_err mp_init_multi(mp_int *mp, ...)
10 mp_err err = MP_OKAY;
11 int n = 0; /* Number of ok inits */
12 mp_int *cur_arg = mp;
13 va_list args;
15 va_start(args, mp); /* init args to next argument from caller */
16 while (cur_arg != NULL) {
17 err = mp_init(cur_arg);
18 if (err != MP_OKAY) {
19 /* Oops - error! Back-track and mp_clear what we already
20 succeeded in init-ing, then return error.
22 va_list clean_args;
24 /* now start cleaning up */
25 cur_arg = mp;
26 va_start(clean_args, mp);
27 while (n-- != 0) {
28 mp_clear(cur_arg);
29 cur_arg = va_arg(clean_args, mp_int *);
31 va_end(clean_args);
32 break;
34 n++;
35 cur_arg = va_arg(args, mp_int *);
37 va_end(args);
38 return err;
41 #endif