1 /* 2 * Copyright (c) 2021-2024 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_CLIENT_SERVICE_H 17 #define HKS_CLIENT_SERVICE_H 18 19 20 #ifdef __cplusplus 21 #include <cstdint> 22 #else 23 #include <stdint.h> 24 #endif 25 26 #include "hks_type_inner.h" 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 int32_t HksServiceInitialize(void); 33 34 int32_t HksServiceRefreshKeyInfo(const struct HksBlob *processName); 35 36 int32_t HksServiceGenerateKey(const struct HksProcessInfo *processInfo, const struct HksBlob *keyAlias, 37 const struct HksParamSet *paramSetIn, struct HksBlob *keyOut); 38 39 int32_t HksServiceSign(const struct HksProcessInfo *processInfo, const struct HksBlob *keyAlias, 40 const struct HksParamSet *paramSet, const struct HksBlob *srcData, struct HksBlob *signature); 41 42 int32_t HksServiceVerify(const struct HksProcessInfo *processInfo, const struct HksBlob *keyAlias, 43 const struct HksParamSet *paramSet, const struct HksBlob *srcData, const struct HksBlob *signature); 44 45 int32_t HksServiceEncrypt(const struct HksProcessInfo *processInfo, const struct HksBlob *keyAlias, 46 const struct HksParamSet *paramSet, const struct HksBlob *plainText, struct HksBlob *cipherText); 47 48 int32_t HksServiceDecrypt(const struct HksProcessInfo *processInfo, const struct HksBlob *keyAlias, 49 const struct HksParamSet *paramSet, const struct HksBlob *cipherText, struct HksBlob *plainText); 50 51 int32_t HksServiceDeleteKey(const struct HksProcessInfo *processInfo, const struct HksBlob *keyAlias, 52 const struct HksParamSet *paramSet); 53 54 int32_t HksServiceKeyExist(const struct HksProcessInfo *processInfo, const struct HksBlob *keyAlias, 55 const struct HksParamSet *paramSet); 56 57 int32_t HksServiceGetKeyParamSet(const struct HksProcessInfo *processInfo, const struct HksBlob *keyAlias, 58 const struct HksParamSet *paramSetIn, struct HksParamSet *paramSetOut); 59 60 int32_t HksServiceGenerateRandom(const struct HksProcessInfo *processInfo, struct HksBlob *random); 61 62 int32_t HksServiceImportKey(const struct HksProcessInfo *processInfo, const struct HksBlob *keyAlias, 63 const struct HksParamSet *paramSet, const struct HksBlob *key); 64 65 int32_t HksServiceExportPublicKey(const struct HksProcessInfo *processInfo, const struct HksBlob *keyAlias, 66 const struct HksParamSet *paramSet, struct HksBlob *key); 67 68 int32_t HksServiceImportWrappedKey(const struct HksProcessInfo *processInfo, const struct HksBlob *keyAlias, 69 const struct HksBlob *wrappingKeyAlias, const struct HksParamSet *paramSet, const struct HksBlob *wrappedKeyData); 70 71 int32_t HksServiceAgreeKey(const struct HksProcessInfo *processInfo, const struct HksParamSet *paramSet, 72 const struct HksBlob *privateKey, const struct HksBlob *peerPublicKey, struct HksBlob *agreedKey); 73 74 int32_t HksServiceDeriveKey(const struct HksProcessInfo *processInfo, const struct HksParamSet *paramSet, 75 const struct HksBlob *mainKey, struct HksBlob *derivedKey); 76 77 int32_t HksServiceMac(const struct HksProcessInfo *processInfo, const struct HksBlob *key, 78 const struct HksParamSet *paramSet, const struct HksBlob *srcData, struct HksBlob *mac); 79 80 int32_t HksServiceGetKeyInfoList(const struct HksProcessInfo *processInfo, const struct HksParamSet *paramSet, 81 struct HksKeyInfo *keyInfoList, uint32_t *listCount); 82 83 int32_t HksServiceAttestKey(const struct HksProcessInfo *processInfo, const struct HksBlob *keyAlias, 84 const struct HksParamSet *paramSet, struct HksBlob *certChain, const uint8_t *remoteObject); 85 86 int32_t HksServiceInit(const struct HksProcessInfo *processInfo, const struct HksBlob *key, 87 const struct HksParamSet *paramSet, struct HksBlob *handle, struct HksBlob *token); 88 89 int32_t HksServiceUpdate(const struct HksBlob *handle, const struct HksProcessInfo *processInfo, 90 const struct HksParamSet *paramSet, const struct HksBlob *inData, struct HksBlob *outData); 91 92 int32_t HksServiceFinish(const struct HksBlob *handle, const struct HksProcessInfo *processInfo, 93 const struct HksParamSet *paramSet, const struct HksBlob *inData, struct HksBlob *outData); 94 95 int32_t HksServiceAbort(const struct HksBlob *handle, const struct HksProcessInfo *processInfo, 96 const struct HksParamSet *paramSet); 97 98 void HksServiceDeleteProcessInfo(const struct HksProcessInfo *processInfo); 99 100 int32_t HksServiceExportChipsetPlatformPublicKey(const struct HksBlob *salt, 101 enum HksChipsetPlatformDecryptScene scene, struct HksBlob *publicKey); 102 103 int32_t BuildFrontUserIdParamSet(const struct HksParamSet *paramSet, 104 struct HksParamSet **outParamSet, int frontUserId); 105 106 int32_t AppendNewInfoForGenKeyInService(const struct HksProcessInfo *processInfo, 107 const struct HksParamSet *paramSet, struct HksParamSet **outParamSet); 108 109 int32_t AppendNewInfoForUseKeyInService(const struct HksParamSet *paramSet, 110 const struct HksProcessInfo *processInfo, struct HksParamSet **outParamSet); 111 112 int32_t AppendStorageLevelIfNotExist(const struct HksParamSet *paramSet, struct HksParamSet **outParamSet); 113 114 int32_t HksServiceListAliases(const struct HksProcessInfo *processInfo, const struct HksParamSet *paramSet, 115 struct HksKeyAliasSet **outData); 116 117 int32_t HksServiceRenameKeyAlias(const struct HksProcessInfo *processInfo, const struct HksBlob *oldKeyAlias, 118 const struct HksParamSet *paramSet, const struct HksBlob *newKeyAlias); 119 120 int32_t HksServiceChangeStorageLevel(const struct HksProcessInfo *processInfo, const struct HksBlob *keyAlias, 121 const struct HksParamSet *srcParamSet, const struct HksParamSet *destParamSet); 122 123 #ifdef __cplusplus 124 } 125 #endif 126 127 #endif 128