1 /* 2 * Copyright (c) 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 PINAUTHTA_EXECUTOR_FUNC_COMMON_H 17 #define PINAUTHTA_EXECUTOR_FUNC_COMMON_H 18 19 #include "adaptor_algorithm.h" 20 #include "attribute.h" 21 #include "buffer.h" 22 #include "pin_db.h" 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif // __cplusplus 27 28 #define PIN_CAPABILITY_LEVEL 3 29 #define PIN_EXECUTOR_SECURITY_LEVEL 2 30 31 #define CONST_FWK_UDID_SIZE 64 32 33 #define CONST_KEK_SALT_SIZE 32 34 35 #define CONST_KEK_AAD "remote_pin_aes_aad" 36 #define CONST_KEK_AAD_SIZE 18 37 38 #define CONST_CHALLENGE_LEN 32 39 40 enum ExecutorRole { 41 SCHEDULER = 0, 42 COLLECTOR = 1, 43 VERIFIER = 2, 44 ALL_IN_ONE = 3, 45 }; 46 47 typedef enum RemotePinMsgId { 48 REMOTE_PIN_MSG_NONE = 0, 49 REMOTE_PIN_COLLECTOR_SYNC = 1, 50 REMOTE_PIN_VERIFIER_ACK = 2, 51 REMOTE_PIN_COLLECTOR_ACK = 3, 52 } RemotePinMsgId; 53 54 typedef struct PinExecutorInfo { 55 uint32_t esl; 56 uint8_t pubKey[ED25519_FIX_PUBKEY_BUFFER_SIZE]; 57 uint32_t maxTemplateAcl; 58 } PinExecutorInfo; 59 60 typedef struct { 61 uint64_t subType; 62 uint32_t remainTimes; 63 uint32_t freezeTime; 64 int32_t nextFailLockoutDuration; 65 } PinCredentialInfos; 66 67 typedef struct AlgoParamOut { 68 uint32_t algoVersion; 69 uint64_t subType; 70 uint8_t algoParameter[CONST_SALT_LEN]; 71 uint8_t challenge[CONST_CHALLENGE_LEN]; 72 } AlgoParamOut; 73 74 int32_t SetBufferToAttribute(Attribute *attribute, AttributeKey key, Buffer *buf); 75 Buffer *GetBufferFromAttribute(const Attribute *attribute, AttributeKey key, uint32_t size); 76 Attribute *GetAttributeDataBase(uint64_t scheduleId, RemotePinMsgId msgId); 77 int32_t FormatTlvMsg(const Attribute *data, const KeyPair *keyPair, uint8_t *msg, uint32_t *msgSize); 78 int32_t VerifyAndGetDataAttribute( 79 uint64_t scheduleId, Attribute **data, const Buffer *pubKey, const uint8_t *msg, uint32_t msgSize); 80 int32_t CheckAttributeDataBase(const Attribute *data, uint64_t scheduleId, RemotePinMsgId msgId, uint64_t *timeStamp); 81 int32_t DoQueryPinInfo(uint64_t templateId, PinCredentialInfos *pinCredentialInfo); 82 bool SetResultDataInfo(Attribute *attribute, int32_t resultCode, uint64_t templateId, Buffer *rootSecret); 83 int32_t PinResultToFwkResult(int32_t pinResult); 84 85 #ifdef __cplusplus 86 } 87 #endif // __cplusplus 88 89 #endif // PINAUTHTA_EXECUTOR_FUNC_COMMON_H 90