1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3 #include "tomcrypt_private.h"
4
5 #ifdef LTC_MPI
6 #include <stdarg.h>
7
ltc_init_multi(void ** a,...)8 int ltc_init_multi(void **a, ...)
9 {
10 void **cur = a;
11 int np = 0;
12 va_list args;
13
14 va_start(args, a);
15 while (cur != NULL) {
16 if (mp_init(cur) != CRYPT_OK) {
17 /* failed */
18 va_list clean_list;
19
20 va_start(clean_list, a);
21 cur = a;
22 while (np--) {
23 mp_clear(*cur);
24 cur = va_arg(clean_list, void**);
25 }
26 va_end(clean_list);
27 va_end(args);
28 return CRYPT_MEM;
29 }
30 ++np;
31 cur = va_arg(args, void**);
32 }
33 va_end(args);
34 return CRYPT_OK;
35 }
36
ltc_init_multi_size(int size_bits,void ** a,...)37 int ltc_init_multi_size(int size_bits, void **a, ...)
38 {
39 void **cur = a;
40 int np = 0;
41 va_list args;
42
43 va_start(args, a);
44 while (cur != NULL) {
45 if (mp_init_size(size_bits, cur) != CRYPT_OK) {
46 /* failed */
47 va_list clean_list;
48
49 va_start(clean_list, a);
50 cur = a;
51 while (np--) {
52 mp_clear(*cur);
53 cur = va_arg(clean_list, void**);
54 }
55 va_end(clean_list);
56 return CRYPT_MEM;
57 }
58 ++np;
59 cur = va_arg(args, void**);
60 }
61 va_end(args);
62 return CRYPT_OK;
63 }
64
ltc_deinit_multi(void * a,...)65 void ltc_deinit_multi(void *a, ...)
66 {
67 void *cur = a;
68 va_list args;
69
70 va_start(args, a);
71 while (cur != NULL) {
72 mp_clear(cur);
73 cur = va_arg(args, void *);
74 }
75 va_end(args);
76 }
77
ltc_cleanup_multi(void ** a,...)78 void ltc_cleanup_multi(void **a, ...)
79 {
80 void **cur = a;
81 va_list args;
82
83 va_start(args, a);
84 while (cur != NULL) {
85 if (*cur != NULL) {
86 mp_clear(*cur);
87 *cur = NULL;
88 }
89 cur = va_arg(args, void**);
90 }
91 va_end(args);
92 }
93
94 #endif
95