13 #define USER_ID_SIZE 64
\r
14 #define SERVER_SIZE 20
\r
15 #define ACCESS_TOKEN_SIZE 40
\r
16 #define DEVICE_ID_SIZE 20
\r
17 #define EXPIRE_MS_SIZE 20
\r
18 #define REFRESH_TOKEN_SIZE 20
\r
19 #define MAX_URL_LEN 128
\r
21 #define OLM_IDENTITY_KEYS_JSON_SIZE 128
\r
22 #define DEVICE_KEY_SIZE 44
\r
23 #define SIGNING_KEY_SIZE 44
\r
25 #define KEY_SHARE_EVENT_LEN 1024
\r
27 #define OLM_ACCOUNT_MEMORY_SIZE 7528
\r
28 #define OLM_ACCOUNT_RANDOM_SIZE 32+32
\r
30 #define OLM_SESSION_MEMORY_SIZE 3352
\r
31 #define OLM_ENCRYPT_RANDOM_SIZE 32
\r
33 #define MEGOLM_OUTBOUND_SESSION_MEMORY_SIZE 232
\r
34 #define MEGOLM_SESSION_ID_SIZE 44
\r
35 #define MEGOLM_SESSION_KEY_SIZE 306
\r
36 #define MEGOLM_INIT_RANDOM_SIZE (4*32 + 32)
\r
38 #define NUM_MEGOLM_SESSIONS 10
\r
39 #define NUM_OLM_SESSIONS 10
\r
40 #define NUM_DEVICES 10
\r
43 Randomize(uint8_t * random, int randomLen);
\r
47 char * sIn, int sInLen,
\r
48 char * sOut, int sOutCap);
\r
50 typedef struct MatrixDevice {
\r
51 char deviceId[DEVICE_ID_SIZE];
\r
52 char deviceKey[DEVICE_KEY_SIZE];
\r
55 typedef struct MatrixOlmSession {
\r
56 const char * deviceId;
\r
59 OlmSession * session;
\r
60 char memory[OLM_SESSION_MEMORY_SIZE];
\r
64 MatrixOlmSessionInit(
\r
65 MatrixOlmSession * session,
\r
66 const char * deviceId);
\r
69 MatrixOlmSessionEncrypt(
\r
70 MatrixOlmSession * session,
\r
71 const char * plaintext,
\r
72 char * outBuffer, int outBufferCap);
\r
76 typedef struct MatrixMegolmInSession {
\r
77 OlmInboundGroupSession * session;
\r
78 } MatrixMegolmInSession;
\r
80 typedef struct MatrixMegolmOutSession {
\r
81 const char * roomId;
\r
83 OlmOutboundGroupSession * session;
\r
84 char memory[MEGOLM_OUTBOUND_SESSION_MEMORY_SIZE];
\r
86 char id[MEGOLM_SESSION_ID_SIZE];
\r
87 char key[MEGOLM_SESSION_KEY_SIZE];
\r
88 } MatrixMegolmOutSession;
\r
91 MatrixMegolmOutSessionInit(
\r
92 MatrixMegolmOutSession * session,
\r
93 const char * roomId);
\r
96 MatrixMegolmOutSessionEncrypt(
\r
97 MatrixMegolmOutSession * session,
\r
98 const char * plaintext,
\r
99 char * outBuffer, int outBufferCap);
\r
103 typedef struct MatrixClient {
\r
104 OlmAccount * olmAccount;
\r
105 char olmAccountMemory[OLM_ACCOUNT_MEMORY_SIZE];
\r
107 MatrixMegolmInSession megolmInSessions[NUM_MEGOLM_SESSIONS];
\r
108 int numMegolmInSessions;
\r
109 MatrixMegolmOutSession megolmOutSessions[NUM_MEGOLM_SESSIONS];
\r
110 int numMegolmOutSessions;
\r
111 MatrixOlmSession olmSessions[NUM_OLM_SESSIONS];
\r
112 int numOlmSessions;
\r
114 MatrixDevice devices[NUM_DEVICES];
\r
117 char deviceKey[DEVICE_KEY_SIZE];
\r
118 char signingKey[DEVICE_KEY_SIZE];
\r
120 char userId[USER_ID_SIZE];
\r
121 char server[SERVER_SIZE];
\r
122 char accessToken[ACCESS_TOKEN_SIZE];
\r
123 char deviceId[DEVICE_ID_SIZE];
\r
124 char expireMs[EXPIRE_MS_SIZE];
\r
125 char refreshToken[REFRESH_TOKEN_SIZE];
\r
127 void * httpUserData;
\r
132 MatrixClient * client,
\r
133 const char * server);
\r
136 MatrixClientSetAccessToken(
\r
137 MatrixClient * client,
\r
138 const char * accessToken);
\r
141 MatrixClientSetDeviceId(
\r
142 MatrixClient * client,
\r
143 const char * deviceId);
\r
146 MatrixClientLoginPassword(
\r
147 MatrixClient * client,
\r
148 const char * username,
\r
149 const char * password,
\r
150 const char * displayName);
\r
153 MatrixClientSendEvent(
\r
154 MatrixClient * client,
\r
155 const char * roomId,
\r
156 const char * msgType,
\r
157 const char * msgBody);
\r
160 MatrixClientSendEventEncrypted(
\r
161 MatrixClient * client,
\r
162 const char * roomId,
\r
163 const char * msgType,
\r
164 const char * msgBody);
\r
168 MatrixClient * client,
\r
169 char * outSyncBuffer, int outSyncCap);
\r
172 MatrixClientShareMegolmOutSession(
\r
173 MatrixClient * client,
\r
174 const char * deviceId,
\r
175 MatrixMegolmOutSession * session);
\r
178 MatrixClientGetMegolmOutSession(
\r
179 MatrixClient * client,
\r
180 const char * roomId,
\r
181 MatrixMegolmOutSession ** outSession);
\r
184 MatrixClientSetMegolmOutSession(
\r
185 MatrixClient * client,
\r
186 const char * roomId,
\r
187 MatrixMegolmOutSession session);
\r
190 MatrixClientGetOlmSession(
\r
191 MatrixClient * client,
\r
192 const char * deviceId,
\r
193 MatrixOlmSession ** outSession);
\r
196 MatrixClientSendToDevice(
\r
197 MatrixClient * client,
\r
198 const char * userId,
\r
199 const char * deviceId,
\r
200 const char * message,
\r
201 const char * msgType);
\r
204 MatrixClientSendToDeviceEncrypted(
\r
205 MatrixClient * client,
\r
206 const char * userId,
\r
207 const char * deviceId,
\r
208 const char * message,
\r
209 const char * msgType);
\r
212 MatrixClientGetDeviceKey(
\r
213 MatrixClient * client,
\r
214 const char * deviceId,
\r
215 char * outDeviceKey, int outDeviceKeyCap);
\r
218 MatrixClientGetDeviceKey(
\r
219 MatrixClient * client,
\r
220 const char * deviceId,
\r
221 char * outDeviceKey, int outDeviceKeyCap);
\r
224 MatrixClientRequestDeviceKeys(
\r
225 MatrixClient * client);
\r
231 MatrixClient * client);
\r
235 MatrixClient * client);
\r
239 MatrixClient * client,
\r
241 char * outResponseBuffer, int outResponseCap,
\r
242 bool authenticated);
\r
246 MatrixClient * client,
\r
248 const char * requestBuffer,
\r
249 char * outResponseBuffer, int outResponseCap,
\r
250 bool authenticated);
\r
254 MatrixClient * client,
\r
256 const char * requestBuffer,
\r
257 char * outResponseBuffer, int outResponseCap,
\r
258 bool authenticated);
\r