1 /* 2 * Copyright (C) 2025 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 #ifndef HDC_HUKS_H 16 #define HDC_HUKS_H 17 #include <string> 18 #include <memory> 19 #include <utility> 20 #include "hks_type.h" 21 namespace Hdc { 22 class HdcHuks { 23 public: 24 explicit HdcHuks(const std::string& keyAlias); 25 bool AesGcmEncrypt(const uint8_t* plainData, int plainDataLen, std::vector<uint8_t>& encryptData); 26 std::pair<uint8_t*, int> AesGcmDecrypt(const std::string& inputData); 27 static int CaculateGcmEncryptLen(int palinDataLen); 28 bool ResetHuksKey(void); 29 private: 30 bool MakeHuksParamSet(struct HksParamSet **paramSet, 31 const struct HksParam *baseParams, int baseParamCount, const struct HksParam *params, int paramCount); 32 bool KeyExist(struct HksParamSet *paramSet); 33 struct HksParamSet* MakeAesGcmDecryptParamSets(std::vector<uint8_t>& nonce); 34 struct HksParamSet* MakeAesGcmEncryptParamSets(uint8_t *nonce, int length); 35 bool CheckEncryptDataLen(const std::string& encryptData); 36 bool CreateAesKey(struct HksParamSet *paramSet); 37 bool DeleteAesKey(HksParamSet *paramSet); 38 void GenerateNonce(uint8_t *nonce, int nonceBufLen); 39 std::string keyAlias; 40 struct HksBlob keyBlobAlias; 41 }; 42 } // namespace Hdc 43 #endif // HDC_HUKS_H