• 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 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 CONST_PUB_KEY_LEN 32U
32 #define RESULT_TLV_LEN 240U
33 
34 typedef struct {
35     uint64_t scheduleId;
36     uint64_t subType;
37     uint8_t salt[CONST_SALT_LEN];
38     uint8_t pinData[CONST_PIN_DATA_LEN];
39 } __attribute__((__packed__)) PinEnrollParam;
40 
41 bool LoadPinDb(void);
42 void DestroyPinDb(void);
43 
44 ResultCode AddPin(PinEnrollParam *pinEnrollParam, uint64_t *templateId, Buffer *outRootSecret);
45 ResultCode DoGetAlgoParameter(uint64_t templateId, uint8_t *salt, uint32_t *saltLen, uint32_t *algoVersion);
46 ResultCode DoGenerateAlgoParameter(uint8_t *algoParameter, uint32_t *algoParameterLength, uint32_t *algoVersion,
47     uint8_t *localDeviceId, uint32_t deviceUuidLength);
48 ResultCode DelPinById(uint64_t templateId);
49 ResultCode AuthPinById(const uint8_t *inputData, const uint32_t inputDataLen, uint64_t templateId,
50     Buffer *outRootSecret, ResultCode *compareRet);
51 ResultCode ComputeFreezeTime(uint64_t templateId, uint32_t *freezeTime, uint32_t count, uint64_t startFreezeTime);
52 ResultCode GetRemainTimes(uint64_t templateId, uint32_t *remainingAuthTimes, uint32_t authErrorCount);
53 ResultCode GetSubType(uint64_t templateId, uint64_t *subType);
54 ResultCode GetAntiBruteInfo(uint64_t templateId, uint32_t *authErrorCount, uint64_t *startFreezeTime);
55 ResultCode RefreshAntiBruteInfoToFile(uint64_t templateId);
56 ResultCode VerifyTemplateDataPin(const uint64_t *templateIdList, uint32_t templateIdListLen);
57 
58 #ifdef __cplusplus
59 }
60 #endif // __cplusplus
61 #endif  // PIN_DB_H