1 /*
2  * Copyright (C) 2023 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 MK_AGREE_TASK_H
17 #define MK_AGREE_TASK_H
18 
19 #include "alg_defs.h"
20 #include "json_utils.h"
21 #include "string_util.h"
22 
23 #define MK_AGREE_MESSAGE_CODE "mkAgreeMsg"
24 #define SALT_LEN 16
25 
26 typedef enum {
27     TASK_TYPE_ISO = 0,
28     TASK_TYPE_PAKE = 1,
29 } MkAgreeTaskType;
30 
31 typedef enum {
32     START_MK_AGREE_REQUEST,
33     SEND_MK_AGREE_RESPONSE,
34 } MkAgreeMessageCode;
35 
36 typedef enum {
37     STATUS_INIT,
38     STATUS_WAIT_MK_REQUEST,
39     STATUS_WAIT_MK_RESPONSE,
40     STATUS_FINISH,
41 } MkAgreeTaskStatus;
42 
43 typedef struct MkAgreeTaskBaseT {
44     void (*destroy)(struct MkAgreeTaskBaseT *);
45     int32_t (*process)(struct MkAgreeTaskBaseT *, const CJson *in, CJson *out);
46     MkAgreeTaskType taskType;
47     MkAgreeTaskStatus taskStatus;
48     int32_t osAccountId;
49     char *peerInfo;
50     char *pdidIndex;
51     char *peerUdid;
52     const AlgLoader *loader;
53 } MkAgreeTaskBase;
54 
55 typedef struct {
56     MkAgreeTaskBase taskBase;
57 } IsoMkAgreeTask;
58 
59 typedef struct {
60     MkAgreeTaskBase taskBase;
61     uint8_t clientSalt[SALT_LEN];
62     uint8_t serverSalt[SALT_LEN];
63 } PakeMkAgreeTask;
64 
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68 
69 int32_t CreateMkAgreeTask(int protocolType, const CJson *in, MkAgreeTaskBase **returnTask);
70 
71 #ifdef __cplusplus
72 }
73 #endif
74 #endif
75