/*
- * Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2021-2022 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
#include "crypto/dh.h"
#include "crypto/ec.h"
-#include "e_os.h" /* strcasecmp() for Windows */
-
struct translation_ctx_st; /* Forwarding */
struct translation_st; /* Forwarding */
/* Convert KDF type strings to numbers */
for (; kdf_type_map->kdf_type_str != NULL; kdf_type_map++)
- if (strcasecmp(ctx->p2, kdf_type_map->kdf_type_str) == 0) {
+ if (OPENSSL_strcasecmp(ctx->p2, kdf_type_map->kdf_type_str) == 0) {
ctx->p1 = kdf_type_map->kdf_type_num;
ret = 1;
break;
return 0;
if (state == PRE_CTRL_TO_PARAMS) {
- ctx->p2 = (char *)ossl_ffc_named_group_get_name
- (ossl_ffc_uid_to_dh_named_group(ctx->p1));
+ if ((ctx->p2 = (char *)ossl_ffc_named_group_get_name
+ (ossl_ffc_uid_to_dh_named_group(ctx->p1))) == NULL) {
+ ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_VALUE);
+ return 0;
+ }
ctx->p1 = 0;
}
if (ctx->action_type != SET)
return 0;
- if (state == PRE_CTRL_STR_TO_PARAMS) {
- ctx->p2 = (char *)ossl_ffc_named_group_get_name
- (ossl_ffc_uid_to_dh_named_group(atoi(ctx->p2)));
+ switch (state) {
+ case PRE_CTRL_TO_PARAMS:
+ if ((ctx->p2 = (char *)ossl_ffc_named_group_get_name
+ (ossl_ffc_uid_to_dh_named_group(ctx->p1))) == NULL) {
+ ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_VALUE);
+ return 0;
+ }
+
+ ctx->p1 = 0;
+ break;
+
+ case PRE_CTRL_STR_TO_PARAMS:
+ if (ctx->p2 == NULL)
+ return 0;
+ if ((ctx->p2 = (char *)ossl_ffc_named_group_get_name
+ (ossl_ffc_uid_to_dh_named_group(atoi(ctx->p2)))) == NULL) {
+ ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_VALUE);
+ return 0;
+ }
+
ctx->p1 = 0;
+ break;
+
+ default:
+ break;
}
return default_fixup_args(state, translation, ctx);
return 0;
if (state == PRE_CTRL_STR_TO_PARAMS) {
- ctx->p2 = (char *)ossl_dh_gen_type_id2name(atoi(ctx->p2));
+ if ((ctx->p2 = (char *)ossl_dh_gen_type_id2name(atoi(ctx->p2)))
+ == NULL) {
+ ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_VALUE);
+ return 0;
+ }
ctx->p1 = strlen(ctx->p2);
}
if ((ctx->action_type == SET && state == PRE_PARAMS_TO_CTRL)
|| (ctx->action_type == GET && state == POST_CTRL_TO_PARAMS)) {
size_t i;
+ int val;
for (i = 0; i < OSSL_NELEM(str_value_map); i++) {
if (strcmp(ctx->p2, str_value_map[i].ptr) == 0)
break;
}
- if (i == OSSL_NELEM(str_value_map)) {
- ctx->p1 = atoi(ctx->p2);
- } else if (state == POST_CTRL_TO_PARAMS) {
+
+ val = i == OSSL_NELEM(str_value_map) ? atoi(ctx->p2)
+ : (int)str_value_map[i].id;
+ if (state == POST_CTRL_TO_PARAMS) {
/*
* EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN weirdness explained further
* up
*/
- *(int *)ctx->orig_p2 = str_value_map[i].id;
+ *(int *)ctx->orig_p2 = val;
} else {
- ctx->p1 = (int)str_value_map[i].id;
+ ctx->p1 = val;
}
ctx->p2 = NULL;
}
OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST, OSSL_PARAM_UTF8_STRING, fix_md },
/*
* The "rsa_oaep_label" ctrl_str expects the value to always be hex.
- * This is accomodated by default_fixup_args() above, which mimics that
+ * This is accommodated by default_fixup_args() above, which mimics that
* expectation for any translation item where |ctrl_str| is NULL and
* |ctrl_hexstr| is non-NULL.
*/
* cmd name in the template.
*/
if (item->ctrl_str != NULL
- && strcasecmp(tmpl->ctrl_str, item->ctrl_str) == 0)
+ && OPENSSL_strcasecmp(tmpl->ctrl_str, item->ctrl_str) == 0)
ctrl_str = tmpl->ctrl_str;
else if (item->ctrl_hexstr != NULL
- && strcasecmp(tmpl->ctrl_hexstr, item->ctrl_hexstr) == 0)
+ && OPENSSL_strcasecmp(tmpl->ctrl_hexstr,
+ item->ctrl_hexstr) == 0)
ctrl_hexstr = tmpl->ctrl_hexstr;
else
continue;
if ((item->action_type != NONE
&& tmpl->action_type != item->action_type)
|| (item->param_key != NULL
- && strcasecmp(tmpl->param_key, item->param_key) != 0))
+ && OPENSSL_strcasecmp(tmpl->param_key,
+ item->param_key) != 0))
continue;
} else {
return NULL;
{
return evp_pkey_setget_params_to_ctrl(pkey, GET, params);
}
-