1 /*
2  * Copyright (c) 2022 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 HKS_ATTEST_UTILS_H
17 #define HKS_ATTEST_UTILS_H
18 
19 #include <stdint.h>
20 
21 #include "dcm_asn1.h"
22 #include "hks_crypto_hal.h"
23 #include "hks_type.h"
24 
25 #define DECLARE_TAG(name, id) \
26     static uint8_t name##Tag[] = { 0x06, id##_SIZE, id }
27 
28 #define DECLARE_OID(name) \
29     static const struct HksBlob name##Oid = { sizeof(name##Tag), name##Tag }
30 
31 enum KmTagType {
32     KM_INVALID = 0 << 28,
33     KM_ENUM = 1 << 28,
34     KM_ENUM_REP = 2 << 28,
35     KM_UINT = 3 << 28,
36     KM_UINT_REP = 4 << 28,
37     KM_ULONG = 5 << 28,
38     KM_DATE = 6 << 28,
39     KM_BOOL = 7 << 28,
40     KM_BIGNUM = 8 << 28,
41     KM_BYTES = 9 << 28,
42     KM_ULONG_REP = 10 << 28,
43 };
44 
45 enum HksCertType {
46     HKS_ROOT_CERT = 0,
47     HKS_CA_CERT,
48     HKS_DEVICE_CERT,
49     HKS_DEVICE_KEY,
50 };
51 
52 enum KmTag {
53     KM_TAG_PRODUCT_MODEL = KM_BYTES | 760,
54     KM_TAG_DISPLAY_ID = KM_BYTES | 761,
55     KM_TAG_VERSION_INCREMENTAL = KM_BYTES | 762,
56     KM_TAG_ATTESTATION_SECURITY_CREDENTIAL = KM_BOOL | 763,
57     KM_TAG_ATTESTATION_ID_SEC_LEVEL_INFO = KM_BYTES | 764,
58     KM_TAG_ATTESTATION_VERSION_INFO = KM_BYTES | 765,
59 
60     KM_TAG_ATTESTATION_ID_UDID = KM_BYTES | 10006,
61 };
62 
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66 
67 int32_t DcmInsertClaim(struct HksBlob *out, const struct HksBlob *oid, const struct HksAsn1Blob *value,
68     uint32_t secLevel);
69 
70 int32_t DcmGetPublicKey(struct HksBlob *key, const struct HksPubKeyInfo *info, const struct HksUsageSpec *usageSpec);
71 
72 #ifdef __cplusplus
73 }
74 #endif
75 
76 #endif