summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/objects
diff options
context:
space:
mode:
authortb <>2024-01-13 11:08:39 +0000
committertb <>2024-01-13 11:08:39 +0000
commit9fffb87f5d35d0387d2fef05868f79d200d8a912 (patch)
treef1a62b5297113e91a818c32f3ecb135d9a98c389 /src/lib/libcrypto/objects
parent455bb26ef6b3e1e6c272effb3d99a0c59a1300d8 (diff)
downloadopenbsd-9fffb87f5d35d0387d2fef05868f79d200d8a912.tar.gz
openbsd-9fffb87f5d35d0387d2fef05868f79d200d8a912.tar.bz2
openbsd-9fffb87f5d35d0387d2fef05868f79d200d8a912.zip
Reimplement {EVP_CIPHER,EVP_MD,OBJ_NAME}_do_all{,_sorted}(3)
This implements the do_all API by simple loops over the tables of digests and ciphers. Since some ciphers are only available on some platforms, we need to skip them if necessary. We use loops in each of the functions rather the convoluted way of reducing some of the loops to others. Since the tables are sorted, as ensured by regress, both do_all() and do_all_sorted() walk the lists in order. In particular, we no longer need to allocate to be able to sort hash tables by name on the fly in a void function that may end up doing nothing because allocation failed. We still need to do an unchecked OPENSSL_init_crypto() call. But that's what prayer and clean living are there for (as beck put it). The OBJ_NAME API is completely misnamed. It has little to do with objects and a lot to do with EVP. Therefore we implement what will remain from its saner replacement in the evp directory, i.e., evp_names.c. ok jsing
Diffstat (limited to 'src/lib/libcrypto/objects')
-rw-r--r--src/lib/libcrypto/objects/o_names.c81
1 files changed, 1 insertions, 80 deletions
diff --git a/src/lib/libcrypto/objects/o_names.c b/src/lib/libcrypto/objects/o_names.c
index 48b95d6767..1007c5e23a 100644
--- a/src/lib/libcrypto/objects/o_names.c
+++ b/src/lib/libcrypto/objects/o_names.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: o_names.c,v 1.24 2023/07/08 12:27:51 beck Exp $ */ 1/* $OpenBSD: o_names.c,v 1.25 2024/01/13 11:08:39 tb Exp $ */
2#include <stdio.h> 2#include <stdio.h>
3#include <stdlib.h> 3#include <stdlib.h>
4#include <string.h> 4#include <string.h>
@@ -240,85 +240,6 @@ OBJ_NAME_remove(const char *name, int type)
240} 240}
241LCRYPTO_ALIAS(OBJ_NAME_remove); 241LCRYPTO_ALIAS(OBJ_NAME_remove);
242 242
243struct doall {
244 int type;
245 void (*fn)(const OBJ_NAME *, void *arg);
246 void *arg;
247};
248
249static void
250do_all_fn_doall_arg(const OBJ_NAME *name, struct doall *d)
251{
252 if (name->type == d->type)
253 d->fn(name, d->arg);
254}
255
256static IMPLEMENT_LHASH_DOALL_ARG_FN(do_all_fn, const OBJ_NAME, struct doall)
257
258void
259OBJ_NAME_do_all(int type, void (*fn)(const OBJ_NAME *, void *arg), void *arg)
260{
261 struct doall d;
262
263 d.type = type;
264 d.fn = fn;
265 d.arg = arg;
266
267 lh_OBJ_NAME_doall_arg(names_lh, LHASH_DOALL_ARG_FN(do_all_fn),
268 struct doall, &d);
269}
270LCRYPTO_ALIAS(OBJ_NAME_do_all);
271
272struct doall_sorted {
273 int type;
274 int n;
275 const OBJ_NAME **names;
276};
277
278static void
279do_all_sorted_fn(const OBJ_NAME *name, void *d_)
280{
281 struct doall_sorted *d = d_;
282
283 if (name->type != d->type)
284 return;
285
286 d->names[d->n++] = name;
287}
288
289static int
290do_all_sorted_cmp(const void *n1_, const void *n2_)
291{
292 const OBJ_NAME * const *n1 = n1_;
293 const OBJ_NAME * const *n2 = n2_;
294
295 return strcmp((*n1)->name, (*n2)->name);
296}
297
298void
299OBJ_NAME_do_all_sorted(int type, void (*fn)(const OBJ_NAME *, void *arg),
300 void *arg)
301{
302 struct doall_sorted d;
303 int n;
304
305 d.type = type;
306 d.names = reallocarray(NULL, lh_OBJ_NAME_num_items(names_lh),
307 sizeof *d.names);
308 d.n = 0;
309 if (d.names != NULL) {
310 OBJ_NAME_do_all(type, do_all_sorted_fn, &d);
311
312 qsort((void *)d.names, d.n, sizeof *d.names, do_all_sorted_cmp);
313
314 for (n = 0; n < d.n; ++n)
315 fn(d.names[n], arg);
316
317 free(d.names);
318 }
319}
320LCRYPTO_ALIAS(OBJ_NAME_do_all_sorted);
321
322static int free_type; 243static int free_type;
323 244
324static void 245static void