diff options
| author | tb <> | 2024-01-13 11:08:39 +0000 |
|---|---|---|
| committer | tb <> | 2024-01-13 11:08:39 +0000 |
| commit | ce175ea71c55a0f97153dd4dc707826abc1242e7 (patch) | |
| tree | f1a62b5297113e91a818c32f3ecb135d9a98c389 /src/lib/libcrypto/evp/names.c | |
| parent | d7ceb399503967145b817054eeaf0251de1eb565 (diff) | |
| download | openbsd-ce175ea71c55a0f97153dd4dc707826abc1242e7.tar.gz openbsd-ce175ea71c55a0f97153dd4dc707826abc1242e7.tar.bz2 openbsd-ce175ea71c55a0f97153dd4dc707826abc1242e7.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/evp/names.c')
| -rw-r--r-- | src/lib/libcrypto/evp/names.c | 93 |
1 files changed, 1 insertions, 92 deletions
diff --git a/src/lib/libcrypto/evp/names.c b/src/lib/libcrypto/evp/names.c index a96301ed56..7f5b455088 100644 --- a/src/lib/libcrypto/evp/names.c +++ b/src/lib/libcrypto/evp/names.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: names.c,v 1.22 2023/12/15 14:22:10 tb Exp $ */ | 1 | /* $OpenBSD: names.c,v 1.23 2024/01/13 11:08:39 tb Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -146,94 +146,3 @@ EVP_cleanup(void) | |||
| 146 | OBJ_cleanup(); | 146 | OBJ_cleanup(); |
| 147 | } | 147 | } |
| 148 | } | 148 | } |
| 149 | |||
| 150 | struct doall_cipher { | ||
| 151 | void *arg; | ||
| 152 | void (*fn)(const EVP_CIPHER *ciph, const char *from, const char *to, | ||
| 153 | void *arg); | ||
| 154 | }; | ||
| 155 | |||
| 156 | static void | ||
| 157 | do_all_cipher_fn(const OBJ_NAME *nm, void *arg) | ||
| 158 | { | ||
| 159 | struct doall_cipher *dc = arg; | ||
| 160 | |||
| 161 | if (nm->alias) | ||
| 162 | dc->fn(NULL, nm->name, nm->data, dc->arg); | ||
| 163 | else | ||
| 164 | dc->fn((const EVP_CIPHER *)nm->data, nm->name, NULL, dc->arg); | ||
| 165 | } | ||
| 166 | |||
| 167 | void | ||
| 168 | EVP_CIPHER_do_all(void (*fn)(const EVP_CIPHER *ciph, const char *from, | ||
| 169 | const char *to, void *x), void *arg) | ||
| 170 | { | ||
| 171 | struct doall_cipher dc; | ||
| 172 | |||
| 173 | /* Prayer and clean living lets you ignore errors, OpenSSL style */ | ||
| 174 | (void) OPENSSL_init_crypto(0, NULL); | ||
| 175 | |||
| 176 | dc.fn = fn; | ||
| 177 | dc.arg = arg; | ||
| 178 | OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH, do_all_cipher_fn, &dc); | ||
| 179 | } | ||
| 180 | |||
| 181 | void | ||
| 182 | EVP_CIPHER_do_all_sorted(void (*fn)(const EVP_CIPHER *ciph, const char *from, | ||
| 183 | const char *to, void *x), void *arg) | ||
| 184 | { | ||
| 185 | struct doall_cipher dc; | ||
| 186 | |||
| 187 | /* Prayer and clean living lets you ignore errors, OpenSSL style */ | ||
| 188 | (void) OPENSSL_init_crypto(0, NULL); | ||
| 189 | |||
| 190 | dc.fn = fn; | ||
| 191 | dc.arg = arg; | ||
| 192 | OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_CIPHER_METH, | ||
| 193 | do_all_cipher_fn, &dc); | ||
| 194 | } | ||
| 195 | |||
| 196 | struct doall_md { | ||
| 197 | void *arg; | ||
| 198 | void (*fn)(const EVP_MD *ciph, const char *from, const char *to, | ||
| 199 | void *arg); | ||
| 200 | }; | ||
| 201 | |||
| 202 | static void | ||
| 203 | do_all_md_fn(const OBJ_NAME *nm, void *arg) | ||
| 204 | { | ||
| 205 | struct doall_md *dc = arg; | ||
| 206 | |||
| 207 | if (nm->alias) | ||
| 208 | dc->fn(NULL, nm->name, nm->data, dc->arg); | ||
| 209 | else | ||
| 210 | dc->fn((const EVP_MD *)nm->data, nm->name, NULL, dc->arg); | ||
| 211 | } | ||
| 212 | |||
| 213 | void | ||
| 214 | EVP_MD_do_all(void (*fn)(const EVP_MD *md, const char *from, const char *to, | ||
| 215 | void *x), void *arg) | ||
| 216 | { | ||
| 217 | struct doall_md dc; | ||
| 218 | |||
| 219 | /* Prayer and clean living lets you ignore errors, OpenSSL style */ | ||
| 220 | (void) OPENSSL_init_crypto(0, NULL); | ||
| 221 | |||
| 222 | dc.fn = fn; | ||
| 223 | dc.arg = arg; | ||
| 224 | OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, do_all_md_fn, &dc); | ||
| 225 | } | ||
| 226 | |||
| 227 | void | ||
| 228 | EVP_MD_do_all_sorted(void (*fn)(const EVP_MD *md, | ||
| 229 | const char *from, const char *to, void *x), void *arg) | ||
| 230 | { | ||
| 231 | struct doall_md dc; | ||
| 232 | |||
| 233 | /* Prayer and clean living lets you ignore errors, OpenSSL style */ | ||
| 234 | (void) OPENSSL_init_crypto(0, NULL); | ||
| 235 | |||
| 236 | dc.fn = fn; | ||
| 237 | dc.arg = arg; | ||
| 238 | OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_MD_METH, do_all_md_fn, &dc); | ||
| 239 | } | ||
