1094332d3Sopenharmony_ci/* 2094332d3Sopenharmony_ci * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License. 5094332d3Sopenharmony_ci * You may obtain a copy of the License at 6094332d3Sopenharmony_ci * 7094332d3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8094332d3Sopenharmony_ci * 9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and 13094332d3Sopenharmony_ci * limitations under the License. 14094332d3Sopenharmony_ci */ 15094332d3Sopenharmony_ci 16094332d3Sopenharmony_ci#ifndef PIN_DB_H 17094332d3Sopenharmony_ci#define PIN_DB_H 18094332d3Sopenharmony_ci 19094332d3Sopenharmony_ci#include "defines.h" 20094332d3Sopenharmony_ci#include "buffer.h" 21094332d3Sopenharmony_ci 22094332d3Sopenharmony_ci#ifdef __cplusplus 23094332d3Sopenharmony_ciextern "C" { 24094332d3Sopenharmony_ci#endif // __cplusplus 25094332d3Sopenharmony_ci 26094332d3Sopenharmony_ci#define INVALID_TEMPLATE_ID 0xFFFFFFFFFFFFFFFF 27094332d3Sopenharmony_ci#define INIT_AUTH_ERROR_COUNT 0 28094332d3Sopenharmony_ci#define INIT_START_FREEZE_TIMES 0 29094332d3Sopenharmony_ci#define CONST_PIN_DATA_LEN 64U 30094332d3Sopenharmony_ci#define CONST_SALT_LEN 32U 31094332d3Sopenharmony_ci#define RESULT_TLV_LEN 240U 32094332d3Sopenharmony_ci 33094332d3Sopenharmony_citypedef struct { 34094332d3Sopenharmony_ci uint64_t scheduleId; 35094332d3Sopenharmony_ci uint64_t subType; 36094332d3Sopenharmony_ci uint8_t salt[CONST_SALT_LEN]; 37094332d3Sopenharmony_ci uint8_t pinData[CONST_PIN_DATA_LEN]; 38094332d3Sopenharmony_ci} __attribute__((__packed__)) PinEnrollParam; 39094332d3Sopenharmony_ci 40094332d3Sopenharmony_cibool LoadPinDb(void); 41094332d3Sopenharmony_civoid DestroyPinDb(void); 42094332d3Sopenharmony_ci 43094332d3Sopenharmony_ciResultCode AddPin(PinEnrollParam *pinEnrollParam, uint64_t *templateId, Buffer *outRootSecret); 44094332d3Sopenharmony_ciResultCode DoGetAlgoParameter(uint64_t templateId, uint8_t *salt, uint32_t *saltLen, uint32_t *algoVersion); 45094332d3Sopenharmony_ciResultCode DoGenerateAlgoParameter(uint8_t *algoParameter, uint32_t *algoParameterLength, uint32_t *algoVersion, 46094332d3Sopenharmony_ci uint8_t *localDeviceId, uint32_t deviceUuidLength); 47094332d3Sopenharmony_ciResultCode DelPinById(uint64_t templateId); 48094332d3Sopenharmony_ciResultCode AuthPinById(const Buffer *inputPinData, uint64_t templateId, Buffer *outRootSecret, ResultCode *compareRet); 49094332d3Sopenharmony_ciResultCode ComputeFreezeTime(uint64_t templateId, uint32_t *freezeTime, uint32_t count, uint64_t startFreezeTime); 50094332d3Sopenharmony_ciResultCode GetRemainTimes(uint64_t templateId, uint32_t *remainingAuthTimes, uint32_t authErrorCount); 51094332d3Sopenharmony_ciResultCode GetSubType(uint64_t templateId, uint64_t *subType); 52094332d3Sopenharmony_ciResultCode GetAntiBruteInfo(uint64_t templateId, uint32_t *authErrorCount, uint64_t *startFreezeTime); 53094332d3Sopenharmony_ciResultCode RefreshAntiBruteInfoToFile(uint64_t templateId); 54094332d3Sopenharmony_ciResultCode VerifyTemplateDataPin(const uint64_t *templateIdList, uint32_t templateIdListLen); 55094332d3Sopenharmony_ciint32_t GetNextFailLockoutDuration(uint32_t authErrorCount); 56094332d3Sopenharmony_ci 57094332d3Sopenharmony_ci#ifdef __cplusplus 58094332d3Sopenharmony_ci} 59094332d3Sopenharmony_ci#endif // __cplusplus 60094332d3Sopenharmony_ci#endif // PIN_DB_H