• 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 AUTH_SESSION_KEY_H
17 #define AUTH_SESSION_KEY_H
18 
19 #include "auth_interface.h"
20 
21 #ifdef __cplusplus
22 #if __cplusplus
23 extern "C" {
24 #endif
25 #endif
26 
27 #define ENCRYPT_INDEX_LEN 4
28 #define ENCRYPT_OVER_HEAD_LEN (OVERHEAD_LEN + ENCRYPT_INDEX_LEN)
29 
30 typedef struct {
31     uint8_t value[SESSION_KEY_LENGTH];
32     uint32_t len;
33 } SessionKey;
34 
35 typedef struct {
36     const uint8_t *inData;
37     uint32_t inLen;
38 } InDataInfo;
39 typedef ListNode SessionKeyList;
40 
41 void InitSessionKeyList(SessionKeyList *list);
42 void DestroySessionKeyList(SessionKeyList *list);
43 int32_t DupSessionKeyList(const SessionKeyList *srcList, SessionKeyList *dstList);
44 
45 uint64_t GetLatestAvailableSessionKeyTime(const SessionKeyList *list, AuthLinkType type);
46 bool HasSessionKey(const SessionKeyList *list);
47 AuthLinkType GetSessionKeyTypeByIndex(const SessionKeyList *list, int32_t index);
48 int32_t AddSessionKey(SessionKeyList *list, int32_t index, const SessionKey *key, AuthLinkType type,
49     bool isOldKey);
50 int32_t SetSessionKeyAvailable(SessionKeyList *list, int32_t index);
51 int32_t GetLatestSessionKey(const SessionKeyList *list, AuthLinkType type, int32_t *index, SessionKey *key);
52 int32_t GetSessionKeyByIndex(const SessionKeyList *list, int32_t index, AuthLinkType type, SessionKey *key);
53 int32_t SetSessionKeyAuthLinkType(const SessionKeyList *list, int32_t index, AuthLinkType type);
54 bool CheckSessionKeyListExistType(const SessionKeyList *list, AuthLinkType type);
55 bool CheckSessionKeyListHasOldKey(const SessionKeyList *list, AuthLinkType type);
56 int32_t ClearOldKey(const SessionKeyList *list, AuthLinkType type);
57 void RemoveSessionkeyByIndex(SessionKeyList *list, int32_t index, AuthLinkType type);
58 void ClearSessionkeyByAuthLinkType(int64_t authId, SessionKeyList *list, AuthLinkType type);
59 
60 int32_t EncryptInner(const SessionKeyList *list, AuthLinkType type, const InDataInfo *inDataInfo,
61     uint8_t **outData, uint32_t *outLen);
62 int32_t DecryptInner(const SessionKeyList *list, AuthLinkType type, const InDataInfo *inDataInfo,
63     uint8_t **outData, uint32_t *outLen);
64 
65 int32_t EncryptData(const SessionKeyList *list, AuthLinkType type, const InDataInfo *inDataInfo,
66     uint8_t *outData, uint32_t *outLen);
67 int32_t DecryptData(const SessionKeyList *list, AuthLinkType type, const InDataInfo *inDataInfo,
68     uint8_t *outData, uint32_t *outLen);
69 
70 void ScheduleUpdateSessionKey(AuthHandle authHandle, uint64_t delatMs);
71 void CancelUpdateSessionKey(int64_t authId);
72 
73 /* For Debug */
74 void DumpSessionkeyList(const SessionKeyList *list);
75 
76 #ifdef __cplusplus
77 #if __cplusplus
78 }
79 #endif
80 #endif
81 #endif /* AUTH_SESSION_KEY_H */
82