1/*	$NetBSD: bn_mp_init_multi.c,v 1.2 2017/01/28 21:31:47 christos Exp $	*/
2
3#include <tommath.h>
4#ifdef BN_MP_INIT_MULTI_C
5/* LibTomMath, multiple-precision integer library -- Tom St Denis
6 *
7 * LibTomMath is a library that provides multiple-precision
8 * integer arithmetic as well as number theoretic functionality.
9 *
10 * The library was designed directly after the MPI library by
11 * Michael Fromberger but has been written from scratch with
12 * additional optimizations in place.
13 *
14 * The library is free for all purposes without any express
15 * guarantee it works.
16 *
17 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
18 */
19#include <stdarg.h>
20
21int mp_init_multi(mp_int *mp, ...)
22{
23    mp_err res = MP_OKAY;      /* Assume ok until proven otherwise */
24    int n = 0;                 /* Number of ok inits */
25    mp_int* cur_arg = mp;
26    va_list args;
27
28    va_start(args, mp);        /* init args to next argument from caller */
29    while (cur_arg != NULL) {
30        if (mp_init(cur_arg) != MP_OKAY) {
31            /* Oops - error! Back-track and mp_clear what we already
32               succeeded in init-ing, then return error.
33            */
34            va_list clean_args;
35
36            /* end the current list */
37            va_end(args);
38
39            /* now start cleaning up */
40            cur_arg = mp;
41            va_start(clean_args, mp);
42            while (n--) {
43                mp_clear(cur_arg);
44                cur_arg = va_arg(clean_args, mp_int*);
45            }
46            va_end(clean_args);
47            res = MP_MEM;
48            break;
49        }
50        n++;
51        cur_arg = va_arg(args, mp_int*);
52    }
53    va_end(args);
54    return res;                /* Assumed ok, if error flagged above. */
55}
56
57#endif
58
59/* Source: /cvs/libtom/libtommath/bn_mp_init_multi.c,v  */
60/* Revision: 1.4  */
61/* Date: 2006/12/28 01:25:13  */
62