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,738 @@
|
|
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
|
+
#include "olm/olm.h"
|
16
|
+
#include "olm/session.hh"
|
17
|
+
#include "olm/account.hh"
|
18
|
+
#include "olm/cipher.h"
|
19
|
+
#include "olm/pickle_encoding.h"
|
20
|
+
#include "olm/utility.hh"
|
21
|
+
#include "olm/base64.hh"
|
22
|
+
#include "olm/memory.hh"
|
23
|
+
|
24
|
+
#include <new>
|
25
|
+
#include <cstring>
|
26
|
+
|
27
|
+
namespace {
|
28
|
+
|
29
|
+
static OlmAccount * to_c(olm::Account * account) {
|
30
|
+
return reinterpret_cast<OlmAccount *>(account);
|
31
|
+
}
|
32
|
+
|
33
|
+
static OlmSession * to_c(olm::Session * session) {
|
34
|
+
return reinterpret_cast<OlmSession *>(session);
|
35
|
+
}
|
36
|
+
|
37
|
+
static OlmUtility * to_c(olm::Utility * utility) {
|
38
|
+
return reinterpret_cast<OlmUtility *>(utility);
|
39
|
+
}
|
40
|
+
|
41
|
+
static olm::Account * from_c(OlmAccount * account) {
|
42
|
+
return reinterpret_cast<olm::Account *>(account);
|
43
|
+
}
|
44
|
+
|
45
|
+
static olm::Session * from_c(OlmSession * session) {
|
46
|
+
return reinterpret_cast<olm::Session *>(session);
|
47
|
+
}
|
48
|
+
|
49
|
+
static olm::Utility * from_c(OlmUtility * utility) {
|
50
|
+
return reinterpret_cast<olm::Utility *>(utility);
|
51
|
+
}
|
52
|
+
|
53
|
+
static std::uint8_t * from_c(void * bytes) {
|
54
|
+
return reinterpret_cast<std::uint8_t *>(bytes);
|
55
|
+
}
|
56
|
+
|
57
|
+
static std::uint8_t const * from_c(void const * bytes) {
|
58
|
+
return reinterpret_cast<std::uint8_t const *>(bytes);
|
59
|
+
}
|
60
|
+
|
61
|
+
std::size_t b64_output_length(
|
62
|
+
size_t raw_length
|
63
|
+
) {
|
64
|
+
return olm::encode_base64_length(raw_length);
|
65
|
+
}
|
66
|
+
|
67
|
+
std::uint8_t * b64_output_pos(
|
68
|
+
std::uint8_t * output,
|
69
|
+
size_t raw_length
|
70
|
+
) {
|
71
|
+
return output + olm::encode_base64_length(raw_length) - raw_length;
|
72
|
+
}
|
73
|
+
|
74
|
+
std::size_t b64_output(
|
75
|
+
std::uint8_t * output, size_t raw_length
|
76
|
+
) {
|
77
|
+
std::size_t base64_length = olm::encode_base64_length(raw_length);
|
78
|
+
std::uint8_t * raw_output = output + base64_length - raw_length;
|
79
|
+
olm::encode_base64(raw_output, raw_length, output);
|
80
|
+
return base64_length;
|
81
|
+
}
|
82
|
+
|
83
|
+
std::size_t b64_input(
|
84
|
+
std::uint8_t * input, size_t b64_length,
|
85
|
+
OlmErrorCode & last_error
|
86
|
+
) {
|
87
|
+
std::size_t raw_length = olm::decode_base64_length(b64_length);
|
88
|
+
if (raw_length == std::size_t(-1)) {
|
89
|
+
last_error = OlmErrorCode::OLM_INVALID_BASE64;
|
90
|
+
return std::size_t(-1);
|
91
|
+
}
|
92
|
+
olm::decode_base64(input, b64_length, input);
|
93
|
+
return raw_length;
|
94
|
+
}
|
95
|
+
|
96
|
+
} // namespace
|
97
|
+
|
98
|
+
|
99
|
+
extern "C" {
|
100
|
+
|
101
|
+
void olm_get_library_version(uint8_t *major, uint8_t *minor, uint8_t *patch) {
|
102
|
+
if (major != NULL) *major = OLMLIB_VERSION_MAJOR;
|
103
|
+
if (minor != NULL) *minor = OLMLIB_VERSION_MINOR;
|
104
|
+
if (patch != NULL) *patch = OLMLIB_VERSION_PATCH;
|
105
|
+
}
|
106
|
+
|
107
|
+
size_t olm_error(void) {
|
108
|
+
return std::size_t(-1);
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
const char * olm_account_last_error(
|
113
|
+
OlmAccount * account
|
114
|
+
) {
|
115
|
+
auto error = from_c(account)->last_error;
|
116
|
+
return _olm_error_to_string(error);
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
const char * olm_session_last_error(
|
121
|
+
OlmSession * session
|
122
|
+
) {
|
123
|
+
auto error = from_c(session)->last_error;
|
124
|
+
return _olm_error_to_string(error);
|
125
|
+
}
|
126
|
+
|
127
|
+
const char * olm_utility_last_error(
|
128
|
+
OlmUtility * utility
|
129
|
+
) {
|
130
|
+
auto error = from_c(utility)->last_error;
|
131
|
+
return _olm_error_to_string(error);
|
132
|
+
}
|
133
|
+
|
134
|
+
size_t olm_account_size(void) {
|
135
|
+
return sizeof(olm::Account);
|
136
|
+
}
|
137
|
+
|
138
|
+
|
139
|
+
size_t olm_session_size(void) {
|
140
|
+
return sizeof(olm::Session);
|
141
|
+
}
|
142
|
+
|
143
|
+
size_t olm_utility_size(void) {
|
144
|
+
return sizeof(olm::Utility);
|
145
|
+
}
|
146
|
+
|
147
|
+
OlmAccount * olm_account(
|
148
|
+
void * memory
|
149
|
+
) {
|
150
|
+
olm::unset(memory, sizeof(olm::Account));
|
151
|
+
return to_c(new(memory) olm::Account());
|
152
|
+
}
|
153
|
+
|
154
|
+
|
155
|
+
OlmSession * olm_session(
|
156
|
+
void * memory
|
157
|
+
) {
|
158
|
+
olm::unset(memory, sizeof(olm::Session));
|
159
|
+
return to_c(new(memory) olm::Session());
|
160
|
+
}
|
161
|
+
|
162
|
+
|
163
|
+
OlmUtility * olm_utility(
|
164
|
+
void * memory
|
165
|
+
) {
|
166
|
+
olm::unset(memory, sizeof(olm::Utility));
|
167
|
+
return to_c(new(memory) olm::Utility());
|
168
|
+
}
|
169
|
+
|
170
|
+
|
171
|
+
size_t olm_clear_account(
|
172
|
+
OlmAccount * account
|
173
|
+
) {
|
174
|
+
/* Clear the memory backing the account */
|
175
|
+
olm::unset(account, sizeof(olm::Account));
|
176
|
+
/* Initialise a fresh account object in case someone tries to use it */
|
177
|
+
new(account) olm::Account();
|
178
|
+
return sizeof(olm::Account);
|
179
|
+
}
|
180
|
+
|
181
|
+
|
182
|
+
size_t olm_clear_session(
|
183
|
+
OlmSession * session
|
184
|
+
) {
|
185
|
+
/* Clear the memory backing the session */
|
186
|
+
olm::unset(session, sizeof(olm::Session));
|
187
|
+
/* Initialise a fresh session object in case someone tries to use it */
|
188
|
+
new(session) olm::Session();
|
189
|
+
return sizeof(olm::Session);
|
190
|
+
}
|
191
|
+
|
192
|
+
|
193
|
+
size_t olm_clear_utility(
|
194
|
+
OlmUtility * utility
|
195
|
+
) {
|
196
|
+
/* Clear the memory backing the session */
|
197
|
+
olm::unset(utility, sizeof(olm::Utility));
|
198
|
+
/* Initialise a fresh session object in case someone tries to use it */
|
199
|
+
new(utility) olm::Utility();
|
200
|
+
return sizeof(olm::Utility);
|
201
|
+
}
|
202
|
+
|
203
|
+
|
204
|
+
size_t olm_pickle_account_length(
|
205
|
+
OlmAccount * account
|
206
|
+
) {
|
207
|
+
return _olm_enc_output_length(pickle_length(*from_c(account)));
|
208
|
+
}
|
209
|
+
|
210
|
+
|
211
|
+
size_t olm_pickle_session_length(
|
212
|
+
OlmSession * session
|
213
|
+
) {
|
214
|
+
return _olm_enc_output_length(pickle_length(*from_c(session)));
|
215
|
+
}
|
216
|
+
|
217
|
+
|
218
|
+
size_t olm_pickle_account(
|
219
|
+
OlmAccount * account,
|
220
|
+
void const * key, size_t key_length,
|
221
|
+
void * pickled, size_t pickled_length
|
222
|
+
) {
|
223
|
+
olm::Account & object = *from_c(account);
|
224
|
+
std::size_t raw_length = pickle_length(object);
|
225
|
+
if (pickled_length < _olm_enc_output_length(raw_length)) {
|
226
|
+
object.last_error = OlmErrorCode::OLM_OUTPUT_BUFFER_TOO_SMALL;
|
227
|
+
return size_t(-1);
|
228
|
+
}
|
229
|
+
pickle(_olm_enc_output_pos(from_c(pickled), raw_length), object);
|
230
|
+
return _olm_enc_output(from_c(key), key_length, from_c(pickled), raw_length);
|
231
|
+
}
|
232
|
+
|
233
|
+
|
234
|
+
size_t olm_pickle_session(
|
235
|
+
OlmSession * session,
|
236
|
+
void const * key, size_t key_length,
|
237
|
+
void * pickled, size_t pickled_length
|
238
|
+
) {
|
239
|
+
olm::Session & object = *from_c(session);
|
240
|
+
std::size_t raw_length = pickle_length(object);
|
241
|
+
if (pickled_length < _olm_enc_output_length(raw_length)) {
|
242
|
+
object.last_error = OlmErrorCode::OLM_OUTPUT_BUFFER_TOO_SMALL;
|
243
|
+
return size_t(-1);
|
244
|
+
}
|
245
|
+
pickle(_olm_enc_output_pos(from_c(pickled), raw_length), object);
|
246
|
+
return _olm_enc_output(from_c(key), key_length, from_c(pickled), raw_length);
|
247
|
+
}
|
248
|
+
|
249
|
+
|
250
|
+
size_t olm_unpickle_account(
|
251
|
+
OlmAccount * account,
|
252
|
+
void const * key, size_t key_length,
|
253
|
+
void * pickled, size_t pickled_length
|
254
|
+
) {
|
255
|
+
olm::Account & object = *from_c(account);
|
256
|
+
std::uint8_t * const pos = from_c(pickled);
|
257
|
+
std::size_t raw_length = _olm_enc_input(
|
258
|
+
from_c(key), key_length, pos, pickled_length, &object.last_error
|
259
|
+
);
|
260
|
+
if (raw_length == std::size_t(-1)) {
|
261
|
+
return std::size_t(-1);
|
262
|
+
}
|
263
|
+
std::uint8_t * const end = pos + raw_length;
|
264
|
+
/* On success unpickle will return (pos + raw_length). If unpickling
|
265
|
+
* terminates too soon then it will return a pointer before
|
266
|
+
* (pos + raw_length). On error unpickle will return (pos + raw_length + 1).
|
267
|
+
*/
|
268
|
+
if (end != unpickle(pos, end + 1, object)) {
|
269
|
+
if (object.last_error == OlmErrorCode::OLM_SUCCESS) {
|
270
|
+
object.last_error = OlmErrorCode::OLM_CORRUPTED_PICKLE;
|
271
|
+
}
|
272
|
+
return std::size_t(-1);
|
273
|
+
}
|
274
|
+
return pickled_length;
|
275
|
+
}
|
276
|
+
|
277
|
+
|
278
|
+
size_t olm_unpickle_session(
|
279
|
+
OlmSession * session,
|
280
|
+
void const * key, size_t key_length,
|
281
|
+
void * pickled, size_t pickled_length
|
282
|
+
) {
|
283
|
+
olm::Session & object = *from_c(session);
|
284
|
+
std::uint8_t * const pos = from_c(pickled);
|
285
|
+
std::size_t raw_length = _olm_enc_input(
|
286
|
+
from_c(key), key_length, pos, pickled_length, &object.last_error
|
287
|
+
);
|
288
|
+
if (raw_length == std::size_t(-1)) {
|
289
|
+
return std::size_t(-1);
|
290
|
+
}
|
291
|
+
|
292
|
+
std::uint8_t * const end = pos + raw_length;
|
293
|
+
/* On success unpickle will return (pos + raw_length). If unpickling
|
294
|
+
* terminates too soon then it will return a pointer before
|
295
|
+
* (pos + raw_length). On error unpickle will return (pos + raw_length + 1).
|
296
|
+
*/
|
297
|
+
if (end != unpickle(pos, end + 1, object)) {
|
298
|
+
if (object.last_error == OlmErrorCode::OLM_SUCCESS) {
|
299
|
+
object.last_error = OlmErrorCode::OLM_CORRUPTED_PICKLE;
|
300
|
+
}
|
301
|
+
return std::size_t(-1);
|
302
|
+
}
|
303
|
+
return pickled_length;
|
304
|
+
}
|
305
|
+
|
306
|
+
|
307
|
+
size_t olm_create_account_random_length(
|
308
|
+
OlmAccount * account
|
309
|
+
) {
|
310
|
+
return from_c(account)->new_account_random_length();
|
311
|
+
}
|
312
|
+
|
313
|
+
|
314
|
+
size_t olm_create_account(
|
315
|
+
OlmAccount * account,
|
316
|
+
void * random, size_t random_length
|
317
|
+
) {
|
318
|
+
size_t result = from_c(account)->new_account(from_c(random), random_length);
|
319
|
+
olm::unset(random, random_length);
|
320
|
+
return result;
|
321
|
+
}
|
322
|
+
|
323
|
+
|
324
|
+
size_t olm_account_identity_keys_length(
|
325
|
+
OlmAccount * account
|
326
|
+
) {
|
327
|
+
return from_c(account)->get_identity_json_length();
|
328
|
+
}
|
329
|
+
|
330
|
+
|
331
|
+
size_t olm_account_identity_keys(
|
332
|
+
OlmAccount * account,
|
333
|
+
void * identity_keys, size_t identity_key_length
|
334
|
+
) {
|
335
|
+
return from_c(account)->get_identity_json(
|
336
|
+
from_c(identity_keys), identity_key_length
|
337
|
+
);
|
338
|
+
}
|
339
|
+
|
340
|
+
|
341
|
+
size_t olm_account_signature_length(
|
342
|
+
OlmAccount * account
|
343
|
+
) {
|
344
|
+
return b64_output_length(from_c(account)->signature_length());
|
345
|
+
}
|
346
|
+
|
347
|
+
|
348
|
+
size_t olm_account_sign(
|
349
|
+
OlmAccount * account,
|
350
|
+
void const * message, size_t message_length,
|
351
|
+
void * signature, size_t signature_length
|
352
|
+
) {
|
353
|
+
std::size_t raw_length = from_c(account)->signature_length();
|
354
|
+
if (signature_length < b64_output_length(raw_length)) {
|
355
|
+
from_c(account)->last_error =
|
356
|
+
OlmErrorCode::OLM_OUTPUT_BUFFER_TOO_SMALL;
|
357
|
+
return std::size_t(-1);
|
358
|
+
}
|
359
|
+
from_c(account)->sign(
|
360
|
+
from_c(message), message_length,
|
361
|
+
b64_output_pos(from_c(signature), raw_length), raw_length
|
362
|
+
);
|
363
|
+
return b64_output(from_c(signature), raw_length);
|
364
|
+
}
|
365
|
+
|
366
|
+
|
367
|
+
size_t olm_account_one_time_keys_length(
|
368
|
+
OlmAccount * account
|
369
|
+
) {
|
370
|
+
return from_c(account)->get_one_time_keys_json_length();
|
371
|
+
}
|
372
|
+
|
373
|
+
|
374
|
+
size_t olm_account_one_time_keys(
|
375
|
+
OlmAccount * account,
|
376
|
+
void * one_time_keys_json, size_t one_time_key_json_length
|
377
|
+
) {
|
378
|
+
return from_c(account)->get_one_time_keys_json(
|
379
|
+
from_c(one_time_keys_json), one_time_key_json_length
|
380
|
+
);
|
381
|
+
}
|
382
|
+
|
383
|
+
|
384
|
+
size_t olm_account_mark_keys_as_published(
|
385
|
+
OlmAccount * account
|
386
|
+
) {
|
387
|
+
return from_c(account)->mark_keys_as_published();
|
388
|
+
}
|
389
|
+
|
390
|
+
|
391
|
+
size_t olm_account_max_number_of_one_time_keys(
|
392
|
+
OlmAccount * account
|
393
|
+
) {
|
394
|
+
return from_c(account)->max_number_of_one_time_keys();
|
395
|
+
}
|
396
|
+
|
397
|
+
|
398
|
+
size_t olm_account_generate_one_time_keys_random_length(
|
399
|
+
OlmAccount * account,
|
400
|
+
size_t number_of_keys
|
401
|
+
) {
|
402
|
+
return from_c(account)->generate_one_time_keys_random_length(number_of_keys);
|
403
|
+
}
|
404
|
+
|
405
|
+
|
406
|
+
size_t olm_account_generate_one_time_keys(
|
407
|
+
OlmAccount * account,
|
408
|
+
size_t number_of_keys,
|
409
|
+
void * random, size_t random_length
|
410
|
+
) {
|
411
|
+
size_t result = from_c(account)->generate_one_time_keys(
|
412
|
+
number_of_keys,
|
413
|
+
from_c(random), random_length
|
414
|
+
);
|
415
|
+
olm::unset(random, random_length);
|
416
|
+
return result;
|
417
|
+
}
|
418
|
+
|
419
|
+
|
420
|
+
size_t olm_create_outbound_session_random_length(
|
421
|
+
OlmSession * session
|
422
|
+
) {
|
423
|
+
return from_c(session)->new_outbound_session_random_length();
|
424
|
+
}
|
425
|
+
|
426
|
+
|
427
|
+
size_t olm_create_outbound_session(
|
428
|
+
OlmSession * session,
|
429
|
+
OlmAccount * account,
|
430
|
+
void const * their_identity_key, size_t their_identity_key_length,
|
431
|
+
void const * their_one_time_key, size_t their_one_time_key_length,
|
432
|
+
void * random, size_t random_length
|
433
|
+
) {
|
434
|
+
std::uint8_t const * id_key = from_c(their_identity_key);
|
435
|
+
std::uint8_t const * ot_key = from_c(their_one_time_key);
|
436
|
+
std::size_t id_key_length = their_identity_key_length;
|
437
|
+
std::size_t ot_key_length = their_one_time_key_length;
|
438
|
+
|
439
|
+
if (olm::decode_base64_length(id_key_length) != CURVE25519_KEY_LENGTH
|
440
|
+
|| olm::decode_base64_length(ot_key_length) != CURVE25519_KEY_LENGTH
|
441
|
+
) {
|
442
|
+
from_c(session)->last_error = OlmErrorCode::OLM_INVALID_BASE64;
|
443
|
+
return std::size_t(-1);
|
444
|
+
}
|
445
|
+
_olm_curve25519_public_key identity_key;
|
446
|
+
_olm_curve25519_public_key one_time_key;
|
447
|
+
|
448
|
+
olm::decode_base64(id_key, id_key_length, identity_key.public_key);
|
449
|
+
olm::decode_base64(ot_key, ot_key_length, one_time_key.public_key);
|
450
|
+
|
451
|
+
size_t result = from_c(session)->new_outbound_session(
|
452
|
+
*from_c(account), identity_key, one_time_key,
|
453
|
+
from_c(random), random_length
|
454
|
+
);
|
455
|
+
olm::unset(random, random_length);
|
456
|
+
return result;
|
457
|
+
}
|
458
|
+
|
459
|
+
|
460
|
+
size_t olm_create_inbound_session(
|
461
|
+
OlmSession * session,
|
462
|
+
OlmAccount * account,
|
463
|
+
void * one_time_key_message, size_t message_length
|
464
|
+
) {
|
465
|
+
std::size_t raw_length = b64_input(
|
466
|
+
from_c(one_time_key_message), message_length, from_c(session)->last_error
|
467
|
+
);
|
468
|
+
if (raw_length == std::size_t(-1)) {
|
469
|
+
return std::size_t(-1);
|
470
|
+
}
|
471
|
+
return from_c(session)->new_inbound_session(
|
472
|
+
*from_c(account), nullptr, from_c(one_time_key_message), raw_length
|
473
|
+
);
|
474
|
+
}
|
475
|
+
|
476
|
+
|
477
|
+
size_t olm_create_inbound_session_from(
|
478
|
+
OlmSession * session,
|
479
|
+
OlmAccount * account,
|
480
|
+
void const * their_identity_key, size_t their_identity_key_length,
|
481
|
+
void * one_time_key_message, size_t message_length
|
482
|
+
) {
|
483
|
+
std::uint8_t const * id_key = from_c(their_identity_key);
|
484
|
+
std::size_t id_key_length = their_identity_key_length;
|
485
|
+
|
486
|
+
if (olm::decode_base64_length(id_key_length) != CURVE25519_KEY_LENGTH) {
|
487
|
+
from_c(session)->last_error = OlmErrorCode::OLM_INVALID_BASE64;
|
488
|
+
return std::size_t(-1);
|
489
|
+
}
|
490
|
+
_olm_curve25519_public_key identity_key;
|
491
|
+
olm::decode_base64(id_key, id_key_length, identity_key.public_key);
|
492
|
+
|
493
|
+
std::size_t raw_length = b64_input(
|
494
|
+
from_c(one_time_key_message), message_length, from_c(session)->last_error
|
495
|
+
);
|
496
|
+
if (raw_length == std::size_t(-1)) {
|
497
|
+
return std::size_t(-1);
|
498
|
+
}
|
499
|
+
return from_c(session)->new_inbound_session(
|
500
|
+
*from_c(account), &identity_key,
|
501
|
+
from_c(one_time_key_message), raw_length
|
502
|
+
);
|
503
|
+
}
|
504
|
+
|
505
|
+
|
506
|
+
size_t olm_session_id_length(
|
507
|
+
OlmSession * session
|
508
|
+
) {
|
509
|
+
return b64_output_length(from_c(session)->session_id_length());
|
510
|
+
}
|
511
|
+
|
512
|
+
size_t olm_session_id(
|
513
|
+
OlmSession * session,
|
514
|
+
void * id, size_t id_length
|
515
|
+
) {
|
516
|
+
std::size_t raw_length = from_c(session)->session_id_length();
|
517
|
+
if (id_length < b64_output_length(raw_length)) {
|
518
|
+
from_c(session)->last_error =
|
519
|
+
OlmErrorCode::OLM_OUTPUT_BUFFER_TOO_SMALL;
|
520
|
+
return std::size_t(-1);
|
521
|
+
}
|
522
|
+
std::size_t result = from_c(session)->session_id(
|
523
|
+
b64_output_pos(from_c(id), raw_length), raw_length
|
524
|
+
);
|
525
|
+
if (result == std::size_t(-1)) {
|
526
|
+
return result;
|
527
|
+
}
|
528
|
+
return b64_output(from_c(id), raw_length);
|
529
|
+
}
|
530
|
+
|
531
|
+
|
532
|
+
int olm_session_has_received_message(
|
533
|
+
OlmSession * session
|
534
|
+
) {
|
535
|
+
return from_c(session)->received_message;
|
536
|
+
}
|
537
|
+
|
538
|
+
size_t olm_matches_inbound_session(
|
539
|
+
OlmSession * session,
|
540
|
+
void * one_time_key_message, size_t message_length
|
541
|
+
) {
|
542
|
+
std::size_t raw_length = b64_input(
|
543
|
+
from_c(one_time_key_message), message_length, from_c(session)->last_error
|
544
|
+
);
|
545
|
+
if (raw_length == std::size_t(-1)) {
|
546
|
+
return std::size_t(-1);
|
547
|
+
}
|
548
|
+
bool matches = from_c(session)->matches_inbound_session(
|
549
|
+
nullptr, from_c(one_time_key_message), raw_length
|
550
|
+
);
|
551
|
+
return matches ? 1 : 0;
|
552
|
+
}
|
553
|
+
|
554
|
+
|
555
|
+
size_t olm_matches_inbound_session_from(
|
556
|
+
OlmSession * session,
|
557
|
+
void const * their_identity_key, size_t their_identity_key_length,
|
558
|
+
void * one_time_key_message, size_t message_length
|
559
|
+
) {
|
560
|
+
std::uint8_t const * id_key = from_c(their_identity_key);
|
561
|
+
std::size_t id_key_length = their_identity_key_length;
|
562
|
+
|
563
|
+
if (olm::decode_base64_length(id_key_length) != CURVE25519_KEY_LENGTH) {
|
564
|
+
from_c(session)->last_error = OlmErrorCode::OLM_INVALID_BASE64;
|
565
|
+
return std::size_t(-1);
|
566
|
+
}
|
567
|
+
_olm_curve25519_public_key identity_key;
|
568
|
+
olm::decode_base64(id_key, id_key_length, identity_key.public_key);
|
569
|
+
|
570
|
+
std::size_t raw_length = b64_input(
|
571
|
+
from_c(one_time_key_message), message_length, from_c(session)->last_error
|
572
|
+
);
|
573
|
+
if (raw_length == std::size_t(-1)) {
|
574
|
+
return std::size_t(-1);
|
575
|
+
}
|
576
|
+
bool matches = from_c(session)->matches_inbound_session(
|
577
|
+
&identity_key, from_c(one_time_key_message), raw_length
|
578
|
+
);
|
579
|
+
return matches ? 1 : 0;
|
580
|
+
}
|
581
|
+
|
582
|
+
|
583
|
+
size_t olm_remove_one_time_keys(
|
584
|
+
OlmAccount * account,
|
585
|
+
OlmSession * session
|
586
|
+
) {
|
587
|
+
size_t result = from_c(account)->remove_key(
|
588
|
+
from_c(session)->bob_one_time_key
|
589
|
+
);
|
590
|
+
if (result == std::size_t(-1)) {
|
591
|
+
from_c(account)->last_error = OlmErrorCode::OLM_BAD_MESSAGE_KEY_ID;
|
592
|
+
}
|
593
|
+
return result;
|
594
|
+
}
|
595
|
+
|
596
|
+
|
597
|
+
size_t olm_encrypt_message_type(
|
598
|
+
OlmSession * session
|
599
|
+
) {
|
600
|
+
return size_t(from_c(session)->encrypt_message_type());
|
601
|
+
}
|
602
|
+
|
603
|
+
|
604
|
+
size_t olm_encrypt_random_length(
|
605
|
+
OlmSession * session
|
606
|
+
) {
|
607
|
+
return from_c(session)->encrypt_random_length();
|
608
|
+
}
|
609
|
+
|
610
|
+
|
611
|
+
size_t olm_encrypt_message_length(
|
612
|
+
OlmSession * session,
|
613
|
+
size_t plaintext_length
|
614
|
+
) {
|
615
|
+
return b64_output_length(
|
616
|
+
from_c(session)->encrypt_message_length(plaintext_length)
|
617
|
+
);
|
618
|
+
}
|
619
|
+
|
620
|
+
|
621
|
+
size_t olm_encrypt(
|
622
|
+
OlmSession * session,
|
623
|
+
void const * plaintext, size_t plaintext_length,
|
624
|
+
void * random, size_t random_length,
|
625
|
+
void * message, size_t message_length
|
626
|
+
) {
|
627
|
+
std::size_t raw_length = from_c(session)->encrypt_message_length(
|
628
|
+
plaintext_length
|
629
|
+
);
|
630
|
+
if (message_length < b64_output_length(raw_length)) {
|
631
|
+
from_c(session)->last_error =
|
632
|
+
OlmErrorCode::OLM_OUTPUT_BUFFER_TOO_SMALL;
|
633
|
+
return std::size_t(-1);
|
634
|
+
}
|
635
|
+
std::size_t result = from_c(session)->encrypt(
|
636
|
+
from_c(plaintext), plaintext_length,
|
637
|
+
from_c(random), random_length,
|
638
|
+
b64_output_pos(from_c(message), raw_length), raw_length
|
639
|
+
);
|
640
|
+
olm::unset(random, random_length);
|
641
|
+
if (result == std::size_t(-1)) {
|
642
|
+
return result;
|
643
|
+
}
|
644
|
+
return b64_output(from_c(message), raw_length);
|
645
|
+
}
|
646
|
+
|
647
|
+
|
648
|
+
size_t olm_decrypt_max_plaintext_length(
|
649
|
+
OlmSession * session,
|
650
|
+
size_t message_type,
|
651
|
+
void * message, size_t message_length
|
652
|
+
) {
|
653
|
+
std::size_t raw_length = b64_input(
|
654
|
+
from_c(message), message_length, from_c(session)->last_error
|
655
|
+
);
|
656
|
+
if (raw_length == std::size_t(-1)) {
|
657
|
+
return std::size_t(-1);
|
658
|
+
}
|
659
|
+
return from_c(session)->decrypt_max_plaintext_length(
|
660
|
+
olm::MessageType(message_type), from_c(message), raw_length
|
661
|
+
);
|
662
|
+
}
|
663
|
+
|
664
|
+
|
665
|
+
size_t olm_decrypt(
|
666
|
+
OlmSession * session,
|
667
|
+
size_t message_type,
|
668
|
+
void * message, size_t message_length,
|
669
|
+
void * plaintext, size_t max_plaintext_length
|
670
|
+
) {
|
671
|
+
std::size_t raw_length = b64_input(
|
672
|
+
from_c(message), message_length, from_c(session)->last_error
|
673
|
+
);
|
674
|
+
if (raw_length == std::size_t(-1)) {
|
675
|
+
return std::size_t(-1);
|
676
|
+
}
|
677
|
+
return from_c(session)->decrypt(
|
678
|
+
olm::MessageType(message_type), from_c(message), raw_length,
|
679
|
+
from_c(plaintext), max_plaintext_length
|
680
|
+
);
|
681
|
+
}
|
682
|
+
|
683
|
+
|
684
|
+
size_t olm_sha256_length(
|
685
|
+
OlmUtility * utility
|
686
|
+
) {
|
687
|
+
return b64_output_length(from_c(utility)->sha256_length());
|
688
|
+
}
|
689
|
+
|
690
|
+
|
691
|
+
size_t olm_sha256(
|
692
|
+
OlmUtility * utility,
|
693
|
+
void const * input, size_t input_length,
|
694
|
+
void * output, size_t output_length
|
695
|
+
) {
|
696
|
+
std::size_t raw_length = from_c(utility)->sha256_length();
|
697
|
+
if (output_length < b64_output_length(raw_length)) {
|
698
|
+
from_c(utility)->last_error =
|
699
|
+
OlmErrorCode::OLM_OUTPUT_BUFFER_TOO_SMALL;
|
700
|
+
return std::size_t(-1);
|
701
|
+
}
|
702
|
+
std::size_t result = from_c(utility)->sha256(
|
703
|
+
from_c(input), input_length,
|
704
|
+
b64_output_pos(from_c(output), raw_length), raw_length
|
705
|
+
);
|
706
|
+
if (result == std::size_t(-1)) {
|
707
|
+
return result;
|
708
|
+
}
|
709
|
+
return b64_output(from_c(output), raw_length);
|
710
|
+
}
|
711
|
+
|
712
|
+
|
713
|
+
size_t olm_ed25519_verify(
|
714
|
+
OlmUtility * utility,
|
715
|
+
void const * key, size_t key_length,
|
716
|
+
void const * message, size_t message_length,
|
717
|
+
void * signature, size_t signature_length
|
718
|
+
) {
|
719
|
+
if (olm::decode_base64_length(key_length) != CURVE25519_KEY_LENGTH) {
|
720
|
+
from_c(utility)->last_error = OlmErrorCode::OLM_INVALID_BASE64;
|
721
|
+
return std::size_t(-1);
|
722
|
+
}
|
723
|
+
_olm_ed25519_public_key verify_key;
|
724
|
+
olm::decode_base64(from_c(key), key_length, verify_key.public_key);
|
725
|
+
std::size_t raw_signature_length = b64_input(
|
726
|
+
from_c(signature), signature_length, from_c(utility)->last_error
|
727
|
+
);
|
728
|
+
if (raw_signature_length == std::size_t(-1)) {
|
729
|
+
return std::size_t(-1);
|
730
|
+
}
|
731
|
+
return from_c(utility)->ed25519_verify(
|
732
|
+
verify_key,
|
733
|
+
from_c(message), message_length,
|
734
|
+
from_c(signature), raw_signature_length
|
735
|
+
);
|
736
|
+
}
|
737
|
+
|
738
|
+
}
|