1 /* 2 * Copyright (c) 2021 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 #ifndef HKS_CRYPTO_ADAPTER_H 17 #define HKS_CRYPTO_ADAPTER_H 18 19 #include <stdbool.h> 20 #include <stdint.h> 21 22 #include "hks_crypto_hal.h" 23 #include "hks_type.h" 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 void HksFillKeySpec(const struct HksParamSet *paramSet, struct HksKeySpec *spec); 30 31 void HksFillUsageSpec(const struct HksParamSet *paramSet, struct HksUsageSpec *usageSpec); 32 33 void HksFreeUsageSpec(struct HksUsageSpec **usageSpec); 34 35 void HksFillKeyDerivationParam(const struct HksParamSet *paramSet, struct HksKeyDerivationParam *param); 36 37 int32_t HksFillAeadParam(const struct HksParamSet *paramSet, struct HksBlob *inputText, struct HksUsageSpec *usageSpec, 38 bool isEncrypt); 39 40 int32_t HksFillIvParam(const struct HksParamSet *paramSet, struct HksUsageSpec *usageSpec); 41 42 int32_t HksBuildCipherUsageSpec(const struct HksParamSet *paramSet, bool isEncrypt, struct HksBlob *inputText, 43 struct HksUsageSpec **outUsageSpec); 44 45 int32_t HksGetEncryptAeTag(const struct HksParamSet *paramSet, const struct HksBlob *inData, struct HksBlob *outData, 46 struct HksBlob *tagAead); 47 48 int32_t HksSetKeyToMaterial(uint32_t alg, bool isPubKey, const struct HksBlob *key, struct HksBlob *keyMaterial); 49 50 int32_t HksGetKeyFromMaterial(uint32_t alg, bool isPubKey, const struct HksBlob *keyMaterial, struct HksBlob *key); 51 52 int32_t HksFormatKeyFromMaterial(uint32_t alg, const struct HksBlob *keyMaterial, struct HksParamSet *paramSetOut); 53 54 #ifdef __cplusplus 55 } 56 #endif 57 58 #endif