1 /*
2 * Copyright (C) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "dh_key_util.h"
17 #include <securec.h>
18 #include "dh_key_util_spi.h"
19 #include "config.h"
20 #include "dh_common_param_spec_generator_openssl.h"
21 #include "key_utils.h"
22 #include "params_parser.h"
23 #include "log.h"
24 #include "memory.h"
25 #include "utils.h"
26
HcfDhKeyUtilCreate(int32_t pLen,int32_t skLen,HcfDhCommParamsSpec ** returnCommonParamSpec)27 HcfResult HcfDhKeyUtilCreate(int32_t pLen, int32_t skLen, HcfDhCommParamsSpec **returnCommonParamSpec)
28 {
29 if ((pLen < 0) || (skLen < 0) || (returnCommonParamSpec == NULL)) {
30 LOGE("Failed to parse params!");
31 return HCF_INVALID_PARAMS;
32 }
33
34 if (skLen > pLen) {
35 LOGE("skLen is greater than pLen!");
36 return HCF_INVALID_PARAMS;
37 }
38
39 HcfDhCommParamsSpecSpi *spiInstance = NULL;
40 HcfResult ret = HcfDhCommonParamSpecCreate(pLen, skLen, &spiInstance);
41 if (ret != HCF_SUCCESS) {
42 LOGE("Failed to create spi object!");
43 return HCF_ERR_MALLOC;
44 }
45 ret = CreateDhCommonSpecImpl(&(spiInstance->paramsSpec), returnCommonParamSpec);
46 if (ret != HCF_SUCCESS) {
47 LOGE("Failed to create spi impl object!");
48 }
49 FreeDhCommParamsSpec(&(spiInstance->paramsSpec));
50 HcfFree(spiInstance);
51 return ret;
52 }