• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 DAS_VERSION_UTIL_H
17 #define DAS_VERSION_UTIL_H
18 
19 #include "pake_defs.h"
20 #include "version_util.h"
21 
22 #define ALG_OFFSET_FOR_PAKE_V1 0
23 #define ALG_OFFSET_FOR_PAKE_V2 5
24 
25 typedef enum {
26     UNSUPPORTED_ALG = 0x0000,
27     DL_PAKE_V1 = 0x0001, // 0001
28     EC_PAKE_V1 = 0x0002, // 0010
29     STS_ALG = 0x0004, // 0100
30     PSK_SPEKE = 0x0008, // 1000
31     ISO_ALG = 0x0010, // 0001 0000
32     DL_PAKE_V2 = 0x0020, // 0010 0000
33     EC_PAKE_V2 = 0x0040, // 0100 0000
34 } DasAlgType;
35 
36 typedef enum {
37     INITIAL,
38     VERSION_CONFIRM,
39     VERSION_DECIDED,
40 } VersionAgreementStatus;
41 
42 typedef struct VersionInfoT {
43     int32_t opCode;
44     VersionAgreementStatus versionStatus;
45     VersionStruct minVersion;
46     VersionStruct curVersion;
47 } VersionInfo;
48 
49 int32_t GetVersionFromJson(const CJson *jsonObj, VersionStruct *minVer, VersionStruct *maxVer);
50 int32_t AddVersionToJson(CJson *jsonObj, const VersionStruct *minVer, const VersionStruct *maxVer);
51 
52 bool IsVersionEqual(VersionStruct *src, VersionStruct *des);
53 int32_t NegotiateVersion(VersionStruct *minVersionPeer, VersionStruct *curVersionPeer,
54     VersionStruct *curVersionSelf);
55 
56 ProtocolType GetPrototolType(VersionStruct *curVersion, OperationCode opCode);
57 PakeAlgType GetSupportedPakeAlg(VersionStruct *curVersion, ProtocolType protocolType);
58 bool IsSupportedPsk(VersionStruct *curVersion);
59 
60 #endif
61