• 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 KEY_AGREE_SESSION_H
17 #define KEY_AGREE_SESSION_H
18 
19 #include "device_auth_defines.h"
20 #include "json_utils.h"
21 #include "key_agree_sdk.h"
22 #include "pake_defs.h"
23 
24 #define FIELD_SDK_ERROR_CODE "_ec"
25 #define FIELD_SDK_STEP "_st"
26 #define FIELD_SDK_PAYLOAD "_pd"
27 #define FIELD_SDK_SEND_TO_PEER "_d"
28 #define FIELD_SDK_VERSION "v"
29 #define FIELD_SDK_CURRENT_VERSION "cv"
30 #define FIELD_PEER_AUTH_ID "peerAuthId"
31 #define FIELD_KCF_DATA "kcfData"
32 #define FIELD_EPK "epk"
33 #define FIELD_SALT "salt"
34 
35 #define CHECK_PTR_RETURN_ERROR_CODE(ptr, paramTag) \
36     do { \
37         if ((ptr) == NULL) { \
38             LOGE(paramTag " is null ptr"); \
39             return HC_ERR_NULL_PTR; \
40         } \
41     } while (0)
42 
43 typedef struct {
44     uint64_t first;
45     uint64_t second;
46     uint64_t third;
47 } VersionStruct;
48 
49 typedef enum {
50     INITIAL,
51     VERSION_CONFIRM,
52     VERSION_DECIDED,
53 } VersionAgreementStatus;
54 
55 typedef struct VersionInfoT {
56     VersionAgreementStatus versionStatus;
57     VersionStruct curVersion;
58 } VersionInfo;
59 
60 typedef enum {
61     SPEKE_MOD_NONE = 0x00000000,
62     DL_SPEKE_MOD_256 = 0x00000001,
63     DL_SPEKE_MOD_384 = 0x00000002,
64     EC_SPEKE_P256 = 0x00000004,
65     EC_SPEKE_X25519 = 0x00000008,
66 } ProtocolPrimeMod;
67 
68 typedef enum {
69     STEP_INIT = -1,
70     STEP_ONE = 1,
71     STEP_TWO = 2,
72     STEP_THREE = 3,
73     STEP_FOUR = 4,
74 } ProtocolStep;
75 
76 typedef struct SpekeSessionT {
77     PakeBaseParams baseParam;
78     uint64_t sessionId;
79     ProtocolStep step;
80     char *extras;
81     bool isFinish;
82     KeyAgreeProtocol protocol;
83     KeyAgreeType keyAgreeType;
84     VersionInfo versionInfo;
85     Uint8Buff deviceId;
86     Uint8Buff sharedSecret;
87     int32_t (*processProtocolAgree)(struct SpekeSessionT *spekeSession, const KeyAgreeBlob *in, KeyAgreeBlob *out);
88     int32_t (*processSession)(struct SpekeSessionT *spekeSession, const KeyAgreeBlob *in, KeyAgreeBlob *out);
89     int32_t (*initSpekeSession)(struct SpekeSessionT *spekeSession, KeyAgreeProtocol protocol);
90     int32_t (*checkAndInitProtocol)(struct SpekeSessionT *spekeSession, KeyAgreeProtocol protocol);
91 } SpekeSession;
92 
93 #ifdef __cplusplus
94 extern "C" {
95 #endif
96 
97 SpekeSession *CreateSpekeSession(void);
98 void DestroySpekeSession(SpekeSession *spekeSession);
99 
100 #ifdef __cplusplus
101 }
102 #endif
103 #endif
104