diff options
Diffstat (limited to 'src/lib/libcrypto/dsa')
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_pmeth.c | 33 |
1 files changed, 10 insertions, 23 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_pmeth.c b/src/lib/libcrypto/dsa/dsa_pmeth.c index 001bdec201..019bee68b2 100644 --- a/src/lib/libcrypto/dsa/dsa_pmeth.c +++ b/src/lib/libcrypto/dsa/dsa_pmeth.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: dsa_pmeth.c,v 1.19 2023/12/28 22:11:26 tb Exp $ */ | 1 | /* $OpenBSD: dsa_pmeth.c,v 1.20 2024/08/26 22:00:47 op 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 | */ |
| @@ -58,6 +58,7 @@ | |||
| 58 | 58 | ||
| 59 | #include <limits.h> | 59 | #include <limits.h> |
| 60 | #include <stdio.h> | 60 | #include <stdio.h> |
| 61 | #include <stdlib.h> | ||
| 61 | #include <string.h> | 62 | #include <string.h> |
| 62 | 63 | ||
| 63 | #include <openssl/asn1t.h> | 64 | #include <openssl/asn1t.h> |
| @@ -244,34 +245,21 @@ pkey_dsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) | |||
| 244 | static int | 245 | static int |
| 245 | pkey_dsa_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value) | 246 | pkey_dsa_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value) |
| 246 | { | 247 | { |
| 247 | long lval; | 248 | const char *errstr; |
| 248 | char *ep; | ||
| 249 | 249 | ||
| 250 | if (!strcmp(type, "dsa_paramgen_bits")) { | 250 | if (!strcmp(type, "dsa_paramgen_bits")) { |
| 251 | int nbits; | 251 | int nbits; |
| 252 | 252 | ||
| 253 | errno = 0; | 253 | nbits = strtonum(value, INT_MIN, INT_MAX, &errstr); |
| 254 | lval = strtol(value, &ep, 10); | 254 | if (errstr != NULL) |
| 255 | if (value[0] == '\0' || *ep != '\0') | 255 | return -2; |
| 256 | goto not_a_number; | ||
| 257 | if ((errno == ERANGE && | ||
| 258 | (lval == LONG_MAX || lval == LONG_MIN)) || | ||
| 259 | (lval > INT_MAX || lval < INT_MIN)) | ||
| 260 | goto out_of_range; | ||
| 261 | nbits = lval; | ||
| 262 | return EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits); | 256 | return EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits); |
| 263 | } else if (!strcmp(type, "dsa_paramgen_q_bits")) { | 257 | } else if (!strcmp(type, "dsa_paramgen_q_bits")) { |
| 264 | int qbits; | 258 | int qbits; |
| 265 | 259 | ||
| 266 | errno = 0; | 260 | qbits = strtonum(value, INT_MIN, INT_MAX, &errstr); |
| 267 | lval = strtol(value, &ep, 10); | 261 | if (errstr != NULL) |
| 268 | if (value[0] == '\0' || *ep != '\0') | 262 | return -2; |
| 269 | goto not_a_number; | ||
| 270 | if ((errno == ERANGE && | ||
| 271 | (lval == LONG_MAX || lval == LONG_MIN)) || | ||
| 272 | (lval > INT_MAX || lval < INT_MIN)) | ||
| 273 | goto out_of_range; | ||
| 274 | qbits = lval; | ||
| 275 | return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, | 263 | return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, |
| 276 | EVP_PKEY_OP_PARAMGEN, EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS, | 264 | EVP_PKEY_OP_PARAMGEN, EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS, |
| 277 | qbits, NULL); | 265 | qbits, NULL); |
| @@ -280,8 +268,7 @@ pkey_dsa_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value) | |||
| 280 | EVP_PKEY_OP_PARAMGEN, EVP_PKEY_CTRL_DSA_PARAMGEN_MD, 0, | 268 | EVP_PKEY_OP_PARAMGEN, EVP_PKEY_CTRL_DSA_PARAMGEN_MD, 0, |
| 281 | (void *)EVP_get_digestbyname(value)); | 269 | (void *)EVP_get_digestbyname(value)); |
| 282 | } | 270 | } |
| 283 | not_a_number: | 271 | |
| 284 | out_of_range: | ||
| 285 | return -2; | 272 | return -2; |
| 286 | } | 273 | } |
| 287 | 274 | ||
