diff options
author | tb <> | 2022-05-05 08:42:27 +0000 |
---|---|---|
committer | tb <> | 2022-05-05 08:42:27 +0000 |
commit | c485c355419bb3824cfc318d95ba44ef5a50a698 (patch) | |
tree | 5132514a9eec791b42c62a94133cef94a4e9ff68 /src/lib/libcrypto | |
parent | eb43e4435b3934080b19c4dd3638c2bc22395d02 (diff) | |
download | openbsd-c485c355419bb3824cfc318d95ba44ef5a50a698.tar.gz openbsd-c485c355419bb3824cfc318d95ba44ef5a50a698.tar.bz2 openbsd-c485c355419bb3824cfc318d95ba44ef5a50a698.zip |
Provide versions of EVP_PKEY_CTX_{str,hex}2ctrl() for internal use.
ok beck jsing
Diffstat (limited to 'src/lib/libcrypto')
-rw-r--r-- | src/lib/libcrypto/evp/evp_locl.h | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/pmeth_lib.c | 36 |
2 files changed, 38 insertions, 2 deletions
diff --git a/src/lib/libcrypto/evp/evp_locl.h b/src/lib/libcrypto/evp/evp_locl.h index c3d9a6a718..43e0ac333d 100644 --- a/src/lib/libcrypto/evp/evp_locl.h +++ b/src/lib/libcrypto/evp/evp_locl.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: evp_locl.h,v 1.22 2022/01/14 08:38:05 tb Exp $ */ | 1 | /* $OpenBSD: evp_locl.h,v 1.23 2022/05/05 08:42:27 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 2000. | 3 | * project 2000. |
4 | */ | 4 | */ |
@@ -505,6 +505,8 @@ struct evp_aead_ctx_st { | |||
505 | void *aead_state; | 505 | void *aead_state; |
506 | }; | 506 | }; |
507 | 507 | ||
508 | int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str); | ||
509 | int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hex); | ||
508 | int EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md_name); | 510 | int EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md_name); |
509 | 511 | ||
510 | __END_HIDDEN_DECLS | 512 | __END_HIDDEN_DECLS |
diff --git a/src/lib/libcrypto/evp/pmeth_lib.c b/src/lib/libcrypto/evp/pmeth_lib.c index d265e2aced..ef28ba09d8 100644 --- a/src/lib/libcrypto/evp/pmeth_lib.c +++ b/src/lib/libcrypto/evp/pmeth_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: pmeth_lib.c,v 1.20 2022/01/10 12:10:26 tb Exp $ */ | 1 | /* $OpenBSD: pmeth_lib.c,v 1.21 2022/05/05 08:42:27 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 | */ |
@@ -56,6 +56,7 @@ | |||
56 | * | 56 | * |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <limits.h> | ||
59 | #include <stdio.h> | 60 | #include <stdio.h> |
60 | #include <stdlib.h> | 61 | #include <stdlib.h> |
61 | #include <string.h> | 62 | #include <string.h> |
@@ -65,6 +66,7 @@ | |||
65 | #include <openssl/err.h> | 66 | #include <openssl/err.h> |
66 | #include <openssl/evp.h> | 67 | #include <openssl/evp.h> |
67 | #include <openssl/objects.h> | 68 | #include <openssl/objects.h> |
69 | #include <openssl/x509v3.h> | ||
68 | 70 | ||
69 | #ifndef OPENSSL_NO_ENGINE | 71 | #ifndef OPENSSL_NO_ENGINE |
70 | #include <openssl/engine.h> | 72 | #include <openssl/engine.h> |
@@ -395,6 +397,38 @@ EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *name, const char *value) | |||
395 | } | 397 | } |
396 | 398 | ||
397 | int | 399 | int |
400 | EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str) | ||
401 | { | ||
402 | size_t len; | ||
403 | |||
404 | if ((len = strlen(str)) > INT_MAX) | ||
405 | return -1; | ||
406 | |||
407 | return ctx->pmeth->ctrl(ctx, cmd, len, (void *)str); | ||
408 | } | ||
409 | |||
410 | int | ||
411 | EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hexstr) | ||
412 | { | ||
413 | unsigned char *hex = NULL; | ||
414 | long length; | ||
415 | int ret = 0; | ||
416 | |||
417 | if ((hex = string_to_hex(hexstr, &length)) == NULL) | ||
418 | goto err; | ||
419 | if (length < 0 || length > INT_MAX) { | ||
420 | ret = -1; | ||
421 | goto err; | ||
422 | } | ||
423 | |||
424 | ret = ctx->pmeth->ctrl(ctx, cmd, length, hex); | ||
425 | |||
426 | err: | ||
427 | free(hex); | ||
428 | return ret; | ||
429 | } | ||
430 | |||
431 | int | ||
398 | EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md_name) | 432 | EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md_name) |
399 | { | 433 | { |
400 | const EVP_MD *md; | 434 | const EVP_MD *md; |