1dfe32fa1Soh_ci/*
2dfe32fa1Soh_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3dfe32fa1Soh_ci * Licensed under the Apache License, Version 2.0 (the "License");
4dfe32fa1Soh_ci * you may not use this file except in compliance with the License.
5dfe32fa1Soh_ci * You may obtain a copy of the License at
6dfe32fa1Soh_ci *
7dfe32fa1Soh_ci *     http://www.apache.org/licenses/LICENSE-2.0
8dfe32fa1Soh_ci *
9dfe32fa1Soh_ci * Unless required by applicable law or agreed to in writing, software
10dfe32fa1Soh_ci * distributed under the License is distributed on an "AS IS" BASIS,
11dfe32fa1Soh_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12dfe32fa1Soh_ci * See the License for the specific language governing permissions and
13dfe32fa1Soh_ci * limitations under the License.
14dfe32fa1Soh_ci */
15dfe32fa1Soh_ci
16dfe32fa1Soh_ci#ifndef HUKS_WRAPPER_H
17dfe32fa1Soh_ci#define HUKS_WRAPPER_H
18dfe32fa1Soh_ci
19dfe32fa1Soh_ci#include <stdint.h>
20dfe32fa1Soh_ci#include "hks_api.h"
21dfe32fa1Soh_ci#include "hks_param.h"
22dfe32fa1Soh_ci
23dfe32fa1Soh_ci#ifdef __cplusplus
24dfe32fa1Soh_ciextern "C" {
25dfe32fa1Soh_ci#endif
26dfe32fa1Soh_ci
27dfe32fa1Soh_cistatic const uint32_t TAG_SIZE = 16;
28dfe32fa1Soh_cistatic const uint32_t NONCE_SIZE = 12;
29dfe32fa1Soh_ci
30dfe32fa1Soh_ci#define ARRAY_SIZE(arr) ((sizeof(arr)) / (sizeof((arr)[0])))
31dfe32fa1Soh_ci#define ASSET_ROOT_USER_UPPERBOUND 99
32dfe32fa1Soh_ci
33dfe32fa1Soh_cienum Accessibility {
34dfe32fa1Soh_ci    DEVICE_POWERED_ON = 0,
35dfe32fa1Soh_ci    DEVICE_FIRST_UNLOCKED = 1,
36dfe32fa1Soh_ci    DEVICE_UNLOCKED = 2,
37dfe32fa1Soh_ci};
38dfe32fa1Soh_ci
39dfe32fa1Soh_cistruct KeyId {
40dfe32fa1Soh_ci    int32_t userId;
41dfe32fa1Soh_ci    struct HksBlob alias;
42dfe32fa1Soh_ci    enum Accessibility accessibility;
43dfe32fa1Soh_ci};
44dfe32fa1Soh_ci
45dfe32fa1Soh_ciint32_t GenerateKey(const struct KeyId *keyId, bool needAuth, bool requirePasswordSet);
46dfe32fa1Soh_ciint32_t DeleteKey(const struct KeyId *keyId);
47dfe32fa1Soh_ciint32_t IsKeyExist(const struct KeyId *keyId);
48dfe32fa1Soh_ciint32_t EncryptData(const struct KeyId *keyId, const struct HksBlob *aad, const struct HksBlob *inData,
49dfe32fa1Soh_ci    struct HksBlob *outData);
50dfe32fa1Soh_ciint32_t DecryptData(const struct KeyId *keyId, const struct HksBlob *aad, const struct HksBlob *inData,
51dfe32fa1Soh_ci    struct HksBlob *outData);
52dfe32fa1Soh_ciint32_t InitKey(const struct KeyId *keyId, uint32_t validTime, struct HksBlob *challenge, struct HksBlob *handle);
53dfe32fa1Soh_ciint32_t ExecCrypt(const struct HksBlob *handle, const struct HksBlob *aad, const struct HksBlob *authToken,
54dfe32fa1Soh_ci    const struct HksBlob *inData, struct HksBlob *outData);
55dfe32fa1Soh_ciint32_t Drop(const struct HksBlob *handle);
56dfe32fa1Soh_ciint32_t RenameKeyAlias(const struct KeyId *keyId, const struct HksBlob *newKeyAlias);
57dfe32fa1Soh_ci
58dfe32fa1Soh_ci#ifdef __cplusplus
59dfe32fa1Soh_ci}
60dfe32fa1Soh_ci#endif
61dfe32fa1Soh_ci#endif