• 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_SDK_H
17 #define KEY_AGREE_SDK_H
18 
19 #include <stdint.h>
20 
21 typedef enum {
22     KEYAGREE_TYPE_CLIENT = 1,
23     KEYAGREE_TYPE_SERVER = 2,
24 } KeyAgreeType;
25 
26 typedef struct {
27     uint64_t sessionId;
28 } KeyAgreeSession;
29 
30 typedef enum {
31     KEYAGREE_PROTOCOL_DL_SPEKE_256 = 1,
32     KEYAGREE_PROTOCOL_DL_SPEKE_384 = 2,
33     KEYAGREE_PROTOCOL_EC_SPEKE_P256 = 3,
34     KEYAGREE_PROTOCOL_EC_SPEKE_X25519 = 4,
35     KEYAGREE_PROTOCOL_ANY = 5,
36 } KeyAgreeProtocol;
37 
38 typedef enum {
39     KEYAGREE_SUCCESS = 0,
40     KEYAGREE_NOT_SUPPORTED = 1,
41     KEYAGREE_BAD_PARAMS = 2,
42     KEYAGREE_BAD_MESSAGE = 3,
43     KEYAGREE_FAIL = 4,
44     KEYAGREE_UNKNOWN = 5,
45 
46     // New errorCode
47     KEYAGREE_INIT_BAD_PARAMS = 10601001,
48     KEYAGREE_INIT_NOT_SUPPORTED = 10601002,
49     KEYAGREE_INIT_ENTITIES_FAIL = 20601001,
50     KEYAGREE_INIT_CREATE_SESSION_FAIL = 20601002,
51     KEYAGREE_INIT_CREATE_SESSION_MGR_FAIL = 20601003,
52     KEYAGREE_INIT_INIT_SESSION_FAIL = 20601004,
53     KEYAGREE_INIT_ADD_SESSION_FAIL = 20601005,
54 
55     KEYAGREE_START_BAD_PARAMS = 10602001,
56     KEYAGREE_START_INVAILD_LEN = 10602002,
57     KEYAGREE_START_GET_SESSION_MGR_FAIL = 20602001,
58     KEYAGREE_START_GET_SESSION_FAIL = 20602002,
59     KEYAGREE_START_INIT_PARAMS_SHAREDSECRET_FAIL = 20602003,
60     KEYAGREE_START_MEMORY_COPY_SHAREDSECRET_FAIL = 20602004,
61     KEYAGREE_START_INIT_PARAMS_DEVID_FAIL = 20602005,
62     KEYAGREE_START_MEMORY_COPY_DEVID_FAIL = 20602006,
63     KEYAGREE_START_ALLOC_MEMORY_FAIL = 20602007,
64     KEYAGREE_START_MEMORY_COPY_EXTRAS_FAIL = 20602008,
65 
66     KEYAGREE_PROCESS_BAD_PARAMS = 10603001,
67     KEYAGREE_PROCESS_INVAILD_LEN = 10603002,
68     KEYAGREE_PROCESS_GET_SESSION_MGR_FAIL = 20603001,
69     KEYAGREE_PROCESS_GET_SESSION_FAIL = 20603002,
70     KEYAGREE_PROCESS_PEER_IS_ONERROR = 30603001,
71     KEYAGREE_PROCESS_PROTOCOL_AGREE_FAIL = 20603003,
72     KEYAGREE_PROCESS_PROTOCOL_SESSION_FAIL = 20603004,
73 
74     KEYAGREE_IS_FINSIH_BAD_PARAMS = 10604001,
75     KEYAGREE_IS_FINSIH_GET_SESSION_MGR_FAIL = 20604001,
76     KEYAGREE_IS_FINSIH_GET_SESSION_FAIL = 20604002,
77     KEYAGREE_IS_FINSIH_ERROR = 20604003,
78     KEYAGREE_IS_FINSIH_NOT_FINSIH = 20604004,
79 
80     KEYAGREE_GET_RESULT_BAD_PARAMS = 10605001,
81     KEYAGREE_GET_RESULT_INVAILD_LEN = 10605002,
82     KEYAGREE_GET_RESULT_GET_SESSION_MGR_FAIL = 20605001,
83     KEYAGREE_GET_RESULT_GET_SESSION_FAIL = 20605002,
84     KEYAGREE_GET_RESULT_NOT_FINSIH = 20605003,
85     KEYAGREE_GET_RESULT_MEMCPY_FAILED = 20605004
86 } KeyAgreeResult;
87 
88 typedef struct {
89     uint8_t *data;
90     uint32_t length; // This length is the requested memory length
91 } KeyAgreeBlob;
92 
93 #ifdef __cplusplus
94 extern "C" {
95 #endif
96 KeyAgreeResult KeyAgreeInitSession(KeyAgreeSession *session, KeyAgreeProtocol protocol, KeyAgreeType type);
97 KeyAgreeResult KeyAgreeStartSession(KeyAgreeSession *session, const KeyAgreeBlob *sharedSecret,
98     const KeyAgreeBlob *deviceId, const char *extras);
99 KeyAgreeResult KeyAgreeGenerateNextMessage(KeyAgreeSession *session, const KeyAgreeBlob *messageReceived,
100     KeyAgreeBlob *messageToTransmit);
101 KeyAgreeResult KeyAgreeIsFinish(KeyAgreeSession *session);
102 KeyAgreeResult KeyAgreeGetResult(KeyAgreeSession *session, KeyAgreeBlob *sessionKey);
103 void KeyAgreeFreeSession(KeyAgreeSession *session);
104 #ifdef __cplusplus
105 }
106 #endif
107 
108 #endif