1 /* 2 * Copyright (c) 2022-2024 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 PIN_DB_H 17 #define PIN_DB_H 18 19 #include "defines.h" 20 #include "buffer.h" 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif // __cplusplus 25 26 #define INVALID_TEMPLATE_ID 0xFFFFFFFFFFFFFFFF 27 #define INIT_AUTH_ERROR_COUNT 0 28 #define INIT_START_FREEZE_TIMES 0 29 #define CONST_PIN_DATA_LEN 64U 30 #define CONST_SALT_LEN 32U 31 #define RESULT_TLV_LEN 240U 32 33 typedef struct { 34 uint64_t scheduleId; 35 uint64_t subType; 36 uint8_t salt[CONST_SALT_LEN]; 37 uint8_t pinData[CONST_PIN_DATA_LEN]; 38 } __attribute__((__packed__)) PinEnrollParam; 39 40 bool LoadPinDb(void); 41 void DestroyPinDb(void); 42 43 ResultCode AddPin(PinEnrollParam *pinEnrollParam, uint64_t *templateId, Buffer *outRootSecret); 44 ResultCode DoGetAlgoParameter(uint64_t templateId, uint8_t *salt, uint32_t *saltLen, uint32_t *algoVersion); 45 ResultCode DoGenerateAlgoParameter(uint8_t *algoParameter, uint32_t *algoParameterLength, uint32_t *algoVersion, 46 uint8_t *localDeviceId, uint32_t deviceUuidLength); 47 ResultCode DelPinById(uint64_t templateId); 48 ResultCode AuthPinById(const Buffer *inputPinData, uint64_t templateId, Buffer *outRootSecret, ResultCode *compareRet); 49 ResultCode ComputeFreezeTime(uint64_t templateId, uint32_t *freezeTime, uint32_t count, uint64_t startFreezeTime); 50 ResultCode GetRemainTimes(uint64_t templateId, uint32_t *remainingAuthTimes, uint32_t authErrorCount); 51 ResultCode GetSubType(uint64_t templateId, uint64_t *subType); 52 ResultCode GetAntiBruteInfo(uint64_t templateId, uint32_t *authErrorCount, uint64_t *startFreezeTime); 53 ResultCode RefreshAntiBruteInfoToFile(uint64_t templateId); 54 ResultCode VerifyTemplateDataPin(const uint64_t *templateIdList, uint32_t templateIdListLen); 55 int32_t GetNextFailLockoutDuration(uint32_t authErrorCount); 56 57 #ifdef __cplusplus 58 } 59 #endif // __cplusplus 60 #endif // PIN_DB_H