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 "huks_adapter_diff_impl.h"
17 #include "crypto_hash_to_point.h"
18 #include "hal_error.h"
19 #include "hc_log.h"
20 #include "hks_api.h"
21 #include "hks_type.h"
22
InitHks(void)23 int32_t InitHks(void)
24 {
25 LOGI("[HUKS]: HksInitialize enter.");
26 int32_t res = HksInitialize();
27 LOGI("[HUKS]: HksInitialize quit. [Res]: %d", res);
28 if (res != HKS_SUCCESS) {
29 LOGE("[HUKS]: HksInitialize fail. [Res]: %d", res);
30 }
31 return res;
32 }
33
HashToPointX25519(const Uint8Buff * hash,Uint8Buff * outEcPoint)34 int32_t HashToPointX25519(const Uint8Buff *hash, Uint8Buff *outEcPoint)
35 {
36 struct HksBlob hashBlob = { hash->length, hash->val };
37 struct HksBlob pointBlob = { outEcPoint->length, outEcPoint->val };
38
39 int32_t res = OpensslHashToPoint(&hashBlob, &pointBlob);
40 if (res != HAL_SUCCESS || pointBlob.size != SHA256_LEN) {
41 LOGE("HashToPoint for x25519 failed, res: %d", res);
42 return HAL_FAILED;
43 }
44
45 return HAL_SUCCESS;
46 }