1/* Copyright 2016 OpenMarket Ltd
2 *
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/**
17 * functions for encoding and decoding messages in the Olm protocol.
18 *
19 * Some of these functions have only C++ bindings, and are declared in
20 * message.hh; in time, they should probably be converted to plain C and
21 * declared here.
22 */
23
24#ifndef OLM_MESSAGE_H_
25#define OLM_MESSAGE_H_
26
27#include <stdint.h>
28#include <stddef.h>
29
30// Note: exports in this file are only for unit tests. Nobody else should be
31// using this externally
32#include "olm/olm_export.h"
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38/**
39 * The length of the buffer needed to hold a group message.
40 */
41OLM_EXPORT size_t _olm_encode_group_message_length(
42 uint32_t chain_index,
43 size_t ciphertext_length,
44 size_t mac_length,
45 size_t signature_length
46);
47
48/**
49 * Writes the message headers into the output buffer.
50 *
51 * version: version number of the olm protocol
52 * message_index: message index
53 * ciphertext_length: length of the ciphertext
54 * output: where to write the output. Should be at least
55 * olm_encode_group_message_length() bytes long.
56 * ciphertext_ptr: returns the address that the ciphertext
57 * should be written to, followed by the MAC and the
58 * signature.
59 *
60 * Returns the size of the message, up to the MAC.
61 */
62OLM_EXPORT size_t _olm_encode_group_message(
63 uint8_t version,
64 uint32_t message_index,
65 size_t ciphertext_length,
66 uint8_t *output,
67 uint8_t **ciphertext_ptr
68);
69
70
71struct _OlmDecodeGroupMessageResults {
72 uint8_t version;
73 uint32_t message_index;
74 int has_message_index;
75 const uint8_t *ciphertext;
76 size_t ciphertext_length;
77};
78
79
80/**
81 * Reads the message headers from the input buffer.
82 */
83OLM_EXPORT void _olm_decode_group_message(
84 const uint8_t *input, size_t input_length,
85 size_t mac_length, size_t signature_length,
86
87 /* output structure: updated with results */
88 struct _OlmDecodeGroupMessageResults *results
89);
90
91
92
93#ifdef __cplusplus
94} // extern "C"
95#endif
96
97#endif /* OLM_MESSAGE_H_ */
98