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