• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 PINAUTHTA_FUNC_H
17 #define PINAUTHTA_FUNC_H
18 
19 #include "pin_db.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif // __cplusplus
24 
25 #define TAG_AND_LEN_BYTE 8
26 #define TAG_ANG_LEN_T 12
27 #define TAG_AND_LEN_S 16
28 #define SIGN_DATA_LEN 64
29 #define PIN_RET_TYPE_LEN 8
30 #define PIN_RET_DATA_LEN 72
31 #define PIN_CAPABILITY_LEVEL 3
32 #define ED25519_FIX_PUBKEY_BUFFER_SIZE 32
33 #define ED25519_FIX_PRIKEY_BUFFER_SIZE 64
34 #define PIN_EXECUTOR_SECURITY_LEVEL 2
35 #define PIN_AUTH_AIBNILITY 7
36 #define ROOT_SECRET_LEN 32U
37 
38 typedef enum {
39     /* Root tag */
40     AUTH_ROOT = 100000,
41     /* Result code */
42     AUTH_RESULT_CODE = 100001,
43     /* Tag of signature data in TLV */
44     AUTH_SIGNATURE = 100004,
45     /* Identify mode */
46     AUTH_IDENTIFY_MODE = 100005,
47     /* Tag of templateId data in TLV */
48     AUTH_TEMPLATE_ID = 100006,
49     /* Tag of templateId list data in TLV */
50     AUTH_TEMPLATE_ID_LIST = 100007,
51     /* Expected attribute, tag of remain count in TLV */
52     AUTH_REMAIN_COUNT = 100009,
53     /* Remain time */
54     AUTH_REMAIN_TIME = 100010,
55     /* Session id, required when decode in C */
56     AUTH_SCHEDULE_ID = 100014,
57     /* Package name */
58     AUTH_CALLER_NAME = 100015,
59     /* Schedule version */
60     AUTH_SCHEDULE_VERSION = 100016,
61     /* Tag of lock out template in TLV */
62     AUTH_LOCK_OUT_TEMPLATE = 100018,
63     /* Tag of unlock template in TLV */
64     AUTH_UNLOCK_TEMPLATE = 100019,
65     /* Tag of data */
66     AUTH_DATA = 100020,
67     /* Tag of auth subType */
68     AUTH_SUBTYPE = 100021,
69     /* Tag of auth schedule mode */
70     AUTH_SCHEDULE_MODE = 100022,
71     /* Tag of property */
72     AUTH_PROPERTY_MODE = 100023,
73     /* Tag of auth type */
74     AUTH_TYPE = 100024,
75     /* Tag of cred id */
76     AUTH_CREDENTIAL_ID = 100025,
77     /* Controller */
78     AUTH_CONTROLLER = 100026,
79     /* calleruid */
80     AUTH_CALLER_UID = 100027,
81     /* result */
82     AUTH_RESULT = 100028,
83     /* capability level */
84     AUTH_CAPABILITY_LEVEL = 100029,
85     /* algorithm setinfo */
86     ALGORITHM_INFO = 100030,
87     /* time stamp */
88     AUTH_TIME_STAMP = 100031,
89     /* root secret */
90     AUTH_ROOT_SECRET = 100032,
91 } AuthAttributeType;
92 
93 typedef struct {
94     uint64_t scheduleId;
95     uint64_t templateId;
96     uint8_t pinData[CONST_PIN_DATA_LEN];
97 } PinAuthParam;
98 
99 typedef struct {
100     uint64_t subType;
101     uint64_t templateId;
102 } QueryCredential;
103 
104 typedef struct {
105     uint64_t subType;
106     uint32_t remainTimes;
107     uint32_t freezeTime;
108 } PinCredentialInfos;
109 
110 typedef struct {
111     uint32_t esl;
112     uint8_t pubKey[CONST_PUB_KEY_LEN];
113 } PinExecutorInfo;
114 
115 ResultCode DoEnrollPin(PinEnrollParam *pinEnrollParam, Buffer *retTlv);
116 ResultCode DoAuthPin(PinAuthParam *pinAuthParam, Buffer *data);
117 ResultCode DoQueryPinInfo(uint64_t templateId, PinCredentialInfos *pinCredentialInfo);
118 ResultCode DoDeleteTemplate(uint64_t templateId);
119 ResultCode GenerateRetTlv(uint32_t result, uint64_t scheduleId, uint64_t templatedId, Buffer *retTlv,
120     Buffer *rootSecret);
121 ResultCode GenerateKeyPair();
122 ResultCode DoGetExecutorInfo(PinExecutorInfo *pinExecutorInfo);
123 ResultCode DoVerifyTemplateData(const uint64_t *templateIdList, uint32_t templateIdListLen);
124 
125 #ifdef __cplusplus
126 }
127 #endif // __cplusplus
128 #endif // PINAUTHTA_FUNC_H
129