ruby_olm 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/ruby_olm/ext_lib_olm/ext_account.c +274 -0
- data/ext/ruby_olm/ext_lib_olm/ext_lib_olm.c +51 -0
- data/ext/ruby_olm/ext_lib_olm/ext_lib_olm.h +13 -0
- data/ext/ruby_olm/ext_lib_olm/ext_session.c +363 -0
- data/ext/ruby_olm/ext_lib_olm/ext_utility.c +69 -0
- data/ext/ruby_olm/ext_lib_olm/extconf.rb +69 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_account.cpp +695 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_account.h +56 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_inbound_group_session.cpp +654 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_inbound_group_session.h +51 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_jni.h +81 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_jni_helper.cpp +224 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_jni_helper.h +30 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_manager.cpp +35 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_manager.h +36 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_outbound_group_session.cpp +563 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_outbound_group_session.h +49 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_pk.cpp +716 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_pk.h +48 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_session.cpp +977 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_session.h +59 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_utility.cpp +236 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_utility.h +40 -0
- data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_decode_message.cpp +14 -0
- data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_decrypt.cpp +65 -0
- data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_group_decrypt.cpp +73 -0
- data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_unpickle_account.cpp +14 -0
- data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_unpickle_session.cpp +14 -0
- data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/include/fuzzing.hh +82 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/account.hh +160 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/base64.h +77 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/base64.hh +63 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/cipher.h +138 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/crypto.h +202 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/error.h +72 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/inbound_group_session.h +235 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/list.hh +119 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/megolm.h +95 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/memory.h +41 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/memory.hh +90 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/message.h +93 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/message.hh +138 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/olm.h +451 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/olm.hh +4 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/outbound_group_session.h +181 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/pickle.h +90 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/pickle.hh +149 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/pickle_encoding.h +76 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/pk.h +214 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/ratchet.hh +184 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/session.hh +156 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/utility.hh +61 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/aes.c +1073 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/aes.h +123 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/aes_test.c +276 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/arcfour.c +45 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/arcfour.h +30 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/arcfour_test.c +47 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/base64.c +135 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/base64.h +27 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/base64_test.c +54 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/blowfish.c +269 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/blowfish.h +32 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/blowfish_test.c +68 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/des.c +269 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/des.h +37 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/des_test.c +83 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md2.c +104 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md2.h +33 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md2_test.c +58 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md5.c +189 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md5.h +34 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md5_test.c +60 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/rot-13.c +35 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/rot-13.h +20 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/rot-13_test.c +44 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha1.c +149 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha1.h +35 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha1_test.c +58 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha256.c +159 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha256.h +34 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha256_test.c +61 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/contrib/Curve25519Donna.c +118 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/contrib/Curve25519Donna.h +53 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/curve25519-donna-c64.c +449 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/curve25519-donna.c +860 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/python-src/curve25519/curve25519module.c +105 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/speed-curve25519.c +50 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/test-curve25519.c +54 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/test-noncanon.c +39 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/test-sc-curve25519.c +72 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna.h +18 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/add_scalar.c +56 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/ed25519.h +38 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/fe.c +1493 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/fe.h +41 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/fixedint.h +72 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/ge.c +467 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/ge.h +74 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/key_exchange.c +79 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/keypair.c +16 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/precomp_data.h +1391 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sc.c +814 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sc.h +12 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/seed.c +40 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sha512.c +275 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sha512.h +21 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sign.c +31 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/verify.c +77 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/test.c +150 -0
- data/ext/ruby_olm/ext_lib_olm/olm/python/dummy/stddef.h +0 -0
- data/ext/ruby_olm/ext_lib_olm/olm/python/dummy/stdint.h +0 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/account.cpp +380 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/base64.cpp +167 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/cipher.cpp +152 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/crypto.cpp +299 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/ed25519.c +22 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/error.c +44 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/inbound_group_session.c +524 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/megolm.c +150 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/memory.cpp +45 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/message.cpp +401 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/olm.cpp +738 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/outbound_group_session.c +363 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/pickle.cpp +242 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/pickle_encoding.c +92 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/pk.cpp +412 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/ratchet.cpp +625 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/session.cpp +462 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/utility.cpp +57 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/include/unittest.hh +107 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_base64.cpp +70 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_crypto.cpp +246 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_group_session.cpp +329 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_list.cpp +92 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_megolm.cpp +134 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_message.cpp +112 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm.cpp +405 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm_decrypt.cpp +90 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm_sha256.cpp +20 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm_signature.cpp +81 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm_using_malloc.cpp +210 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_pk.cpp +166 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_ratchet.cpp +221 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_session.cpp +144 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMAccount.h +51 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMAccount_Private.h +25 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMInboundGroupSession.h +38 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMKit.h +37 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMMessage.h +38 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMOutboundGroupSession.h +32 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMPkDecryption.h +71 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMPkEncryption.h +42 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMPkMessage.h +31 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMSerializable.h +29 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMSession.h +44 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMSession_Private.h +26 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMUtility.h +49 -0
- data/ext/ruby_olm/ext_lib_olm/staging/account.cpp +380 -0
- data/ext/ruby_olm/ext_lib_olm/staging/aes.c +1073 -0
- data/ext/ruby_olm/ext_lib_olm/staging/base64.cpp +167 -0
- data/ext/ruby_olm/ext_lib_olm/staging/cipher.cpp +152 -0
- data/ext/ruby_olm/ext_lib_olm/staging/crypto.cpp +299 -0
- data/ext/ruby_olm/ext_lib_olm/staging/curve25519-donna.c +860 -0
- data/ext/ruby_olm/ext_lib_olm/staging/ed25519.c +22 -0
- data/ext/ruby_olm/ext_lib_olm/staging/error.c +44 -0
- data/ext/ruby_olm/ext_lib_olm/staging/inbound_group_session.c +524 -0
- data/ext/ruby_olm/ext_lib_olm/staging/megolm.c +150 -0
- data/ext/ruby_olm/ext_lib_olm/staging/memory.cpp +45 -0
- data/ext/ruby_olm/ext_lib_olm/staging/message.cpp +401 -0
- data/ext/ruby_olm/ext_lib_olm/staging/olm.cpp +738 -0
- data/ext/ruby_olm/ext_lib_olm/staging/outbound_group_session.c +363 -0
- data/ext/ruby_olm/ext_lib_olm/staging/pickle.cpp +242 -0
- data/ext/ruby_olm/ext_lib_olm/staging/pickle_encoding.c +92 -0
- data/ext/ruby_olm/ext_lib_olm/staging/pk.cpp +412 -0
- data/ext/ruby_olm/ext_lib_olm/staging/ratchet.cpp +625 -0
- data/ext/ruby_olm/ext_lib_olm/staging/session.cpp +461 -0
- data/ext/ruby_olm/ext_lib_olm/staging/sha256.c +159 -0
- data/ext/ruby_olm/ext_lib_olm/staging/utility.cpp +57 -0
- data/lib/ruby_olm/account.rb +42 -0
- data/lib/ruby_olm/message.rb +6 -0
- data/lib/ruby_olm/olm_error.rb +70 -0
- data/lib/ruby_olm/olm_message.rb +25 -0
- data/lib/ruby_olm/pre_key_message.rb +6 -0
- data/lib/ruby_olm/session.rb +16 -0
- data/lib/ruby_olm/version.rb +5 -0
- data/lib/ruby_olm.rb +10 -0
- data/rakefile +18 -0
- data/test/examples/test_bob_no_answer.rb +62 -0
- data/test/examples/test_exchange.rb +60 -0
- data/test/spec/test_account.rb +152 -0
- data/test/unit/test_account_methods.rb +85 -0
- metadata +282 -0
@@ -0,0 +1,93 @@
|
|
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
|
+
#ifdef __cplusplus
|
31
|
+
extern "C" {
|
32
|
+
#endif
|
33
|
+
|
34
|
+
/**
|
35
|
+
* The length of the buffer needed to hold a group message.
|
36
|
+
*/
|
37
|
+
size_t _olm_encode_group_message_length(
|
38
|
+
uint32_t chain_index,
|
39
|
+
size_t ciphertext_length,
|
40
|
+
size_t mac_length,
|
41
|
+
size_t signature_length
|
42
|
+
);
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Writes the message headers into the output buffer.
|
46
|
+
*
|
47
|
+
* version: version number of the olm protocol
|
48
|
+
* message_index: message index
|
49
|
+
* ciphertext_length: length of the ciphertext
|
50
|
+
* output: where to write the output. Should be at least
|
51
|
+
* olm_encode_group_message_length() bytes long.
|
52
|
+
* ciphertext_ptr: returns the address that the ciphertext
|
53
|
+
* should be written to, followed by the MAC and the
|
54
|
+
* signature.
|
55
|
+
*
|
56
|
+
* Returns the size of the message, up to the MAC.
|
57
|
+
*/
|
58
|
+
size_t _olm_encode_group_message(
|
59
|
+
uint8_t version,
|
60
|
+
uint32_t message_index,
|
61
|
+
size_t ciphertext_length,
|
62
|
+
uint8_t *output,
|
63
|
+
uint8_t **ciphertext_ptr
|
64
|
+
);
|
65
|
+
|
66
|
+
|
67
|
+
struct _OlmDecodeGroupMessageResults {
|
68
|
+
uint8_t version;
|
69
|
+
uint32_t message_index;
|
70
|
+
int has_message_index;
|
71
|
+
const uint8_t *ciphertext;
|
72
|
+
size_t ciphertext_length;
|
73
|
+
};
|
74
|
+
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Reads the message headers from the input buffer.
|
78
|
+
*/
|
79
|
+
void _olm_decode_group_message(
|
80
|
+
const uint8_t *input, size_t input_length,
|
81
|
+
size_t mac_length, size_t signature_length,
|
82
|
+
|
83
|
+
/* output structure: updated with results */
|
84
|
+
struct _OlmDecodeGroupMessageResults *results
|
85
|
+
);
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
#ifdef __cplusplus
|
90
|
+
} // extern "C"
|
91
|
+
#endif
|
92
|
+
|
93
|
+
#endif /* OLM_MESSAGE_H_ */
|
@@ -0,0 +1,138 @@
|
|
1
|
+
/* Copyright 2015 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
|
+
/**
|
18
|
+
* functions for encoding and decoding messages in the Olm protocol.
|
19
|
+
*
|
20
|
+
* Some of these functions have plain-C bindings, and are declared in
|
21
|
+
* message.h; in time, all of the functions declared here should probably be
|
22
|
+
* converted to plain C and moved to message.h.
|
23
|
+
*/
|
24
|
+
|
25
|
+
#include "message.h"
|
26
|
+
|
27
|
+
#include <cstddef>
|
28
|
+
#include <cstdint>
|
29
|
+
|
30
|
+
|
31
|
+
namespace olm {
|
32
|
+
|
33
|
+
/**
|
34
|
+
* The length of the buffer needed to hold a message.
|
35
|
+
*/
|
36
|
+
std::size_t encode_message_length(
|
37
|
+
std::uint32_t counter,
|
38
|
+
std::size_t ratchet_key_length,
|
39
|
+
std::size_t ciphertext_length,
|
40
|
+
std::size_t mac_length
|
41
|
+
);
|
42
|
+
|
43
|
+
|
44
|
+
struct MessageWriter {
|
45
|
+
std::uint8_t * ratchet_key;
|
46
|
+
std::uint8_t * ciphertext;
|
47
|
+
};
|
48
|
+
|
49
|
+
|
50
|
+
struct MessageReader {
|
51
|
+
std::uint8_t version;
|
52
|
+
bool has_counter;
|
53
|
+
std::uint32_t counter;
|
54
|
+
std::uint8_t const * input; std::size_t input_length;
|
55
|
+
std::uint8_t const * ratchet_key; std::size_t ratchet_key_length;
|
56
|
+
std::uint8_t const * ciphertext; std::size_t ciphertext_length;
|
57
|
+
};
|
58
|
+
|
59
|
+
|
60
|
+
/**
|
61
|
+
* Writes the message headers into the output buffer.
|
62
|
+
* Populates the writer struct with pointers into the output buffer.
|
63
|
+
*/
|
64
|
+
void encode_message(
|
65
|
+
MessageWriter & writer,
|
66
|
+
std::uint8_t version,
|
67
|
+
std::uint32_t counter,
|
68
|
+
std::size_t ratchet_key_length,
|
69
|
+
std::size_t ciphertext_length,
|
70
|
+
std::uint8_t * output
|
71
|
+
);
|
72
|
+
|
73
|
+
|
74
|
+
/**
|
75
|
+
* Reads the message headers from the input buffer.
|
76
|
+
* Populates the reader struct with pointers into the input buffer.
|
77
|
+
*/
|
78
|
+
void decode_message(
|
79
|
+
MessageReader & reader,
|
80
|
+
std::uint8_t const * input, std::size_t input_length,
|
81
|
+
std::size_t mac_length
|
82
|
+
);
|
83
|
+
|
84
|
+
|
85
|
+
struct PreKeyMessageWriter {
|
86
|
+
std::uint8_t * identity_key;
|
87
|
+
std::uint8_t * base_key;
|
88
|
+
std::uint8_t * one_time_key;
|
89
|
+
std::uint8_t * message;
|
90
|
+
};
|
91
|
+
|
92
|
+
|
93
|
+
struct PreKeyMessageReader {
|
94
|
+
std::uint8_t version;
|
95
|
+
std::uint8_t const * identity_key; std::size_t identity_key_length;
|
96
|
+
std::uint8_t const * base_key; std::size_t base_key_length;
|
97
|
+
std::uint8_t const * one_time_key; std::size_t one_time_key_length;
|
98
|
+
std::uint8_t const * message; std::size_t message_length;
|
99
|
+
};
|
100
|
+
|
101
|
+
|
102
|
+
/**
|
103
|
+
* The length of the buffer needed to hold a message.
|
104
|
+
*/
|
105
|
+
std::size_t encode_one_time_key_message_length(
|
106
|
+
std::size_t identity_key_length,
|
107
|
+
std::size_t base_key_length,
|
108
|
+
std::size_t one_time_key_length,
|
109
|
+
std::size_t message_length
|
110
|
+
);
|
111
|
+
|
112
|
+
|
113
|
+
/**
|
114
|
+
* Writes the message headers into the output buffer.
|
115
|
+
* Populates the writer struct with pointers into the output buffer.
|
116
|
+
*/
|
117
|
+
void encode_one_time_key_message(
|
118
|
+
PreKeyMessageWriter & writer,
|
119
|
+
std::uint8_t version,
|
120
|
+
std::size_t identity_key_length,
|
121
|
+
std::size_t base_key_length,
|
122
|
+
std::size_t one_time_key_length,
|
123
|
+
std::size_t message_length,
|
124
|
+
std::uint8_t * output
|
125
|
+
);
|
126
|
+
|
127
|
+
|
128
|
+
/**
|
129
|
+
* Reads the message headers from the input buffer.
|
130
|
+
* Populates the reader struct with pointers into the input buffer.
|
131
|
+
*/
|
132
|
+
void decode_one_time_key_message(
|
133
|
+
PreKeyMessageReader & reader,
|
134
|
+
std::uint8_t const * input, std::size_t input_length
|
135
|
+
);
|
136
|
+
|
137
|
+
|
138
|
+
} // namespace olm
|
@@ -0,0 +1,451 @@
|
|
1
|
+
/* Copyright 2015, 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
|
+
#ifndef OLM_H_
|
17
|
+
#define OLM_H_
|
18
|
+
|
19
|
+
#include <stddef.h>
|
20
|
+
#include <stdint.h>
|
21
|
+
|
22
|
+
#include "olm/inbound_group_session.h"
|
23
|
+
#include "olm/outbound_group_session.h"
|
24
|
+
|
25
|
+
#ifdef __cplusplus
|
26
|
+
extern "C" {
|
27
|
+
#endif
|
28
|
+
|
29
|
+
static const size_t OLM_MESSAGE_TYPE_PRE_KEY = 0;
|
30
|
+
static const size_t OLM_MESSAGE_TYPE_MESSAGE = 1;
|
31
|
+
|
32
|
+
typedef struct OlmAccount OlmAccount;
|
33
|
+
typedef struct OlmSession OlmSession;
|
34
|
+
typedef struct OlmUtility OlmUtility;
|
35
|
+
|
36
|
+
/** Get the version number of the library.
|
37
|
+
* Arguments will be updated if non-null.
|
38
|
+
*/
|
39
|
+
void olm_get_library_version(uint8_t *major, uint8_t *minor, uint8_t *patch);
|
40
|
+
|
41
|
+
/** The size of an account object in bytes */
|
42
|
+
size_t olm_account_size(void);
|
43
|
+
|
44
|
+
/** The size of a session object in bytes */
|
45
|
+
size_t olm_session_size(void);
|
46
|
+
|
47
|
+
/** The size of a utility object in bytes */
|
48
|
+
size_t olm_utility_size(void);
|
49
|
+
|
50
|
+
/** Initialise an account object using the supplied memory
|
51
|
+
* The supplied memory must be at least olm_account_size() bytes */
|
52
|
+
OlmAccount * olm_account(
|
53
|
+
void * memory
|
54
|
+
);
|
55
|
+
|
56
|
+
/** Initialise a session object using the supplied memory
|
57
|
+
* The supplied memory must be at least olm_session_size() bytes */
|
58
|
+
OlmSession * olm_session(
|
59
|
+
void * memory
|
60
|
+
);
|
61
|
+
|
62
|
+
/** Initialise a utility object using the supplied memory
|
63
|
+
* The supplied memory must be at least olm_utility_size() bytes */
|
64
|
+
OlmUtility * olm_utility(
|
65
|
+
void * memory
|
66
|
+
);
|
67
|
+
|
68
|
+
/** The value that olm will return from a function if there was an error */
|
69
|
+
size_t olm_error(void);
|
70
|
+
|
71
|
+
/** A null terminated string describing the most recent error to happen to an
|
72
|
+
* account */
|
73
|
+
const char * olm_account_last_error(
|
74
|
+
OlmAccount * account
|
75
|
+
);
|
76
|
+
|
77
|
+
/** A null terminated string describing the most recent error to happen to a
|
78
|
+
* session */
|
79
|
+
const char * olm_session_last_error(
|
80
|
+
OlmSession * session
|
81
|
+
);
|
82
|
+
|
83
|
+
/** A null terminated string describing the most recent error to happen to a
|
84
|
+
* utility */
|
85
|
+
const char * olm_utility_last_error(
|
86
|
+
OlmUtility * utility
|
87
|
+
);
|
88
|
+
|
89
|
+
/** Clears the memory used to back this account */
|
90
|
+
size_t olm_clear_account(
|
91
|
+
OlmAccount * account
|
92
|
+
);
|
93
|
+
|
94
|
+
/** Clears the memory used to back this session */
|
95
|
+
size_t olm_clear_session(
|
96
|
+
OlmSession * session
|
97
|
+
);
|
98
|
+
|
99
|
+
/** Clears the memory used to back this utility */
|
100
|
+
size_t olm_clear_utility(
|
101
|
+
OlmUtility * utility
|
102
|
+
);
|
103
|
+
|
104
|
+
/** Returns the number of bytes needed to store an account */
|
105
|
+
size_t olm_pickle_account_length(
|
106
|
+
OlmAccount * account
|
107
|
+
);
|
108
|
+
|
109
|
+
/** Returns the number of bytes needed to store a session */
|
110
|
+
size_t olm_pickle_session_length(
|
111
|
+
OlmSession * session
|
112
|
+
);
|
113
|
+
|
114
|
+
/** Stores an account as a base64 string. Encrypts the account using the
|
115
|
+
* supplied key. Returns the length of the pickled account on success.
|
116
|
+
* Returns olm_error() on failure. If the pickle output buffer
|
117
|
+
* is smaller than olm_pickle_account_length() then
|
118
|
+
* olm_account_last_error() will be "OUTPUT_BUFFER_TOO_SMALL" */
|
119
|
+
size_t olm_pickle_account(
|
120
|
+
OlmAccount * account,
|
121
|
+
void const * key, size_t key_length,
|
122
|
+
void * pickled, size_t pickled_length
|
123
|
+
);
|
124
|
+
|
125
|
+
/** Stores a session as a base64 string. Encrypts the session using the
|
126
|
+
* supplied key. Returns the length of the pickled session on success.
|
127
|
+
* Returns olm_error() on failure. If the pickle output buffer
|
128
|
+
* is smaller than olm_pickle_session_length() then
|
129
|
+
* olm_session_last_error() will be "OUTPUT_BUFFER_TOO_SMALL" */
|
130
|
+
size_t olm_pickle_session(
|
131
|
+
OlmSession * session,
|
132
|
+
void const * key, size_t key_length,
|
133
|
+
void * pickled, size_t pickled_length
|
134
|
+
);
|
135
|
+
|
136
|
+
/** Loads an account from a pickled base64 string. Decrypts the account using
|
137
|
+
* the supplied key. Returns olm_error() on failure. If the key doesn't
|
138
|
+
* match the one used to encrypt the account then olm_account_last_error()
|
139
|
+
* will be "BAD_ACCOUNT_KEY". If the base64 couldn't be decoded then
|
140
|
+
* olm_account_last_error() will be "INVALID_BASE64". The input pickled
|
141
|
+
* buffer is destroyed */
|
142
|
+
size_t olm_unpickle_account(
|
143
|
+
OlmAccount * account,
|
144
|
+
void const * key, size_t key_length,
|
145
|
+
void * pickled, size_t pickled_length
|
146
|
+
);
|
147
|
+
|
148
|
+
/** Loads a session from a pickled base64 string. Decrypts the session using
|
149
|
+
* the supplied key. Returns olm_error() on failure. If the key doesn't
|
150
|
+
* match the one used to encrypt the account then olm_session_last_error()
|
151
|
+
* will be "BAD_ACCOUNT_KEY". If the base64 couldn't be decoded then
|
152
|
+
* olm_session_last_error() will be "INVALID_BASE64". The input pickled
|
153
|
+
* buffer is destroyed */
|
154
|
+
size_t olm_unpickle_session(
|
155
|
+
OlmSession * session,
|
156
|
+
void const * key, size_t key_length,
|
157
|
+
void * pickled, size_t pickled_length
|
158
|
+
);
|
159
|
+
|
160
|
+
/** The number of random bytes needed to create an account.*/
|
161
|
+
size_t olm_create_account_random_length(
|
162
|
+
OlmAccount * account
|
163
|
+
);
|
164
|
+
|
165
|
+
/** Creates a new account. Returns olm_error() on failure. If there weren't
|
166
|
+
* enough random bytes then olm_account_last_error() will be
|
167
|
+
* "NOT_ENOUGH_RANDOM" */
|
168
|
+
size_t olm_create_account(
|
169
|
+
OlmAccount * account,
|
170
|
+
void * random, size_t random_length
|
171
|
+
);
|
172
|
+
|
173
|
+
/** The size of the output buffer needed to hold the identity keys */
|
174
|
+
size_t olm_account_identity_keys_length(
|
175
|
+
OlmAccount * account
|
176
|
+
);
|
177
|
+
|
178
|
+
/** Writes the public parts of the identity keys for the account into the
|
179
|
+
* identity_keys output buffer. Returns olm_error() on failure. If the
|
180
|
+
* identity_keys buffer was too small then olm_account_last_error() will be
|
181
|
+
* "OUTPUT_BUFFER_TOO_SMALL". */
|
182
|
+
size_t olm_account_identity_keys(
|
183
|
+
OlmAccount * account,
|
184
|
+
void * identity_keys, size_t identity_key_length
|
185
|
+
);
|
186
|
+
|
187
|
+
|
188
|
+
/** The length of an ed25519 signature encoded as base64. */
|
189
|
+
size_t olm_account_signature_length(
|
190
|
+
OlmAccount * account
|
191
|
+
);
|
192
|
+
|
193
|
+
/** Signs a message with the ed25519 key for this account. Returns olm_error()
|
194
|
+
* on failure. If the signature buffer was too small then
|
195
|
+
* olm_account_last_error() will be "OUTPUT_BUFFER_TOO_SMALL" */
|
196
|
+
size_t olm_account_sign(
|
197
|
+
OlmAccount * account,
|
198
|
+
void const * message, size_t message_length,
|
199
|
+
void * signature, size_t signature_length
|
200
|
+
);
|
201
|
+
|
202
|
+
/** The size of the output buffer needed to hold the one time keys */
|
203
|
+
size_t olm_account_one_time_keys_length(
|
204
|
+
OlmAccount * account
|
205
|
+
);
|
206
|
+
|
207
|
+
/** Writes the public parts of the unpublished one time keys for the account
|
208
|
+
* into the one_time_keys output buffer.
|
209
|
+
* <p>
|
210
|
+
* The returned data is a JSON-formatted object with the single property
|
211
|
+
* <tt>curve25519</tt>, which is itself an object mapping key id to
|
212
|
+
* base64-encoded Curve25519 key. For example:
|
213
|
+
* <pre>
|
214
|
+
* {
|
215
|
+
* curve25519: {
|
216
|
+
* "AAAAAA": "wo76WcYtb0Vk/pBOdmduiGJ0wIEjW4IBMbbQn7aSnTo",
|
217
|
+
* "AAAAAB": "LRvjo46L1X2vx69sS9QNFD29HWulxrmW11Up5AfAjgU"
|
218
|
+
* }
|
219
|
+
* }
|
220
|
+
* </pre>
|
221
|
+
* Returns olm_error() on failure.
|
222
|
+
* <p>
|
223
|
+
* If the one_time_keys buffer was too small then olm_account_last_error()
|
224
|
+
* will be "OUTPUT_BUFFER_TOO_SMALL". */
|
225
|
+
size_t olm_account_one_time_keys(
|
226
|
+
OlmAccount * account,
|
227
|
+
void * one_time_keys, size_t one_time_keys_length
|
228
|
+
);
|
229
|
+
|
230
|
+
/** Marks the current set of one time keys as being published. */
|
231
|
+
size_t olm_account_mark_keys_as_published(
|
232
|
+
OlmAccount * account
|
233
|
+
);
|
234
|
+
|
235
|
+
/** The largest number of one time keys this account can store. */
|
236
|
+
size_t olm_account_max_number_of_one_time_keys(
|
237
|
+
OlmAccount * account
|
238
|
+
);
|
239
|
+
|
240
|
+
/** The number of random bytes needed to generate a given number of new one
|
241
|
+
* time keys. */
|
242
|
+
size_t olm_account_generate_one_time_keys_random_length(
|
243
|
+
OlmAccount * account,
|
244
|
+
size_t number_of_keys
|
245
|
+
);
|
246
|
+
|
247
|
+
/** Generates a number of new one time keys. If the total number of keys stored
|
248
|
+
* by this account exceeds max_number_of_one_time_keys() then the old keys are
|
249
|
+
* discarded. Returns olm_error() on error. If the number of random bytes is
|
250
|
+
* too small then olm_account_last_error() will be "NOT_ENOUGH_RANDOM". */
|
251
|
+
size_t olm_account_generate_one_time_keys(
|
252
|
+
OlmAccount * account,
|
253
|
+
size_t number_of_keys,
|
254
|
+
void * random, size_t random_length
|
255
|
+
);
|
256
|
+
|
257
|
+
/** The number of random bytes needed to create an outbound session */
|
258
|
+
size_t olm_create_outbound_session_random_length(
|
259
|
+
OlmSession * session
|
260
|
+
);
|
261
|
+
|
262
|
+
/** Creates a new out-bound session for sending messages to a given identity_key
|
263
|
+
* and one_time_key. Returns olm_error() on failure. If the keys couldn't be
|
264
|
+
* decoded as base64 then olm_session_last_error() will be "INVALID_BASE64"
|
265
|
+
* If there weren't enough random bytes then olm_session_last_error() will
|
266
|
+
* be "NOT_ENOUGH_RANDOM". */
|
267
|
+
size_t olm_create_outbound_session(
|
268
|
+
OlmSession * session,
|
269
|
+
OlmAccount * account,
|
270
|
+
void const * their_identity_key, size_t their_identity_key_length,
|
271
|
+
void const * their_one_time_key, size_t their_one_time_key_length,
|
272
|
+
void * random, size_t random_length
|
273
|
+
);
|
274
|
+
|
275
|
+
/** Create a new in-bound session for sending/receiving messages from an
|
276
|
+
* incoming PRE_KEY message. Returns olm_error() on failure. If the base64
|
277
|
+
* couldn't be decoded then olm_session_last_error will be "INVALID_BASE64".
|
278
|
+
* If the message was for an unsupported protocol version then
|
279
|
+
* olm_session_last_error() will be "BAD_MESSAGE_VERSION". If the message
|
280
|
+
* couldn't be decoded then then olm_session_last_error() will be
|
281
|
+
* "BAD_MESSAGE_FORMAT". If the message refers to an unknown one time
|
282
|
+
* key then olm_session_last_error() will be "BAD_MESSAGE_KEY_ID". */
|
283
|
+
size_t olm_create_inbound_session(
|
284
|
+
OlmSession * session,
|
285
|
+
OlmAccount * account,
|
286
|
+
void * one_time_key_message, size_t message_length
|
287
|
+
);
|
288
|
+
|
289
|
+
/** Create a new in-bound session for sending/receiving messages from an
|
290
|
+
* incoming PRE_KEY message. Returns olm_error() on failure. If the base64
|
291
|
+
* couldn't be decoded then olm_session_last_error will be "INVALID_BASE64".
|
292
|
+
* If the message was for an unsupported protocol version then
|
293
|
+
* olm_session_last_error() will be "BAD_MESSAGE_VERSION". If the message
|
294
|
+
* couldn't be decoded then then olm_session_last_error() will be
|
295
|
+
* "BAD_MESSAGE_FORMAT". If the message refers to an unknown one time
|
296
|
+
* key then olm_session_last_error() will be "BAD_MESSAGE_KEY_ID". */
|
297
|
+
size_t olm_create_inbound_session_from(
|
298
|
+
OlmSession * session,
|
299
|
+
OlmAccount * account,
|
300
|
+
void const * their_identity_key, size_t their_identity_key_length,
|
301
|
+
void * one_time_key_message, size_t message_length
|
302
|
+
);
|
303
|
+
|
304
|
+
/** The length of the buffer needed to return the id for this session. */
|
305
|
+
size_t olm_session_id_length(
|
306
|
+
OlmSession * session
|
307
|
+
);
|
308
|
+
|
309
|
+
/** An identifier for this session. Will be the same for both ends of the
|
310
|
+
* conversation. If the id buffer is too small then olm_session_last_error()
|
311
|
+
* will be "OUTPUT_BUFFER_TOO_SMALL". */
|
312
|
+
size_t olm_session_id(
|
313
|
+
OlmSession * session,
|
314
|
+
void * id, size_t id_length
|
315
|
+
);
|
316
|
+
|
317
|
+
int olm_session_has_received_message(
|
318
|
+
OlmSession *session
|
319
|
+
);
|
320
|
+
|
321
|
+
/** Checks if the PRE_KEY message is for this in-bound session. This can happen
|
322
|
+
* if multiple messages are sent to this account before this account sends a
|
323
|
+
* message in reply. The one_time_key_message buffer is destroyed. Returns 1 if
|
324
|
+
* the session matches. Returns 0 if the session does not match. Returns
|
325
|
+
* olm_error() on failure. If the base64 couldn't be decoded then
|
326
|
+
* olm_session_last_error will be "INVALID_BASE64". If the message was for an
|
327
|
+
* unsupported protocol version then olm_session_last_error() will be
|
328
|
+
* "BAD_MESSAGE_VERSION". If the message couldn't be decoded then then
|
329
|
+
* olm_session_last_error() will be "BAD_MESSAGE_FORMAT". */
|
330
|
+
size_t olm_matches_inbound_session(
|
331
|
+
OlmSession * session,
|
332
|
+
void * one_time_key_message, size_t message_length
|
333
|
+
);
|
334
|
+
|
335
|
+
/** Checks if the PRE_KEY message is for this in-bound session. This can happen
|
336
|
+
* if multiple messages are sent to this account before this account sends a
|
337
|
+
* message in reply. The one_time_key_message buffer is destroyed. Returns 1 if
|
338
|
+
* the session matches. Returns 0 if the session does not match. Returns
|
339
|
+
* olm_error() on failure. If the base64 couldn't be decoded then
|
340
|
+
* olm_session_last_error will be "INVALID_BASE64". If the message was for an
|
341
|
+
* unsupported protocol version then olm_session_last_error() will be
|
342
|
+
* "BAD_MESSAGE_VERSION". If the message couldn't be decoded then then
|
343
|
+
* olm_session_last_error() will be "BAD_MESSAGE_FORMAT". */
|
344
|
+
size_t olm_matches_inbound_session_from(
|
345
|
+
OlmSession * session,
|
346
|
+
void const * their_identity_key, size_t their_identity_key_length,
|
347
|
+
void * one_time_key_message, size_t message_length
|
348
|
+
);
|
349
|
+
|
350
|
+
/** Removes the one time keys that the session used from the account. Returns
|
351
|
+
* olm_error() on failure. If the account doesn't have any matching one time
|
352
|
+
* keys then olm_account_last_error() will be "BAD_MESSAGE_KEY_ID". */
|
353
|
+
size_t olm_remove_one_time_keys(
|
354
|
+
OlmAccount * account,
|
355
|
+
OlmSession * session
|
356
|
+
);
|
357
|
+
|
358
|
+
/** The type of the next message that olm_encrypt() will return. Returns
|
359
|
+
* OLM_MESSAGE_TYPE_PRE_KEY if the message will be a PRE_KEY message.
|
360
|
+
* Returns OLM_MESSAGE_TYPE_MESSAGE if the message will be a normal message.
|
361
|
+
* Returns olm_error on failure. */
|
362
|
+
size_t olm_encrypt_message_type(
|
363
|
+
OlmSession * session
|
364
|
+
);
|
365
|
+
|
366
|
+
/** The number of random bytes needed to encrypt the next message. */
|
367
|
+
size_t olm_encrypt_random_length(
|
368
|
+
OlmSession * session
|
369
|
+
);
|
370
|
+
|
371
|
+
/** The size of the next message in bytes for the given number of plain-text
|
372
|
+
* bytes. */
|
373
|
+
size_t olm_encrypt_message_length(
|
374
|
+
OlmSession * session,
|
375
|
+
size_t plaintext_length
|
376
|
+
);
|
377
|
+
|
378
|
+
/** Encrypts a message using the session. Returns the length of the message in
|
379
|
+
* bytes on success. Writes the message as base64 into the message buffer.
|
380
|
+
* Returns olm_error() on failure. If the message buffer is too small then
|
381
|
+
* olm_session_last_error() will be "OUTPUT_BUFFER_TOO_SMALL". If there
|
382
|
+
* weren't enough random bytes then olm_session_last_error() will be
|
383
|
+
* "NOT_ENOUGH_RANDOM". */
|
384
|
+
size_t olm_encrypt(
|
385
|
+
OlmSession * session,
|
386
|
+
void const * plaintext, size_t plaintext_length,
|
387
|
+
void * random, size_t random_length,
|
388
|
+
void * message, size_t message_length
|
389
|
+
);
|
390
|
+
|
391
|
+
/** The maximum number of bytes of plain-text a given message could decode to.
|
392
|
+
* The actual size could be different due to padding. The input message buffer
|
393
|
+
* is destroyed. Returns olm_error() on failure. If the message base64
|
394
|
+
* couldn't be decoded then olm_session_last_error() will be
|
395
|
+
* "INVALID_BASE64". If the message is for an unsupported version of the
|
396
|
+
* protocol then olm_session_last_error() will be "BAD_MESSAGE_VERSION".
|
397
|
+
* If the message couldn't be decoded then olm_session_last_error() will be
|
398
|
+
* "BAD_MESSAGE_FORMAT". */
|
399
|
+
size_t olm_decrypt_max_plaintext_length(
|
400
|
+
OlmSession * session,
|
401
|
+
size_t message_type,
|
402
|
+
void * message, size_t message_length
|
403
|
+
);
|
404
|
+
|
405
|
+
/** Decrypts a message using the session. The input message buffer is destroyed.
|
406
|
+
* Returns the length of the plain-text on success. Returns olm_error() on
|
407
|
+
* failure. If the plain-text buffer is smaller than
|
408
|
+
* olm_decrypt_max_plaintext_length() then olm_session_last_error()
|
409
|
+
* will be "OUTPUT_BUFFER_TOO_SMALL". If the base64 couldn't be decoded then
|
410
|
+
* olm_session_last_error() will be "INVALID_BASE64". If the message is for
|
411
|
+
* an unsupported version of the protocol then olm_session_last_error() will
|
412
|
+
* be "BAD_MESSAGE_VERSION". If the message couldn't be decoded then
|
413
|
+
* olm_session_last_error() will be BAD_MESSAGE_FORMAT".
|
414
|
+
* If the MAC on the message was invalid then olm_session_last_error() will
|
415
|
+
* be "BAD_MESSAGE_MAC". */
|
416
|
+
size_t olm_decrypt(
|
417
|
+
OlmSession * session,
|
418
|
+
size_t message_type,
|
419
|
+
void * message, size_t message_length,
|
420
|
+
void * plaintext, size_t max_plaintext_length
|
421
|
+
);
|
422
|
+
|
423
|
+
/** The length of the buffer needed to hold the SHA-256 hash. */
|
424
|
+
size_t olm_sha256_length(
|
425
|
+
OlmUtility * utility
|
426
|
+
);
|
427
|
+
|
428
|
+
/** Calculates the SHA-256 hash of the input and encodes it as base64. If the
|
429
|
+
* output buffer is smaller than olm_sha256_length() then
|
430
|
+
* olm_utility_last_error() will be "OUTPUT_BUFFER_TOO_SMALL". */
|
431
|
+
size_t olm_sha256(
|
432
|
+
OlmUtility * utility,
|
433
|
+
void const * input, size_t input_length,
|
434
|
+
void * output, size_t output_length
|
435
|
+
);
|
436
|
+
|
437
|
+
/** Verify an ed25519 signature. If the key was too small then
|
438
|
+
* olm_session_last_error will be "INVALID_BASE64". If the signature was invalid
|
439
|
+
* then olm_utility_last_error() will be "BAD_MESSAGE_MAC". */
|
440
|
+
size_t olm_ed25519_verify(
|
441
|
+
OlmUtility * utility,
|
442
|
+
void const * key, size_t key_length,
|
443
|
+
void const * message, size_t message_length,
|
444
|
+
void * signature, size_t signature_length
|
445
|
+
);
|
446
|
+
|
447
|
+
#ifdef __cplusplus
|
448
|
+
}
|
449
|
+
#endif
|
450
|
+
|
451
|
+
#endif /* OLM_H_ */
|