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 32 enum Accessibility { 33 DEVICE_POWERED_ON = 0, 34 DEVICE_FIRST_UNLOCKED = 1, 35 DEVICE_UNLOCKED = 2, 36 }; 37 38 struct KeyId { 39 int32_t userId; 40 struct HksBlob alias; 41 enum Accessibility accessibility; 42 }; 43 44 int32_t GenerateKey(const struct KeyId *keyId, bool needAuth, bool requirePasswordSet); 45 int32_t DeleteKey(const struct KeyId *keyId); 46 int32_t IsKeyExist(const struct KeyId *keyId); 47 int32_t EncryptData(const struct KeyId *keyId, const struct HksBlob *aad, const struct HksBlob *inData, 48 struct HksBlob *outData); 49 int32_t DecryptData(const struct KeyId *keyId, const struct HksBlob *aad, const struct HksBlob *inData, 50 struct HksBlob *outData); 51 int32_t InitKey(const struct KeyId *keyId, uint32_t validTime, struct HksBlob *challenge, struct HksBlob *handle); 52 int32_t ExecCrypt(const struct HksBlob *handle, const struct HksBlob *aad, const struct HksBlob *authToken, 53 const struct HksBlob *inData, struct HksBlob *outData); 54 int32_t Drop(const struct HksBlob *handle); 55 56 #ifdef __cplusplus 57 } 58 #endif 59 #endif