1 /*
2  * Copyright (c) 2023-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 HKS_CHIPSET_PLATFORM_DECRYPT_H
16 #define HKS_CHIPSET_PLATFORM_DECRYPT_H
17 
18 #include <stddef.h>
19 #include <stdint.h>
20 
21 #include "hks_type.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 // Key protection scheme based on chipset platform key
28 enum {
29     PLATFORM_KEY_INPUT_PARAMS_COUNT = 7,
30     // The user must pass 16 bytes of salt, although only first 15 bytes will be used,
31     // the last byte of salt from user is ignored and will be replaced by huks
32     PLATFORM_KEY_SALT_SIZE = 16,
33     PLATFORM_KEY_PLATFORM_PRI_KEY_SIZE = 32,
34     PLATFORM_KEY_PLATFORM_PUB_KEY_SIZE = PLATFORM_KEY_PLATFORM_PRI_KEY_SIZE * 2,
35     PLATFORM_KEY_BUSINESS_ID_SIZE = 16,
36     PLATFORM_KEY_CUSTOM_INFO_SIZE = 16,
37     PLATFORM_KEY_HMAC_MESSAGE_SIZE = PLATFORM_KEY_BUSINESS_ID_SIZE + PLATFORM_KEY_CUSTOM_INFO_SIZE,
38     PLATFORM_KEY_IV_SIZE = 12,
39     PLATFORM_KEY_AAD_SIZE = 16,
40     PLATFORM_KEY_TAG_SIZE = 16,
41     PLATFORM_KEY_TEXT_MIN_LEN = 1,
42     PLATFORM_KEY_TEXT_MAX_LEN = 512,
43 
44     PLATFORM_KEY_SALT_PADDING_BYTE_TA_TO_TA = 0xFF,
45     PLATFORM_KEY_SHARED_KEY_SIZE = 32,
46     PLATFORM_KEY_WRAPPED_KEY_SIZE = 32,
47 };
48 
49 int32_t HuksCoreChipsetPlatformDecrypt(const struct HksParamSet *paramSet,
50     enum HksChipsetPlatformDecryptScene scene, struct HksBlob *plainText);
51 
52 int32_t HuksCoreExportChipsetPlatformPublicKey(const struct HksBlob *salt,
53     enum HksChipsetPlatformDecryptScene scene, struct HksBlob *publicKey);
54 
55 #ifdef __cplusplus
56 }
57 #endif
58 
59 #endif /* HKS_CHIPSET_PLATFORM_DECRYPT_H */