+#define OLM_IDENTITY_KEYS_JSON_SIZE 128\r
+#define DEVICE_KEY_SIZE 44\r
+#define SIGNING_KEY_SIZE 44\r
+#define ONETIME_KEY_SIZE 44\r
+#define MASTER_KEY_SIZE 44\r
+\r
+#define KEY_SHARE_EVENT_LEN 1024\r
+\r
+#define OLM_ACCOUNT_MEMORY_SIZE 7528\r
+#define OLM_ACCOUNT_RANDOM_SIZE (32+32)\r
+\r
+#define OLM_SESSION_MEMORY_SIZE 3352\r
+#define OLM_ENCRYPT_RANDOM_SIZE 32\r
+#define OLM_OUTBOUND_SESSION_RANDOM_SIZE (32*2)\r
+\r
+#define OLM_ONETIME_KEYS_RANDOM_SIZE (32*10)\r
+#define OLM_KEY_ID_SIZE 32\r
+\r
+#define OLM_SIGNATURE_SIZE 128\r
+\r
+#define MEGOLM_OUTBOUND_SESSION_MEMORY_SIZE 232\r
+#define MEGOLM_SESSION_ID_SIZE 44\r
+#define MEGOLM_SESSION_KEY_SIZE 306\r
+#define MEGOLM_INIT_RANDOM_SIZE (4*32 + 32)\r
+\r
+#define JSON_ONETIME_KEY_SIZE 128\r
+#define JSON_ONETIME_KEY_SIGNED_SIZE 256\r
+#define JSON_SIGNATURE_SIZE 256\r
+\r
+#define NUM_MEGOLM_SESSIONS 2\r
+#define NUM_OLM_SESSIONS 2\r
+#define NUM_DEVICES 10\r
+\r
+// HTTP\r
+\r
+typedef struct MatrixHttpConnection MatrixHttpConnection;\r
+\r
+bool\r
+MatrixHttpInit(\r
+ MatrixHttpConnection ** hc,\r
+ const char * host);\r
+\r
+bool\r
+MatrixHttpDeinit(\r
+ MatrixHttpConnection ** hc);\r
+ \r
+bool\r
+MatrixHttpSetAccessToken(\r
+ MatrixHttpConnection * hc,\r
+ const char * accessToken);\r
+\r
+bool\r
+MatrixHttpGet(\r
+ MatrixHttpConnection * hc,\r
+ const char * url,\r
+ char * outResponseBuffer, int outResponseCap,\r
+ bool authenticated);\r
+\r
+bool\r
+MatrixHttpPost(\r
+ MatrixHttpConnection * hc,\r
+ const char * url,\r
+ const char * requestBuffer,\r
+ char * outResponseBuffer, int outResponseCap,\r
+ bool authenticated);\r
+\r
+bool\r
+MatrixHttpPut(\r
+ MatrixHttpConnection * hc,\r
+ const char * url,\r
+ const char * requestBuffer,\r
+ char * outResponseBuffer, int outResponseCap,\r
+ bool authenticated);\r
+\r
+\r
+\r
+// Matrix Device\r
+\r
+typedef struct MatrixDevice {\r
+ char deviceId[DEVICE_ID_SIZE];\r
+ char deviceKey[DEVICE_KEY_SIZE];\r
+ char signingKey[SIGNING_KEY_SIZE];\r
+} MatrixDevice;\r
+\r
+\r
+// Matrix Olm Account\r
+\r
+typedef struct MatrixOlmAccount {\r
+ OlmAccount * account;\r
+ char memory[OLM_ACCOUNT_MEMORY_SIZE];\r
+} MatrixOlmAccount;\r
+\r
+bool\r
+MatrixOlmAccountInit(\r
+ MatrixOlmAccount * account);\r
+\r
+bool\r
+MatrixOlmAccountUnpickle(\r
+ MatrixOlmAccount * account,\r
+ void * pickled, int pickledLen,\r
+ const void * key, int keyLen);\r
+\r
+bool\r
+MatrixOlmAccountGetDeviceKey(\r
+ MatrixOlmAccount * account,\r
+ char * key, int keyCap);\r
+ \r
+bool\r
+MatrixOlmAccountGetSigningKey(\r
+ MatrixOlmAccount * account,\r
+ char * key, int keyCap);\r
+\r
+\r
+// Matrix Olm Session\r
+\r
+typedef struct MatrixOlmSession {\r
+ const char * deviceId; // TODO: char[]\r
+\r
+ int type;\r
+ OlmSession * session;\r
+ char memory[OLM_SESSION_MEMORY_SIZE];\r
+} MatrixOlmSession;\r
+\r
+bool\r
+MatrixOlmSessionUnpickle(\r
+ MatrixOlmSession * session,\r
+ const char * deviceId,\r
+ void * pickled, int pickledLen,\r
+ const void * key, int keyLen);\r
+\r
+// create an olm sesseion from a type 0 message\r
+bool\r
+MatrixOlmSessionFrom(\r
+ MatrixOlmSession * session,\r
+ OlmAccount * olmAccount,\r
+ const char * deviceId,\r
+ const char * deviceKey,\r
+ const char * encrypted);\r
+\r
+// create a new olm session from a claimed onetime key\r
+bool\r
+MatrixOlmSessionTo(\r
+ MatrixOlmSession * session,\r
+ OlmAccount * olmAccount,\r
+ const char * deviceId,\r
+ const char * deviceKey,\r
+ const char * deviceOnetimeKey);\r
+\r
+bool\r
+MatrixOlmSessionEncrypt(\r
+ MatrixOlmSession * session,\r
+ const char * plaintext,\r
+ char * outBuffer, int outBufferCap);\r
+\r
+bool\r
+MatrixOlmSessionDecrypt(\r
+ MatrixOlmSession * session,\r
+ size_t messageType,\r
+ char * encrypted,\r
+ char * outBuffer, int outBufferCap);\r
+\r
+\r
+// Matrix Megolm Session\r
+\r
+typedef struct MatrixMegolmInSession {\r
+ char roomId[ROOM_ID_SIZE];\r
+ char id[MEGOLM_SESSION_ID_SIZE];\r
+ char key[MEGOLM_SESSION_KEY_SIZE];\r
+\r
+ OlmInboundGroupSession * session;\r
+ char memory[MEGOLM_OUTBOUND_SESSION_MEMORY_SIZE];\r
+\r
+} MatrixMegolmInSession;\r
+\r
+bool\r
+MatrixMegolmInSessionInit(\r
+ MatrixMegolmInSession * session,\r
+ const char * roomId,\r
+ const char * sessionId,\r
+ const char * sessionKey, int sessionKeyLen);\r
+\r
+bool\r
+MatrixMegolmInSessionDecrypt(\r
+ MatrixMegolmInSession * session,\r
+ const char * encrypted, int encryptedLen,\r
+ char * outDecrypted, int outDecryptedCap);\r
+\r
+typedef struct MatrixMegolmOutSession {\r
+ char roomId[ROOM_ID_SIZE];\r
+ char id[MEGOLM_SESSION_ID_SIZE];\r
+ char key[MEGOLM_SESSION_KEY_SIZE];\r
+\r
+ OlmOutboundGroupSession * session;\r
+ char memory[MEGOLM_OUTBOUND_SESSION_MEMORY_SIZE];\r
+} MatrixMegolmOutSession;\r
+\r
+bool\r
+MatrixMegolmOutSessionInit(\r
+ MatrixMegolmOutSession * session,\r
+ const char * roomId);\r
+\r
+bool\r
+MatrixMegolmOutSessionEncrypt(\r
+ MatrixMegolmOutSession * session,\r
+ const char * plaintext,\r
+ char * outBuffer, int outBufferCap);\r
+\r
+\r
+// Matrix Client\r