diff options
author | tb <> | 2023-07-22 18:12:09 +0000 |
---|---|---|
committer | tb <> | 2023-07-22 18:12:09 +0000 |
commit | 4a1818d4f47ef3432864be3ebf457f896326f9bd (patch) | |
tree | 624aab24f83a92a867d89c46b5a8c019cbe8aa28 | |
parent | 7522b5e7ecfbecb152c67cbcb3d391407d2b9f46 (diff) | |
download | openbsd-4a1818d4f47ef3432864be3ebf457f896326f9bd.tar.gz openbsd-4a1818d4f47ef3432864be3ebf457f896326f9bd.tar.bz2 openbsd-4a1818d4f47ef3432864be3ebf457f896326f9bd.zip |
Neuter OBJ_add_sigid() and OBJ_sigid_free()
These functions will be removed in the upcoming bump. Nothing uses them,
so it won't hurt if they become noops. This allows us to garbage collect
the sig_app and sigx_app stacks and make a first step towards simplifying
the OBJ_bsearch_() dances. Also sprinkle some const correctness... because
we can.
intermediate step towards a diff that is ok jsing
-rw-r--r-- | src/lib/libcrypto/objects/obj_xref.c | 104 |
1 files changed, 11 insertions, 93 deletions
diff --git a/src/lib/libcrypto/objects/obj_xref.c b/src/lib/libcrypto/objects/obj_xref.c index 2318c86ce2..ac1459c123 100644 --- a/src/lib/libcrypto/objects/obj_xref.c +++ b/src/lib/libcrypto/objects/obj_xref.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: obj_xref.c,v 1.9 2023/07/08 12:27:51 beck Exp $ */ | 1 | /* $OpenBSD: obj_xref.c,v 1.10 2023/07/22 18:12:09 tb Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2006. | 3 | * project 2006. |
4 | */ | 4 | */ |
@@ -60,7 +60,6 @@ | |||
60 | #include "obj_xref.h" | 60 | #include "obj_xref.h" |
61 | 61 | ||
62 | DECLARE_STACK_OF(nid_triple) | 62 | DECLARE_STACK_OF(nid_triple) |
63 | STACK_OF(nid_triple) *sig_app, *sigx_app; | ||
64 | 63 | ||
65 | static int | 64 | static int |
66 | sig_cmp(const nid_triple *a, const nid_triple *b) | 65 | sig_cmp(const nid_triple *a, const nid_triple *b) |
@@ -68,10 +67,6 @@ sig_cmp(const nid_triple *a, const nid_triple *b) | |||
68 | return a->sign_id - b->sign_id; | 67 | return a->sign_id - b->sign_id; |
69 | } | 68 | } |
70 | 69 | ||
71 | static int sig_cmp_BSEARCH_CMP_FN(const void *, const void *); | ||
72 | static int sig_cmp(nid_triple const *, nid_triple const *); | ||
73 | static nid_triple *OBJ_bsearch_sig(nid_triple *key, nid_triple const *base, int num); | ||
74 | |||
75 | static int | 70 | static int |
76 | sig_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) | 71 | sig_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) |
77 | { | 72 | { |
@@ -80,24 +75,14 @@ sig_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) | |||
80 | return sig_cmp(a, b); | 75 | return sig_cmp(a, b); |
81 | } | 76 | } |
82 | 77 | ||
83 | static nid_triple * | 78 | static const nid_triple * |
84 | OBJ_bsearch_sig(nid_triple *key, nid_triple const *base, int num) | 79 | OBJ_bsearch_sig(nid_triple *key, nid_triple const *base, int num) |
85 | { | 80 | { |
86 | return (nid_triple *)OBJ_bsearch_(key, base, num, sizeof(nid_triple), | 81 | return OBJ_bsearch_(key, base, num, sizeof(nid_triple), |
87 | sig_cmp_BSEARCH_CMP_FN); | 82 | sig_cmp_BSEARCH_CMP_FN); |
88 | } | 83 | } |
89 | 84 | ||
90 | static int | 85 | static int |
91 | sig_sk_cmp(const nid_triple * const *a, const nid_triple * const *b) | ||
92 | { | ||
93 | return (*a)->sign_id - (*b)->sign_id; | ||
94 | } | ||
95 | |||
96 | static int sigx_cmp_BSEARCH_CMP_FN(const void *, const void *); | ||
97 | static int sigx_cmp(const nid_triple * const *, const nid_triple * const *); | ||
98 | static const nid_triple * *OBJ_bsearch_sigx(const nid_triple * *key, const nid_triple * const *base, int num); | ||
99 | |||
100 | static int | ||
101 | sigx_cmp(const nid_triple * const *a, const nid_triple * const *b) | 86 | sigx_cmp(const nid_triple * const *a, const nid_triple * const *b) |
102 | { | 87 | { |
103 | int ret; | 88 | int ret; |
@@ -108,7 +93,6 @@ sigx_cmp(const nid_triple * const *a, const nid_triple * const *b) | |||
108 | return (*a)->pkey_id - (*b)->pkey_id; | 93 | return (*a)->pkey_id - (*b)->pkey_id; |
109 | } | 94 | } |
110 | 95 | ||
111 | |||
112 | static int | 96 | static int |
113 | sigx_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) | 97 | sigx_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) |
114 | { | 98 | { |
@@ -117,10 +101,10 @@ sigx_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) | |||
117 | return sigx_cmp(a, b); | 101 | return sigx_cmp(a, b); |
118 | } | 102 | } |
119 | 103 | ||
120 | static const nid_triple * * | 104 | static const nid_triple * const* |
121 | OBJ_bsearch_sigx(const nid_triple * *key, const nid_triple * const *base, int num) | 105 | OBJ_bsearch_sigx(const nid_triple * *key, const nid_triple * const *base, int num) |
122 | { | 106 | { |
123 | return (const nid_triple * *)OBJ_bsearch_(key, base, num, sizeof(const nid_triple *), | 107 | return OBJ_bsearch_(key, base, num, sizeof(const nid_triple *), |
124 | sigx_cmp_BSEARCH_CMP_FN); | 108 | sigx_cmp_BSEARCH_CMP_FN); |
125 | } | 109 | } |
126 | 110 | ||
@@ -131,19 +115,8 @@ OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid) | |||
131 | const nid_triple *rv = NULL; | 115 | const nid_triple *rv = NULL; |
132 | tmp.sign_id = signid; | 116 | tmp.sign_id = signid; |
133 | 117 | ||
134 | if (sig_app) { | 118 | if ((rv = OBJ_bsearch_sig(&tmp, sigoid_srt, |
135 | int idx = sk_nid_triple_find(sig_app, &tmp); | 119 | sizeof(sigoid_srt) / sizeof(nid_triple))) == NULL) |
136 | if (idx >= 0) | ||
137 | rv = sk_nid_triple_value(sig_app, idx); | ||
138 | } | ||
139 | |||
140 | #ifndef OBJ_XREF_TEST2 | ||
141 | if (rv == NULL) { | ||
142 | rv = OBJ_bsearch_sig(&tmp, sigoid_srt, | ||
143 | sizeof(sigoid_srt) / sizeof(nid_triple)); | ||
144 | } | ||
145 | #endif | ||
146 | if (rv == NULL) | ||
147 | return 0; | 120 | return 0; |
148 | if (pdig_nid) | 121 | if (pdig_nid) |
149 | *pdig_nid = rv->hash_id; | 122 | *pdig_nid = rv->hash_id; |
@@ -158,26 +131,13 @@ OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid) | |||
158 | { | 131 | { |
159 | nid_triple tmp; | 132 | nid_triple tmp; |
160 | const nid_triple *t = &tmp; | 133 | const nid_triple *t = &tmp; |
161 | const nid_triple **rv = NULL; | 134 | const nid_triple *const *rv; |
162 | 135 | ||
163 | tmp.hash_id = dig_nid; | 136 | tmp.hash_id = dig_nid; |
164 | tmp.pkey_id = pkey_nid; | 137 | tmp.pkey_id = pkey_nid; |
165 | 138 | ||
166 | if (sigx_app) { | 139 | if ((rv = OBJ_bsearch_sigx(&t, sigoid_srt_xref, |
167 | int idx = sk_nid_triple_find(sigx_app, &tmp); | 140 | sizeof(sigoid_srt_xref) / sizeof(nid_triple *))) == NULL) |
168 | if (idx >= 0) { | ||
169 | t = sk_nid_triple_value(sigx_app, idx); | ||
170 | rv = &t; | ||
171 | } | ||
172 | } | ||
173 | |||
174 | #ifndef OBJ_XREF_TEST2 | ||
175 | if (rv == NULL) { | ||
176 | rv = OBJ_bsearch_sigx(&t, sigoid_srt_xref, | ||
177 | sizeof(sigoid_srt_xref) / sizeof(nid_triple *)); | ||
178 | } | ||
179 | #endif | ||
180 | if (rv == NULL) | ||
181 | return 0; | 141 | return 0; |
182 | if (psignid) | 142 | if (psignid) |
183 | *psignid = (*rv)->sign_id; | 143 | *psignid = (*rv)->sign_id; |
@@ -188,54 +148,12 @@ LCRYPTO_ALIAS(OBJ_find_sigid_by_algs); | |||
188 | int | 148 | int |
189 | OBJ_add_sigid(int signid, int dig_id, int pkey_id) | 149 | OBJ_add_sigid(int signid, int dig_id, int pkey_id) |
190 | { | 150 | { |
191 | nid_triple *ntr; | 151 | return 0; |
192 | |||
193 | if (!sig_app) | ||
194 | sig_app = sk_nid_triple_new(sig_sk_cmp); | ||
195 | if (!sig_app) | ||
196 | return 0; | ||
197 | if (!sigx_app) | ||
198 | sigx_app = sk_nid_triple_new(sigx_cmp); | ||
199 | if (!sigx_app) | ||
200 | return 0; | ||
201 | ntr = reallocarray(NULL, 3, sizeof(int)); | ||
202 | if (!ntr) | ||
203 | return 0; | ||
204 | ntr->sign_id = signid; | ||
205 | ntr->hash_id = dig_id; | ||
206 | ntr->pkey_id = pkey_id; | ||
207 | |||
208 | if (!sk_nid_triple_push(sig_app, ntr)) { | ||
209 | free(ntr); | ||
210 | return 0; | ||
211 | } | ||
212 | |||
213 | if (!sk_nid_triple_push(sigx_app, ntr)) | ||
214 | return 0; | ||
215 | |||
216 | sk_nid_triple_sort(sig_app); | ||
217 | sk_nid_triple_sort(sigx_app); | ||
218 | |||
219 | return 1; | ||
220 | } | 152 | } |
221 | LCRYPTO_ALIAS(OBJ_add_sigid); | 153 | LCRYPTO_ALIAS(OBJ_add_sigid); |
222 | 154 | ||
223 | static void | ||
224 | sid_free(nid_triple *tt) | ||
225 | { | ||
226 | free(tt); | ||
227 | } | ||
228 | |||
229 | void | 155 | void |
230 | OBJ_sigid_free(void) | 156 | OBJ_sigid_free(void) |
231 | { | 157 | { |
232 | if (sig_app) { | ||
233 | sk_nid_triple_pop_free(sig_app, sid_free); | ||
234 | sig_app = NULL; | ||
235 | } | ||
236 | if (sigx_app) { | ||
237 | sk_nid_triple_free(sigx_app); | ||
238 | sigx_app = NULL; | ||
239 | } | ||
240 | } | 158 | } |
241 | LCRYPTO_ALIAS(OBJ_sigid_free); | 159 | LCRYPTO_ALIAS(OBJ_sigid_free); |