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,181 @@
|
|
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
|
+
#ifndef OLM_OUTBOUND_GROUP_SESSION_H_
|
16
|
+
#define OLM_OUTBOUND_GROUP_SESSION_H_
|
17
|
+
|
18
|
+
#include <stddef.h>
|
19
|
+
#include <stdint.h>
|
20
|
+
|
21
|
+
#ifdef __cplusplus
|
22
|
+
extern "C" {
|
23
|
+
#endif
|
24
|
+
|
25
|
+
typedef struct OlmOutboundGroupSession OlmOutboundGroupSession;
|
26
|
+
|
27
|
+
/** get the size of an outbound group session, in bytes. */
|
28
|
+
size_t olm_outbound_group_session_size(void);
|
29
|
+
|
30
|
+
/**
|
31
|
+
* Initialise an outbound group session object using the supplied memory
|
32
|
+
* The supplied memory should be at least olm_outbound_group_session_size()
|
33
|
+
* bytes.
|
34
|
+
*/
|
35
|
+
OlmOutboundGroupSession * olm_outbound_group_session(
|
36
|
+
void *memory
|
37
|
+
);
|
38
|
+
|
39
|
+
/**
|
40
|
+
* A null terminated string describing the most recent error to happen to a
|
41
|
+
* group session */
|
42
|
+
const char *olm_outbound_group_session_last_error(
|
43
|
+
const OlmOutboundGroupSession *session
|
44
|
+
);
|
45
|
+
|
46
|
+
/** Clears the memory used to back this group session */
|
47
|
+
size_t olm_clear_outbound_group_session(
|
48
|
+
OlmOutboundGroupSession *session
|
49
|
+
);
|
50
|
+
|
51
|
+
/** Returns the number of bytes needed to store an outbound group session */
|
52
|
+
size_t olm_pickle_outbound_group_session_length(
|
53
|
+
const OlmOutboundGroupSession *session
|
54
|
+
);
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Stores a group session as a base64 string. Encrypts the session using the
|
58
|
+
* supplied key. Returns the length of the session on success.
|
59
|
+
*
|
60
|
+
* Returns olm_error() on failure. If the pickle output buffer
|
61
|
+
* is smaller than olm_pickle_outbound_group_session_length() then
|
62
|
+
* olm_outbound_group_session_last_error() will be "OUTPUT_BUFFER_TOO_SMALL"
|
63
|
+
*/
|
64
|
+
size_t olm_pickle_outbound_group_session(
|
65
|
+
OlmOutboundGroupSession *session,
|
66
|
+
void const * key, size_t key_length,
|
67
|
+
void * pickled, size_t pickled_length
|
68
|
+
);
|
69
|
+
|
70
|
+
/**
|
71
|
+
* Loads a group session from a pickled base64 string. Decrypts the session
|
72
|
+
* using the supplied key.
|
73
|
+
*
|
74
|
+
* Returns olm_error() on failure. If the key doesn't match the one used to
|
75
|
+
* encrypt the account then olm_outbound_group_session_last_error() will be
|
76
|
+
* "BAD_ACCOUNT_KEY". If the base64 couldn't be decoded then
|
77
|
+
* olm_outbound_group_session_last_error() will be "INVALID_BASE64". The input
|
78
|
+
* pickled buffer is destroyed
|
79
|
+
*/
|
80
|
+
size_t olm_unpickle_outbound_group_session(
|
81
|
+
OlmOutboundGroupSession *session,
|
82
|
+
void const * key, size_t key_length,
|
83
|
+
void * pickled, size_t pickled_length
|
84
|
+
);
|
85
|
+
|
86
|
+
|
87
|
+
/** The number of random bytes needed to create an outbound group session */
|
88
|
+
size_t olm_init_outbound_group_session_random_length(
|
89
|
+
const OlmOutboundGroupSession *session
|
90
|
+
);
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Start a new outbound group session. Returns olm_error() on failure. On
|
94
|
+
* failure last_error will be set with an error code. The last_error will be
|
95
|
+
* NOT_ENOUGH_RANDOM if the number of random bytes was too small.
|
96
|
+
*/
|
97
|
+
size_t olm_init_outbound_group_session(
|
98
|
+
OlmOutboundGroupSession *session,
|
99
|
+
uint8_t *random, size_t random_length
|
100
|
+
);
|
101
|
+
|
102
|
+
/**
|
103
|
+
* The number of bytes that will be created by encrypting a message
|
104
|
+
*/
|
105
|
+
size_t olm_group_encrypt_message_length(
|
106
|
+
OlmOutboundGroupSession *session,
|
107
|
+
size_t plaintext_length
|
108
|
+
);
|
109
|
+
|
110
|
+
/**
|
111
|
+
* Encrypt some plain-text. Returns the length of the encrypted message or
|
112
|
+
* olm_error() on failure. On failure last_error will be set with an
|
113
|
+
* error code. The last_error will be OUTPUT_BUFFER_TOO_SMALL if the output
|
114
|
+
* buffer is too small.
|
115
|
+
*/
|
116
|
+
size_t olm_group_encrypt(
|
117
|
+
OlmOutboundGroupSession *session,
|
118
|
+
uint8_t const * plaintext, size_t plaintext_length,
|
119
|
+
uint8_t * message, size_t message_length
|
120
|
+
);
|
121
|
+
|
122
|
+
|
123
|
+
/**
|
124
|
+
* Get the number of bytes returned by olm_outbound_group_session_id()
|
125
|
+
*/
|
126
|
+
size_t olm_outbound_group_session_id_length(
|
127
|
+
const OlmOutboundGroupSession *session
|
128
|
+
);
|
129
|
+
|
130
|
+
/**
|
131
|
+
* Get a base64-encoded identifier for this session.
|
132
|
+
*
|
133
|
+
* Returns the length of the session id on success or olm_error() on
|
134
|
+
* failure. On failure last_error will be set with an error code. The
|
135
|
+
* last_error will be OUTPUT_BUFFER_TOO_SMALL if the id buffer was too
|
136
|
+
* small.
|
137
|
+
*/
|
138
|
+
size_t olm_outbound_group_session_id(
|
139
|
+
OlmOutboundGroupSession *session,
|
140
|
+
uint8_t * id, size_t id_length
|
141
|
+
);
|
142
|
+
|
143
|
+
/**
|
144
|
+
* Get the current message index for this session.
|
145
|
+
*
|
146
|
+
* Each message is sent with an increasing index; this returns the index for
|
147
|
+
* the next message.
|
148
|
+
*/
|
149
|
+
uint32_t olm_outbound_group_session_message_index(
|
150
|
+
OlmOutboundGroupSession *session
|
151
|
+
);
|
152
|
+
|
153
|
+
/**
|
154
|
+
* Get the number of bytes returned by olm_outbound_group_session_key()
|
155
|
+
*/
|
156
|
+
size_t olm_outbound_group_session_key_length(
|
157
|
+
const OlmOutboundGroupSession *session
|
158
|
+
);
|
159
|
+
|
160
|
+
/**
|
161
|
+
* Get the base64-encoded current ratchet key for this session.
|
162
|
+
*
|
163
|
+
* Each message is sent with a different ratchet key. This function returns the
|
164
|
+
* ratchet key that will be used for the next message.
|
165
|
+
*
|
166
|
+
* Returns the length of the ratchet key on success or olm_error() on
|
167
|
+
* failure. On failure last_error will be set with an error code. The
|
168
|
+
* last_error will be OUTPUT_BUFFER_TOO_SMALL if the buffer was too small.
|
169
|
+
*/
|
170
|
+
size_t olm_outbound_group_session_key(
|
171
|
+
OlmOutboundGroupSession *session,
|
172
|
+
uint8_t * key, size_t key_length
|
173
|
+
);
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
#ifdef __cplusplus
|
178
|
+
} // extern "C"
|
179
|
+
#endif
|
180
|
+
|
181
|
+
#endif /* OLM_OUTBOUND_GROUP_SESSION_H_ */
|
@@ -0,0 +1,90 @@
|
|
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
|
+
#ifndef OLM_PICKLE_H_
|
16
|
+
#define OLM_PICKLE_H_
|
17
|
+
|
18
|
+
#include <stdint.h>
|
19
|
+
|
20
|
+
#ifdef __cplusplus
|
21
|
+
extern "C" {
|
22
|
+
#endif
|
23
|
+
|
24
|
+
struct _olm_ed25519_public_key;
|
25
|
+
struct _olm_ed25519_key_pair;
|
26
|
+
|
27
|
+
|
28
|
+
#define _olm_pickle_uint32_length(value) 4
|
29
|
+
uint8_t * _olm_pickle_uint32(uint8_t * pos, uint32_t value);
|
30
|
+
uint8_t const * _olm_unpickle_uint32(
|
31
|
+
uint8_t const * pos, uint8_t const * end,
|
32
|
+
uint32_t *value
|
33
|
+
);
|
34
|
+
|
35
|
+
|
36
|
+
#define _olm_pickle_bool_length(value) 1
|
37
|
+
uint8_t * _olm_pickle_bool(uint8_t * pos, int value);
|
38
|
+
uint8_t const * _olm_unpickle_bool(
|
39
|
+
uint8_t const * pos, uint8_t const * end,
|
40
|
+
int *value
|
41
|
+
);
|
42
|
+
|
43
|
+
#define _olm_pickle_bytes_length(bytes, bytes_length) (bytes_length)
|
44
|
+
uint8_t * _olm_pickle_bytes(uint8_t * pos, uint8_t const * bytes,
|
45
|
+
size_t bytes_length);
|
46
|
+
uint8_t const * _olm_unpickle_bytes(uint8_t const * pos, uint8_t const * end,
|
47
|
+
uint8_t * bytes, size_t bytes_length);
|
48
|
+
|
49
|
+
|
50
|
+
/** Get the number of bytes needed to pickle an ed25519 public key */
|
51
|
+
size_t _olm_pickle_ed25519_public_key_length(
|
52
|
+
const struct _olm_ed25519_public_key * value
|
53
|
+
);
|
54
|
+
|
55
|
+
/** Pickle the ed25519 public key. Returns a pointer to the next free space in
|
56
|
+
* the buffer. */
|
57
|
+
uint8_t * _olm_pickle_ed25519_public_key(
|
58
|
+
uint8_t *pos, const struct _olm_ed25519_public_key * value
|
59
|
+
);
|
60
|
+
|
61
|
+
/** Unpickle the ed25519 public key. Returns a pointer to the next item in the
|
62
|
+
* buffer. */
|
63
|
+
const uint8_t * _olm_unpickle_ed25519_public_key(
|
64
|
+
const uint8_t *pos, const uint8_t *end,
|
65
|
+
struct _olm_ed25519_public_key * value
|
66
|
+
);
|
67
|
+
|
68
|
+
/** Get the number of bytes needed to pickle an ed25519 key pair */
|
69
|
+
size_t _olm_pickle_ed25519_key_pair_length(
|
70
|
+
const struct _olm_ed25519_key_pair * value
|
71
|
+
);
|
72
|
+
|
73
|
+
/** Pickle the ed25519 key pair. Returns a pointer to the next free space in
|
74
|
+
* the buffer. */
|
75
|
+
uint8_t * _olm_pickle_ed25519_key_pair(
|
76
|
+
uint8_t *pos, const struct _olm_ed25519_key_pair * value
|
77
|
+
);
|
78
|
+
|
79
|
+
/** Unpickle the ed25519 key pair. Returns a pointer to the next item in the
|
80
|
+
* buffer. */
|
81
|
+
const uint8_t * _olm_unpickle_ed25519_key_pair(
|
82
|
+
const uint8_t *pos, const uint8_t *end,
|
83
|
+
struct _olm_ed25519_key_pair * value
|
84
|
+
);
|
85
|
+
|
86
|
+
#ifdef __cplusplus
|
87
|
+
} // extern "C"
|
88
|
+
#endif
|
89
|
+
|
90
|
+
#endif /* OLM_PICKLE_H */
|
@@ -0,0 +1,149 @@
|
|
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
|
+
#ifndef OLM_PICKLE_HH_
|
16
|
+
#define OLM_PICKLE_HH_
|
17
|
+
|
18
|
+
#include "olm/list.hh"
|
19
|
+
#include "olm/crypto.h"
|
20
|
+
|
21
|
+
#include <cstring>
|
22
|
+
#include <cstdint>
|
23
|
+
|
24
|
+
namespace olm {
|
25
|
+
|
26
|
+
inline std::size_t pickle_length(
|
27
|
+
const std::uint32_t & value
|
28
|
+
) {
|
29
|
+
return 4;
|
30
|
+
}
|
31
|
+
|
32
|
+
std::uint8_t * pickle(
|
33
|
+
std::uint8_t * pos,
|
34
|
+
std::uint32_t value
|
35
|
+
);
|
36
|
+
|
37
|
+
std::uint8_t const * unpickle(
|
38
|
+
std::uint8_t const * pos, std::uint8_t const * end,
|
39
|
+
std::uint32_t & value
|
40
|
+
);
|
41
|
+
|
42
|
+
|
43
|
+
inline std::size_t pickle_length(
|
44
|
+
const bool & value
|
45
|
+
) {
|
46
|
+
return 1;
|
47
|
+
}
|
48
|
+
|
49
|
+
std::uint8_t * pickle(
|
50
|
+
std::uint8_t * pos,
|
51
|
+
bool value
|
52
|
+
);
|
53
|
+
|
54
|
+
std::uint8_t const * unpickle(
|
55
|
+
std::uint8_t const * pos, std::uint8_t const * end,
|
56
|
+
bool & value
|
57
|
+
);
|
58
|
+
|
59
|
+
|
60
|
+
template<typename T, std::size_t max_size>
|
61
|
+
std::size_t pickle_length(
|
62
|
+
olm::List<T, max_size> const & list
|
63
|
+
) {
|
64
|
+
std::size_t length = pickle_length(std::uint32_t(list.size()));
|
65
|
+
for (auto const & value : list) {
|
66
|
+
length += pickle_length(value);
|
67
|
+
}
|
68
|
+
return length;
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
template<typename T, std::size_t max_size>
|
73
|
+
std::uint8_t * pickle(
|
74
|
+
std::uint8_t * pos,
|
75
|
+
olm::List<T, max_size> const & list
|
76
|
+
) {
|
77
|
+
pos = pickle(pos, std::uint32_t(list.size()));
|
78
|
+
for (auto const & value : list) {
|
79
|
+
pos = pickle(pos, value);
|
80
|
+
}
|
81
|
+
return pos;
|
82
|
+
}
|
83
|
+
|
84
|
+
|
85
|
+
template<typename T, std::size_t max_size>
|
86
|
+
std::uint8_t const * unpickle(
|
87
|
+
std::uint8_t const * pos, std::uint8_t const * end,
|
88
|
+
olm::List<T, max_size> & list
|
89
|
+
) {
|
90
|
+
std::uint32_t size;
|
91
|
+
pos = unpickle(pos, end, size);
|
92
|
+
while (size-- && pos != end) {
|
93
|
+
T * value = list.insert(list.end());
|
94
|
+
pos = unpickle(pos, end, *value);
|
95
|
+
}
|
96
|
+
return pos;
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
std::uint8_t * pickle_bytes(
|
101
|
+
std::uint8_t * pos,
|
102
|
+
std::uint8_t const * bytes, std::size_t bytes_length
|
103
|
+
);
|
104
|
+
|
105
|
+
std::uint8_t const * unpickle_bytes(
|
106
|
+
std::uint8_t const * pos, std::uint8_t const * end,
|
107
|
+
std::uint8_t * bytes, std::size_t bytes_length
|
108
|
+
);
|
109
|
+
|
110
|
+
|
111
|
+
std::size_t pickle_length(
|
112
|
+
const _olm_curve25519_public_key & value
|
113
|
+
);
|
114
|
+
|
115
|
+
|
116
|
+
std::uint8_t * pickle(
|
117
|
+
std::uint8_t * pos,
|
118
|
+
const _olm_curve25519_public_key & value
|
119
|
+
);
|
120
|
+
|
121
|
+
|
122
|
+
std::uint8_t const * unpickle(
|
123
|
+
std::uint8_t const * pos, std::uint8_t const * end,
|
124
|
+
_olm_curve25519_public_key & value
|
125
|
+
);
|
126
|
+
|
127
|
+
|
128
|
+
std::size_t pickle_length(
|
129
|
+
const _olm_curve25519_key_pair & value
|
130
|
+
);
|
131
|
+
|
132
|
+
|
133
|
+
std::uint8_t * pickle(
|
134
|
+
std::uint8_t * pos,
|
135
|
+
const _olm_curve25519_key_pair & value
|
136
|
+
);
|
137
|
+
|
138
|
+
|
139
|
+
std::uint8_t const * unpickle(
|
140
|
+
std::uint8_t const * pos, std::uint8_t const * end,
|
141
|
+
_olm_curve25519_key_pair & value
|
142
|
+
);
|
143
|
+
|
144
|
+
} // namespace olm
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
#endif /* OLM_PICKLE_HH */
|
@@ -0,0 +1,76 @@
|
|
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
|
+
/* functions for encrypting and decrypting pickled representations of objects */
|
17
|
+
|
18
|
+
#ifndef OLM_PICKLE_ENCODING_H_
|
19
|
+
#define OLM_PICKLE_ENCODING_H_
|
20
|
+
|
21
|
+
#include <stddef.h>
|
22
|
+
#include <stdint.h>
|
23
|
+
|
24
|
+
#include "olm/error.h"
|
25
|
+
|
26
|
+
#ifdef __cplusplus
|
27
|
+
extern "C" {
|
28
|
+
#endif
|
29
|
+
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Get the number of bytes needed to encode a pickle of the length given
|
33
|
+
*/
|
34
|
+
size_t _olm_enc_output_length(size_t raw_length);
|
35
|
+
|
36
|
+
/**
|
37
|
+
* Get the point in the output buffer that the raw pickle should be written to.
|
38
|
+
*
|
39
|
+
* In order that we can use the same buffer for the raw pickle, and the encoded
|
40
|
+
* pickle, the raw pickle needs to be written at the end of the buffer. (The
|
41
|
+
* base-64 encoding would otherwise overwrite the end of the input before it
|
42
|
+
* was encoded.)
|
43
|
+
*/
|
44
|
+
uint8_t *_olm_enc_output_pos(uint8_t * output, size_t raw_length);
|
45
|
+
|
46
|
+
/**
|
47
|
+
* Encrypt and encode the given pickle in-situ.
|
48
|
+
*
|
49
|
+
* The raw pickle should have been written to enc_output_pos(pickle,
|
50
|
+
* raw_length).
|
51
|
+
*
|
52
|
+
* Returns the number of bytes in the encoded pickle.
|
53
|
+
*/
|
54
|
+
size_t _olm_enc_output(
|
55
|
+
uint8_t const * key, size_t key_length,
|
56
|
+
uint8_t *pickle, size_t raw_length
|
57
|
+
);
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Decode and decrypt the given pickle in-situ.
|
61
|
+
*
|
62
|
+
* Returns the number of bytes in the decoded pickle, or olm_error() on error,
|
63
|
+
* in which case *last_error will be updated, if last_error is non-NULL.
|
64
|
+
*/
|
65
|
+
size_t _olm_enc_input(
|
66
|
+
uint8_t const * key, size_t key_length,
|
67
|
+
uint8_t * input, size_t b64_length,
|
68
|
+
enum OlmErrorCode * last_error
|
69
|
+
);
|
70
|
+
|
71
|
+
|
72
|
+
#ifdef __cplusplus
|
73
|
+
} // extern "C"
|
74
|
+
#endif
|
75
|
+
|
76
|
+
#endif /* OLM_PICKLE_ENCODING_H_ */
|
@@ -0,0 +1,214 @@
|
|
1
|
+
/* Copyright 2018 New Vector 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_PK_H_
|
17
|
+
#define OLM_PK_H_
|
18
|
+
|
19
|
+
#include <stddef.h>
|
20
|
+
#include <stdint.h>
|
21
|
+
|
22
|
+
#ifdef __cplusplus
|
23
|
+
extern "C" {
|
24
|
+
#endif
|
25
|
+
|
26
|
+
typedef struct OlmPkEncryption OlmPkEncryption;
|
27
|
+
|
28
|
+
/* The size of an encryption object in bytes */
|
29
|
+
size_t olm_pk_encryption_size(void);
|
30
|
+
|
31
|
+
/** Initialise an encryption object using the supplied memory
|
32
|
+
* The supplied memory must be at least olm_pk_encryption_size() bytes */
|
33
|
+
OlmPkEncryption *olm_pk_encryption(
|
34
|
+
void * memory
|
35
|
+
);
|
36
|
+
|
37
|
+
/** A null terminated string describing the most recent error to happen to an
|
38
|
+
* encryption object */
|
39
|
+
const char * olm_pk_encryption_last_error(
|
40
|
+
OlmPkEncryption * encryption
|
41
|
+
);
|
42
|
+
|
43
|
+
/** Clears the memory used to back this encryption object */
|
44
|
+
size_t olm_clear_pk_encryption(
|
45
|
+
OlmPkEncryption *encryption
|
46
|
+
);
|
47
|
+
|
48
|
+
/** Set the recipient's public key for encrypting to */
|
49
|
+
size_t olm_pk_encryption_set_recipient_key(
|
50
|
+
OlmPkEncryption *encryption,
|
51
|
+
void const *public_key, size_t public_key_length
|
52
|
+
);
|
53
|
+
|
54
|
+
/** Get the length of the ciphertext that will correspond to a plaintext of the
|
55
|
+
* given length. */
|
56
|
+
size_t olm_pk_ciphertext_length(
|
57
|
+
OlmPkEncryption *encryption,
|
58
|
+
size_t plaintext_length
|
59
|
+
);
|
60
|
+
|
61
|
+
/** Get the length of the message authentication code. */
|
62
|
+
size_t olm_pk_mac_length(
|
63
|
+
OlmPkEncryption *encryption
|
64
|
+
);
|
65
|
+
|
66
|
+
/** Get the length of a public or ephemeral key */
|
67
|
+
size_t olm_pk_key_length(void);
|
68
|
+
|
69
|
+
/** The number of random bytes needed to encrypt a message. */
|
70
|
+
size_t olm_pk_encrypt_random_length(
|
71
|
+
OlmPkEncryption *encryption
|
72
|
+
);
|
73
|
+
|
74
|
+
/** Encrypt a plaintext for the recipient set using
|
75
|
+
* olm_pk_encryption_set_recipient_key. Writes to the ciphertext, mac, and
|
76
|
+
* ephemeral_key buffers, whose values should be sent to the recipient. mac is
|
77
|
+
* a Message Authentication Code to ensure that the data is received and
|
78
|
+
* decrypted properly. ephemeral_key is the public part of the ephemeral key
|
79
|
+
* used (together with the recipient's key) to generate a symmetric encryption
|
80
|
+
* key. Returns olm_error() on failure. If the ciphertext, mac, or
|
81
|
+
* ephemeral_key buffers were too small then olm_pk_encryption_last_error()
|
82
|
+
* will be "OUTPUT_BUFFER_TOO_SMALL". If there weren't enough random bytes then
|
83
|
+
* olm_pk_encryption_last_error() will be "OLM_INPUT_BUFFER_TOO_SMALL". */
|
84
|
+
size_t olm_pk_encrypt(
|
85
|
+
OlmPkEncryption *encryption,
|
86
|
+
void const * plaintext, size_t plaintext_length,
|
87
|
+
void * ciphertext, size_t ciphertext_length,
|
88
|
+
void * mac, size_t mac_length,
|
89
|
+
void * ephemeral_key, size_t ephemeral_key_size,
|
90
|
+
void * random, size_t random_length
|
91
|
+
);
|
92
|
+
|
93
|
+
typedef struct OlmPkDecryption OlmPkDecryption;
|
94
|
+
|
95
|
+
/* The size of a decryption object in bytes */
|
96
|
+
size_t olm_pk_decryption_size(void);
|
97
|
+
|
98
|
+
/** Initialise a decryption object using the supplied memory
|
99
|
+
* The supplied memory must be at least olm_pk_decryption_size() bytes */
|
100
|
+
OlmPkDecryption *olm_pk_decryption(
|
101
|
+
void * memory
|
102
|
+
);
|
103
|
+
|
104
|
+
/** A null terminated string describing the most recent error to happen to a
|
105
|
+
* decription object */
|
106
|
+
const char * olm_pk_decryption_last_error(
|
107
|
+
OlmPkDecryption * decryption
|
108
|
+
);
|
109
|
+
|
110
|
+
/** Clears the memory used to back this decryption object */
|
111
|
+
size_t olm_clear_pk_decryption(
|
112
|
+
OlmPkDecryption *decryption
|
113
|
+
);
|
114
|
+
|
115
|
+
/** Get the number of bytes required to store an olm private key
|
116
|
+
*/
|
117
|
+
size_t olm_pk_private_key_length(void);
|
118
|
+
|
119
|
+
/** DEPRECATED: Use olm_pk_private_key_length()
|
120
|
+
*/
|
121
|
+
size_t olm_pk_generate_key_random_length(void);
|
122
|
+
|
123
|
+
/** Initialise the key from the private part of a key as returned by
|
124
|
+
* olm_pk_get_private_key(). The associated public key will be written to the
|
125
|
+
* pubkey buffer. Returns olm_error() on failure. If the pubkey buffer is too
|
126
|
+
* small then olm_pk_decryption_last_error() will be "OUTPUT_BUFFER_TOO_SMALL".
|
127
|
+
* If the private key was not long enough then olm_pk_decryption_last_error()
|
128
|
+
* will be "OLM_INPUT_BUFFER_TOO_SMALL".
|
129
|
+
*
|
130
|
+
* Note that the pubkey is a base64 encoded string, but the private key is
|
131
|
+
* an unencoded byte array
|
132
|
+
*/
|
133
|
+
size_t olm_pk_key_from_private(
|
134
|
+
OlmPkDecryption * decryption,
|
135
|
+
void * pubkey, size_t pubkey_length,
|
136
|
+
void * privkey, size_t privkey_length
|
137
|
+
);
|
138
|
+
|
139
|
+
/** DEPRECATED: Use olm_pk_key_from_private
|
140
|
+
*/
|
141
|
+
size_t olm_pk_generate_key(
|
142
|
+
OlmPkDecryption * decryption,
|
143
|
+
void * pubkey, size_t pubkey_length,
|
144
|
+
void * privkey, size_t privkey_length
|
145
|
+
);
|
146
|
+
|
147
|
+
/** Returns the number of bytes needed to store a decryption object. */
|
148
|
+
size_t olm_pickle_pk_decryption_length(
|
149
|
+
OlmPkDecryption * decryption
|
150
|
+
);
|
151
|
+
|
152
|
+
/** Stores decryption object as a base64 string. Encrypts the object using the
|
153
|
+
* supplied key. Returns the length of the pickled object on success.
|
154
|
+
* Returns olm_error() on failure. If the pickle output buffer
|
155
|
+
* is smaller than olm_pickle_account_length() then
|
156
|
+
* olm_pk_decryption_last_error() will be "OUTPUT_BUFFER_TOO_SMALL" */
|
157
|
+
size_t olm_pickle_pk_decryption(
|
158
|
+
OlmPkDecryption * decryption,
|
159
|
+
void const * key, size_t key_length,
|
160
|
+
void *pickled, size_t pickled_length
|
161
|
+
);
|
162
|
+
|
163
|
+
/** Loads a decryption object from a pickled base64 string. The associated
|
164
|
+
* public key will be written to the pubkey buffer. Decrypts the object using
|
165
|
+
* the supplied key. Returns olm_error() on failure. If the key doesn't
|
166
|
+
* match the one used to encrypt the account then olm_pk_decryption_last_error()
|
167
|
+
* will be "BAD_ACCOUNT_KEY". If the base64 couldn't be decoded then
|
168
|
+
* olm_pk_decryption_last_error() will be "INVALID_BASE64". The input pickled
|
169
|
+
* buffer is destroyed */
|
170
|
+
size_t olm_unpickle_pk_decryption(
|
171
|
+
OlmPkDecryption * decryption,
|
172
|
+
void const * key, size_t key_length,
|
173
|
+
void *pickled, size_t pickled_length,
|
174
|
+
void *pubkey, size_t pubkey_length
|
175
|
+
);
|
176
|
+
|
177
|
+
/** Get the length of the plaintext that will correspond to a ciphertext of the
|
178
|
+
* given length. */
|
179
|
+
size_t olm_pk_max_plaintext_length(
|
180
|
+
OlmPkDecryption * decryption,
|
181
|
+
size_t ciphertext_length
|
182
|
+
);
|
183
|
+
|
184
|
+
/** Decrypt a ciphertext. The input ciphertext buffer is destroyed. See the
|
185
|
+
* olm_pk_encrypt function for descriptions of the ephemeral_key and mac
|
186
|
+
* arguments. Returns the length of the plaintext on success. Returns
|
187
|
+
* olm_error() on failure. If the plaintext buffer is too small then
|
188
|
+
* olm_pk_encryption_last_error() will be "OUTPUT_BUFFER_TOO_SMALL". */
|
189
|
+
size_t olm_pk_decrypt(
|
190
|
+
OlmPkDecryption * decryption,
|
191
|
+
void const * ephemeral_key, size_t ephemeral_key_length,
|
192
|
+
void const * mac, size_t mac_length,
|
193
|
+
void * ciphertext, size_t ciphertext_length,
|
194
|
+
void * plaintext, size_t max_plaintext_length
|
195
|
+
);
|
196
|
+
|
197
|
+
/**
|
198
|
+
* Get the private key for an OlmDecryption object as an unencoded byte array
|
199
|
+
* private_key must be a pointer to a buffer of at least
|
200
|
+
* olm_pk_private_key_length() bytes and this length must be passed in
|
201
|
+
* private_key_length. If the given buffer is too small, returns olm_error()
|
202
|
+
* and olm_pk_encryption_last_error() will be "OUTPUT_BUFFER_TOO_SMALL".
|
203
|
+
* Returns the number of bytes written.
|
204
|
+
*/
|
205
|
+
size_t olm_pk_get_private_key(
|
206
|
+
OlmPkDecryption * decryption,
|
207
|
+
void *private_key, size_t private_key_length
|
208
|
+
);
|
209
|
+
|
210
|
+
#ifdef __cplusplus
|
211
|
+
}
|
212
|
+
#endif
|
213
|
+
|
214
|
+
#endif /* OLM_PK_H_ */
|