Mercurial > dropbear
comparison ampi.c @ 0:d7da3b1e1540 libtomcrypt
put back the 0.95 makefile which was inadvertently merged over
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 31 May 2004 18:21:40 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d7da3b1e1540 |
---|---|
1 /* Code submitted by Svante Seleborg, cleaned up by Tom St Denis */ | |
2 | |
3 #include "mycrypt.h" | |
4 #include <stdarg.h> | |
5 | |
6 #ifdef MPI | |
7 | |
8 mp_err mp_init_multi(mp_int *mp, ...) | |
9 { | |
10 mp_err res = MP_OKAY; /* Assume ok until proven otherwise */ | |
11 int n = 0; /* Number of ok inits */ | |
12 mp_int* cur_arg = mp; | |
13 va_list args; | |
14 | |
15 va_start(args, mp); /* init args to next argument from caller */ | |
16 while (cur_arg != NULL) { | |
17 if (mp_init(cur_arg) != MP_OKAY) { | |
18 /* Oops - error! Back-track and mp_clear what we already | |
19 succeeded in init-ing, then return error. | |
20 */ | |
21 va_list clean_args; | |
22 cur_arg = mp; | |
23 va_start(clean_args, mp); | |
24 while (n--) { | |
25 mp_clear(cur_arg); | |
26 cur_arg = va_arg(clean_args, mp_int*); | |
27 } | |
28 va_end(clean_args); | |
29 res = MP_MEM; | |
30 break; | |
31 } | |
32 n++; | |
33 cur_arg = va_arg(args, mp_int*); | |
34 } | |
35 va_end(args); | |
36 return res; /* Assumed ok, if error flagged above. */ | |
37 } | |
38 | |
39 /* | |
40 Clear all arguments given, ended by a NULL marker. | |
41 */ | |
42 void mp_clear_multi(mp_int *mp, ...) | |
43 { | |
44 mp_int* next_mp = mp; | |
45 va_list args; | |
46 va_start(args, mp); | |
47 while (next_mp != NULL) { | |
48 mp_clear(next_mp); | |
49 next_mp = va_arg(args, mp_int*); | |
50 } | |
51 va_end(args); | |
52 } | |
53 | |
54 #endif | |
55 |