/src/dropbear/libtomcrypt/src/math/multi.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* LibTomCrypt, modular cryptographic library -- Tom St Denis |
2 | | * |
3 | | * LibTomCrypt is a library that provides various cryptographic |
4 | | * algorithms in a highly modular and flexible manner. |
5 | | * |
6 | | * The library is free for all purposes without any express |
7 | | * guarantee it works. |
8 | | */ |
9 | | #include "tomcrypt.h" |
10 | | |
11 | | #ifdef LTC_MPI |
12 | | #include <stdarg.h> |
13 | | |
14 | | int ltc_init_multi(void **a, ...) |
15 | 740k | { |
16 | 740k | void **cur = a; |
17 | 740k | int np = 0; |
18 | 740k | va_list args; |
19 | | |
20 | 740k | va_start(args, a); |
21 | 3.30M | while (cur != NULL) { |
22 | 2.56M | if (mp_init(cur) != CRYPT_OK) { |
23 | | /* failed */ |
24 | 0 | va_list clean_list; |
25 | |
|
26 | 0 | va_start(clean_list, a); |
27 | 0 | cur = a; |
28 | 0 | while (np--) { |
29 | 0 | mp_clear(*cur); |
30 | 0 | cur = va_arg(clean_list, void**); |
31 | 0 | } |
32 | 0 | va_end(clean_list); |
33 | 0 | va_end(args); |
34 | 0 | return CRYPT_MEM; |
35 | 0 | } |
36 | 2.56M | ++np; |
37 | 2.56M | cur = va_arg(args, void**); |
38 | 2.56M | } |
39 | 740k | va_end(args); |
40 | 740k | return CRYPT_OK; |
41 | 740k | } |
42 | | |
43 | | void ltc_deinit_multi(void *a, ...) |
44 | 740k | { |
45 | 740k | void *cur = a; |
46 | 740k | va_list args; |
47 | | |
48 | 740k | va_start(args, a); |
49 | 3.30M | while (cur != NULL) { |
50 | 2.56M | mp_clear(cur); |
51 | 2.56M | cur = va_arg(args, void *); |
52 | 2.56M | } |
53 | 740k | va_end(args); |
54 | 740k | } |
55 | | |
56 | | void ltc_cleanup_multi(void **a, ...) |
57 | 0 | { |
58 | 0 | void **cur = a; |
59 | 0 | va_list args; |
60 | |
|
61 | 0 | va_start(args, a); |
62 | 0 | while (cur != NULL) { |
63 | 0 | if (*cur != NULL) { |
64 | 0 | mp_clear(*cur); |
65 | 0 | *cur = NULL; |
66 | 0 | } |
67 | 0 | cur = va_arg(args, void**); |
68 | 0 | } |
69 | 0 | va_end(args); |
70 | 0 | } |
71 | | |
72 | | #endif |
73 | | |
74 | | /* ref: $Format:%D$ */ |
75 | | /* git commit: $Format:%H$ */ |
76 | | /* commit time: $Format:%ai$ */ |