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 #ifndef HUKS_AES_ADAPTER_H 16 #define HUKS_AES_ADAPTER_H 17 18 #include "hks_param.h" 19 #include "hks_type.h" 20 #include "array_buffer_util.h" 21 22 namespace OHOS { 23 namespace IntellVoiceUtils { 24 class HuksAesAdapter { 25 public: 26 HuksAesAdapter() = default; 27 ~HuksAesAdapter() = default; 28 29 static int32_t Encrypt(std::unique_ptr<Uint8ArrayBuffer> &inBuffer, std::unique_ptr<Uint8ArrayBuffer> &outBuffer); 30 static int32_t Decrypt(std::unique_ptr<Uint8ArrayBuffer> &inBuffer, std::unique_ptr<Uint8ArrayBuffer> &outBuffer); 31 private: 32 33 static int32_t IsKeyExist(struct HksBlob *keyAlias, bool &isExist); 34 static int32_t GenerateKey(struct HksBlob *keyAlias); 35 static int32_t ConstructParamSet(struct HksParamSet **paramSet, const struct HksParam *params, 36 uint32_t paramCount); 37 static int32_t CreateEncryptParamSet(struct HksParamSet **encryptParamSet, struct HksBlob *encryptNonce); 38 static int32_t CreateDecryptParamSet(struct HksParamSet **decryptParamSet, struct HksBlob *decryptNonce, 39 struct HksBlob *decryptAead); 40 static int32_t UpdateAndFinish(const struct HksBlob *handle, const struct HksParamSet *paramSet, 41 const struct HksBlob *inData, struct HksBlob *outData); 42 }; 43 } 44 } 45 #endif