1 /* 2 * Copyright (c) 2021 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 AUTH_SESSIONKEY_H 17 #define AUTH_SESSIONKEY_H 18 19 #include "auth_manager.h" 20 #include "common_list.h" 21 #include "softbus_adapter_crypto.h" 22 #include "softbus_def.h" 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 #define MESSAGE_INDEX_LEN 4 29 #define ENCRYPT_OVER_HEAD_LEN (OVERHEAD_LEN + MESSAGE_INDEX_LEN) 30 #define MAX_KEY_LIST_SIZE 20 31 #define LOW_32_BIT 0xFFFFFFFF 32 33 typedef struct { 34 uint32_t type; 35 char deviceKey[MAX_DEVICE_KEY_LEN]; 36 uint32_t deviceKeyLen; 37 AuthSideFlag side; 38 int32_t seq; 39 } NecessaryDevInfo; 40 41 typedef struct { 42 char deviceKey[MAX_DEVICE_KEY_LEN]; 43 uint32_t deviceKeyLen; 44 uint32_t type; 45 int32_t seq; 46 uint8_t sessionKey[SESSION_KEY_LENGTH]; 47 uint32_t sessionKeyLen; 48 char peerUdid[UDID_BUF_LEN]; 49 AuthSideFlag side; 50 ListNode node; 51 } SessionKeyList; 52 53 void AuthSetLocalSessionKey(const NecessaryDevInfo *devInfo, const char *peerUdid, 54 const uint8_t *sessionKey, uint32_t sessionKeyLen); 55 bool AuthIsDeviceVerified(uint32_t type, const char *deviceKey, uint32_t deviceKeyLen); 56 bool AuthIsSeqInKeyList(int32_t seq); 57 void AuthSessionKeyListInit(void); 58 void AuthClearSessionKeyBySeq(int32_t seq); 59 void AuthClearAllSessionKey(void); 60 61 #ifdef __cplusplus 62 } 63 #endif 64 #endif /* AUTH_SESSIONKEY_H */ 65