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,90 @@
|
|
1
|
+
#include "olm/olm.h"
|
2
|
+
#include "unittest.hh"
|
3
|
+
|
4
|
+
struct test_case {
|
5
|
+
const char *msghex;
|
6
|
+
const char *expected_error;
|
7
|
+
};
|
8
|
+
|
9
|
+
const test_case test_cases[] = {
|
10
|
+
{ "41776f", "BAD_MESSAGE_FORMAT" },
|
11
|
+
{ "7fff6f0101346d671201", "BAD_MESSAGE_FORMAT" },
|
12
|
+
{ "ee776f41496f674177804177778041776f6716670a677d6f670a67c2677d", "BAD_MESSAGE_FORMAT" },
|
13
|
+
{ "e9e9c9c1e9e9c9e9c9c1e9e9c9c1", "BAD_MESSAGE_FORMAT" },
|
14
|
+
};
|
15
|
+
|
16
|
+
|
17
|
+
const char * session_data =
|
18
|
+
"E0p44KO2y2pzp9FIjv0rud2wIvWDi2dx367kP4Fz/9JCMrH+aG369HGymkFtk0+PINTLB9lQRt"
|
19
|
+
"ohea5d7G/UXQx3r5y4IWuyh1xaRnojEZQ9a5HRZSNtvmZ9NY1f1gutYa4UtcZcbvczN8b/5Bqg"
|
20
|
+
"e16cPUH1v62JKLlhoAJwRkH1wU6fbyOudERg5gdXA971btR+Q2V8GKbVbO5fGKL5phmEPVXyMs"
|
21
|
+
"rfjLdzQrgjOTxN8Pf6iuP+WFPvfnR9lDmNCFxJUVAdLIMnLuAdxf1TGcS+zzCzEE8btIZ99mHF"
|
22
|
+
"dGvPXeH8qLeNZA";
|
23
|
+
|
24
|
+
void decode_hex(
|
25
|
+
const char * input,
|
26
|
+
std::uint8_t * output, std::size_t output_length
|
27
|
+
) {
|
28
|
+
std::uint8_t * end = output + output_length;
|
29
|
+
while (output != end) {
|
30
|
+
char high = *(input++);
|
31
|
+
char low = *(input++);
|
32
|
+
if (high >= 'a') high -= 'a' - ('9' + 1);
|
33
|
+
if (low >= 'a') low -= 'a' - ('9' + 1);
|
34
|
+
uint8_t value = ((high - '0') << 4) | (low - '0');
|
35
|
+
*(output++) = value;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
void decrypt_case(int message_type, const test_case * test_case) {
|
40
|
+
std::uint8_t session_memory[olm_session_size()];
|
41
|
+
::OlmSession * session = ::olm_session(session_memory);
|
42
|
+
|
43
|
+
std::uint8_t pickled[strlen(session_data)];
|
44
|
+
::memcpy(pickled, session_data, sizeof(pickled));
|
45
|
+
assert_not_equals(
|
46
|
+
::olm_error(),
|
47
|
+
::olm_unpickle_session(session, "", 0, pickled, sizeof(pickled))
|
48
|
+
);
|
49
|
+
|
50
|
+
std::size_t message_length = strlen(test_case->msghex) / 2;
|
51
|
+
std::uint8_t * message = (std::uint8_t *) ::malloc(message_length);
|
52
|
+
decode_hex(test_case->msghex, message, message_length);
|
53
|
+
|
54
|
+
size_t max_length = olm_decrypt_max_plaintext_length(
|
55
|
+
session, message_type, message, message_length
|
56
|
+
);
|
57
|
+
|
58
|
+
if (test_case->expected_error) {
|
59
|
+
assert_equals(::olm_error(), max_length);
|
60
|
+
assert_equals(
|
61
|
+
std::string(test_case->expected_error),
|
62
|
+
std::string(::olm_session_last_error(session))
|
63
|
+
);
|
64
|
+
free(message);
|
65
|
+
return;
|
66
|
+
}
|
67
|
+
|
68
|
+
assert_not_equals(::olm_error(), max_length);
|
69
|
+
|
70
|
+
uint8_t plaintext[max_length];
|
71
|
+
decode_hex(test_case->msghex, message, message_length);
|
72
|
+
olm_decrypt(
|
73
|
+
session, message_type,
|
74
|
+
message, message_length,
|
75
|
+
plaintext, max_length
|
76
|
+
);
|
77
|
+
free(message);
|
78
|
+
}
|
79
|
+
|
80
|
+
|
81
|
+
int main() {
|
82
|
+
{
|
83
|
+
TestCase my_test("Olm decrypt test");
|
84
|
+
|
85
|
+
for (unsigned int i = 0; i < sizeof(test_cases)/ sizeof(test_cases[0]); ++i) {
|
86
|
+
decrypt_case(0, &test_cases[i]);
|
87
|
+
}
|
88
|
+
|
89
|
+
}
|
90
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#include "olm/olm.h"
|
2
|
+
#include "unittest.hh"
|
3
|
+
|
4
|
+
int main() {
|
5
|
+
{
|
6
|
+
TestCase("Olm sha256 test");
|
7
|
+
|
8
|
+
|
9
|
+
std::uint8_t utility_buffer[::olm_utility_size()];
|
10
|
+
::OlmUtility * utility = ::olm_utility(utility_buffer);
|
11
|
+
|
12
|
+
assert_equals(std::size_t(43), ::olm_sha256_length(utility));
|
13
|
+
std::uint8_t output[43];
|
14
|
+
::olm_sha256(utility, "Hello, World", 12, output, 43);
|
15
|
+
|
16
|
+
std::uint8_t expected_output[] = "A2daxT/5zRU1zMffzfosRYxSGDcfQY3BNvLRmsH76KU";
|
17
|
+
assert_equals(output, expected_output, 43);
|
18
|
+
|
19
|
+
}
|
20
|
+
}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
#include "olm/olm.h"
|
2
|
+
#include "unittest.hh"
|
3
|
+
|
4
|
+
#include <cstddef>
|
5
|
+
#include <cstdint>
|
6
|
+
#include <cstring>
|
7
|
+
|
8
|
+
struct MockRandom {
|
9
|
+
MockRandom(std::uint8_t tag, std::uint8_t offset = 0)
|
10
|
+
: tag(tag), current(offset) {}
|
11
|
+
void operator()(
|
12
|
+
void * buf, std::size_t length
|
13
|
+
) {
|
14
|
+
std::uint8_t * bytes = (std::uint8_t *) buf;
|
15
|
+
while (length > 32) {
|
16
|
+
bytes[0] = tag;
|
17
|
+
std::memset(bytes + 1, current, 31);
|
18
|
+
length -= 32;
|
19
|
+
bytes += 32;
|
20
|
+
current += 1;
|
21
|
+
}
|
22
|
+
if (length) {
|
23
|
+
bytes[0] = tag;
|
24
|
+
std::memset(bytes + 1, current, length - 1);
|
25
|
+
current += 1;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
std::uint8_t tag;
|
29
|
+
std::uint8_t current;
|
30
|
+
};
|
31
|
+
|
32
|
+
std::uint8_t * check_malloc(std::size_t size) {
|
33
|
+
if (size == std::size_t(-1)) {
|
34
|
+
assert_not_equals(std::size_t(-1), size);
|
35
|
+
}
|
36
|
+
return (std::uint8_t *)::malloc(size);
|
37
|
+
}
|
38
|
+
|
39
|
+
|
40
|
+
int main() {
|
41
|
+
|
42
|
+
{ /** Signing Test */
|
43
|
+
TestCase test_case("Signing test");
|
44
|
+
|
45
|
+
MockRandom mock_random_a('A', 0x00);
|
46
|
+
|
47
|
+
void * account_buffer = check_malloc(::olm_account_size());
|
48
|
+
::OlmAccount * account = ::olm_account(account_buffer);
|
49
|
+
|
50
|
+
std::size_t random_size = ::olm_create_account_random_length(account);
|
51
|
+
void * random = check_malloc(random_size);
|
52
|
+
mock_random_a(random, random_size);
|
53
|
+
::olm_create_account(account, random, random_size);
|
54
|
+
::free(random);
|
55
|
+
|
56
|
+
std::size_t message_size = 12;
|
57
|
+
void * message = check_malloc(message_size);
|
58
|
+
::memcpy(message, "Hello, World", message_size);
|
59
|
+
|
60
|
+
std::size_t signature_size = ::olm_account_signature_length(account);
|
61
|
+
void * signature = check_malloc(signature_size);
|
62
|
+
assert_not_equals(std::size_t(-1), ::olm_account_sign(
|
63
|
+
account, message, message_size, signature, signature_size
|
64
|
+
));
|
65
|
+
|
66
|
+
std::size_t id_keys_size = ::olm_account_identity_keys_length(account);
|
67
|
+
std::uint8_t * id_keys = (std::uint8_t *) check_malloc(id_keys_size);
|
68
|
+
assert_not_equals(std::size_t(-1), ::olm_account_identity_keys(
|
69
|
+
account, id_keys, id_keys_size
|
70
|
+
));
|
71
|
+
|
72
|
+
void * utility_buffer = check_malloc(::olm_utility_size());
|
73
|
+
::OlmUtility * utility = ::olm_utility(utility_buffer);
|
74
|
+
|
75
|
+
assert_not_equals(std::size_t(-1), ::olm_ed25519_verify(
|
76
|
+
utility, id_keys + 71, 43, message, message_size, signature, signature_size
|
77
|
+
));
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
}
|
@@ -0,0 +1,210 @@
|
|
1
|
+
#include "olm/olm.h"
|
2
|
+
#include "unittest.hh"
|
3
|
+
|
4
|
+
#include <cstddef>
|
5
|
+
#include <cstdint>
|
6
|
+
#include <cstring>
|
7
|
+
|
8
|
+
struct MockRandom {
|
9
|
+
MockRandom(std::uint8_t tag, std::uint8_t offset = 0)
|
10
|
+
: tag(tag), current(offset) {}
|
11
|
+
void operator()(
|
12
|
+
void * buf, std::size_t length
|
13
|
+
) {
|
14
|
+
std::uint8_t * bytes = (std::uint8_t *) buf;
|
15
|
+
while (length > 32) {
|
16
|
+
bytes[0] = tag;
|
17
|
+
std::memset(bytes + 1, current, 31);
|
18
|
+
length -= 32;
|
19
|
+
bytes += 32;
|
20
|
+
current += 1;
|
21
|
+
}
|
22
|
+
if (length) {
|
23
|
+
bytes[0] = tag;
|
24
|
+
std::memset(bytes + 1, current, length - 1);
|
25
|
+
current += 1;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
std::uint8_t tag;
|
29
|
+
std::uint8_t current;
|
30
|
+
};
|
31
|
+
|
32
|
+
std::uint8_t * check_malloc(std::size_t size) {
|
33
|
+
if (size == std::size_t(-1)) {
|
34
|
+
assert_not_equals(std::size_t(-1), size);
|
35
|
+
}
|
36
|
+
return (std::uint8_t *)::malloc(size);
|
37
|
+
}
|
38
|
+
|
39
|
+
int main() {
|
40
|
+
|
41
|
+
{ /** More messages test */
|
42
|
+
|
43
|
+
TestCase test_case("More messages test");
|
44
|
+
MockRandom mock_random_a('A', 0x00);
|
45
|
+
MockRandom mock_random_b('B', 0x80);
|
46
|
+
|
47
|
+
void * a_account_buffer = check_malloc(::olm_account_size());
|
48
|
+
::OlmAccount *a_account = ::olm_account(a_account_buffer);
|
49
|
+
|
50
|
+
std::size_t a_random_size = ::olm_create_account_random_length(a_account);
|
51
|
+
void * a_random = check_malloc(a_random_size);
|
52
|
+
mock_random_a(a_random, a_random_size);
|
53
|
+
::olm_create_account(a_account, a_random, a_random_size);
|
54
|
+
free(a_random);
|
55
|
+
|
56
|
+
void * b_account_buffer = check_malloc(::olm_account_size());
|
57
|
+
::OlmAccount *b_account = ::olm_account(b_account_buffer);
|
58
|
+
|
59
|
+
std::size_t b_random_size = ::olm_create_account_random_length(b_account);
|
60
|
+
void * b_random = check_malloc(b_random_size);
|
61
|
+
mock_random_b(b_random, b_random_size);
|
62
|
+
::olm_create_account(b_account, b_random, b_random_size);
|
63
|
+
free(b_random);
|
64
|
+
|
65
|
+
std::size_t o_random_size = ::olm_account_generate_one_time_keys_random_length(
|
66
|
+
b_account, 42
|
67
|
+
);
|
68
|
+
void * o_random = check_malloc(o_random_size);
|
69
|
+
mock_random_b(o_random, o_random_size);
|
70
|
+
::olm_account_generate_one_time_keys(b_account, 42, o_random, o_random_size);
|
71
|
+
free(o_random);
|
72
|
+
|
73
|
+
|
74
|
+
std::size_t b_id_keys_size = ::olm_account_identity_keys_length(b_account);
|
75
|
+
std::size_t b_ot_keys_size = ::olm_account_one_time_keys_length(b_account);
|
76
|
+
std::uint8_t * b_id_keys = (std::uint8_t *) check_malloc(b_id_keys_size);
|
77
|
+
std::uint8_t * b_ot_keys = (std::uint8_t *) check_malloc(b_ot_keys_size);
|
78
|
+
::olm_account_identity_keys(b_account, b_id_keys, b_id_keys_size);
|
79
|
+
::olm_account_one_time_keys(b_account, b_ot_keys, b_ot_keys_size);
|
80
|
+
|
81
|
+
void * a_session_buffer = check_malloc(::olm_session_size());
|
82
|
+
::OlmSession *a_session = ::olm_session(a_session_buffer);
|
83
|
+
|
84
|
+
std::size_t a_rand_size = ::olm_create_outbound_session_random_length(a_session);
|
85
|
+
void * a_rand = check_malloc(a_rand_size);
|
86
|
+
mock_random_a(a_rand, a_rand_size);
|
87
|
+
assert_not_equals(std::size_t(-1), ::olm_create_outbound_session(
|
88
|
+
a_session, a_account,
|
89
|
+
b_id_keys + 15, 43,
|
90
|
+
b_ot_keys + 25, 43,
|
91
|
+
a_rand, a_rand_size
|
92
|
+
));
|
93
|
+
free(b_id_keys);
|
94
|
+
free(b_ot_keys);
|
95
|
+
free(a_rand);
|
96
|
+
|
97
|
+
void * plaintext = malloc(12);
|
98
|
+
::memcpy(plaintext, "Hello, World", 12);
|
99
|
+
|
100
|
+
std::size_t message_1_size = ::olm_encrypt_message_length(a_session, 12);
|
101
|
+
void * message_1 = check_malloc(message_1_size);
|
102
|
+
std::size_t a_message_random_size = ::olm_encrypt_random_length(a_session);
|
103
|
+
void * a_message_random = check_malloc(a_message_random_size);
|
104
|
+
mock_random_a(a_message_random, a_message_random_size);
|
105
|
+
assert_equals(std::size_t(0), ::olm_encrypt_message_type(a_session));
|
106
|
+
assert_not_equals(std::size_t(-1), ::olm_encrypt(
|
107
|
+
a_session,
|
108
|
+
plaintext, 12,
|
109
|
+
a_message_random, a_message_random_size,
|
110
|
+
message_1, message_1_size
|
111
|
+
));
|
112
|
+
free(a_message_random);
|
113
|
+
|
114
|
+
void * tmp_message_1 = check_malloc(message_1_size);
|
115
|
+
std::memcpy(tmp_message_1, message_1, message_1_size);
|
116
|
+
|
117
|
+
void * b_session_buffer = check_malloc(olm_account_size());
|
118
|
+
::OlmSession *b_session = ::olm_session(b_session_buffer);
|
119
|
+
::olm_create_inbound_session(
|
120
|
+
b_session, b_account, tmp_message_1, message_1_size
|
121
|
+
);
|
122
|
+
|
123
|
+
std::memcpy(tmp_message_1, message_1, message_1_size);
|
124
|
+
|
125
|
+
std::size_t plaintext_1_size = ::olm_decrypt_max_plaintext_length(
|
126
|
+
b_session, 0, tmp_message_1, message_1_size
|
127
|
+
);
|
128
|
+
void * plaintext_1 = check_malloc(plaintext_1_size);
|
129
|
+
std::memcpy(tmp_message_1, message_1, message_1_size);
|
130
|
+
assert_equals(std::size_t(12), ::olm_decrypt(
|
131
|
+
b_session, 0,
|
132
|
+
tmp_message_1, message_1_size,
|
133
|
+
plaintext_1, plaintext_1_size
|
134
|
+
));
|
135
|
+
free(tmp_message_1);
|
136
|
+
free(plaintext_1);
|
137
|
+
free(message_1);
|
138
|
+
|
139
|
+
assert_not_equals(
|
140
|
+
std::size_t(-1), ::olm_remove_one_time_keys(b_account, b_session)
|
141
|
+
);
|
142
|
+
|
143
|
+
for (unsigned i = 0; i < 8; ++i) {
|
144
|
+
{
|
145
|
+
std::size_t msg_a_size = ::olm_encrypt_message_length(a_session, 12);
|
146
|
+
std::size_t rnd_a_size = ::olm_encrypt_random_length(a_session);
|
147
|
+
void * msg_a = check_malloc(msg_a_size);
|
148
|
+
void * rnd_a = check_malloc(rnd_a_size);
|
149
|
+
mock_random_a(rnd_a, rnd_a_size);
|
150
|
+
std::size_t type_a = ::olm_encrypt_message_type(a_session);
|
151
|
+
assert_not_equals(std::size_t(-1), ::olm_encrypt(
|
152
|
+
a_session, plaintext, 12, rnd_a, rnd_a_size, msg_a, msg_a_size
|
153
|
+
));
|
154
|
+
free(rnd_a);
|
155
|
+
|
156
|
+
void * tmp_a = check_malloc(msg_a_size);
|
157
|
+
std::memcpy(tmp_a, msg_a, msg_a_size);
|
158
|
+
std::size_t out_a_size = ::olm_decrypt_max_plaintext_length(
|
159
|
+
b_session, type_a, tmp_a, msg_a_size
|
160
|
+
);
|
161
|
+
void * out_a = check_malloc(out_a_size);
|
162
|
+
std::memcpy(tmp_a, msg_a, msg_a_size);
|
163
|
+
assert_equals(std::size_t(12), ::olm_decrypt(
|
164
|
+
b_session, type_a, tmp_a, msg_a_size, out_a, out_a_size
|
165
|
+
));
|
166
|
+
free(tmp_a);
|
167
|
+
free(msg_a);
|
168
|
+
free(out_a);
|
169
|
+
}
|
170
|
+
{
|
171
|
+
std::size_t msg_b_size = ::olm_encrypt_message_length(b_session, 12);
|
172
|
+
std::size_t rnd_b_size = ::olm_encrypt_random_length(b_session);
|
173
|
+
void * msg_b = check_malloc(msg_b_size);
|
174
|
+
void * rnd_b = check_malloc(rnd_b_size);
|
175
|
+
mock_random_b(rnd_b, rnd_b_size);
|
176
|
+
std::size_t type_b = ::olm_encrypt_message_type(b_session);
|
177
|
+
assert_not_equals(std::size_t(-1), ::olm_encrypt(
|
178
|
+
b_session, plaintext, 12, rnd_b, rnd_b_size, msg_b, msg_b_size
|
179
|
+
));
|
180
|
+
free(rnd_b);
|
181
|
+
|
182
|
+
void * tmp_b = check_malloc(msg_b_size);
|
183
|
+
std::memcpy(tmp_b, msg_b, msg_b_size);
|
184
|
+
std::size_t out_b_size = ::olm_decrypt_max_plaintext_length(
|
185
|
+
a_session, type_b, tmp_b, msg_b_size
|
186
|
+
);
|
187
|
+
void * out_b = check_malloc(out_b_size);
|
188
|
+
std::memcpy(tmp_b, msg_b, msg_b_size);
|
189
|
+
assert_equals(std::size_t(12), ::olm_decrypt(
|
190
|
+
a_session, type_b, msg_b, msg_b_size, out_b, out_b_size
|
191
|
+
));
|
192
|
+
free(tmp_b);
|
193
|
+
free(msg_b);
|
194
|
+
free(out_b);
|
195
|
+
}
|
196
|
+
}
|
197
|
+
::olm_clear_account(a_account);
|
198
|
+
::olm_clear_account(b_account);
|
199
|
+
::olm_clear_session(a_session);
|
200
|
+
::olm_clear_session(b_session);
|
201
|
+
|
202
|
+
free(a_account_buffer);
|
203
|
+
free(b_account_buffer);
|
204
|
+
free(a_session_buffer);
|
205
|
+
free(b_session_buffer);
|
206
|
+
free(plaintext);
|
207
|
+
|
208
|
+
}
|
209
|
+
|
210
|
+
}
|
@@ -0,0 +1,166 @@
|
|
1
|
+
#include "olm/pk.h"
|
2
|
+
#include "olm/crypto.h"
|
3
|
+
#include "olm/olm.h"
|
4
|
+
|
5
|
+
#include "unittest.hh"
|
6
|
+
|
7
|
+
#include <iostream>
|
8
|
+
|
9
|
+
int main() {
|
10
|
+
|
11
|
+
|
12
|
+
{ /* Encryption Test Case 1 */
|
13
|
+
|
14
|
+
TestCase test_case("Public Key Encryption/Decryption Test Case 1");
|
15
|
+
|
16
|
+
std::uint8_t decryption_buffer[olm_pk_decryption_size()];
|
17
|
+
OlmPkDecryption *decryption = olm_pk_decryption(decryption_buffer);
|
18
|
+
|
19
|
+
std::uint8_t alice_private[32] = {
|
20
|
+
0x77, 0x07, 0x6D, 0x0A, 0x73, 0x18, 0xA5, 0x7D,
|
21
|
+
0x3C, 0x16, 0xC1, 0x72, 0x51, 0xB2, 0x66, 0x45,
|
22
|
+
0xDF, 0x4C, 0x2F, 0x87, 0xEB, 0xC0, 0x99, 0x2A,
|
23
|
+
0xB1, 0x77, 0xFB, 0xA5, 0x1D, 0xB9, 0x2C, 0x2A
|
24
|
+
};
|
25
|
+
|
26
|
+
const std::uint8_t *alice_public = (std::uint8_t *) "hSDwCYkwp1R0i33ctD73Wg2/Og0mOBr066SpjqqbTmo";
|
27
|
+
|
28
|
+
std::uint8_t bob_private[32] = {
|
29
|
+
0x5D, 0xAB, 0x08, 0x7E, 0x62, 0x4A, 0x8A, 0x4B,
|
30
|
+
0x79, 0xE1, 0x7F, 0x8B, 0x83, 0x80, 0x0E, 0xE6,
|
31
|
+
0x6F, 0x3B, 0xB1, 0x29, 0x26, 0x18, 0xB6, 0xFD,
|
32
|
+
0x1C, 0x2F, 0x8B, 0x27, 0xFF, 0x88, 0xE0, 0xEB
|
33
|
+
};
|
34
|
+
|
35
|
+
const std::uint8_t *bob_public = (std::uint8_t *) "3p7bfXt9wbTTW2HC7OQ1Nz+DQ8hbeGdNrfx+FG+IK08";
|
36
|
+
|
37
|
+
std::uint8_t pubkey[::olm_pk_key_length()];
|
38
|
+
|
39
|
+
olm_pk_key_from_private(
|
40
|
+
decryption,
|
41
|
+
pubkey, sizeof(pubkey),
|
42
|
+
alice_private, sizeof(alice_private)
|
43
|
+
);
|
44
|
+
|
45
|
+
assert_equals(alice_public, pubkey, olm_pk_key_length());
|
46
|
+
|
47
|
+
uint8_t *alice_private_back_out = (uint8_t *)malloc(olm_pk_private_key_length());
|
48
|
+
olm_pk_get_private_key(decryption, alice_private_back_out, olm_pk_private_key_length());
|
49
|
+
assert_equals(alice_private, alice_private_back_out, olm_pk_private_key_length());
|
50
|
+
free(alice_private_back_out);
|
51
|
+
|
52
|
+
std::uint8_t encryption_buffer[olm_pk_encryption_size()];
|
53
|
+
OlmPkEncryption *encryption = olm_pk_encryption(encryption_buffer);
|
54
|
+
|
55
|
+
olm_pk_encryption_set_recipient_key(encryption, pubkey, sizeof(pubkey));
|
56
|
+
|
57
|
+
const size_t plaintext_length = 14;
|
58
|
+
const std::uint8_t *plaintext = (std::uint8_t *) "This is a test";
|
59
|
+
|
60
|
+
size_t ciphertext_length = olm_pk_ciphertext_length(encryption, plaintext_length);
|
61
|
+
std::uint8_t *ciphertext_buffer = (std::uint8_t *) malloc(ciphertext_length);
|
62
|
+
|
63
|
+
std::uint8_t output_buffer[olm_pk_mac_length(encryption)];
|
64
|
+
std::uint8_t ephemeral_key[olm_pk_key_length()];
|
65
|
+
|
66
|
+
olm_pk_encrypt(
|
67
|
+
encryption,
|
68
|
+
plaintext, plaintext_length,
|
69
|
+
ciphertext_buffer, ciphertext_length,
|
70
|
+
output_buffer, sizeof(output_buffer),
|
71
|
+
ephemeral_key, sizeof(ephemeral_key),
|
72
|
+
bob_private, sizeof(bob_private)
|
73
|
+
);
|
74
|
+
|
75
|
+
assert_equals(bob_public, ephemeral_key, olm_pk_key_length());
|
76
|
+
|
77
|
+
size_t max_plaintext_length = olm_pk_max_plaintext_length(decryption, ciphertext_length);
|
78
|
+
std::uint8_t *plaintext_buffer = (std::uint8_t *) malloc(max_plaintext_length);
|
79
|
+
|
80
|
+
olm_pk_decrypt(
|
81
|
+
decryption,
|
82
|
+
ephemeral_key, sizeof(ephemeral_key),
|
83
|
+
output_buffer, sizeof(output_buffer),
|
84
|
+
ciphertext_buffer, ciphertext_length,
|
85
|
+
plaintext_buffer, max_plaintext_length
|
86
|
+
);
|
87
|
+
|
88
|
+
assert_equals(plaintext, plaintext_buffer, plaintext_length);
|
89
|
+
|
90
|
+
free(ciphertext_buffer);
|
91
|
+
free(plaintext_buffer);
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
{ /* Encryption Test Case 1 */
|
96
|
+
|
97
|
+
TestCase test_case("Public Key Decryption pickling");
|
98
|
+
|
99
|
+
std::uint8_t decryption_buffer[olm_pk_decryption_size()];
|
100
|
+
OlmPkDecryption *decryption = olm_pk_decryption(decryption_buffer);
|
101
|
+
|
102
|
+
std::uint8_t alice_private[32] = {
|
103
|
+
0x77, 0x07, 0x6D, 0x0A, 0x73, 0x18, 0xA5, 0x7D,
|
104
|
+
0x3C, 0x16, 0xC1, 0x72, 0x51, 0xB2, 0x66, 0x45,
|
105
|
+
0xDF, 0x4C, 0x2F, 0x87, 0xEB, 0xC0, 0x99, 0x2A,
|
106
|
+
0xB1, 0x77, 0xFB, 0xA5, 0x1D, 0xB9, 0x2C, 0x2A
|
107
|
+
};
|
108
|
+
|
109
|
+
const std::uint8_t *alice_public = (std::uint8_t *) "hSDwCYkwp1R0i33ctD73Wg2/Og0mOBr066SpjqqbTmoK";
|
110
|
+
|
111
|
+
std::uint8_t pubkey[olm_pk_key_length()];
|
112
|
+
|
113
|
+
olm_pk_key_from_private(
|
114
|
+
decryption,
|
115
|
+
pubkey, sizeof(pubkey),
|
116
|
+
alice_private, sizeof(alice_private)
|
117
|
+
);
|
118
|
+
|
119
|
+
const uint8_t *PICKLE_KEY=(uint8_t *)"secret_key";
|
120
|
+
std::uint8_t pickle_buffer[olm_pickle_pk_decryption_length(decryption)];
|
121
|
+
const uint8_t *expected_pickle = (uint8_t *) "qx37WTQrjZLz5tId/uBX9B3/okqAbV1ofl9UnHKno1eipByCpXleAAlAZoJgYnCDOQZDQWzo3luTSfkF9pU1mOILCbbouubs6TVeDyPfgGD9i86J8irHjA";
|
122
|
+
|
123
|
+
olm_pickle_pk_decryption(
|
124
|
+
decryption,
|
125
|
+
PICKLE_KEY, strlen((char *)PICKLE_KEY),
|
126
|
+
pickle_buffer, sizeof(pickle_buffer)
|
127
|
+
);
|
128
|
+
assert_equals(expected_pickle, pickle_buffer, olm_pickle_pk_decryption_length(decryption));
|
129
|
+
|
130
|
+
olm_clear_pk_decryption(decryption);
|
131
|
+
|
132
|
+
memset(pubkey, 0, olm_pk_key_length());
|
133
|
+
|
134
|
+
olm_unpickle_pk_decryption(
|
135
|
+
decryption,
|
136
|
+
PICKLE_KEY, strlen((char *)PICKLE_KEY),
|
137
|
+
pickle_buffer, sizeof(pickle_buffer),
|
138
|
+
pubkey, sizeof(pubkey)
|
139
|
+
);
|
140
|
+
|
141
|
+
assert_equals(alice_public, pubkey, olm_pk_key_length());
|
142
|
+
|
143
|
+
char *ciphertext = strdup("ntk49j/KozVFtSqJXhCejg");
|
144
|
+
const char *mac = "zpzU6BkZcNI";
|
145
|
+
const char *ephemeral_key = "3p7bfXt9wbTTW2HC7OQ1Nz+DQ8hbeGdNrfx+FG+IK08";
|
146
|
+
|
147
|
+
size_t max_plaintext_length = olm_pk_max_plaintext_length(decryption, strlen(ciphertext));
|
148
|
+
std::uint8_t *plaintext_buffer = (std::uint8_t *) malloc(max_plaintext_length);
|
149
|
+
|
150
|
+
olm_pk_decrypt(
|
151
|
+
decryption,
|
152
|
+
ephemeral_key, strlen(ephemeral_key),
|
153
|
+
mac, strlen(mac),
|
154
|
+
ciphertext, strlen(ciphertext),
|
155
|
+
plaintext_buffer, max_plaintext_length
|
156
|
+
);
|
157
|
+
|
158
|
+
const std::uint8_t *plaintext = (std::uint8_t *) "This is a test";
|
159
|
+
|
160
|
+
assert_equals(plaintext, plaintext_buffer, strlen((const char *)plaintext));
|
161
|
+
|
162
|
+
free(ciphertext);
|
163
|
+
free(plaintext_buffer);
|
164
|
+
|
165
|
+
}
|
166
|
+
}
|