• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 2048U
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     uint32_t pinLength;
39 } __attribute__((__packed__)) PinEnrollParam;
40 
41 typedef struct {
42     uint64_t oldTemplateId;
43     uint64_t curTemplateId;
44     uint64_t newTemplateId;
45     Buffer *newRootSecret;
46 } __attribute__((__packed__)) AbandonCacheParam;
47 
48 bool LoadPinDb(void);
49 void DestroyPinDb(void);
50 
51 ResultCode AddPin(PinEnrollParam *pinEnrollParam, uint64_t *templateId, Buffer *outRootSecret);
52 ResultCode DoGetAlgoParameter(uint64_t templateId, uint8_t *salt, uint32_t *saltLen, uint32_t *algoVersion);
53 ResultCode DoGenerateAlgoParameter(uint8_t *algoParameter, uint32_t *algoParameterLength, uint32_t *algoVersion,
54     uint8_t *localDeviceId, uint32_t deviceUuidLength);
55 ResultCode DelPinById(uint64_t templateId);
56 ResultCode AuthPinById(const Buffer *inputPinData, uint64_t templateId, uint32_t pinLength,
57     Buffer *outRootSecret, ResultCode *compareRet);
58 ResultCode ComputeFreezeTime(uint64_t templateId, uint32_t *freezeTime, uint32_t count, uint64_t startFreezeTime);
59 ResultCode GetRemainTimes(uint64_t templateId, uint32_t *remainingAuthTimes, uint32_t authErrorCount);
60 ResultCode GetSubType(uint64_t templateId, uint64_t *subType);
61 ResultCode GetAntiBruteInfo(uint64_t templateId, uint32_t *authErrorCount, uint64_t *startFreezeTime);
62 ResultCode RefreshAntiBruteInfoToFile(uint64_t templateId);
63 ResultCode VerifyTemplateDataPin(const uint64_t *templateIdList, uint32_t templateIdListLen);
64 int32_t GetNextFailLockoutDuration(uint32_t authErrorCount);
65 Buffer *GetRootSecretPlainInfo(Buffer *oldRootSecret, const Buffer *cipherInfo);
66 Buffer *GenerateDecodeRootSecret(uint64_t templateId, Buffer *oldRootSecret);
67 ResultCode Abandon(uint64_t oldTemplateId, uint64_t newTemplateId, Buffer *oldRootSecret, Buffer *newRootSecret);
68 void DestroyAbandonParam(void);
69 ResultCode WriteRootSecretFile(uint64_t templateId, uint64_t newTemplateId, Buffer *ciperInfo);
70 ResultCode ReadRootSecretFile(uint64_t templateId, uint64_t *newTemplateId, Buffer **ciperInfo);
71 ResultCode ReWriteRootSecretFile(uint64_t templateId);
72 ResultCode GetCredentialLength(uint64_t templateId, uint32_t *credentialLength);
73 ResultCode RestartLockoutDurationByUserId(int32_t userId);
74 #ifdef __cplusplus
75 }
76 #endif // __cplusplus
77 #endif  // PIN_DB_H