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 #ifndef HUKS_WRAPPER_H 17 #define HUKS_WRAPPER_H 18 19 #include <stdint.h> 20 #include "hks_api.h" 21 #include "hks_param.h" 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 static const uint32_t TAG_SIZE = 16; 28 static const uint32_t NONCE_SIZE = 12; 29 30 #define ARRAY_SIZE(arr) ((sizeof(arr)) / (sizeof((arr)[0]))) 31 #define ASSET_ROOT_USER_UPPERBOUND 99 32 33 enum Accessibility { 34 DEVICE_POWERED_ON = 0, 35 DEVICE_FIRST_UNLOCKED = 1, 36 DEVICE_UNLOCKED = 2, 37 }; 38 39 struct KeyId { 40 int32_t userId; 41 struct HksBlob alias; 42 enum Accessibility accessibility; 43 }; 44 45 int32_t GenerateKey(const struct KeyId *keyId, bool needAuth, bool requirePasswordSet); 46 int32_t DeleteKey(const struct KeyId *keyId); 47 int32_t IsKeyExist(const struct KeyId *keyId); 48 int32_t EncryptData(const struct KeyId *keyId, const struct HksBlob *aad, const struct HksBlob *inData, 49 struct HksBlob *outData); 50 int32_t DecryptData(const struct KeyId *keyId, const struct HksBlob *aad, const struct HksBlob *inData, 51 struct HksBlob *outData); 52 int32_t InitKey(const struct KeyId *keyId, uint32_t validTime, struct HksBlob *challenge, struct HksBlob *handle); 53 int32_t ExecCrypt(const struct HksBlob *handle, const struct HksBlob *aad, const struct HksBlob *authToken, 54 const struct HksBlob *inData, struct HksBlob *outData); 55 int32_t Drop(const struct HksBlob *handle); 56 int32_t RenameKeyAlias(const struct KeyId *keyId, const struct HksBlob *newKeyAlias); 57 58 #ifdef __cplusplus 59 } 60 #endif 61 #endif