aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.rst23
-rwxr-xr-xbuild_shared_library.py2
-rw-r--r--docs/Axolotl.svg6
-rw-r--r--include/axolotl/axolotl.hh295
-rw-r--r--include/olm/account.hh (renamed from include/axolotl/account.hh)16
-rw-r--r--include/olm/base64.hh (renamed from include/axolotl/base64.hh)4
-rw-r--r--include/olm/cipher.hh (renamed from include/axolotl/cipher.hh)8
-rw-r--r--include/olm/crypto.hh (renamed from include/axolotl/crypto.hh)10
-rw-r--r--include/olm/error.hh (renamed from include/axolotl/error.hh)4
-rw-r--r--include/olm/list.hh (renamed from include/axolotl/list.hh)10
-rw-r--r--include/olm/memory.hh (renamed from include/axolotl/memory.hh)4
-rw-r--r--include/olm/message.hh (renamed from include/axolotl/message.hh)4
-rw-r--r--include/olm/olm.hh295
-rw-r--r--include/olm/pickle.hh (renamed from include/axolotl/pickle.hh)20
-rw-r--r--include/olm/ratchet.hh (renamed from include/axolotl/ratchet.hh)10
-rw-r--r--include/olm/session.hh (renamed from include/axolotl/session.hh)12
-rw-r--r--javascript/axolotl_pre.js1
-rwxr-xr-xjavascript/build.py6
-rw-r--r--javascript/demo.html10
-rw-r--r--javascript/olm_post.js (renamed from javascript/axolotl_post.js)66
-rw-r--r--javascript/olm_pre.js1
-rwxr-xr-xolm.py (renamed from axolotl.py)136
-rw-r--r--src/account.cpp88
-rw-r--r--src/base64.cpp10
-rw-r--r--src/cipher.cpp46
-rw-r--r--src/crypto.cpp70
-rw-r--r--src/memory.cpp6
-rw-r--r--src/message.cpp20
-rw-r--r--src/olm.cpp (renamed from src/axolotl.cpp)234
-rw-r--r--src/pickle.cpp38
-rw-r--r--src/ratchet.cpp258
-rw-r--r--src/session.cpp170
-rw-r--r--tests/test_axolotl.cpp269
-rw-r--r--tests/test_base64.cpp10
-rw-r--r--tests/test_crypto.cpp44
-rw-r--r--tests/test_list.cpp6
-rw-r--r--tests/test_message.cpp12
-rw-r--r--tests/test_olm.cpp269
-rw-r--r--tests/test_ratchet.cpp36
39 files changed, 1268 insertions, 1261 deletions
diff --git a/README.rst b/README.rst
index c5b7ba8..3a382ab 100644
--- a/README.rst
+++ b/README.rst
@@ -1,5 +1,5 @@
-Axolotlpp
-=========
+Olm
+===
An implementation of the axolotl ratchet as described by
https://github.com/trevp/axolotl/wiki, written in C++11 and exposed as a C API
@@ -7,7 +7,7 @@ https://github.com/trevp/axolotl/wiki, written in C++11 and exposed as a C API
Building
--------
-To build axolotlpp as a shared library run:
+To build olm as a shared library run:
.. code:: bash
@@ -29,19 +29,19 @@ To build the javascript bindings run:
Design
------
-Axolotlpp is designed to be easy port to different platforms and to be easy
+Olm is designed to be easy port to different platforms and to be easy
to write bindings for.
Error Handling
~~~~~~~~~~~~~~
-All C functions in the API for axolotlpp return ``axolotl_error()`` on error.
+All C functions in the API for olm return ``olm_error()`` on error.
This makes it easy to check for error conditions within the language bindings.
Random Numbers
~~~~~~~~~~~~~~
-Axolotlpp doesn't generate random numbers itself. Instead the caller must
+Olm doesn't generate random numbers itself. Instead the caller must
provide the random data. This makes it easier to port the library to different
platforms since the caller can use whatever cryptographic random number
generator their platform provides.
@@ -49,7 +49,7 @@ generator their platform provides.
Memory
~~~~~~
-Axolotlpp avoids calling malloc or allocating memory on the heap itself.
+Olm avoids calling malloc or allocating memory on the heap itself.
Instead the library calculates how much memory will be needed to hold the
output and the caller supplies a buffer of the appropriate size.
@@ -62,6 +62,13 @@ strings will find it easier to handle the output.
Dependencies
~~~~~~~~~~~~
-Axolotlpp uses pure C implementations of the cryptographic primitives used by
+Olm uses pure C implementations of the cryptographic primitives used by
the ratchet. While this decreases the performance it makes it much easier
to compile the library for different architectures.
+
+What's an olm?
+~~~~~~~~~~~~~~
+
+It's a really cool species of European troglodytic salamander.
+Matthew once tried to climb into a pool full of them in Postojnska Jama.
+http://www.postojnska-jama.eu/en/about-the-cave/meet-the-dragon-s-offspring/
diff --git a/build_shared_library.py b/build_shared_library.py
index 1081846..6dbafcd 100755
--- a/build_shared_library.py
+++ b/build_shared_library.py
@@ -25,7 +25,7 @@ source_files = glob.glob("src/*.cpp")
compile_args = "g++ -O0 -g -Iinclude -Ilib --std=c++11 --shared -fPIC".split()
compile_args += source_files
-library = "build/libaxolotl.so"
+library = "build/libolm.so"
def run(args):
print " ".join(args)
diff --git a/docs/Axolotl.svg b/docs/Axolotl.svg
index 934f3ab..26ee8c3 100644
--- a/docs/Axolotl.svg
+++ b/docs/Axolotl.svg
@@ -229,7 +229,7 @@
y="-64"
x="32"
id="tspan4814"
- sodipodi:role="line">&quot;AXOLOTL_ROOT&quot;</tspan></text>
+ sodipodi:role="line">&quot;OLM_ROOT&quot;</tspan></text>
</g>
<g
transform="translate(64,0)"
@@ -622,7 +622,7 @@
sodipodi:role="line"
id="tspan4695"
x="32"
- y="-64">&quot;AXOLOTL_KEYS&quot;</tspan></text>
+ y="-64">&quot;OLM_KEYS&quot;</tspan></text>
</g>
<text
xml:space="preserve"
@@ -848,7 +848,7 @@
sodipodi:role="line"
id="tspan4904"
x="32"
- y="-64">&quot;AXOLOTL_RATCHET&quot;</tspan></text>
+ y="-64">&quot;OLM_RATCHET&quot;</tspan></text>
</g>
<g
id="g4906"
diff --git a/include/axolotl/axolotl.hh b/include/axolotl/axolotl.hh
deleted file mode 100644
index 90065a7..0000000
--- a/include/axolotl/axolotl.hh
+++ /dev/null
@@ -1,295 +0,0 @@
-/* Copyright 2015 OpenMarket Ltd
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef AXOLOTL_HH_
-#define AXOLOTL_HH_
-
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-static const size_t AXOLOTL_MESSAGE_TYPE_PRE_KEY = 0;
-static const size_t AXOLOTL_MESSAGE_TYPE_MESSAGE = 1;
-
-struct AxolotlAccount;
-struct AxolotlSession;
-
-/** The size of an account object in bytes */
-size_t axolotl_account_size();
-
-/** The size of a session object in bytes */
-size_t axolotl_session_size();
-
-/** Initialise an account object using the supplied memory
- * The supplied memory must be at least axolotl_account_size() bytes */
-AxolotlAccount * axolotl_account(
- void * memory
-);
-
-/** Initialise a session object using the supplied memory
- * The supplied memory must be at least axolotl_session_size() bytes */
-AxolotlSession * axolotl_session(
- void * memory
-);
-
-/** The value that axolotl will return from a function if there was an error */
-size_t axolotl_error();
-
-/** A null terminated string describing the most recent error to happen to an
- * account */
-const char * axolotl_account_last_error(
- AxolotlSession * account
-);
-
-/** A null terminated string describing the most recent error to happen to a
- * session */
-const char * axolotl_session_last_error(
- AxolotlSession * session
-);
-
-/** Returns the number of bytes needed to store an account */
-size_t axolotl_pickle_account_length(
- AxolotlAccount * account
-);
-
-/** Returns the number of bytes needed to store a session */
-size_t axolotl_pickle_session_length(
- AxolotlSession * session
-);
-
-/** Stores an account as a base64 string. Encrypts the account using the
- * supplied key. Returns the length of the pickled account on success.
- * Returns axolotl_error() on failure. If the pickle output buffer
- * is smaller than axolotl_pickle_account_length() then
- * axolotl_account_last_error() will be "OUTPUT_BUFFER_TOO_SMALL" */
-size_t axolotl_pickle_account(
- AxolotlAccount * account,
- void const * key, size_t key_length,
- void * pickled, size_t pickled_length
-);
-
-/** Stores a session as a base64 string. Encrypts the session using the
- * supplied key. Returns the length of the pickled session on success.
- * Returns axolotl_error() on failure. If the pickle output buffer
- * is smaller than axolotl_pickle_session_length() then
- * axolotl_session_last_error() will be "OUTPUT_BUFFER_TOO_SMALL" */
-size_t axolotl_pickle_session(
- AxolotlSession * session,
- void const * key, size_t key_length,
- void * pickled, size_t pickled_length
-);
-
-/** Loads an account from a pickled base64 string. Decrypts the account using
- * the supplied key. Returns axolotl_error() on failure. If the key doesn't
- * match the one used to encrypt the account then axolotl_account_last_error()
- * will be "BAD_ACCOUNT_KEY". If the base64 couldn't be decoded then
- * axolotl_account_last_error() will be "INVALID_BASE64". The input pickled
- * buffer is destroyed */
-size_t axolotl_unpickle_account(
- AxolotlAccount * account,
- void const * key, size_t key_length,
- void * pickled, size_t pickled_length
-);
-
-/** Loads a session from a pickled base64 string. Decrypts the session using
- * the supplied key. Returns axolotl_error() on failure. If the key doesn't
- * match the one used to encrypt the account then axolotl_session_last_error()
- * will be "BAD_ACCOUNT_KEY". If the base64 couldn't be decoded then
- * axolotl_session_last_error() will be "INVALID_BASE64". The input pickled
- * buffer is destroyed */
-size_t axolotl_unpickle_session(
- AxolotlSession * session,
- void const * key, size_t key_length,
- void * pickled, size_t pickled_length
-);
-
-/** The number of random bytes needed to create an account.*/
-size_t axolotl_create_account_random_length(
- AxolotlAccount * account
-);
-
-/** Creates a new account. Returns axolotl_error() on failure. If weren't
- * enough random bytes then axolotl_account_last_error() will be
- * "NOT_ENOUGH_RANDOM" */
-size_t axolotl_create_account(
- AxolotlAccount * account,
- void const * random, size_t random_length
-);
-
-/** The size of the output buffer needed to hold the identity keys */
-size_t axolotl_account_identity_keys_length(
- AxolotlAccount * account
-);
-
-/** Writes the public parts of the identity keys for the account into the
- * identity_keys output buffer. The output is formatted as though it was
- * created with sprintf(output, "[[%10d,\"%43s\"]\n]", key_id, key_base64).
- * The output can either be parsed as fixed width using the above format or by
- * a JSON parser. Returns axolotl_error() on failure. If the identity_keys
- * buffer was too small then axolotl_account_last_error() will be
- * "OUTPUT_BUFFER_TOO_SMALL". */
-size_t axolotl_account_identity_keys(
- AxolotlAccount * account,
- void * identity_keys, size_t identity_key_length
-);
-
-/** The size of the output buffer needed to hold the one time keys */
-size_t axolotl_account_one_time_keys_length(
- AxolotlAccount * account
-);
-
-/** Writes the public parts of the one time keys for the account into the
- * one_time_keys output buffer. The first key will be formatted as though it was
- * created with sprintf(output, "[[%10d,\"%43s\"]\n", key_id, key_base64).
- * subsequent keys are formatted with ",[%10d,\"%43s\"]\n". The final byte of
- * output will be "]". The output can either be parsed as fixed width using
- * the above format or by a JSON parser. Returns axolotl_error() on failure.
- * If the one_time_keys buffer was too small then axolotl_account_last_error()
- * will be "OUTPUT_BUFFER_TOO_SMALL". */
-size_t axolotl_account_one_time_keys(
- AxolotlAccount * account,
- void * one_time_keys, size_t one_time_keys_length
-);
-
-/* TODO: Add methods for marking keys as used, generating new keys, and
- * tracking which keys have been uploaded to the central servers */
-
-/** The number of random bytes needed to create an outbound session */
-size_t axolotl_create_outbound_session_random_length(
- AxolotlSession * session
-);
-
-/** Creates a new out-bound session for sending messages to a given identity_key
- * and one_time_key. Returns axolotl_error() on failure. If the keys couldn't be
- * decoded as base64 then axolotl_session_last_error() will be "INVALID_BASE64"
- * If there weren't enough random bytes then axolotl_session_last_error() will
- * be "NOT_ENOUGH_RANDOM". */
-size_t axolotl_create_outbound_session(
- AxolotlSession * session,
- AxolotlAccount * account,
- void const * their_identity_key, size_t their_identity_key_length,
- unsigned their_one_time_key_id,
- void const * their_one_time_key, size_t their_one_time_key_length,
- void const * random, size_t random_length
-);
-
-/** Create a new in-bound session for sending/receiving messages from an
- * incoming PRE_KEY message. Returns axolotl_error() on failure. If the base64
- * couldn't be decoded then axolotl_session_last_error will be "INVALID_BASE64".
- * If the message was for an unsupported protocol version then
- * axolotl_session_last_error() will be "BAD_MESSAGE_VERSION". If the message
- * couldn't be decoded then then axolotl_session_last_error() will be
- * "BAD_MESSAGE_FORMAT". If the message refers to an unknown one time
- * key then axolotl_session_last_error() will be "BAD_MESSAGE_KEY_ID". */
-size_t axolotl_create_inbound_session(
- AxolotlSession * session,
- AxolotlAccount * account,
- void * one_time_key_message, size_t message_length
-);
-
-/** Checks if the PRE_KEY message is for this in-bound session. This can happen
- * if multiple messages are sent to this account before this account sends a
- * message in reply. Returns axolotl_error() on failure. If the base64
- * couldn't be decoded then axolotl_session_last_error will be "INVALID_BASE64".
- * If the message was for an unsupported protocol version then
- * axolotl_session_last_error() will be "BAD_MESSAGE_VERSION". If the message
- * couldn't be decoded then then axolotl_session_last_error() will be
- * "BAD_MESSAGE_FORMAT". */
-size_t axolotl_matches_inbound_session(
- AxolotlSession * session,
- void * one_time_key_message, size_t message_length
-);
-
-/** Removes the one time keys that the session used from the account. Returns
- * axolotl_error() on failure. If the account doesn't have any matching one time
- * keys then axolotl_account_last_error() will be "BAD_MESSAGE_KEY_ID". */
-size_t axolotl_remove_one_time_keys(
- AxolotlAccount * account,
- AxolotlSession * session
-);
-
-/** The type of the next message that axolotl_encrypt() will return. Returns
- * AXOLOTL_MESSAGE_TYPE_PRE_KEY if the message will be a PRE_KEY message.
- * Returns AXOLOTL_MESSAGE_TYPE_MESSAGE if the message will be a normal message.
- * Returns axolotl_error on failure. */
-size_t axolotl_encrypt_message_type(
- AxolotlSession * session
-);
-
-/** The number of random bytes needed to encrypt the next message. */
-size_t axolotl_encrypt_random_length(
- AxolotlSession * session
-);
-
-/** The size of the next message in bytes for the given number of plain-text
- * bytes. */
-size_t axolotl_encrypt_message_length(
- AxolotlSession * session,
- size_t plaintext_length
-);
-
-/** Encrypts a message using the session. Returns the length of the message in
- * bytes on success. Writes the message as base64 into the message buffer.
- * Returns axolotl_error() on failure. If the message buffer is too small then
- * axolotl_session_last_error() will be "OUTPUT_BUFFER_TOO_SMALL". If there
- * weren't enough random bytes then axolotl_session_last_error() will be
- * "NOT_ENOUGH_RANDOM". */
-size_t axolotl_encrypt(
- AxolotlSession * session,
- void const * plaintext, size_t plaintext_length,
- void const * random, size_t random_length,
- void * message, size_t message_length
-);
-
-/** The maximum number of bytes of plain-text a given message could decode to.
- * The actual size could be different due to padding. The input message buffer
- * is destroyed. Returns axolotl_error() on failure. If the message base64
- * couldn't be decoded then axolotl_session_last_error() will be
- * "INVALID_BASE64". If the message is for an unsupported version of the
- * protocol then axolotl_session_last_error() will be "BAD_MESSAGE_VERSION".
- * If the message couldn't be decoded then axolotl_session_last_error() will be
- * "BAD_MESSAGE_FORMAT". */
-size_t axolotl_decrypt_max_plaintext_length(
- AxolotlSession * session,
- size_t message_type,
- void * message, size_t message_length
-);
-
-/** Decrypts a message using the session. The input message buffer is destroyed.
- * Returns the length of the plain-text on success. Returns axolotl_error() on
- * failure. If the plain-text buffer is smaller than
- * axolotl_decrypt_max_plaintext_length() then axolotl_session_last_error()
- * will be "OUTPUT_BUFFER_TOO_SMALL". If the base64 couldn't be decoded then
- * axolotl_session_last_error() will be "INVALID_BASE64". If the message is for
- * an unsupported version of the protocol then axolotl_session_last_error() will
- * be "BAD_MESSAGE_VERSION". If the message couldn't be decoded then
- * axolotl_session_last_error() will be BAD_MESSAGE_FORMAT".
- * If the MAC on the message was invalid then axolotl_session_last_error() will
- * be "BAD_MESSAGE_MAC". */
-size_t axolotl_decrypt(
- AxolotlSession * session,
- size_t message_type,
- void * message, size_t message_length,
- void * plaintext, size_t max_plaintext_length
-);
-
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* AXOLOTL_HH_ */
diff --git a/include/axolotl/account.hh b/include/olm/account.hh
index 54621fd..8094a25 100644
--- a/include/axolotl/account.hh
+++ b/include/olm/account.hh
@@ -12,16 +12,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef AXOLOTL_ACCOUNT_HH_
-#define AXOLOTL_ACCOUNT_HH_
+#ifndef OLM_ACCOUNT_HH_
+#define OLM_ACCOUNT_HH_
-#include "axolotl/list.hh"
-#include "axolotl/crypto.hh"
-#include "axolotl/error.hh"
+#include "olm/list.hh"
+#include "olm/crypto.hh"
+#include "olm/error.hh"
#include <cstdint>
-namespace axolotl {
+namespace olm {
struct LocalKey {
@@ -79,6 +79,6 @@ std::uint8_t const * unpickle(
);
-} // namespace axolotl
+} // namespace olm
-#endif /* AXOLOTL_ACCOUNT_HH_ */
+#endif /* OLM_ACCOUNT_HH_ */
diff --git a/include/axolotl/base64.hh b/include/olm/base64.hh
index 361a558..0a7435b 100644
--- a/include/axolotl/base64.hh
+++ b/include/olm/base64.hh
@@ -18,7 +18,7 @@
#include <cstddef>
#include <cstdint>
-namespace axolotl {
+namespace olm {
std::size_t encode_base64_length(
@@ -43,7 +43,7 @@ void decode_base64(
);
-} // namespace axolotl
+} // namespace olm
#endif /* AXOLOLT_BASE64_HH_ */
diff --git a/include/axolotl/cipher.hh b/include/olm/cipher.hh
index 5a077aa..f71b3af 100644
--- a/include/axolotl/cipher.hh
+++ b/include/olm/cipher.hh
@@ -13,13 +13,13 @@
* limitations under the License.
*/
-#ifndef AXOLOTL_CIPHER_HH_
-#define AXOLOTL_CIPHER_HH_
+#ifndef OLM_CIPHER_HH_
+#define OLM_CIPHER_HH_
#include <cstdint>
#include <cstddef>
-namespace axolotl {
+namespace olm {
class Cipher {
public:
@@ -125,4 +125,4 @@ private:
} // namespace
-#endif /* AXOLOTL_CIPHER_HH_ */
+#endif /* OLM_CIPHER_HH_ */
diff --git a/include/axolotl/crypto.hh b/include/olm/crypto.hh
index 7564e8f..b299e12 100644
--- a/include/axolotl/crypto.hh
+++ b/include/olm/crypto.hh
@@ -12,13 +12,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef AXOLOTL_CRYPTO_HH_
-#define AXOLOTL_CRYPTO_HH_
+#ifndef OLM_CRYPTO_HH_
+#define OLM_CRYPTO_HH_
#include <cstdint>
#include <cstddef>
-namespace axolotl {
+namespace olm {
struct Curve25519PublicKey {
@@ -143,6 +143,6 @@ void hkdf_sha256(
std::uint8_t * output, std::size_t output_length
);
-} // namespace axolotl
+} // namespace olm
-#endif /* AXOLOTL_CRYPTO_HH_ */
+#endif /* OLM_CRYPTO_HH_ */
diff --git a/include/axolotl/error.hh b/include/olm/error.hh
index 781705e..960de72 100644
--- a/include/axolotl/error.hh
+++ b/include/olm/error.hh
@@ -15,7 +15,7 @@
#ifndef ERROR_HH_
#define ERROR_HH_
-namespace axolotl {
+namespace olm {
enum struct ErrorCode {
SUCCESS = 0, /*!< There wasn't an error */
@@ -29,6 +29,6 @@ enum struct ErrorCode {
BAD_ACCOUNT_KEY = 8, /*!< The supplied account key is invalid */
};
-} // namespace axolotl
+} // namespace olm
#endif /* ERROR_HH_ */
diff --git a/include/axolotl/list.hh b/include/olm/list.hh
index 604f00f..e4bf951 100644
--- a/include/axolotl/list.hh
+++ b/include/olm/list.hh
@@ -12,12 +12,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef AXOLOTL_LIST_HH_
-#define AXOLOTL_LIST_HH_
+#ifndef OLM_LIST_HH_
+#define OLM_LIST_HH_
#include <cstddef>
-namespace axolotl {
+namespace olm {
template<typename T, std::size_t max_size>
class List {
@@ -114,6 +114,6 @@ private:
T _data[max_size];
};
-} // namespace axolotl
+} // namespace olm
-#endif /* AXOLOTL_LIST_HH_ */
+#endif /* OLM_LIST_HH_ */
diff --git a/include/axolotl/memory.hh b/include/olm/memory.hh
index 68b577d..b19c74b 100644
--- a/include/axolotl/memory.hh
+++ b/include/olm/memory.hh
@@ -15,7 +15,7 @@
#include <cstddef>
#include <cstdint>
-namespace axolotl {
+namespace olm {
/** Clear the memory held in the buffer */
void unset(
@@ -35,4 +35,4 @@ bool is_equal(
std::size_t length
);
-} // namespace axolotl
+} // namespace olm
diff --git a/include/axolotl/message.hh b/include/olm/message.hh
index 4d7a1c7..fefdd20 100644
--- a/include/axolotl/message.hh
+++ b/include/olm/message.hh
@@ -16,7 +16,7 @@
#include <cstdint>
-namespace axolotl {
+namespace olm {
/**
* The length of the buffer needed to hold a message.
@@ -123,4 +123,4 @@ void decode_one_time_key_message(
);
-} // namespace axolotl
+} // namespace olm
diff --git a/include/olm/olm.hh b/include/olm/olm.hh
new file mode 100644
index 0000000..fca35c4
--- /dev/null
+++ b/include/olm/olm.hh
@@ -0,0 +1,295 @@
+/* Copyright 2015 OpenMarket Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef OLM_HH_
+#define OLM_HH_
+
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static const size_t OLM_MESSAGE_TYPE_PRE_KEY = 0;
+static const size_t OLM_MESSAGE_TYPE_MESSAGE = 1;
+
+struct OlmAccount;
+struct OlmSession;
+
+/** The size of an account object in bytes */
+size_t olm_account_size();
+
+/** The size of a session object in bytes */
+size_t olm_session_size();
+
+/** Initialise an account object using the supplied memory
+ * The supplied memory must be at least olm_account_size() bytes */
+OlmAccount * olm_account(
+ void * memory
+);
+
+/** Initialise a session object using the supplied memory
+ * The supplied memory must be at least olm_session_size() bytes */
+OlmSession * olm_session(
+ void * memory
+);
+
+/** The value that olm will return from a function if there was an error */
+size_t olm_error();
+
+/** A null terminated string describing the most recent error to happen to an
+ * account */
+const char * olm_account_last_error(
+ OlmSession * account
+);
+
+/** A null terminated string describing the most recent error to happen to a
+ * session */
+const char * olm_session_last_error(
+ OlmSession * session
+);
+
+/** Returns the number of bytes needed to store an account */
+size_t olm_pickle_account_length(
+ OlmAccount * account
+);
+
+/** Returns the number of bytes needed to store a session */
+size_t olm_pickle_session_length(
+ OlmSession * session
+);
+
+/** Stores an account as a base64 string. Encrypts the account using the
+ * supplied key. Returns the length of the pickled account on success.
+ * Returns olm_error() on failure. If the pickle output buffer
+ * is smaller than olm_pickle_account_length() then
+ * olm_account_last_error() will be "OUTPUT_BUFFER_TOO_SMALL" */
+size_t olm_pickle_account(
+ OlmAccount * account,
+ void const * key, size_t key_length,
+ void * pickled, size_t pickled_length
+);
+
+/** Stores a session as a base64 string. Encrypts the session using the
+ * supplied key. Returns the length of the pickled session on success.
+ * Returns olm_error() on failure. If the pickle output buffer
+ * is smaller than olm_pickle_session_length() then
+ * olm_session_last_error() will be "OUTPUT_BUFFER_TOO_SMALL" */
+size_t olm_pickle_session(
+ OlmSession * session,
+ void const * key, size_t key_length,
+ void * pickled, size_t pickled_length
+);
+
+/** Loads an account from a pickled base64 string. Decrypts the account using
+ * the supplied key. Returns olm_error() on failure. If the key doesn't
+ * match the one used to encrypt the account then olm_account_last_error()
+ * will be "BAD_ACCOUNT_KEY". If the base64 couldn't be decoded then
+ * olm_account_last_error() will be "INVALID_BASE64". The input pickled
+ * buffer is destroyed */
+size_t olm_unpickle_account(
+ OlmAccount * account,
+ void const * key, size_t key_length,
+ void * pickled, size_t pickled_length
+);
+
+/** Loads a session from a pickled base64 string. Decrypts the session using
+ * the supplied key. Returns olm_error() on failure. If the key doesn't
+ * match the one used to encrypt the account then olm_session_last_error()
+ * will be "BAD_ACCOUNT_KEY". If the base64 couldn't be decoded then
+ * olm_session_last_error() will be "INVALID_BASE64". The input pickled
+ * buffer is destroyed */
+size_t olm_unpickle_session(
+ OlmSession * session,
+ void const * key, size_t key_length,
+ void * pickled, size_t pickled_length
+);
+
+/** The number of random bytes needed to create an account.*/
+size_t olm_create_account_random_length(
+ OlmAccount * account
+);
+
+/** Creates a new account. Returns olm_error() on failure. If weren't
+ * enough random bytes then olm_account_last_error() will be
+ * "NOT_ENOUGH_RANDOM" */
+size_t olm_create_account(
+ OlmAccount * account,
+ void const * random, size_t random_length
+);
+
+/** The size of the output buffer needed to hold the identity keys */
+size_t olm_account_identity_keys_length(
+ OlmAccount * account
+);
+
+/** Writes the public parts of the identity keys for the account into the
+ * identity_keys output buffer. The output is formatted as though it was
+ * created with sprintf(output, "[[%10d,\"%43s\"]\n]", key_id, key_base64).
+ * The output can either be parsed as fixed width using the above format or by
+ * a JSON parser. Returns olm_error() on failure. If the identity_keys
+ * buffer was too small then olm_account_last_error() will be
+ * "OUTPUT_BUFFER_TOO_SMALL". */
+size_t olm_account_identity_keys(
+ OlmAccount * account,
+ void * identity_keys, size_t identity_key_length
+);
+
+/** The size of the output buffer needed to hold the one time keys */
+size_t olm_account_one_time_keys_length(
+ OlmAccount * account
+);
+
+/** Writes the public parts of the one time keys for the account into the
+ * one_time_keys output buffer. The first key will be formatted as though it was
+ * created with sprintf(output, "[[%10d,\"%43s\"]\n", key_id, key_base64).
+ * subsequent keys are formatted with ",[%10d,\"%43s\"]\n". The final byte of
+ * output will be "]". The output can either be parsed as fixed width using
+ * the above format or by a JSON parser. Returns olm_error() on failure.
+ * If the one_time_keys buffer was too small then olm_account_last_error()
+ * will be "OUTPUT_BUFFER_TOO_SMALL". */
+size_t olm_account_one_time_keys(
+ OlmAccount * account,
+ void * one_time_keys, size_t one_time_keys_length
+);
+
+/* TODO: Add methods for marking keys as used, generating new keys, and
+ * tracking which keys have been uploaded to the central servers */
+
+/** The number of random bytes needed to create an outbound session */
+size_t olm_create_outbound_session_random_length(
+ OlmSession * session
+);
+
+/** Creates a new out-bound session for sending messages to a given identity_key
+ * and one_time_key. Returns olm_error() on failure. If the keys couldn't be
+ * decoded as base64 then olm_session_last_error() will be "INVALID_BASE64"
+ * If there weren't enough random bytes then olm_session_last_error() will
+ * be "NOT_ENOUGH_RANDOM". */
+size_t olm_create_outbound_session(
+ OlmSession * session,
+ OlmAccount * account,
+ void const * their_identity_key, size_t their_identity_key_length,
+ unsigned their_one_time_key_id,
+ void const * their_one_time_key, size_t their_one_time_key_length,
+ void const * random, size_t random_length
+);
+
+/** Create a new in-bound session for sending/receiving messages from an
+ * incoming PRE_KEY message. Returns olm_error() on failure. If the base64
+ * couldn't be decoded then olm_session_last_error will be "INVALID_BASE64".
+ * If the message was for an unsupported protocol version then
+ * olm_session_last_error() will be "BAD_MESSAGE_VERSION". If the message
+ * couldn't be decoded then then olm_session_last_error() will be
+ * "BAD_MESSAGE_FORMAT". If the message refers to an unknown one time
+ * key then olm_session_last_error() will be "BAD_MESSAGE_KEY_ID". */
+size_t olm_create_inbound_session(
+ OlmSession * session,
+ OlmAccount * account,
+ void * one_time_key_message, size_t message_length
+);
+
+/** Checks if the PRE_KEY message is for this in-bound session. This can happen
+ * if multiple messages are sent to this account before this account sends a
+ * message in reply. Returns olm_error() on failure. If the base64
+ * couldn't be decoded then olm_session_last_error will be "INVALID_BASE64".
+ * If the message was for an unsupported protocol version then
+ * olm_session_last_error() will be "BAD_MESSAGE_VERSION". If the message
+ * couldn't be decoded then then olm_session_last_error() will be
+ * "BAD_MESSAGE_FORMAT". */
+size_t olm_matches_inbound_session(
+ OlmSession * session,
+ void * one_time_key_message, size_t message_length
+);
+
+/** Removes the one time keys that the session used from the account. Returns
+ * olm_error() on failure. If the account doesn't have any matching one time
+ * keys then olm_account_last_error() will be "BAD_MESSAGE_KEY_ID". */
+size_t olm_remove_one_time_keys(
+ OlmAccount * account,
+ OlmSession * session
+);
+
+/** The type of the next message that olm_encrypt() will return. Returns
+ * OLM_MESSAGE_TYPE_PRE_KEY if the message will be a PRE_KEY message.
+ * Returns OLM_MESSAGE_TYPE_MESSAGE if the message will be a normal message.
+ * Returns olm_error on failure. */
+size_t olm_encrypt_message_type(
+ OlmSession * session
+);
+
+/** The number of random bytes needed to encrypt the next message. */
+size_t olm_encrypt_random_length(
+ OlmSession * session
+);
+
+/** The size of the next message in bytes for the given number of plain-text
+ * bytes. */
+size_t olm_encrypt_message_length(
+ OlmSession * session,
+ size_t plaintext_length
+);
+
+/** Encrypts a message using the session. Returns the length of the message in
+ * bytes on success. Writes the message as base64 into the message buffer.
+ * Returns olm_error() on failure. If the message buffer is too small then
+ * olm_session_last_error() will be "OUTPUT_BUFFER_TOO_SMALL". If there
+ * weren't enough random bytes then olm_session_last_error() will be
+ * "NOT_ENOUGH_RANDOM". */
+size_t olm_encrypt(
+ OlmSession * session,
+ void const * plaintext, size_t plaintext_length,
+ void const * random, size_t random_length,
+ void * message, size_t message_length
+);
+
+/** The maximum number of bytes of plain-text a given message could decode to.
+ * The actual size could be different due to padding. The input message buffer
+ * is destroyed. Returns olm_error() on failure. If the message base64
+ * couldn't be decoded then olm_session_last_error() will be
+ * "INVALID_BASE64". If the message is for an unsupported version of the
+ * protocol then olm_session_last_error() will be "BAD_MESSAGE_VERSION".
+ * If the message couldn't be decoded then olm_session_last_error() will be
+ * "BAD_MESSAGE_FORMAT". */
+size_t olm_decrypt_max_plaintext_length(
+ OlmSession * session,
+ size_t message_type,
+ void * message, size_t message_length
+);
+
+/** Decrypts a message using the session. The input message buffer is destroyed.
+ * Returns the length of the plain-text on success. Returns olm_error() on
+ * failure. If the plain-text buffer is smaller than
+ * olm_decrypt_max_plaintext_length() then olm_session_last_error()
+ * will be "OUTPUT_BUFFER_TOO_SMALL". If the base64 couldn't be decoded then
+ * olm_session_last_error() will be "INVALID_BASE64". If the message is for
+ * an unsupported version of the protocol then olm_session_last_error() will
+ * be "BAD_MESSAGE_VERSION". If the message couldn't be decoded then
+ * olm_session_last_error() will be BAD_MESSAGE_FORMAT".
+ * If the MAC on the message was invalid then olm_session_last_error() will
+ * be "BAD_MESSAGE_MAC". */
+size_t olm_decrypt(
+ OlmSession * session,
+ size_t message_type,
+ void * message, size_t message_length,
+ void * plaintext, size_t max_plaintext_length
+);
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* OLM_HH_ */
diff --git a/include/axolotl/pickle.hh b/include/olm/pickle.hh
index 8134971..1676e23 100644
--- a/include/axolotl/pickle.hh
+++ b/include/olm/pickle.hh
@@ -12,16 +12,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef AXOLOTL_PICKLE_HH_
-#define AXOLOTL_PICKLE_HH_
+#ifndef OLM_PICKLE_HH_
+#define OLM_PICKLE_HH_
-#include "axolotl/list.hh"
-#include "axolotl/crypto.hh"
+#include "olm/list.hh"
+#include "olm/crypto.hh"
#include <cstring>
#include <cstdint>
-namespace axolotl {
+namespace olm {
static std::size_t pickle_length(
const std::uint32_t & value
@@ -79,7 +79,7 @@ static std::uint8_t const * unpickle(
template<typename T, std::size_t max_size>
std::size_t pickle_length(
- axolotl::List<T, max_size> const & list
+ olm::List<T, max_size> const & list
) {
std::size_t length = pickle_length(std::uint32_t(list.size()));
for (auto const & value : list) {
@@ -92,7 +92,7 @@ std::size_t pickle_length(
template<typename T, std::size_t max_size>
std::uint8_t * pickle(
std::uint8_t * pos,
- axolotl::List<T, max_size> const & list
+ olm::List<T, max_size> const & list
) {
pos = pickle(pos, std::uint32_t(list.size()));
for (auto const & value : list) {
@@ -105,7 +105,7 @@ std::uint8_t * pickle(
template<typename T, std::size_t max_size>
std::uint8_t const * unpickle(
std::uint8_t const * pos, std::uint8_t const * end,
- axolotl::List<T, max_size> & list
+ olm::List<T, max_size> & list
) {
std::uint32_t size;
pos = unpickle(pos, end, size);
@@ -170,9 +170,9 @@ std::uint8_t const * unpickle(
);
-} // namespace axolotl
+} // namespace olm
-#endif /* AXOLOTL_PICKLE_HH */
+#endif /* OLM_PICKLE_HH */
diff --git a/include/axolotl/ratchet.hh b/include/olm/ratchet.hh
index 0874cf0..7274255 100644
--- a/include/axolotl/ratchet.hh
+++ b/include/olm/ratchet.hh
@@ -13,11 +13,11 @@
* limitations under the License.
*/
-#include "axolotl/crypto.hh"
-#include "axolotl/list.hh"
-#include "axolotl/error.hh"
+#include "olm/crypto.hh"
+#include "olm/list.hh"
+#include "olm/error.hh"
-namespace axolotl {
+namespace olm {
class Cipher;
@@ -174,4 +174,4 @@ std::uint8_t const * unpickle(
);
-} // namespace axolotl
+} // namespace olm
diff --git a/include/axolotl/session.hh b/include/olm/session.hh
index 17f1653..a0aff08 100644
--- a/include/axolotl/session.hh
+++ b/include/olm/session.hh
@@ -12,12 +12,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef AXOLOTL_SESSION_HH_
-#define AXOLOTL_SESSION_HH_
+#ifndef OLM_SESSION_HH_
+#define OLM_SESSION_HH_
-#include "axolotl/ratchet.hh"
+#include "olm/ratchet.hh"
-namespace axolotl {
+namespace olm {
class Account;
@@ -109,6 +109,6 @@ std::uint8_t const * unpickle(
);
-} // namespace axolotl
+} // namespace olm
-#endif /* AXOLOTL_SESSION_HH_ */
+#endif /* OLM_SESSION_HH_ */
diff --git a/javascript/axolotl_pre.js b/javascript/axolotl_pre.js
deleted file mode 100644
index 69df923..0000000
--- a/javascript/axolotl_pre.js
+++ /dev/null
@@ -1 +0,0 @@
-Axolotl = function() {
diff --git a/javascript/build.py b/javascript/build.py
index 08436fd..68b7e45 100755
--- a/javascript/build.py
+++ b/javascript/build.py
@@ -28,8 +28,8 @@ if not os.path.exists("build"):
os.mkdir("build")
functions = set()
-RE_FUNCTION=re.compile("(axolotl_[^( ]*)\\(")
-with open("include/axolotl/axolotl.hh") as header:
+RE_FUNCTION=re.compile("(olm_[^( ]*)\\(")
+with open("include/olm/olm.hh") as header:
for line in header:
match = RE_FUNCTION.search(line)
if match:
@@ -60,7 +60,7 @@ compile_args += ("--pre-js", pre_js)
compile_args += ("--post-js", post_js)
compile_args += ("-s", "EXPORTED_FUNCTIONS=@" + exported_functions)
-library = "build/axolotl.js"
+library = "build/olm.js"
def run(args):
print args
diff --git a/javascript/demo.html b/javascript/demo.html
index ce4bfed..cace119 100644
--- a/javascript/demo.html
+++ b/javascript/demo.html
@@ -1,6 +1,6 @@
<html>
<head>
-<script src="../build/axolotl.js"></script>
+<script src="../build/olm.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function (event) {
@@ -19,10 +19,10 @@ document.addEventListener("DOMContentLoaded", function (event) {
return {start:start, done:done};
}
- var alice = new Axolotl.Account();
- var bob = new Axolotl.Account();
- var a_session = new Axolotl.Session();
- var b_session = new Axolotl.Session();
+ var alice = new Olm.Account();
+ var bob = new Olm.Account();
+ var a_session = new Olm.Session();
+ var b_session = new Olm.Session();
var message_1;
var tasks = [];
diff --git a/javascript/axolotl_post.js b/javascript/olm_post.js
index 570c66f..6ebd198 100644
--- a/javascript/axolotl_post.js
+++ b/javascript/olm_post.js
@@ -2,7 +2,7 @@ var runtime = Module['Runtime'];
var malloc = Module['_malloc'];
var free = Module['_free'];
var Pointer_stringify = Module['Pointer_stringify'];
-var AXOLOTL_ERROR = Module['_axolotl_error']();
+var OLM_ERROR = Module['_olm_error']();
function stack(size_or_array) {
return Module['allocate'](size_or_array, 'i8', Module['ALLOC_STACK']);
@@ -31,19 +31,19 @@ function restore_stack(wrapped) {
}
function Account() {
- var size = Module['_axolotl_account_size']();
+ var size = Module['_olm_account_size']();
this.buf = malloc(size);
- this.ptr = Module['_axolotl_account'](this.buf);
+ this.ptr = Module['_olm_account'](this.buf);
}
function account_method(wrapped) {
return function() {
var result = wrapped.apply(this, arguments);
- if (result === AXOLOTL_ERROR) {
+ if (result === OLM_ERROR) {
var message = Pointer_stringify(
- Module['_axolotl_account_last_error'](arguments[0])
+ Module['_olm_account_last_error'](arguments[0])
);
- throw new Error("AXOLOTL." + message);
+ throw new Error("OLM." + message);
}
return result;
}
@@ -55,20 +55,20 @@ Account.prototype['free'] = function() {
Account.prototype['create'] = restore_stack(function() {
var random_length = account_method(
- Module['_axolotl_create_account_random_length']
+ Module['_olm_create_account_random_length']
)(this.ptr);
var random = random_stack(random_length);
- account_method(Module['_axolotl_create_account'])(
+ account_method(Module['_olm_create_account'])(
this.ptr, random, random_length
);
});
Account.prototype['identity_keys'] = restore_stack(function() {
var keys_length = account_method(
- Module['_axolotl_account_identity_keys_length']
+ Module['_olm_account_identity_keys_length']
)(this.ptr);
var keys = stack(keys_length);
- account_method(Module['_axolotl_account_identity_keys'])(
+ account_method(Module['_olm_account_identity_keys'])(
this.ptr, keys, keys_length
);
return Pointer_stringify(keys, keys_length);
@@ -76,10 +76,10 @@ Account.prototype['identity_keys'] = restore_stack(function() {
Account.prototype['one_time_keys'] = restore_stack(function() {
var keys_length = account_method(
- Module['_axolotl_account_one_time_keys_length']
+ Module['_olm_account_one_time_keys_length']
)(this.ptr);
var keys = stack(keys_length);
- account_method(Module['_axolotl_account_one_time_keys'])(
+ account_method(Module['_olm_account_one_time_keys'])(
this.ptr, keys, keys_length
);
return Pointer_stringify(keys, keys_length);
@@ -88,11 +88,11 @@ Account.prototype['one_time_keys'] = restore_stack(function() {
Account.prototype['pickle'] = restore_stack(function(key) {
var key_array = array_from_string(key);
var pickle_length = account_method(
- Module['_axolotl_pickle_account_length']
+ Module['_olm_pickle_account_length']
)(this.ptr);
var key_buffer = stack(key_array);
var pickle_buffer = stack(pickle_length);
- account_method(Module['_axolotl_pickle_account'])(
+ account_method(Module['_olm_pickle_account'])(
this.ptr, key_buffer, key_array.length, pickle_buffer, pickle_length
);
return Pointer_stringify(pickle_buffer, pickle_length);
@@ -103,26 +103,26 @@ Account.prototype['unpickle'] = restore_stack(function(key, pickle) {
var key_buffer = stack(key_array);
var pickle_array = array_from_string(pickle);
var pickle_buffer = stack(pickle_length);
- account_method(Module['_axolotl_unpickle_account'])(
+ account_method(Module['_olm_unpickle_account'])(
this.ptr, key_buffer, key_array.length, pickle_buffer,
pickle_array.length
);
});
function Session() {
- var size = Module['_axolotl_session_size']();
+ var size = Module['_olm_session_size']();
this.buf = malloc(size);
- this.ptr = Module['_axolotl_session'](this.buf);
+ this.ptr = Module['_olm_session'](this.buf);
}
function session_method(wrapped) {
return function() {
var result = wrapped.apply(this, arguments);
- if (result === AXOLOTL_ERROR) {
+ if (result === OLM_ERROR) {
var message = Pointer_stringify(
- Module['_axolotl_session_last_error'](arguments[0])
+ Module['_olm_session_last_error'](arguments[0])
);
- throw new Error("AXOLOTL." + message);
+ throw new Error("OLM." + message);
}
return result;
}
@@ -135,11 +135,11 @@ Session.prototype['free'] = function() {
Session.prototype['pickle'] = restore_stack(function(key) {
var key_array = array_from_string(key);
var pickle_length = session_method(
- Module['_axolotl_pickle_session_length']
+ Module['_olm_pickle_session_length']
)(this.ptr);
var key_buffer = stack(key_array);
var pickle_buffer = stack(pickle_length);
- session_method(Module['_axolotl_pickle_session'])(
+ session_method(Module['_olm_pickle_session'])(
this.ptr, key_buffer, key_array.length, pickle_buffer, pickle_length
);
return Pointer_stringify(pickle_buffer, pickle_length);
@@ -150,7 +150,7 @@ Session.prototype['unpickle'] = restore_stack(function(key, pickle) {
var key_buffer = stack(key_array);
var pickle_array = array_from_string(pickle);
var pickle_buffer = stack(pickle_array);
- session_method(Module['_axolotl_unpickle_session'])(
+ session_method(Module['_olm_unpickle_session'])(
this.ptr, key_buffer, key_array.length, pickle_buffer,
pickle_array.length
);
@@ -160,14 +160,14 @@ Session.prototype['create_outbound'] = restore_stack(function(
account, their_identity_key, their_one_time_key_id, their_one_time_key
) {
var random_length = session_method(
- Module['_axolotl_create_outbound_session_random_length']
+ Module['_olm_create_outbound_session_random_length']
)(this.ptr);
var random = random_stack(random_length);
var identity_key_array = array_from_string(their_identity_key);
var one_time_key_array = array_from_string(their_one_time_key);
var identity_key_buffer = stack(identity_key_array);
var one_time_key_buffer = stack(one_time_key_array);
- session_method(Module['_axolotl_create_outbound_session'])(
+ session_method(Module['_olm_create_outbound_session'])(
this.ptr, account.ptr,
identity_key_buffer, identity_key_array.length,
their_one_time_key_id,
@@ -181,7 +181,7 @@ Session.prototype['create_inbound'] = restore_stack(function(
) {
var message_array = array_from_string(one_time_key_message);
var message_buffer = stack(message_array);
- session_method(Module['_axolotl_create_inbound_session'])(
+ session_method(Module['_olm_create_inbound_session'])(
this.ptr, account.ptr, message_buffer, message_array.length
);
});
@@ -191,7 +191,7 @@ Session.prototype['matches_inbound'] = restore_stack(function(
) {
var message_array = array_from_string(one_time_key_message);
var message_buffer = stack(message_array);
- return session_method(Module['_axolotl_matches_inbound_session'])(
+ return session_method(Module['_olm_matches_inbound_session'])(
this.ptr, account.ptr, message_buffer, message_array.length
) ? true : false;
});
@@ -200,19 +200,19 @@ Session.prototype['encrypt'] = restore_stack(function(
plaintext
) {
var random_length = session_method(
- Module['_axolotl_encrypt_random_length']
+ Module['_olm_encrypt_random_length']
)(this.ptr);
var message_type = session_method(
- Module['_axolotl_encrypt_message_type']
+ Module['_olm_encrypt_message_type']
)(this.ptr);
var plaintext_array = array_from_string(plaintext);
var message_length = session_method(
- Module['_axolotl_encrypt_message_length']
+ Module['_olm_encrypt_message_length']
)(this.ptr, plaintext_array.length);
var random = random_stack(random_length);
var plaintext_buffer = stack(plaintext_array);
var message_buffer = stack(message_length);
- session_method(Module['_axolotl_encrypt'])(
+ session_method(Module['_olm_encrypt'])(
this.ptr,
plaintext_buffer, plaintext_array.length,
random, random_length,
@@ -230,13 +230,13 @@ Session.prototype['decrypt'] = restore_stack(function(
var message_array = array_from_string(message);
var message_buffer = stack(message_array);
var max_plaintext_length = session_method(
- Module['_axolotl_decrypt_max_plaintext_length']
+ Module['_olm_decrypt_max_plaintext_length']
)(this.ptr, message_type, message_buffer, message_array.length);
// caculating the length destroys the input buffer.
// So we copy the array to a new buffer
var message_buffer = stack(message_array);
var plaintext_buffer = stack(max_plaintext_length);
- var plaintext_length = session_method(Module["_axolotl_decrypt"])(
+ var plaintext_length = session_method(Module["_olm_decrypt"])(
this.ptr, message_type,
message_buffer, message.length,
plaintext_buffer, max_plaintext_length
diff --git a/javascript/olm_pre.js b/javascript/olm_pre.js
new file mode 100644
index 0000000..c7b0d5e
--- /dev/null
+++ b/javascript/olm_pre.js
@@ -0,0 +1 @@
+Olm = function() {
diff --git a/axolotl.py b/olm.py
index 239a6ce..a481ac7 100755
--- a/axolotl.py
+++ b/olm.py
@@ -2,31 +2,31 @@
from ctypes import *
import json
-lib = cdll.LoadLibrary("build/libaxolotl.so")
+lib = cdll.LoadLibrary("build/libolm.so")
-lib.axolotl_error.argtypes = []
-lib.axolotl_error.restypes = c_size_t
+lib.olm_error.argtypes = []
+lib.olm_error.restypes = c_size_t
-ERR = lib.axolotl_error()
+ERR = lib.olm_error()
-class AxolotlError(Exception):
+class OlmError(Exception):
pass
-lib.axolotl_account_size.argtypes = []
-lib.axolotl_account_size.restype = c_size_t
+lib.olm_account_size.argtypes = []
+lib.olm_account_size.restype = c_size_t
-lib.axolotl_account.argtypes = [c_void_p]
-lib.axolotl_account.restype = c_void_p
+lib.olm_account.argtypes = [c_void_p]
+lib.olm_account.restype = c_void_p
-lib.axolotl_account_last_error.argtypes = [c_void_p]
-lib.axolotl_account_last_error.restype = c_char_p
+lib.olm_account_last_error.argtypes = [c_void_p]
+lib.olm_account_last_error.restype = c_char_p
def account_errcheck(res, func, args):
if res == ERR:
- raise AxolotlError("%s: %s" % (
- func.__name__, lib.axolotl_account_last_error(args[0])
+ raise OlmError("%s: %s" % (
+ func.__name__, lib.olm_account_last_error(args[0])
))
return res
@@ -38,17 +38,17 @@ def account_function(func, *types):
account_function(
- lib.axolotl_pickle_account, c_void_p, c_size_t, c_void_p, c_size_t
+ lib.olm_pickle_account, c_void_p, c_size_t, c_void_p, c_size_t
)
account_function(
- lib.axolotl_unpickle_account, c_void_p, c_size_t, c_void_p, c_size_t
+ lib.olm_unpickle_account, c_void_p, c_size_t, c_void_p, c_size_t
)
-account_function(lib.axolotl_create_account_random_length)
-account_function(lib.axolotl_create_account, c_void_p, c_size_t)
-account_function(lib.axolotl_account_identity_keys_length)
-account_function(lib.axolotl_account_identity_keys, c_void_p, c_size_t)
-account_function(lib.axolotl_account_one_time_keys_length)
-account_function(lib.axolotl_account_one_time_keys, c_void_p, c_size_t)
+account_function(lib.olm_create_account_random_length)
+account_function(lib.olm_create_account, c_void_p, c_size_t)
+account_function(lib.olm_account_identity_keys_length)
+account_function(lib.olm_account_identity_keys, c_void_p, c_size_t)
+account_function(lib.olm_account_one_time_keys_length)
+account_function(lib.olm_account_one_time_keys, c_void_p, c_size_t)
def read_random(n):
with open("/dev/urandom", "rb") as f:
@@ -56,20 +56,20 @@ def read_random(n):
class Account(object):
def __init__(self):
- self.buf = create_string_buffer(lib.axolotl_account_size())
- self.ptr = lib.axolotl_account(self.buf)
+ self.buf = create_string_buffer(lib.olm_account_size())
+ self.ptr = lib.olm_account(self.buf)
def create(self):
- random_length = lib.axolotl_create_account_random_length(self.ptr)
+ random_length = lib.olm_create_account_random_length(self.ptr)
random = read_random(random_length)
random_buffer = create_string_buffer(random)
- lib.axolotl_create_account(self.ptr, random_buffer, random_length)
+ lib.olm_create_account(self.ptr, random_buffer, random_length)
def pickle(self, key):
key_buffer = create_string_buffer(key)
- pickle_length = lib.axolotl_pickle_account_length(self.ptr)
+ pickle_length = lib.olm_pickle_account_length(self.ptr)
pickle_buffer = create_string_buffer(pickle_length)
- lib.axolotl_pickle_account(
+ lib.olm_pickle_account(
self.ptr, key_buffer, len(key), pickle_buffer, pickle_length
)
return pickle_buffer.raw
@@ -77,40 +77,40 @@ class Account(object):
def unpickle(self, key, pickle):
key_buffer = create_string_buffer(key)
pickle_buffer = create_string_buffer(pickle)
- lib.axolotl_unpickle_account(
+ lib.olm_unpickle_account(
self.ptr, key_buffer, len(key), pickle_buffer, len(pickle)
)
def identity_keys(self):
- out_length = lib.axolotl_account_identity_keys_length(self.ptr)
+ out_length = lib.olm_account_identity_keys_length(self.ptr)
out_buffer = create_string_buffer(out_length)
- lib.axolotl_account_identity_keys(self.ptr, out_buffer, out_length)
+ lib.olm_account_identity_keys(self.ptr, out_buffer, out_length)
return json.loads(out_buffer.raw)
def one_time_keys(self):
- out_length = lib.axolotl_account_one_time_keys_length(self.ptr)
+ out_length = lib.olm_account_one_time_keys_length(self.ptr)
out_buffer = create_string_buffer(out_length)
- lib.axolotl_account_one_time_keys(self.ptr, out_buffer, out_length)
+ lib.olm_account_one_time_keys(self.ptr, out_buffer, out_length)
return json.loads(out_buffer.raw)
def clear(self):
pass
-lib.axolotl_session_size.argtypes = []
-lib.axolotl_session_size.restype = c_size_t
+lib.olm_session_size.argtypes = []
+lib.olm_session_size.restype = c_size_t
-lib.axolotl_session.argtypes = [c_void_p]
-lib.axolotl_session.restype = c_void_p
+lib.olm_session.argtypes = [c_void_p]
+lib.olm_session.restype = c_void_p
-lib.axolotl_session_last_error.argtypes = [c_void_p]
-lib.axolotl_session_last_error.restype = c_char_p
+lib.olm_session_last_error.argtypes = [c_void_p]
+lib.olm_session_last_error.restype = c_char_p
def session_errcheck(res, func, args):
if res == ERR:
- raise AxolotlError("%s: %s" % (
- func.__name__, lib.axolotl_session_last_error(args[0])
+ raise OlmError("%s: %s" % (
+ func.__name__, lib.olm_session_last_error(args[0])
))
return res
@@ -120,16 +120,16 @@ def session_function(func, *types):
func.restypes = c_size_t
func.errcheck = session_errcheck
-session_function(lib.axolotl_session_last_error)
+session_function(lib.olm_session_last_error)
session_function(
- lib.axolotl_pickle_session, c_void_p, c_size_t, c_void_p, c_size_t
+ lib.olm_pickle_session, c_void_p, c_size_t, c_void_p, c_size_t
)
session_function(
- lib.axolotl_unpickle_session, c_void_p, c_size_t, c_void_p, c_size_t
+ lib.olm_unpickle_session, c_void_p, c_size_t, c_void_p, c_size_t
)
-session_function(lib.axolotl_create_outbound_session_random_length)
+session_function(lib.olm_create_outbound_session_random_length)
session_function(
- lib.axolotl_create_outbound_session,
+ lib.olm_create_outbound_session,
c_void_p, # Account
c_void_p, c_size_t, # Identity Key
c_uint, # One Time Key Id
@@ -137,27 +137,27 @@ session_function(
c_void_p, c_size_t, # Random
)
session_function(
- lib.axolotl_create_inbound_session,
+ lib.olm_create_inbound_session,
c_void_p, # Account
c_void_p, c_size_t, # Pre Key Message
)
-session_function(lib.axolotl_matches_inbound_session, c_void_p, c_size_t)
-session_function(lib.axolotl_encrypt_message_type)
-session_function(lib.axolotl_encrypt_random_length)
-session_function(lib.axolotl_encrypt_message_length, c_size_t)
+session_function(lib.olm_matches_inbound_session, c_void_p, c_size_t)
+session_function(lib.olm_encrypt_message_type)
+session_function(lib.olm_encrypt_random_length)
+session_function(lib.olm_encrypt_message_length, c_size_t)
session_function(
- lib.axolotl_encrypt,
+ lib.olm_encrypt,
c_void_p, c_size_t, # Plaintext
c_void_p, c_size_t, # Random
c_void_p, c_size_t, # Message
);
session_function(
- lib.axolotl_decrypt_max_plaintext_length,
+ lib.olm_decrypt_max_plaintext_length,
c_size_t, # Message Type
c_void_p, c_size_t, # Message
)
session_function(
- lib.axolotl_decrypt,
+ lib.olm_decrypt,
c_size_t, # Message Type
c_void_p, c_size_t, # Message
c_void_p, c_size_t, # Plaintext
@@ -165,14 +165,14 @@ session_function(
class Session(object):
def __init__(self):
- self.buf = create_string_buffer(lib.axolotl_session_size())
- self.ptr = lib.axolotl_session(self.buf)
+ self.buf = create_string_buffer(lib.olm_session_size())
+ self.ptr = lib.olm_session(self.buf)
def pickle(self, key):
key_buffer = create_string_buffer(key)
- pickle_length = lib.axolotl_pickle_session_length(self.ptr)
+ pickle_length = lib.olm_pickle_session_length(self.ptr)
pickle_buffer = create_string_buffer(pickle_length)
- lib.axolotl_pickle_session(
+ lib.olm_pickle_session(
self.ptr, key_buffer, len(key), pickle_buffer, pickle_length
)
return pickle_buffer.raw
@@ -180,18 +180,18 @@ class Session(object):
def unpickle(self, key, pickle):
key_buffer = create_string_buffer(key)
pickle_buffer = create_string_buffer(pickle)
- lib.axolotl_unpickle_session(
+ lib.olm_unpickle_session(
self.ptr, key_buffer, len(key), pickle_buffer, len(pickle)
)
def create_outbound(self, account, identity_key, one_time_key_id,
one_time_key):
- r_length = lib.axolotl_create_outbound_session_random_length(self.ptr)
+ r_length = lib.olm_create_outbound_session_random_length(self.ptr)
random = read_random(r_length)
random_buffer = create_string_buffer(random)
identity_key_buffer = create_string_buffer(identity_key)
one_time_key_buffer = create_string_buffer(one_time_key)
- lib.axolotl_create_outbound_session(
+ lib.olm_create_outbound_session(
self.ptr,
account.ptr,
identity_key_buffer, len(identity_key),
@@ -202,7 +202,7 @@ class Session(object):
def create_inbound(self, account, one_time_key_message):
one_time_key_message_buffer = create_string_buffer(one_time_key_message)
- lib.axolotl_create_inbound_session(
+ lib.olm_create_inbound_session(
self.ptr,
account.ptr,
one_time_key_message_buffer, len(one_time_key_message)
@@ -210,25 +210,25 @@ class Session(object):
def matches_inbound(self, one_time_key_message):
one_time_key_message_buffer = create_string_buffer(one_time_key_message)
- return bool(lib.axolotl_create_inbound_session(
+ return bool(lib.olm_create_inbound_session(
self.ptr,
one_time_key_message_buffer, len(one_time_key_message)
))
def encrypt(self, plaintext):
- r_length = lib.axolotl_encrypt_random_length(self.ptr)
+ r_length = lib.olm_encrypt_random_length(self.ptr)
random = read_random(r_length)
random_buffer = create_string_buffer(random)
- message_type = lib.axolotl_encrypt_message_type(self.ptr)
- message_length = lib.axolotl_encrypt_message_length(
+ message_type = lib.olm_encrypt_message_type(self.ptr)
+ message_length = lib.olm_encrypt_message_length(
self.ptr, len(plaintext)
)
message_buffer = create_string_buffer(message_length)
plaintext_buffer = create_string_buffer(plaintext)
- lib.axolotl_encrypt(
+ lib.olm_encrypt(
self.ptr,
plaintext_buffer, len(plaintext),
random_buffer, r_length,
@@ -238,12 +238,12 @@ class Session(object):
def decrypt(self, message_type, message):
message_buffer = create_string_buffer(message)
- max_plaintext_length = lib.axolotl_decrypt_max_plaintext_length(
+ max_plaintext_length = lib.olm_decrypt_max_plaintext_length(
self.ptr, message_type, message_buffer, len(message)
)
plaintext_buffer = create_string_buffer(max_plaintext_length)
message_buffer = create_string_buffer(message)
- plaintext_length = lib.axolotl_decrypt(
+ plaintext_length = lib.olm_decrypt(
self.ptr, message_type, message_buffer, len(message),
plaintext_buffer, max_plaintext_length
)
diff --git a/src/account.cpp b/src/account.cpp
index cafa014..45e4b6d 100644
--- a/src/account.cpp
+++ b/src/account.cpp
@@ -12,20 +12,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "axolotl/account.hh"
-#include "axolotl/pickle.hh"
+#include "olm/account.hh"
+#include "olm/pickle.hh"
-axolotl::LocalKey const * axolotl::Account::lookup_key(
+olm::LocalKey const * olm::Account::lookup_key(
std::uint32_t id
) {
- for (axolotl::LocalKey const & key : one_time_keys) {
+ for (olm::LocalKey const & key : one_time_keys) {
if (key.id == id) return &key;
}
return 0;
}
-std::size_t axolotl::Account::remove_key(
+std::size_t olm::Account::remove_key(
std::uint32_t id
) {
LocalKey * i;
@@ -38,34 +38,34 @@ std::size_t axolotl::Account::remove_key(
return std::size_t(-1);
}
-std::size_t axolotl::Account::new_account_random_length() {
+std::size_t olm::Account::new_account_random_length() {
return 103 * 32;
}
-std::size_t axolotl::Account::new_account(
+std::size_t olm::Account::new_account(
uint8_t const * random, std::size_t random_length
) {
if (random_length < new_account_random_length()) {
- last_error = axolotl::ErrorCode::NOT_ENOUGH_RANDOM;
+ last_error = olm::ErrorCode::NOT_ENOUGH_RANDOM;
return std::size_t(-1);
}
unsigned id = 0;
identity_key.id = ++id;
- axolotl::generate_key(random, identity_key.key);
+ olm::generate_key(random, identity_key.key);
random += 32;
random += 32;
last_resort_one_time_key.id = ++id;
- axolotl::generate_key(random, last_resort_one_time_key.key);
+ olm::generate_key(random, last_resort_one_time_key.key);
random += 32;
for (unsigned i = 0; i < 10; ++i) {
LocalKey & key = *one_time_keys.insert(one_time_keys.end());
key.id = ++id;
- axolotl::generate_key(random, key.key);
+ olm::generate_key(random, key.key);
random += 32;
}
@@ -73,94 +73,94 @@ std::size_t axolotl::Account::new_account(
}
-namespace axolotl {
+namespace olm {
static std::size_t pickle_length(
- axolotl::LocalKey const & value
+ olm::LocalKey const & value
) {
- return axolotl::pickle_length(value.id) + axolotl::pickle_length(value.key);
+ return olm::pickle_length(value.id) + olm::pickle_length(value.key);
}
static std::uint8_t * pickle(
std::uint8_t * pos,
- axolotl::LocalKey const & value
+ olm::LocalKey const & value
) {
- pos = axolotl::pickle(pos, value.id);
- pos = axolotl::pickle(pos, value.key);
+ pos = olm::pickle(pos, value.id);
+ pos = olm::pickle(pos, value.key);
return pos;
}
static std::uint8_t const * unpickle(
std::uint8_t const * pos, std::uint8_t const * end,
- axolotl::LocalKey & value
+ olm::LocalKey & value
) {
- pos = axolotl::unpickle(pos, end, value.id);
- pos = axolotl::unpickle(pos, end, value.key);
+ pos = olm::unpickle(pos, end, value.id);
+ pos = olm::unpickle(pos, end, value.key);
return pos;
}
static std::size_t pickle_length(
- axolotl::SignedKey const & value
+ olm::SignedKey const & value
) {
- return axolotl::pickle_length((axolotl::LocalKey const &) value) + 64;
+ return olm::pickle_length((olm::LocalKey const &) value) + 64;
}
static std::uint8_t * pickle(
std::uint8_t * pos,
- axolotl::SignedKey const & value
+ olm::SignedKey const & value
) {
- pos = axolotl::pickle(pos, (axolotl::LocalKey const &) value);
- pos = axolotl::pickle_bytes(pos, value.signature, 64);
+ pos = olm::pickle(pos, (olm::LocalKey const &) value);
+ pos = olm::pickle_bytes(pos, value.signature, 64);
return pos;
}
static std::uint8_t const * unpickle(
std::uint8_t const * pos, std::uint8_t const * end,
- axolotl::SignedKey & value
+ olm::SignedKey & value
) {
- pos = axolotl::unpickle(pos, end, (axolotl::LocalKey &) value);
- pos = axolotl::unpickle_bytes(pos, end, value.signature, 64);
+ pos = olm::unpickle(pos, end, (olm::LocalKey &) value);
+ pos = olm::unpickle_bytes(pos, end, value.signature, 64);
return pos;
}
-} // namespace axolotl
+} // namespace olm
-std::size_t axolotl::pickle_length(
- axolotl::Account const & value
+std::size_t olm::pickle_length(
+ olm::Account const & value
) {
std::size_t length = 0;
- length += axolotl::pickle_length(value.identity_key);
- length += axolotl::pickle_length(value.last_resort_one_time_key);
- length += axolotl::pickle_length(value.one_time_keys);
+ length += olm::pickle_length(value.identity_key);
+ length += olm::pickle_length(value.last_resort_one_time_key);
+ length += olm::pickle_length(value.one_time_keys);
return length;
}
-std::uint8_t * axolotl::pickle(
+std::uint8_t * olm::pickle(
std::uint8_t * pos,
- axolotl::Account const & value
+ olm::Account const & value
) {
- pos = axolotl::pickle(pos, value.identity_key);
- pos = axolotl::pickle(pos, value.last_resort_one_time_key);
- pos = axolotl::pickle(pos, value.one_time_keys);
+ pos = olm::pickle(pos, value.identity_key);
+ pos = olm::pickle(pos, value.last_resort_one_time_key);
+ pos = olm::pickle(pos, value.one_time_keys);
return pos;
}
-std::uint8_t const * axolotl::unpickle(
+std::uint8_t const * olm::unpickle(
std::uint8_t const * pos, std::uint8_t const * end,
- axolotl::Account & value
+ olm::Account & value
) {
- pos = axolotl::unpickle(pos, end, value.identity_key);
- pos = axolotl::unpickle(pos, end, value.last_resort_one_time_key);
- pos = axolotl::unpickle(pos, end, value.one_time_keys);
+ pos = olm::unpickle(pos, end, value.identity_key);
+ pos = olm::unpickle(pos, end, value.last_resort_one_time_key);
+ pos = olm::unpickle(pos, end, value.one_time_keys);
return pos;
}
diff --git a/src/base64.cpp b/src/base64.cpp
index 6fafa44..a8631a1 100644
--- a/src/base64.cpp
+++ b/src/base64.cpp
@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "axolotl/base64.hh"
+#include "olm/base64.hh"
namespace {
@@ -45,14 +45,14 @@ static const std::uint8_t DECODE_BASE64[128] = {
} // namespace
-std::size_t axolotl::encode_base64_length(
+std::size_t olm::encode_base64_length(
std::size_t input_length
) {
return 4 * ((input_length + 2) / 3) + (input_length + 2) % 3 - 2;
}
-void axolotl::encode_base64(
+void olm::encode_base64(
std::uint8_t const * input, std::size_t input_length,
std::uint8_t * output
) {
@@ -87,7 +87,7 @@ void axolotl::encode_base64(
}
-std::size_t axolotl::decode_base64_length(
+std::size_t olm::decode_base64_length(
std::size_t input_length
) {
if (input_length % 4 == 1) {
@@ -98,7 +98,7 @@ std::size_t axolotl::decode_base64_length(
}
-void axolotl::decode_base64(
+void olm::decode_base64(
std::uint8_t const * input, std::size_t input_length,
std::uint8_t * output
) {
diff --git a/src/cipher.cpp b/src/cipher.cpp
index 2d700b1..2202746 100644
--- a/src/cipher.cpp
+++ b/src/cipher.cpp
@@ -12,12 +12,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "axolotl/cipher.hh"
-#include "axolotl/crypto.hh"
-#include "axolotl/memory.hh"
+#include "olm/cipher.hh"
+#include "olm/crypto.hh"
+#include "olm/memory.hh"
#include <cstring>
-axolotl::Cipher::~Cipher() {
+olm::Cipher::~Cipher() {
}
@@ -26,9 +26,9 @@ namespace {
static const std::size_t SHA256_LENGTH = 32;
struct DerivedKeys {
- axolotl::Aes256Key aes_key;
+ olm::Aes256Key aes_key;
std::uint8_t mac_key[SHA256_LENGTH];
- axolotl::Aes256Iv aes_iv;
+ olm::Aes256Iv aes_iv;
};
@@ -38,7 +38,7 @@ static void derive_keys(
DerivedKeys & keys
) {
std::uint8_t derived_secrets[80];
- axolotl::hkdf_sha256(
+ olm::hkdf_sha256(
key, key_length,
nullptr, 0,
kdf_info, kdf_info_length,
@@ -47,7 +47,7 @@ static void derive_keys(
std::memcpy(keys.aes_key.key, derived_secrets, 32);
std::memcpy(keys.mac_key, derived_secrets + 32, 32);
std::memcpy(keys.aes_iv.iv, derived_secrets + 64, 16);
- axolotl::unset(derived_secrets);
+ olm::unset(derived_secrets);
}
static const std::size_t MAC_LENGTH = 8;
@@ -55,26 +55,26 @@ static const std::size_t MAC_LENGTH = 8;
} // namespace
-axolotl::CipherAesSha256::CipherAesSha256(
+olm::CipherAesSha256::CipherAesSha256(
std::uint8_t const * kdf_info, std::size_t kdf_info_length
) : kdf_info(kdf_info), kdf_info_length(kdf_info_length) {
}
-std::size_t axolotl::CipherAesSha256::mac_length() const {
+std::size_t olm::CipherAesSha256::mac_length() const {
return MAC_LENGTH;
}
-std::size_t axolotl::CipherAesSha256::encrypt_ciphertext_length(
+std::size_t olm::CipherAesSha256::encrypt_ciphertext_length(
std::size_t plaintext_length
) const {
- return axolotl::aes_encrypt_cbc_length(plaintext_length);
+ return olm::aes_encrypt_cbc_length(plaintext_length);
}
-std::size_t axolotl::CipherAesSha256::encrypt(
+std::size_t olm::CipherAesSha256::encrypt(
std::uint8_t const * key, std::size_t key_length,
std::uint8_t const * plaintext, std::size_t plaintext_length,
std::uint8_t * ciphertext, std::size_t ciphertext_length,
@@ -88,28 +88,28 @@ std::size_t axolotl::CipherAesSha256::encrypt(
derive_keys(kdf_info, kdf_info_length, key, key_length, keys);
- axolotl::aes_encrypt_cbc(
+ olm::aes_encrypt_cbc(
keys.aes_key, keys.aes_iv, plaintext, plaintext_length, ciphertext
);
- axolotl::hmac_sha256(
+ olm::hmac_sha256(
keys.mac_key, SHA256_LENGTH, output, output_length - MAC_LENGTH, mac
);
std::memcpy(output + output_length - MAC_LENGTH, mac, MAC_LENGTH);
- axolotl::unset(keys);
+ olm::unset(keys);
return output_length;
}
-std::size_t axolotl::CipherAesSha256::decrypt_max_plaintext_length(
+std::size_t olm::CipherAesSha256::decrypt_max_plaintext_length(
std::size_t ciphertext_length
) const {
return ciphertext_length;
}
-std::size_t axolotl::CipherAesSha256::decrypt(
+std::size_t olm::CipherAesSha256::decrypt(
std::uint8_t const * key, std::size_t key_length,
std::uint8_t const * input, std::size_t input_length,
std::uint8_t const * ciphertext, std::size_t ciphertext_length,
@@ -120,20 +120,20 @@ std::size_t axolotl::CipherAesSha256::decrypt(
derive_keys(kdf_info, kdf_info_length, key, key_length, keys);
- axolotl::hmac_sha256(
+ olm::hmac_sha256(
keys.mac_key, SHA256_LENGTH, input, input_length - MAC_LENGTH, mac
);
std::uint8_t const * input_mac = input + input_length - MAC_LENGTH;
- if (!axolotl::is_equal(input_mac, mac, MAC_LENGTH)) {
- axolotl::unset(keys);
+ if (!olm::is_equal(input_mac, mac, MAC_LENGTH)) {
+ olm::unset(keys);
return std::size_t(-1);
}
- std::size_t plaintext_length = axolotl::aes_decrypt_cbc(
+ std::size_t plaintext_length = olm::aes_decrypt_cbc(
keys.aes_key, keys.aes_iv, ciphertext, ciphertext_length, plaintext
);
- axolotl::unset(keys);
+ olm::unset(keys);
return plaintext_length;
}
diff --git a/src/crypto.cpp b/src/crypto.cpp
index b287919..ebe4724 100644
--- a/src/crypto.cpp
+++ b/src/crypto.cpp
@@ -12,8 +12,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "axolotl/crypto.hh"
-#include "axolotl/memory.hh"
+#include "olm/crypto.hh"
+#include "olm/memory.hh"
#include <cstring>
@@ -110,7 +110,7 @@ inline void hmac_sha256_init(
}
::sha256_init(context);
::sha256_update(context, i_pad, SHA256_BLOCK_LENGTH);
- axolotl::unset(i_pad);
+ olm::unset(i_pad);
}
@@ -129,16 +129,16 @@ inline void hmac_sha256_final(
::sha256_init(&final_context);
::sha256_update(&final_context, o_pad, sizeof(o_pad));
::sha256_final(&final_context, output);
- axolotl::unset(final_context);
- axolotl::unset(o_pad);
+ olm::unset(final_context);
+ olm::unset(o_pad);
}
} // namespace
-void axolotl::generate_key(
+void olm::generate_key(
std::uint8_t const * random_32_bytes,
- axolotl::Curve25519KeyPair & key_pair
+ olm::Curve25519KeyPair & key_pair
) {
std::memcpy(key_pair.private_key, random_32_bytes, 32);
::curve25519_donna(
@@ -147,17 +147,17 @@ void axolotl::generate_key(
}
-void axolotl::curve25519_shared_secret(
- axolotl::Curve25519KeyPair const & our_key,
- axolotl::Curve25519PublicKey const & their_key,
+void olm::curve25519_shared_secret(
+ olm::Curve25519KeyPair const & our_key,
+ olm::Curve25519PublicKey const & their_key,
std::uint8_t * output
) {
::curve25519_donna(output, our_key.private_key, their_key.public_key);
}
-void axolotl::curve25519_sign(
- axolotl::Curve25519KeyPair const & our_key,
+void olm::curve25519_sign(
+ olm::Curve25519KeyPair const & our_key,
std::uint8_t const * message, std::size_t message_length,
std::uint8_t * output
) {
@@ -174,8 +174,8 @@ void axolotl::curve25519_sign(
}
-bool axolotl::curve25519_verify(
- axolotl::Curve25519PublicKey const & their_key,
+bool olm::curve25519_verify(
+ olm::Curve25519PublicKey const & their_key,
std::uint8_t const * message, std::size_t message_length,
std::uint8_t const * signature
) {
@@ -191,16 +191,16 @@ bool axolotl::curve25519_verify(
);
}
-std::size_t axolotl::aes_encrypt_cbc_length(
+std::size_t olm::aes_encrypt_cbc_length(
std::size_t input_length
) {
return input_length + AES_BLOCK_LENGTH - input_length % AES_BLOCK_LENGTH;
}
-void axolotl::aes_encrypt_cbc(
- axolotl::Aes256Key const & key,
- axolotl::Aes256Iv const & iv,
+void olm::aes_encrypt_cbc(
+ olm::Aes256Key const & key,
+ olm::Aes256Iv const & iv,
std::uint8_t const * input, std::size_t input_length,
std::uint8_t * output
) {
@@ -224,14 +224,14 @@ void axolotl::aes_encrypt_cbc(
input_block[i] ^= AES_BLOCK_LENGTH - input_length;
}
::aes_encrypt(input_block, output, key_schedule, 256);
- axolotl::unset(key_schedule);
- axolotl::unset(input_block);
+ olm::unset(key_schedule);
+ olm::unset(input_block);
}
-std::size_t axolotl::aes_decrypt_cbc(
- axolotl::Aes256Key const & key,
- axolotl::Aes256Iv const & iv,
+std::size_t olm::aes_decrypt_cbc(
+ olm::Aes256Key const & key,
+ olm::Aes256Iv const & iv,
std::uint8_t const * input, std::size_t input_length,
std::uint8_t * output
) {
@@ -246,15 +246,15 @@ std::size_t axolotl::aes_decrypt_cbc(
xor_block<AES_BLOCK_LENGTH>(&output[i], block1);
std::memcpy(block1, block2, AES_BLOCK_LENGTH);
}
- axolotl::unset(key_schedule);
- axolotl::unset(block1);
- axolotl::unset(block2);
+ olm::unset(key_schedule);
+ olm::unset(block1);
+ olm::unset(block2);
std::size_t padding = output[input_length - 1];
return (padding > input_length) ? std::size_t(-1) : (input_length - padding);
}
-void axolotl::sha256(
+void olm::sha256(
std::uint8_t const * input, std::size_t input_length,
std::uint8_t * output
) {
@@ -262,10 +262,10 @@ void axolotl::sha256(
::sha256_init(&context);
::sha256_update(&context, input, input_length);
::sha256_final(&context, output);
- axolotl::unset(context);
+ olm::unset(context);
}
-void axolotl::hmac_sha256(
+void olm::hmac_sha256(
std::uint8_t const * key, std::size_t key_length,
std::uint8_t const * input, std::size_t input_length,
std::uint8_t * output
@@ -276,12 +276,12 @@ void axolotl::hmac_sha256(
hmac_sha256_init(&context, hmac_key);
::sha256_update(&context, input, input_length);
hmac_sha256_final(&context, hmac_key, output);
- axolotl::unset(hmac_key);
- axolotl::unset(context);
+ olm::unset(hmac_key);
+ olm::unset(context);
}
-void axolotl::hkdf_sha256(
+void olm::hkdf_sha256(
std::uint8_t const * input, std::size_t input_length,
std::uint8_t const * salt, std::size_t salt_length,
std::uint8_t const * info, std::size_t info_length,
@@ -320,7 +320,7 @@ void axolotl::hkdf_sha256(
hmac_sha256_final(&context, hmac_key, step_result);
}
std::memcpy(output, step_result, bytes_remaining);
- axolotl::unset(context);
- axolotl::unset(hmac_key);
- axolotl::unset(step_result);
+ olm::unset(context);
+ olm::unset(hmac_key);
+ olm::unset(step_result);
}
diff --git a/src/memory.cpp b/src/memory.cpp
index deb3076..16a4683 100644
--- a/src/memory.cpp
+++ b/src/memory.cpp
@@ -12,10 +12,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "axolotl/memory.hh"
+#include "olm/memory.hh"
-void axolotl::unset(
+void olm::unset(
void volatile * buffer, std::size_t buffer_length
) {
char volatile * pos = reinterpret_cast<char volatile *>(buffer);
@@ -26,7 +26,7 @@ void axolotl::unset(
}
-bool axolotl::is_equal(
+bool olm::is_equal(
std::uint8_t const * buffer_a,
std::uint8_t const * buffer_b,
std::size_t length
diff --git a/src/message.cpp b/src/message.cpp
index 343b094..af43916 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "axolotl/message.hh"
+#include "olm/message.hh"
namespace {
@@ -161,7 +161,7 @@ std::uint8_t const * skip_unknown(
} // namespace
-std::size_t axolotl::encode_message_length(
+std::size_t olm::encode_message_length(
std::uint32_t counter,
std::size_t ratchet_key_length,
std::size_t ciphertext_length,
@@ -176,8 +176,8 @@ std::size_t axolotl::encode_message_length(
}
-void axolotl::encode_message(
- axolotl::MessageWriter & writer,
+void olm::encode_message(
+ olm::MessageWriter & writer,
std::uint8_t version,
std::uint32_t counter,
std::size_t ratchet_key_length,
@@ -192,8 +192,8 @@ void axolotl::encode_message(
}
-void axolotl::decode_message(
- axolotl::MessageReader & reader,
+void olm::decode_message(
+ olm::MessageReader & reader,
std::uint8_t const * input, std::size_t input_length,
std::size_t mac_length
) {
@@ -240,7 +240,7 @@ static std::uint8_t const MESSAGE_TAG = 042;
} // namespace
-std::size_t axolotl::encode_one_time_key_message_length(
+std::size_t olm::encode_one_time_key_message_length(
std::uint32_t one_time_key_id,
std::size_t identity_key_length,
std::size_t base_key_length,
@@ -255,8 +255,8 @@ std::size_t axolotl::encode_one_time_key_message_length(
}
-void axolotl::encode_one_time_key_message(
- axolotl::PreKeyMessageWriter & writer,
+void olm::encode_one_time_key_message(
+ olm::PreKeyMessageWriter & writer,
std::uint8_t version,
std::uint32_t one_time_key_id,
std::size_t identity_key_length,
@@ -273,7 +273,7 @@ void axolotl::encode_one_time_key_message(
}
-void axolotl::decode_one_time_key_message(
+void olm::decode_one_time_key_message(
PreKeyMessageReader & reader,
std::uint8_t const * input, std::size_t input_length
) {
diff --git a/src/axolotl.cpp b/src/olm.cpp
index 2586204..f5425fa 100644
--- a/src/axolotl.cpp
+++ b/src/olm.cpp
@@ -12,31 +12,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "axolotl/axolotl.hh"
-#include "axolotl/session.hh"
-#include "axolotl/account.hh"
-#include "axolotl/base64.hh"
-#include "axolotl/cipher.hh"
+#include "olm/olm.hh"
+#include "olm/session.hh"
+#include "olm/account.hh"
+#include "olm/base64.hh"
+#include "olm/cipher.hh"
#include <new>
#include <cstring>
namespace {
-static AxolotlAccount * to_c(axolotl::Account * account) {
- return reinterpret_cast<AxolotlAccount *>(account);
+static OlmAccount * to_c(olm::Account * account) {
+ return reinterpret_cast<OlmAccount *>(account);
}
-static AxolotlSession * to_c(axolotl::Session * account) {
- return reinterpret_cast<AxolotlSession *>(account);
+static OlmSession * to_c(olm::Session * account) {
+ return reinterpret_cast<OlmSession *>(account);
}
-static axolotl::Account * from_c(AxolotlAccount * account) {
- return reinterpret_cast<axolotl::Account *>(account);
+static olm::Account * from_c(OlmAccount * account) {
+ return reinterpret_cast<olm::Account *>(account);
}
-static axolotl::Session * from_c(AxolotlSession * account) {
- return reinterpret_cast<axolotl::Session *>(account);
+static olm::Session * from_c(OlmSession * account) {
+ return reinterpret_cast<olm::Session *>(account);
}
static std::uint8_t * from_c(void * bytes) {
@@ -49,7 +49,7 @@ static std::uint8_t const * from_c(void const * bytes) {
static const std::uint8_t CIPHER_KDF_INFO[] = "Pickle";
-static const axolotl::CipherAesSha256 PICKLE_CIPHER(
+static const olm::CipherAesSha256 PICKLE_CIPHER(
CIPHER_KDF_INFO, sizeof(CIPHER_KDF_INFO) -1
);
@@ -58,7 +58,7 @@ std::size_t enc_output_length(
) {
std::size_t length = PICKLE_CIPHER.encrypt_ciphertext_length(raw_length);
length += PICKLE_CIPHER.mac_length();
- return axolotl::encode_base64_length(length);
+ return olm::encode_base64_length(length);
}
@@ -68,7 +68,7 @@ std::uint8_t * enc_output_pos(
) {
std::size_t length = PICKLE_CIPHER.encrypt_ciphertext_length(raw_length);
length += PICKLE_CIPHER.mac_length();
- return output + axolotl::encode_base64_length(length) - length;
+ return output + olm::encode_base64_length(length) - length;
}
std::size_t enc_output(
@@ -79,7 +79,7 @@ std::size_t enc_output(
raw_length
);
std::size_t length = ciphertext_length + PICKLE_CIPHER.mac_length();
- std::size_t base64_length = axolotl::encode_base64_length(length);
+ std::size_t base64_length = olm::encode_base64_length(length);
std::uint8_t * raw_output = output + base64_length - length;
PICKLE_CIPHER.encrypt(
key, key_length,
@@ -87,21 +87,21 @@ std::size_t enc_output(
raw_output, ciphertext_length,
raw_output, length
);
- axolotl::encode_base64(raw_output, length, output);
+ olm::encode_base64(raw_output, length, output);
return raw_length;
}
std::size_t enc_input(
std::uint8_t const * key, std::size_t key_length,
std::uint8_t * input, size_t b64_length,
- axolotl::ErrorCode & last_error
+ olm::ErrorCode & last_error
) {
- std::size_t enc_length = axolotl::decode_base64_length(b64_length);
+ std::size_t enc_length = olm::decode_base64_length(b64_length);
if (enc_length == std::size_t(-1)) {
- last_error = axolotl::ErrorCode::INVALID_BASE64;
+ last_error = olm::ErrorCode::INVALID_BASE64;
return std::size_t(-1);
}
- axolotl::decode_base64(input, b64_length, input);
+ olm::decode_base64(input, b64_length, input);
std::size_t raw_length = enc_length - PICKLE_CIPHER.mac_length();
std::size_t result = PICKLE_CIPHER.decrypt(
key, key_length,
@@ -110,7 +110,7 @@ std::size_t enc_input(
input, raw_length
);
if (result == std::size_t(-1)) {
- last_error = axolotl::ErrorCode::BAD_ACCOUNT_KEY;
+ last_error = olm::ErrorCode::BAD_ACCOUNT_KEY;
}
return result;
}
@@ -119,35 +119,35 @@ std::size_t enc_input(
std::size_t b64_output_length(
size_t raw_length
) {
- return axolotl::encode_base64_length(raw_length);
+ return olm::encode_base64_length(raw_length);
}
std::uint8_t * b64_output_pos(
std::uint8_t * output,
size_t raw_length
) {
- return output + axolotl::encode_base64_length(raw_length) - raw_length;
+ return output + olm::encode_base64_length(raw_length) - raw_length;
}
std::size_t b64_output(
std::uint8_t * output, size_t raw_length
) {
- std::size_t base64_length = axolotl::encode_base64_length(raw_length);
+ std::size_t base64_length = olm::encode_base64_length(raw_length);
std::uint8_t * raw_output = output + base64_length - raw_length;
- axolotl::encode_base64(raw_output, raw_length, output);
+ olm::encode_base64(raw_output, raw_length, output);
return base64_length;
}
std::size_t b64_input(
std::uint8_t * input, size_t b64_length,
- axolotl::ErrorCode & last_error
+ olm::ErrorCode & last_error
) {
- std::size_t raw_length = axolotl::decode_base64_length(b64_length);
+ std::size_t raw_length = olm::decode_base64_length(b64_length);
if (raw_length == std::size_t(-1)) {
- last_error = axolotl::ErrorCode::INVALID_BASE64;
+ last_error = olm::ErrorCode::INVALID_BASE64;
return std::size_t(-1);
}
- axolotl::decode_base64(input, b64_length, input);
+ olm::decode_base64(input, b64_length, input);
return raw_length;
}
@@ -169,13 +169,13 @@ const char * errors[9] {
extern "C" {
-size_t axolotl_error() {
+size_t olm_error() {
return std::size_t(-1);
}
-const char * axolotl_account_last_error(
- AxolotlSession * account
+const char * olm_account_last_error(
+ OlmSession * account
) {
unsigned error = unsigned(from_c(account)->last_error);
if (error < 9) {
@@ -186,8 +186,8 @@ const char * axolotl_account_last_error(
}
-const char * axolotl_session_last_error(
- AxolotlSession * session
+const char * olm_session_last_error(
+ OlmSession * session
) {
unsigned error = unsigned(from_c(session)->last_error);
if (error < 9) {
@@ -198,53 +198,53 @@ const char * axolotl_session_last_error(
}
-size_t axolotl_account_size() {
- return sizeof(axolotl::Account);
+size_t olm_account_size() {
+ return sizeof(olm::Account);
}
-size_t axolotl_session_size() {
- return sizeof(axolotl::Session);
+size_t olm_session_size() {
+ return sizeof(olm::Session);
}
-AxolotlAccount * axolotl_account(
+OlmAccount * olm_account(
void * memory
) {
- return to_c(new(memory) axolotl::Account());
+ return to_c(new(memory) olm::Account());
}
-AxolotlSession * axolotl_session(
+OlmSession * olm_session(
void * memory
) {
- return to_c(new(memory) axolotl::Session());
+ return to_c(new(memory) olm::Session());
}
-size_t axolotl_pickle_account_length(
- AxolotlAccount * account
+size_t olm_pickle_account_length(
+ OlmAccount * account
) {
return enc_output_length(pickle_length(*from_c(account)));
}
-size_t axolotl_pickle_session_length(
- AxolotlSession * session
+size_t olm_pickle_session_length(
+ OlmSession * session
) {
return enc_output_length(pickle_length(*from_c(session)));
}
-size_t axolotl_pickle_account(
- AxolotlAccount * account,
+size_t olm_pickle_account(
+ OlmAccount * account,
void const * key, size_t key_length,
void * pickled, size_t pickled_length
) {
- axolotl::Account & object = *from_c(account);
+ olm::Account & object = *from_c(account);
std::size_t raw_length = pickle_length(object);
if (pickled_length < enc_output_length(raw_length)) {
- object.last_error = axolotl::ErrorCode::OUTPUT_BUFFER_TOO_SMALL;
+ object.last_error = olm::ErrorCode::OUTPUT_BUFFER_TOO_SMALL;
return size_t(-1);
}
pickle(enc_output_pos(from_c(pickled), raw_length), object);
@@ -252,15 +252,15 @@ size_t axolotl_pickle_account(
}
-size_t axolotl_pickle_session(
- AxolotlSession * session,
+size_t olm_pickle_session(
+ OlmSession * session,
void const * key, size_t key_length,
void * pickled, size_t pickled_length
) {
- axolotl::Session & object = *from_c(session);
+ olm::Session & object = *from_c(session);
std::size_t raw_length = pickle_length(object);
if (pickled_length < enc_output_length(raw_length)) {
- object.last_error = axolotl::ErrorCode::OUTPUT_BUFFER_TOO_SMALL;
+ object.last_error = olm::ErrorCode::OUTPUT_BUFFER_TOO_SMALL;
return size_t(-1);
}
pickle(enc_output_pos(from_c(pickled), raw_length), object);
@@ -268,12 +268,12 @@ size_t axolotl_pickle_session(
}
-size_t axolotl_unpickle_account(
- AxolotlAccount * account,
+size_t olm_unpickle_account(
+ OlmAccount * account,
void const * key, size_t key_length,
void * pickled, size_t pickled_length
) {
- axolotl::Account & object = *from_c(account);
+ olm::Account & object = *from_c(account);
std::uint8_t * const pos = from_c(pickled);
std::size_t raw_length = enc_input(
from_c(key), key_length, pos, pickled_length, object.last_error
@@ -287,12 +287,12 @@ size_t axolotl_unpickle_account(
}
-size_t axolotl_unpickle_session(
- AxolotlSession * session,
+size_t olm_unpickle_session(
+ OlmSession * session,
void const * key, size_t key_length,
void * pickled, size_t pickled_length
) {
- axolotl::Session & object = *from_c(session);
+ olm::Session & object = *from_c(session);
std::uint8_t * const pos = from_c(pickled);
std::size_t raw_length = enc_input(
from_c(key), key_length, pos, pickled_length, object.last_error
@@ -306,15 +306,15 @@ size_t axolotl_unpickle_session(
}
-size_t axolotl_create_account_random_length(
- AxolotlAccount * account
+size_t olm_create_account_random_length(
+ OlmAccount * account
) {
return from_c(account)->new_account_random_length();
}
-size_t axolotl_create_account(
- AxolotlAccount * account,
+size_t olm_create_account(
+ OlmAccount * account,
void const * random, size_t random_length
) {
return from_c(account)->new_account(from_c(random), random_length);
@@ -323,10 +323,10 @@ size_t axolotl_create_account(
namespace {
static const std::size_t OUTPUT_KEY_LENGTH = 2 + 10 + 2 +
- axolotl::encode_base64_length(32) + 3;
+ olm::encode_base64_length(32) + 3;
void output_key(
- axolotl::LocalKey const & key,
+ olm::LocalKey const & key,
std::uint8_t sep,
std::uint8_t * output
) {
@@ -343,7 +343,7 @@ void output_key(
}
output[12] = ',';
output[13] = '"';
- axolotl::encode_base64(key.key.public_key, 32, output + 14);
+ olm::encode_base64(key.key.public_key, 32, output + 14);
output[OUTPUT_KEY_LENGTH - 3] = '"';
output[OUTPUT_KEY_LENGTH - 2] = ']';
output[OUTPUT_KEY_LENGTH - 1] = '\n';
@@ -352,21 +352,21 @@ void output_key(
} // namespace
-size_t axolotl_account_identity_keys_length(
- AxolotlAccount * account
+size_t olm_account_identity_keys_length(
+ OlmAccount * account
) {
return OUTPUT_KEY_LENGTH + 1;
}
-size_t axolotl_account_identity_keys(
- AxolotlAccount * account,
+size_t olm_account_identity_keys(
+ OlmAccount * account,
void * identity_keys, size_t identity_key_length
) {
- std::size_t length = axolotl_account_identity_keys_length(account);
+ std::size_t length = olm_account_identity_keys_length(account);
if (identity_key_length < length) {
from_c(account)->last_error =
- axolotl::ErrorCode::OUTPUT_BUFFER_TOO_SMALL;
+ olm::ErrorCode::OUTPUT_BUFFER_TOO_SMALL;
return size_t(-1);
}
std::uint8_t * output = from_c(identity_keys);
@@ -377,22 +377,22 @@ size_t axolotl_account_identity_keys(
}
-size_t axolotl_account_one_time_keys_length(
- AxolotlAccount * account
+size_t olm_account_one_time_keys_length(
+ OlmAccount * account
) {
size_t count = from_c(account)->one_time_keys.size();
return OUTPUT_KEY_LENGTH * (count + 1) + 1;
}
-size_t axolotl_account_one_time_keys(
- AxolotlAccount * account,
+size_t olm_account_one_time_keys(
+ OlmAccount * account,
void * identity_keys, size_t identity_key_length
) {
- std::size_t length = axolotl_account_one_time_keys_length(account);
+ std::size_t length = olm_account_one_time_keys_length(account);
if (identity_key_length < length) {
from_c(account)->last_error =
- axolotl::ErrorCode::OUTPUT_BUFFER_TOO_SMALL;
+ olm::ErrorCode::OUTPUT_BUFFER_TOO_SMALL;
return size_t(-1);
}
std::uint8_t * output = from_c(identity_keys);
@@ -407,35 +407,35 @@ size_t axolotl_account_one_time_keys(
}
-size_t axolotl_create_outbound_session_random_length(
- AxolotlSession * session
+size_t olm_create_outbound_session_random_length(
+ OlmSession * session
) {
return from_c(session)->new_outbound_session_random_length();
}
-size_t axolotl_create_outbound_session(
- AxolotlSession * session,
- AxolotlAccount * account,
+size_t olm_create_outbound_session(
+ OlmSession * session,
+ OlmAccount * account,
void const * their_identity_key, size_t their_identity_key_length,
unsigned their_one_time_key_id,
void const * their_one_time_key, size_t their_one_time_key_length,
void const * random, size_t random_length
) {
- if (axolotl::decode_base64_length(their_identity_key_length) != 32
- || axolotl::decode_base64_length(their_one_time_key_length) != 32
+ if (olm::decode_base64_length(their_identity_key_length) != 32
+ || olm::decode_base64_length(their_one_time_key_length) != 32
) {
- from_c(session)->last_error = axolotl::ErrorCode::INVALID_BASE64;
+ from_c(session)->last_error = olm::ErrorCode::INVALID_BASE64;
return std::size_t(-1);
}
- axolotl::Curve25519PublicKey identity_key;
- axolotl::RemoteKey one_time_key;
+ olm::Curve25519PublicKey identity_key;
+ olm::RemoteKey one_time_key;
- axolotl::decode_base64(
+ olm::decode_base64(
from_c(their_identity_key), their_identity_key_length,
identity_key.public_key
);
one_time_key.id = their_one_time_key_id;
- axolotl::decode_base64(
+ olm::decode_base64(
from_c(their_one_time_key), their_one_time_key_length,
one_time_key.key.public_key
);
@@ -447,9 +447,9 @@ size_t axolotl_create_outbound_session(
}
-size_t axolotl_create_inbound_session(
- AxolotlSession * session,
- AxolotlAccount * account,
+size_t olm_create_inbound_session(
+ OlmSession * session,
+ OlmAccount * account,
void * one_time_key_message, size_t message_length
) {
std::size_t raw_length = b64_input(
@@ -464,8 +464,8 @@ size_t axolotl_create_inbound_session(
}
-size_t axolotl_matches_inbound_session(
- AxolotlSession * session,
+size_t olm_matches_inbound_session(
+ OlmSession * session,
void * one_time_key_message, size_t message_length
) {
std::size_t raw_length = b64_input(
@@ -481,36 +481,36 @@ size_t axolotl_matches_inbound_session(
}
-size_t axolotl_remove_one_time_keys(
- AxolotlAccount * account,
- AxolotlSession * session
+size_t olm_remove_one_time_keys(
+ OlmAccount * account,
+ OlmSession * session
) {
size_t result = from_c(account)->remove_key(
from_c(session)->bob_one_time_key_id
);
if (result == std::size_t(-1)) {
- from_c(account)->last_error = axolotl::ErrorCode::BAD_MESSAGE_KEY_ID;
+ from_c(account)->last_error = olm::ErrorCode::BAD_MESSAGE_KEY_ID;
}
return result;
}
-size_t axolotl_encrypt_message_type(
- AxolotlSession * session
+size_t olm_encrypt_message_type(
+ OlmSession * session
) {
return size_t(from_c(session)->encrypt_message_type());
}
-size_t axolotl_encrypt_random_length(
- AxolotlSession * session
+size_t olm_encrypt_random_length(
+ OlmSession * session
) {
return from_c(session)->encrypt_random_length();
}
-size_t axolotl_encrypt_message_length(
- AxolotlSession * session,
+size_t olm_encrypt_message_length(
+ OlmSession * session,
size_t plaintext_length
) {
return b64_output_length(
@@ -519,8 +519,8 @@ size_t axolotl_encrypt_message_length(
}
-size_t axolotl_encrypt(
- AxolotlSession * session,
+size_t olm_encrypt(
+ OlmSession * session,
void const * plaintext, size_t plaintext_length,
void const * random, size_t random_length,
void * message, size_t message_length
@@ -530,7 +530,7 @@ size_t axolotl_encrypt(
);
if (message_length < raw_length) {
from_c(session)->last_error =
- axolotl::ErrorCode::OUTPUT_BUFFER_TOO_SMALL;
+ olm::ErrorCode::OUTPUT_BUFFER_TOO_SMALL;
return std::size_t(-1);
}
from_c(session)->encrypt(
@@ -542,8 +542,8 @@ size_t axolotl_encrypt(
}
-size_t axolotl_decrypt_max_plaintext_length(
- AxolotlSession * session,
+size_t olm_decrypt_max_plaintext_length(
+ OlmSession * session,
size_t message_type,
void * message, size_t message_length
) {
@@ -554,13 +554,13 @@ size_t axolotl_decrypt_max_plaintext_length(
return std::size_t(-1);
}
return from_c(session)->decrypt_max_plaintext_length(
- axolotl::MessageType(message_type), from_c(message), raw_length
+ olm::MessageType(message_type), from_c(message), raw_length
);
}
-size_t axolotl_decrypt(
- AxolotlSession * session,
+size_t olm_decrypt(
+ OlmSession * session,
size_t message_type,
void * message, size_t message_length,
void * plaintext, size_t max_plaintext_length
@@ -572,7 +572,7 @@ size_t axolotl_decrypt(
return std::size_t(-1);
}
return from_c(session)->decrypt(
- axolotl::MessageType(message_type), from_c(message), raw_length,
+ olm::MessageType(message_type), from_c(message), raw_length,
from_c(plaintext), max_plaintext_length
);
}
diff --git a/src/pickle.cpp b/src/pickle.cpp
index 1597326..3aa64ed 100644
--- a/src/pickle.cpp
+++ b/src/pickle.cpp
@@ -12,32 +12,32 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "axolotl/pickle.hh"
+#include "olm/pickle.hh"
-std::size_t axolotl::pickle_length(
- const axolotl::Curve25519PublicKey & value
+std::size_t olm::pickle_length(
+ const olm::Curve25519PublicKey & value
) {
return sizeof(value.public_key);
}
-std::uint8_t * axolotl::pickle(
+std::uint8_t * olm::pickle(
std::uint8_t * pos,
- const axolotl::Curve25519PublicKey & value
+ const olm::Curve25519PublicKey & value
) {
- pos = axolotl::pickle_bytes(
+ pos = olm::pickle_bytes(
pos, value.public_key, sizeof(value.public_key)
);
return pos;
}
-std::uint8_t const * axolotl::unpickle(
+std::uint8_t const * olm::unpickle(
std::uint8_t const * pos, std::uint8_t const * end,
- axolotl::Curve25519PublicKey & value
+ olm::Curve25519PublicKey & value
) {
- pos = axolotl::unpickle_bytes(
+ pos = olm::unpickle_bytes(
pos, end, value.public_key, sizeof(value.public_key)
);
return pos;
@@ -45,35 +45,35 @@ std::uint8_t const * axolotl::unpickle(
}
-std::size_t axolotl::pickle_length(
- const axolotl::Curve25519KeyPair & value
+std::size_t olm::pickle_length(
+ const olm::Curve25519KeyPair & value
) {
return sizeof(value.public_key) + sizeof(value.private_key);
}
-std::uint8_t * axolotl::pickle(
+std::uint8_t * olm::pickle(
std::uint8_t * pos,
- const axolotl::Curve25519KeyPair & value
+ const olm::Curve25519KeyPair & value
) {
- pos = axolotl::pickle_bytes(
+ pos = olm::pickle_bytes(
pos, value.public_key, sizeof(value.public_key)
);
- pos = axolotl::pickle_bytes(
+ pos = olm::pickle_bytes(
pos, value.private_key, sizeof(value.private_key)
);
return pos;
}
-std::uint8_t const * axolotl::unpickle(
+std::uint8_t const * olm::unpickle(
std::uint8_t const * pos, std::uint8_t const * end,
- axolotl::Curve25519KeyPair & value
+ olm::Curve25519KeyPair & value
) {
- pos = axolotl::unpickle_bytes(
+ pos = olm::unpickle_bytes(
pos, end, value.public_key, sizeof(value.public_key)
);
- pos = axolotl::unpickle_bytes(
+ pos = olm::unpickle_bytes(
pos, end, value.private_key, sizeof(value.private_key)
);
return pos;
diff --git a/src/ratchet.cpp b/src/ratchet.cpp
index 37d2d4e..2f361fa 100644
--- a/src/ratchet.cpp
+++ b/src/ratchet.cpp
@@ -12,11 +12,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "axolotl/ratchet.hh"
-#include "axolotl/message.hh"
-#include "axolotl/memory.hh"
-#include "axolotl/cipher.hh"
-#include "axolotl/pickle.hh"
+#include "olm/ratchet.hh"
+#include "olm/message.hh"
+#include "olm/memory.hh"
+#include "olm/cipher.hh"
+#include "olm/pickle.hh"
#include <cstring>
@@ -24,23 +24,23 @@
namespace {
std::uint8_t PROTOCOL_VERSION = 3;
-std::size_t KEY_LENGTH = axolotl::Curve25519PublicKey::LENGTH;
+std::size_t KEY_LENGTH = olm::Curve25519PublicKey::LENGTH;
std::uint8_t MESSAGE_KEY_SEED[1] = {0x01};
std::uint8_t CHAIN_KEY_SEED[1] = {0x02};
std::size_t MAX_MESSAGE_GAP = 2000;
void create_chain_key(
- axolotl::SharedKey const & root_key,
- axolotl::Curve25519KeyPair const & our_key,
- axolotl::Curve25519PublicKey const & their_key,
- axolotl::KdfInfo const & info,
- axolotl::SharedKey & new_root_key,
- axolotl::ChainKey & new_chain_key
+ olm::SharedKey const & root_key,
+ olm::Curve25519KeyPair const & our_key,
+ olm::Curve25519PublicKey const & their_key,
+ olm::KdfInfo const & info,
+ olm::SharedKey & new_root_key,
+ olm::ChainKey & new_chain_key
) {
- axolotl::SharedKey secret;
- axolotl::curve25519_shared_secret(our_key, their_key, secret);
+ olm::SharedKey secret;
+ olm::curve25519_shared_secret(our_key, their_key, secret);
std::uint8_t derived_secrets[64];
- axolotl::hkdf_sha256(
+ olm::hkdf_sha256(
secret, sizeof(secret),
root_key, sizeof(root_key),
info.ratchet_info, info.ratchet_info_length,
@@ -49,16 +49,16 @@ void create_chain_key(
std::memcpy(new_root_key, derived_secrets, 32);
std::memcpy(new_chain_key.key, derived_secrets + 32, 32);
new_chain_key.index = 0;
- axolotl::unset(derived_secrets);
- axolotl::unset(secret);
+ olm::unset(derived_secrets);
+ olm::unset(secret);
}
void advance_chain_key(
- axolotl::ChainKey const & chain_key,
- axolotl::ChainKey & new_chain_key
+ olm::ChainKey const & chain_key,
+ olm::ChainKey & new_chain_key
) {
- axolotl::hmac_sha256(
+ olm::hmac_sha256(
chain_key.key, sizeof(chain_key.key),
CHAIN_KEY_SEED, sizeof(CHAIN_KEY_SEED),
new_chain_key.key
@@ -68,11 +68,11 @@ void advance_chain_key(
void create_message_keys(
- axolotl::ChainKey const & chain_key,
- axolotl::KdfInfo const & info,
- axolotl::MessageKey & message_key
+ olm::ChainKey const & chain_key,
+ olm::KdfInfo const & info,
+ olm::MessageKey & message_key
) {
- axolotl::hmac_sha256(
+ olm::hmac_sha256(
chain_key.key, sizeof(chain_key.key),
MESSAGE_KEY_SEED, sizeof(MESSAGE_KEY_SEED),
message_key.key
@@ -82,9 +82,9 @@ void create_message_keys(
std::size_t verify_mac_and_decrypt(
- axolotl::Cipher const & cipher,
- axolotl::MessageKey const & message_key,
- axolotl::MessageReader const & reader,
+ olm::Cipher const & cipher,
+ olm::MessageKey const & message_key,
+ olm::MessageReader const & reader,
std::uint8_t * plaintext, std::size_t max_plaintext_length
) {
return cipher.decrypt(
@@ -97,9 +97,9 @@ std::size_t verify_mac_and_decrypt(
std::size_t verify_mac_and_decrypt_for_existing_chain(
- axolotl::Ratchet const & session,
- axolotl::ChainKey const & chain,
- axolotl::MessageReader const & reader,
+ olm::Ratchet const & session,
+ olm::ChainKey const & chain,
+ olm::MessageReader const & reader,
std::uint8_t * plaintext, std::size_t max_plaintext_length
) {
if (reader.counter < chain.index) {
@@ -111,13 +111,13 @@ std::size_t verify_mac_and_decrypt_for_existing_chain(
return std::size_t(-1);
}
- axolotl::ChainKey new_chain = chain;
+ olm::ChainKey new_chain = chain;
while (new_chain.index < reader.counter) {
advance_chain_key(new_chain, new_chain);
}
- axolotl::MessageKey message_key;
+ olm::MessageKey message_key;
create_message_keys(new_chain, session.kdf_info, message_key);
std::size_t result = verify_mac_and_decrypt(
@@ -125,18 +125,18 @@ std::size_t verify_mac_and_decrypt_for_existing_chain(
plaintext, max_plaintext_length
);
- axolotl::unset(new_chain);
+ olm::unset(new_chain);
return result;
}
std::size_t verify_mac_and_decrypt_for_new_chain(
- axolotl::Ratchet const & session,
- axolotl::MessageReader const & reader,
+ olm::Ratchet const & session,
+ olm::MessageReader const & reader,
std::uint8_t * plaintext, std::size_t max_plaintext_length
) {
- axolotl::SharedKey new_root_key;
- axolotl::ReceiverChain new_chain;
+ olm::SharedKey new_root_key;
+ olm::ReceiverChain new_chain;
/* They shouldn't move to a new chain until we've sent them a message
* acknowledging the last one */
@@ -162,29 +162,29 @@ std::size_t verify_mac_and_decrypt_for_new_chain(
session, new_chain.chain_key, reader,
plaintext, max_plaintext_length
);
- axolotl::unset(new_root_key);
- axolotl::unset(new_chain);
+ olm::unset(new_root_key);
+ olm::unset(new_chain);
return result;
}
} // namespace
-axolotl::Ratchet::Ratchet(
- axolotl::KdfInfo const & kdf_info,
+olm::Ratchet::Ratchet(
+ olm::KdfInfo const & kdf_info,
Cipher const & ratchet_cipher
) : kdf_info(kdf_info),
ratchet_cipher(ratchet_cipher),
- last_error(axolotl::ErrorCode::SUCCESS) {
+ last_error(olm::ErrorCode::SUCCESS) {
}
-void axolotl::Ratchet::initialise_as_bob(
+void olm::Ratchet::initialise_as_bob(
std::uint8_t const * shared_secret, std::size_t shared_secret_length,
- axolotl::Curve25519PublicKey const & their_ratchet_key
+ olm::Curve25519PublicKey const & their_ratchet_key
) {
std::uint8_t derived_secrets[64];
- axolotl::hkdf_sha256(
+ olm::hkdf_sha256(
shared_secret, shared_secret_length,
nullptr, 0,
kdf_info.root_info, kdf_info.root_info_length,
@@ -195,16 +195,16 @@ void axolotl::Ratchet::initialise_as_bob(
std::memcpy(root_key, derived_secrets, 32);
std::memcpy(receiver_chains[0].chain_key.key, derived_secrets + 32, 32);
receiver_chains[0].ratchet_key = their_ratchet_key;
- axolotl::unset(derived_secrets);
+ olm::unset(derived_secrets);
}
-void axolotl::Ratchet::initialise_as_alice(
+void olm::Ratchet::initialise_as_alice(
std::uint8_t const * shared_secret, std::size_t shared_secret_length,
- axolotl::Curve25519KeyPair const & our_ratchet_key
+ olm::Curve25519KeyPair const & our_ratchet_key
) {
std::uint8_t derived_secrets[64];
- axolotl::hkdf_sha256(
+ olm::hkdf_sha256(
shared_secret, shared_secret_length,
nullptr, 0,
kdf_info.root_info, kdf_info.root_info_length,
@@ -215,14 +215,14 @@ void axolotl::Ratchet::initialise_as_alice(
std::memcpy(root_key, derived_secrets, 32);
std::memcpy(sender_chain[0].chain_key.key, derived_secrets + 32, 32);
sender_chain[0].ratchet_key = our_ratchet_key;
- axolotl::unset(derived_secrets);
+ olm::unset(derived_secrets);
}
-namespace axolotl {
+namespace olm {
static std::size_t pickle_length(
- const axolotl::SharedKey & value
+ const olm::SharedKey & value
) {
return KEY_LENGTH;
}
@@ -230,135 +230,135 @@ static std::size_t pickle_length(
static std::uint8_t * pickle(
std::uint8_t * pos,
- const axolotl::SharedKey & value
+ const olm::SharedKey & value
) {
- return axolotl::pickle_bytes(pos, value, KEY_LENGTH);
+ return olm::pickle_bytes(pos, value, KEY_LENGTH);
}
static std::uint8_t const * unpickle(
std::uint8_t const * pos, std::uint8_t const * end,
- axolotl::SharedKey & value
+ olm::SharedKey & value
) {
- return axolotl::unpickle_bytes(pos, end, value, KEY_LENGTH);
+ return olm::unpickle_bytes(pos, end, value, KEY_LENGTH);
}
static std::size_t pickle_length(
- const axolotl::SenderChain & value
+ const olm::SenderChain & value
) {
std::size_t length = 0;
- length += axolotl::pickle_length(value.ratchet_key);
- length += axolotl::pickle_length(value.chain_key.key);
- length += axolotl::pickle_length(value.chain_key.index);
+ length += olm::pickle_length(value.ratchet_key);
+ length += olm::pickle_length(value.chain_key.key);
+ length += olm::pickle_length(value.chain_key.index);
return length;
}
static std::uint8_t * pickle(
std::uint8_t * pos,
- const axolotl::SenderChain & value
+ const olm::SenderChain & value
) {
- pos = axolotl::pickle(pos, value.ratchet_key);
- pos = axolotl::pickle(pos, value.chain_key.key);
- pos = axolotl::pickle(pos, value.chain_key.index);
+ pos = olm::pickle(pos, value.ratchet_key);
+ pos = olm::pickle(pos, value.chain_key.key);
+ pos = olm::pickle(pos, value.chain_key.index);
return pos;
}
static std::uint8_t const * unpickle(
std::uint8_t const * pos, std::uint8_t const * end,
- axolotl::SenderChain & value
+ olm::SenderChain & value
) {
- pos = axolotl::unpickle(pos, end, value.ratchet_key);
- pos = axolotl::unpickle(pos, end, value.chain_key.key);
- pos = axolotl::unpickle(pos, end, value.chain_key.index);
+ pos = olm::unpickle(pos, end, value.ratchet_key);
+ pos = olm::unpickle(pos, end, value.chain_key.key);
+ pos = olm::unpickle(pos, end, value.chain_key.index);
return pos;
}
static std::size_t pickle_length(
- const axolotl::ReceiverChain & value
+ const olm::ReceiverChain & value
) {
std::size_t length = 0;
- length += axolotl::pickle_length(value.ratchet_key);
- length += axolotl::pickle_length(value.chain_key.key);
- length += axolotl::pickle_length(value.chain_key.index);
+ length += olm::pickle_length(value.ratchet_key);
+ length += olm::pickle_length(value.chain_key.key);
+ length += olm::pickle_length(value.chain_key.index);
return length;
}
static std::uint8_t * pickle(
std::uint8_t * pos,
- const axolotl::ReceiverChain & value
+ const olm::ReceiverChain & value
) {
- pos = axolotl::pickle(pos, value.ratchet_key);
- pos = axolotl::pickle(pos, value.chain_key.key);
- pos = axolotl::pickle(pos, value.chain_key.index);
+ pos = olm::pickle(pos, value.ratchet_key);
+ pos = olm::pickle(pos, value.chain_key.key);
+ pos = olm::pickle(pos, value.chain_key.index);
return pos;
}
static std::uint8_t const * unpickle(
std::uint8_t const * pos, std::uint8_t const * end,
- axolotl::ReceiverChain & value
+ olm::ReceiverChain & value
) {
- pos = axolotl::unpickle(pos, end, value.ratchet_key);
- pos = axolotl::unpickle(pos, end, value.chain_key.key);
- pos = axolotl::unpickle(pos, end, value.chain_key.index);
+ pos = olm::unpickle(pos, end, value.ratchet_key);
+ pos = olm::unpickle(pos, end, value.chain_key.key);
+ pos = olm::unpickle(pos, end, value.chain_key.index);
return pos;
}
static std::size_t pickle_length(
- const axolotl::SkippedMessageKey & value
+ const olm::SkippedMessageKey & value
) {
std::size_t length = 0;
- length += axolotl::pickle_length(value.ratchet_key);
- length += axolotl::pickle_length(value.message_key.key);
- length += axolotl::pickle_length(value.message_key.index);
+ length += olm::pickle_length(value.ratchet_key);
+ length += olm::pickle_length(value.message_key.key);
+ length += olm::pickle_length(value.message_key.index);
return length;
}
static std::uint8_t * pickle(
std::uint8_t * pos,
- const axolotl::SkippedMessageKey & value
+ const olm::SkippedMessageKey & value
) {
- pos = axolotl::pickle(pos, value.ratchet_key);
- pos = axolotl::pickle(pos, value.message_key.key);
- pos = axolotl::pickle(pos, value.message_key.index);
+ pos = olm::pickle(pos, value.ratchet_key);
+ pos = olm::pickle(pos, value.message_key.key);
+ pos = olm::pickle(pos, value.message_key.index);
return pos;
}
static std::uint8_t const * unpickle(
std::uint8_t const * pos, std::uint8_t const * end,
- axolotl::SkippedMessageKey & value
+ olm::SkippedMessageKey & value
) {
- pos = axolotl::unpickle(pos, end, value.ratchet_key);
- pos = axolotl::unpickle(pos, end, value.message_key.key);
- pos = axolotl::unpickle(pos, end, value.message_key.index);
+ pos = olm::unpickle(pos, end, value.ratchet_key);
+ pos = olm::unpickle(pos, end, value.message_key.key);
+ pos = olm::unpickle(pos, end, value.message_key.index);
return pos;
}
-} // namespace axolotl
+} // namespace olm
-std::size_t axolotl::pickle_length(
- axolotl::Ratchet const & value
+std::size_t olm::pickle_length(
+ olm::Ratchet const & value
) {
std::size_t length = 0;
length += KEY_LENGTH;
- length += axolotl::pickle_length(value.sender_chain);
- length += axolotl::pickle_length(value.receiver_chains);
- length += axolotl::pickle_length(value.skipped_message_keys);
+ length += olm::pickle_length(value.sender_chain);
+ length += olm::pickle_length(value.receiver_chains);
+ length += olm::pickle_length(value.skipped_message_keys);
return length;
}
-std::uint8_t * axolotl::pickle(
+std::uint8_t * olm::pickle(
std::uint8_t * pos,
- axolotl::Ratchet const & value
+ olm::Ratchet const & value
) {
pos = pickle(pos, value.root_key);
pos = pickle(pos, value.sender_chain);
@@ -368,9 +368,9 @@ std::uint8_t * axolotl::pickle(
}
-std::uint8_t const * axolotl::unpickle(
+std::uint8_t const * olm::unpickle(
std::uint8_t const * pos, std::uint8_t const * end,
- axolotl::Ratchet & value
+ olm::Ratchet & value
) {
pos = unpickle(pos, end, value.root_key);
pos = unpickle(pos, end, value.sender_chain);
@@ -380,7 +380,7 @@ std::uint8_t const * axolotl::unpickle(
}
-std::size_t axolotl::Ratchet::encrypt_output_length(
+std::size_t olm::Ratchet::encrypt_output_length(
std::size_t plaintext_length
) {
std::size_t counter = 0;
@@ -390,18 +390,18 @@ std::size_t axolotl::Ratchet::encrypt_output_length(
std::size_t padded = ratchet_cipher.encrypt_ciphertext_length(
plaintext_length
);
- return axolotl::encode_message_length(
+ return olm::encode_message_length(
counter, KEY_LENGTH, padded, ratchet_cipher.mac_length()
);
}
-std::size_t axolotl::Ratchet::encrypt_random_length() {
+std::size_t olm::Ratchet::encrypt_random_length() {
return sender_chain.empty() ? KEY_LENGTH : 0;
}
-std::size_t axolotl::Ratchet::encrypt(
+std::size_t olm::Ratchet::encrypt(
std::uint8_t const * plaintext, std::size_t plaintext_length,
std::uint8_t const * random, std::size_t random_length,
std::uint8_t * output, std::size_t max_output_length
@@ -409,17 +409,17 @@ std::size_t axolotl::Ratchet::encrypt(
std::size_t output_length = encrypt_output_length(plaintext_length);
if (random_length < encrypt_random_length()) {
- last_error = axolotl::ErrorCode::NOT_ENOUGH_RANDOM;
+ last_error = olm::ErrorCode::NOT_ENOUGH_RANDOM;
return std::size_t(-1);
}
if (max_output_length < output_length) {
- last_error = axolotl::ErrorCode::OUTPUT_BUFFER_TOO_SMALL;
+ last_error = olm::ErrorCode::OUTPUT_BUFFER_TOO_SMALL;
return std::size_t(-1);
}
if (sender_chain.empty()) {
sender_chain.insert();
- axolotl::generate_key(random, sender_chain[0].ratchet_key);
+ olm::generate_key(random, sender_chain[0].ratchet_key);
create_chain_key(
root_key,
sender_chain[0].ratchet_key,
@@ -439,9 +439,9 @@ std::size_t axolotl::Ratchet::encrypt(
std::uint32_t counter = keys.index;
Curve25519PublicKey const & ratchet_key = sender_chain[0].ratchet_key;
- axolotl::MessageWriter writer;
+ olm::MessageWriter writer;
- axolotl::encode_message(
+ olm::encode_message(
writer, PROTOCOL_VERSION, counter, KEY_LENGTH, ciphertext_length, output
);
@@ -454,21 +454,21 @@ std::size_t axolotl::Ratchet::encrypt(
output, output_length
);
- axolotl::unset(keys);
+ olm::unset(keys);
return output_length;
}
-std::size_t axolotl::Ratchet::decrypt_max_plaintext_length(
+std::size_t olm::Ratchet::decrypt_max_plaintext_length(
std::uint8_t const * input, std::size_t input_length
) {
- axolotl::MessageReader reader;
- axolotl::decode_message(
+ olm::MessageReader reader;
+ olm::decode_message(
reader, input, input_length, ratchet_cipher.mac_length()
);
if (!reader.ciphertext) {
- last_error = axolotl::ErrorCode::BAD_MESSAGE_FORMAT;
+ last_error = olm::ErrorCode::BAD_MESSAGE_FORMAT;
return std::size_t(-1);
}
@@ -476,22 +476,22 @@ std::size_t axolotl::Ratchet::decrypt_max_plaintext_length(
}
-std::size_t axolotl::Ratchet::decrypt(
+std::size_t olm::Ratchet::decrypt(
std::uint8_t const * input, std::size_t input_length,
std::uint8_t * plaintext, std::size_t max_plaintext_length
) {
- axolotl::MessageReader reader;
- axolotl::decode_message(
+ olm::MessageReader reader;
+ olm::decode_message(
reader, input, input_length, ratchet_cipher.mac_length()
);
if (reader.version != PROTOCOL_VERSION) {
- last_error = axolotl::ErrorCode::BAD_MESSAGE_VERSION;
+ last_error = olm::ErrorCode::BAD_MESSAGE_VERSION;
return std::size_t(-1);
}
if (!reader.has_counter || !reader.ratchet_key || !reader.ciphertext) {
- last_error = axolotl::ErrorCode::BAD_MESSAGE_FORMAT;
+ last_error = olm::ErrorCode::BAD_MESSAGE_FORMAT;
return std::size_t(-1);
}
@@ -500,17 +500,17 @@ std::size_t axolotl::Ratchet::decrypt(
);
if (max_plaintext_length < max_length) {
- last_error = axolotl::ErrorCode::OUTPUT_BUFFER_TOO_SMALL;
+ last_error = olm::ErrorCode::OUTPUT_BUFFER_TOO_SMALL;
return std::size_t(-1);
}
if (reader.ratchet_key_length != KEY_LENGTH) {
- last_error = axolotl::ErrorCode::BAD_MESSAGE_FORMAT;
+ last_error = olm::ErrorCode::BAD_MESSAGE_FORMAT;
return std::size_t(-1);
}
ReceiverChain * chain = nullptr;
- for (axolotl::ReceiverChain & receiver_chain : receiver_chains) {
+ for (olm::ReceiverChain & receiver_chain : receiver_chains) {
if (0 == std::memcmp(
receiver_chain.ratchet_key.public_key, reader.ratchet_key,
KEY_LENGTH
@@ -529,7 +529,7 @@ std::size_t axolotl::Ratchet::decrypt(
} else if (chain->chain_key.index > reader.counter) {
/* Chain already advanced beyond the key for this message
* Check if the message keys are in the skipped key list. */
- for (axolotl::SkippedMessageKey & skipped : skipped_message_keys) {
+ for (olm::SkippedMessageKey & skipped : skipped_message_keys) {
if (reader.counter == skipped.message_key.index
&& 0 == std::memcmp(
skipped.ratchet_key.public_key, reader.ratchet_key,
@@ -546,7 +546,7 @@ std::size_t axolotl::Ratchet::decrypt(
if (result != std::size_t(-1)) {
/* Remove the key from the skipped keys now that we've
* decoded the message it corresponds to. */
- axolotl::unset(skipped);
+ olm::unset(skipped);
skipped_message_keys.erase(&skipped);
return result;
}
@@ -559,7 +559,7 @@ std::size_t axolotl::Ratchet::decrypt(
}
if (result == std::size_t(-1)) {
- last_error = axolotl::ErrorCode::BAD_MESSAGE_MAC;
+ last_error = olm::ErrorCode::BAD_MESSAGE_MAC;
return std::size_t(-1);
}
@@ -576,12 +576,12 @@ std::size_t axolotl::Ratchet::decrypt(
root_key, sender_chain[0].ratchet_key, chain->ratchet_key,
kdf_info, root_key, chain->chain_key
);
- axolotl::unset(sender_chain[0]);
+ olm::unset(sender_chain[0]);
sender_chain.erase(sender_chain.begin());
}
while (chain->chain_key.index < reader.counter) {
- axolotl::SkippedMessageKey & key = *skipped_message_keys.insert();
+ olm::SkippedMessageKey & key = *skipped_message_keys.insert();
create_message_keys(chain->chain_key, kdf_info, key.message_key);
key.ratchet_key = chain->ratchet_key;
advance_chain_key(chain->chain_key, chain->chain_key);
diff --git a/src/session.cpp b/src/session.cpp
index 9d0935b..a028431 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -12,13 +12,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "axolotl/session.hh"
-#include "axolotl/cipher.hh"
-#include "axolotl/crypto.hh"
-#include "axolotl/account.hh"
-#include "axolotl/memory.hh"
-#include "axolotl/message.hh"
-#include "axolotl/pickle.hh"
+#include "olm/session.hh"
+#include "olm/cipher.hh"
+#include "olm/crypto.hh"
+#include "olm/account.hh"
+#include "olm/memory.hh"
+#include "olm/message.hh"
+#include "olm/pickle.hh"
#include <cstring>
@@ -27,51 +27,51 @@ namespace {
static const std::size_t KEY_LENGTH = 32;
static const std::uint8_t PROTOCOL_VERSION = 0x3;
-static const std::uint8_t ROOT_KDF_INFO[] = "AXOLOTL_ROOT";
-static const std::uint8_t RATCHET_KDF_INFO[] = "AXOLOTL_RATCHET";
-static const std::uint8_t CIPHER_KDF_INFO[] = "AXOLOTL_KEYS";
+static const std::uint8_t ROOT_KDF_INFO[] = "OLM_ROOT";
+static const std::uint8_t RATCHET_KDF_INFO[] = "OLM_RATCHET";
+static const std::uint8_t CIPHER_KDF_INFO[] = "OLM_KEYS";
-static const axolotl::CipherAesSha256 AXOLOTL_CIPHER(
+static const olm::CipherAesSha256 OLM_CIPHER(
CIPHER_KDF_INFO, sizeof(CIPHER_KDF_INFO) -1
);
-static const axolotl::KdfInfo AXOLOTL_KDF_INFO = {
+static const olm::KdfInfo OLM_KDF_INFO = {
ROOT_KDF_INFO, sizeof(ROOT_KDF_INFO) - 1,
RATCHET_KDF_INFO, sizeof(RATCHET_KDF_INFO) - 1
};
} // namespace
-axolotl::Session::Session(
-) : ratchet(AXOLOTL_KDF_INFO, AXOLOTL_CIPHER),
- last_error(axolotl::ErrorCode::SUCCESS),
+olm::Session::Session(
+) : ratchet(OLM_KDF_INFO, OLM_CIPHER),
+ last_error(olm::ErrorCode::SUCCESS),
received_message(false),
bob_one_time_key_id(0) {
}
-std::size_t axolotl::Session::new_outbound_session_random_length() {
+std::size_t olm::Session::new_outbound_session_random_length() {
return KEY_LENGTH * 2;
}
-std::size_t axolotl::Session::new_outbound_session(
- axolotl::Account const & local_account,
- axolotl::Curve25519PublicKey const & identity_key,
- axolotl::RemoteKey const & one_time_key,
+std::size_t olm::Session::new_outbound_session(
+ olm::Account const & local_account,
+ olm::Curve25519PublicKey const & identity_key,
+ olm::RemoteKey const & one_time_key,
std::uint8_t const * random, std::size_t random_length
) {
if (random_length < new_outbound_session_random_length()) {
- last_error = axolotl::ErrorCode::NOT_ENOUGH_RANDOM;
+ last_error = olm::ErrorCode::NOT_ENOUGH_RANDOM;
return std::size_t(-1);
}
Curve25519KeyPair base_key;
- axolotl::generate_key(random, base_key);
+ olm::generate_key(random, base_key);
Curve25519KeyPair ratchet_key;
- axolotl::generate_key(random + 32, ratchet_key);
+ olm::generate_key(random + 32, ratchet_key);
received_message = false;
alice_identity_key.id = local_account.identity_key.id;
@@ -81,21 +81,21 @@ std::size_t axolotl::Session::new_outbound_session(
std::uint8_t shared_secret[96];
- axolotl::curve25519_shared_secret(
+ olm::curve25519_shared_secret(
local_account.identity_key.key, one_time_key.key, shared_secret
);
- axolotl::curve25519_shared_secret(
+ olm::curve25519_shared_secret(
base_key, identity_key, shared_secret + 32
);
- axolotl::curve25519_shared_secret(
+ olm::curve25519_shared_secret(
base_key, one_time_key.key, shared_secret + 64
);
ratchet.initialise_as_alice(shared_secret, 96, ratchet_key);
- axolotl::unset(base_key);
- axolotl::unset(ratchet_key);
- axolotl::unset(shared_secret);
+ olm::unset(base_key);
+ olm::unset(ratchet_key);
+ olm::unset(shared_secret);
return std::size_t(0);
}
@@ -103,7 +103,7 @@ std::size_t axolotl::Session::new_outbound_session(
namespace {
bool check_message_fields(
- axolotl::PreKeyMessageReader & reader
+ olm::PreKeyMessageReader & reader
) {
bool ok = true;
ok = ok && reader.identity_key;
@@ -118,19 +118,19 @@ bool check_message_fields(
} // namespace
-std::size_t axolotl::Session::new_inbound_session(
- axolotl::Account & local_account,
+std::size_t olm::Session::new_inbound_session(
+ olm::Account & local_account,
std::uint8_t const * one_time_key_message, std::size_t message_length
) {
- axolotl::PreKeyMessageReader reader;
+ olm::PreKeyMessageReader reader;
decode_one_time_key_message(reader, one_time_key_message, message_length);
if (!check_message_fields(reader)) {
- last_error = axolotl::ErrorCode::BAD_MESSAGE_FORMAT;
+ last_error = olm::ErrorCode::BAD_MESSAGE_FORMAT;
return std::size_t(-1);
}
- axolotl::MessageReader message_reader;
+ olm::MessageReader message_reader;
decode_message(
message_reader, reader.message, reader.message_length,
ratchet.ratchet_cipher.mac_length()
@@ -138,34 +138,34 @@ std::size_t axolotl::Session::new_inbound_session(
if (!message_reader.ratchet_key
|| message_reader.ratchet_key_length != KEY_LENGTH) {
- last_error = axolotl::ErrorCode::BAD_MESSAGE_FORMAT;
+ last_error = olm::ErrorCode::BAD_MESSAGE_FORMAT;
return std::size_t(-1);
}
std::memcpy(alice_identity_key.key.public_key, reader.identity_key, 32);
std::memcpy(alice_base_key.public_key, reader.base_key, 32);
bob_one_time_key_id = reader.one_time_key_id;
- axolotl::Curve25519PublicKey ratchet_key;
+ olm::Curve25519PublicKey ratchet_key;
std::memcpy(ratchet_key.public_key, message_reader.ratchet_key, 32);
- axolotl::LocalKey const * bob_one_time_key = local_account.lookup_key(
+ olm::LocalKey const * bob_one_time_key = local_account.lookup_key(
bob_one_time_key_id
);
if (!bob_one_time_key) {
- last_error = axolotl::ErrorCode::BAD_MESSAGE_KEY_ID;
+ last_error = olm::ErrorCode::BAD_MESSAGE_KEY_ID;
return std::size_t(-1);
}
std::uint8_t shared_secret[96];
- axolotl::curve25519_shared_secret(
+ olm::curve25519_shared_secret(
bob_one_time_key->key, alice_identity_key.key, shared_secret
);
- axolotl::curve25519_shared_secret(
+ olm::curve25519_shared_secret(
local_account.identity_key.key, alice_base_key, shared_secret + 32
);
- axolotl::curve25519_shared_secret(
+ olm::curve25519_shared_secret(
bob_one_time_key->key, alice_base_key, shared_secret + 64
);
@@ -175,10 +175,10 @@ std::size_t axolotl::Session::new_inbound_session(
}
-bool axolotl::Session::matches_inbound_session(
+bool olm::Session::matches_inbound_session(
std::uint8_t const * one_time_key_message, std::size_t message_length
) {
- axolotl::PreKeyMessageReader reader;
+ olm::PreKeyMessageReader reader;
decode_one_time_key_message(reader, one_time_key_message, message_length);
if (!check_message_fields(reader)) {
@@ -197,16 +197,16 @@ bool axolotl::Session::matches_inbound_session(
}
-axolotl::MessageType axolotl::Session::encrypt_message_type() {
+olm::MessageType olm::Session::encrypt_message_type() {
if (received_message) {
- return axolotl::MessageType::MESSAGE;
+ return olm::MessageType::MESSAGE;
} else {
- return axolotl::MessageType::PRE_KEY;
+ return olm::MessageType::PRE_KEY;
}
}
-std::size_t axolotl::Session::encrypt_message_length(
+std::size_t olm::Session::encrypt_message_length(
std::size_t plaintext_length
) {
std::size_t message_length = ratchet.encrypt_output_length(
@@ -226,18 +226,18 @@ std::size_t axolotl::Session::encrypt_message_length(
}
-std::size_t axolotl::Session::encrypt_random_length() {
+std::size_t olm::Session::encrypt_random_length() {
return ratchet.encrypt_random_length();
}
-std::size_t axolotl::Session::encrypt(
+std::size_t olm::Session::encrypt(
std::uint8_t const * plaintext, std::size_t plaintext_length,
std::uint8_t const * random, std::size_t random_length,
std::uint8_t * message, std::size_t message_length
) {
if (message_length < encrypt_message_length(plaintext_length)) {
- last_error = axolotl::ErrorCode::OUTPUT_BUFFER_TOO_SMALL;
+ last_error = olm::ErrorCode::OUTPUT_BUFFER_TOO_SMALL;
return std::size_t(-1);
}
std::uint8_t * message_body;
@@ -248,7 +248,7 @@ std::size_t axolotl::Session::encrypt(
if (received_message) {
message_body = message;
} else {
- axolotl::PreKeyMessageWriter writer;
+ olm::PreKeyMessageWriter writer;
encode_one_time_key_message(
writer,
PROTOCOL_VERSION,
@@ -275,26 +275,26 @@ std::size_t axolotl::Session::encrypt(
if (result == std::size_t(-1)) {
last_error = ratchet.last_error;
- ratchet.last_error = axolotl::ErrorCode::SUCCESS;
+ ratchet.last_error = olm::ErrorCode::SUCCESS;
}
return result;
}
-std::size_t axolotl::Session::decrypt_max_plaintext_length(
+std::size_t olm::Session::decrypt_max_plaintext_length(
MessageType message_type,
std::uint8_t const * message, std::size_t message_length
) {
std::uint8_t const * message_body;
std::size_t message_body_length;
- if (message_type == axolotl::MessageType::MESSAGE) {
+ if (message_type == olm::MessageType::MESSAGE) {
message_body = message;
message_body_length = message_length;
} else {
- axolotl::PreKeyMessageReader reader;
+ olm::PreKeyMessageReader reader;
decode_one_time_key_message(reader, message, message_length);
if (!reader.message) {
- last_error = axolotl::ErrorCode::BAD_MESSAGE_FORMAT;
+ last_error = olm::ErrorCode::BAD_MESSAGE_FORMAT;
return std::size_t(-1);
}
message_body = reader.message;
@@ -307,27 +307,27 @@ std::size_t axolotl::Session::decrypt_max_plaintext_length(
if (result == std::size_t(-1)) {
last_error = ratchet.last_error;
- ratchet.last_error = axolotl::ErrorCode::SUCCESS;
+ ratchet.last_error = olm::ErrorCode::SUCCESS;
}
return result;
}
-std::size_t axolotl::Session::decrypt(
- axolotl::MessageType message_type,
+std::size_t olm::Session::decrypt(
+ olm::MessageType message_type,
std::uint8_t const * message, std::size_t message_length,
std::uint8_t * plaintext, std::size_t max_plaintext_length
) {
std::uint8_t const * message_body;
std::size_t message_body_length;
- if (message_type == axolotl::MessageType::MESSAGE) {
+ if (message_type == olm::MessageType::MESSAGE) {
message_body = message;
message_body_length = message_length;
} else {
- axolotl::PreKeyMessageReader reader;
+ olm::PreKeyMessageReader reader;
decode_one_time_key_message(reader, message, message_length);
if (!reader.message) {
- last_error = axolotl::ErrorCode::BAD_MESSAGE_FORMAT;
+ last_error = olm::ErrorCode::BAD_MESSAGE_FORMAT;
return std::size_t(-1);
}
message_body = reader.message;
@@ -340,7 +340,7 @@ std::size_t axolotl::Session::decrypt(
if (result == std::size_t(-1)) {
last_error = ratchet.last_error;
- ratchet.last_error = axolotl::ErrorCode::SUCCESS;
+ ratchet.last_error = olm::ErrorCode::SUCCESS;
} else {
received_message = true;
}
@@ -348,44 +348,44 @@ std::size_t axolotl::Session::decrypt(
}
-std::size_t axolotl::pickle_length(
+std::size_t olm::pickle_length(
Session const & value
) {
std::size_t length = 0;
- length += axolotl::pickle_length(value.received_message);
- length += axolotl::pickle_length(value.alice_identity_key.id);
- length += axolotl::pickle_length(value.alice_identity_key.key);
- length += axolotl::pickle_length(value.alice_base_key);
- length += axolotl::pickle_length(value.bob_one_time_key_id);
- length += axolotl::pickle_length(value.ratchet);
+ length += olm::pickle_length(value.received_message);
+ length += olm::pickle_length(value.alice_identity_key.id);
+ length += olm::pickle_length(value.alice_identity_key.key);
+ length += olm::pickle_length(value.alice_base_key);
+ length += olm::pickle_length(value.bob_one_time_key_id);
+ length += olm::pickle_length(value.ratchet);
return length;
}
-std::uint8_t * axolotl::pickle(
+std::uint8_t * olm::pickle(
std::uint8_t * pos,
Session const & value
) {
- pos = axolotl::pickle(pos, value.received_message);
- pos = axolotl::pickle(pos, value.alice_identity_key.id);
- pos = axolotl::pickle(pos, value.alice_identity_key.key);
- pos = axolotl::pickle(pos, value.alice_base_key);
- pos = axolotl::pickle(pos, value.bob_one_time_key_id);
- pos = axolotl::pickle(pos, value.ratchet);
+ pos = olm::pickle(pos, value.received_message);
+ pos = olm::pickle(pos, value.alice_identity_key.id);
+ pos = olm::pickle(pos, value.alice_identity_key.key);
+ pos = olm::pickle(pos, value.alice_base_key);
+ pos = olm::pickle(pos, value.bob_one_time_key_id);
+ pos = olm::pickle(pos, value.ratchet);
return pos;
}
-std::uint8_t const * axolotl::unpickle(
+std::uint8_t const * olm::unpickle(
std::uint8_t const * pos, std::uint8_t const * end,
Session & value
) {
- pos = axolotl::unpickle(pos, end, value.received_message);
- pos = axolotl::unpickle(pos, end, value.alice_identity_key.id);
- pos = axolotl::unpickle(pos, end, value.alice_identity_key.key);
- pos = axolotl::unpickle(pos, end, value.alice_base_key);
- pos = axolotl::unpickle(pos, end, value.bob_one_time_key_id);
- pos = axolotl::unpickle(pos, end, value.ratchet);
+ pos = olm::unpickle(pos, end, value.received_message);
+ pos = olm::unpickle(pos, end, value.alice_identity_key.id);
+ pos = olm::unpickle(pos, end, value.alice_identity_key.key);
+ pos = olm::unpickle(pos, end, value.alice_base_key);
+ pos = olm::unpickle(pos, end, value.bob_one_time_key_id);
+ pos = olm::unpickle(pos, end, value.ratchet);
return pos;
}
diff --git a/tests/test_axolotl.cpp b/tests/test_axolotl.cpp
deleted file mode 100644
index e8bfcc8..0000000
--- a/tests/test_axolotl.cpp
+++ /dev/null
@@ -1,269 +0,0 @@
-#include "axolotl/axolotl.hh"
-#include "unittest.hh"
-
-#include <cstddef>
-#include <cstdint>
-#include <cstring>
-
-struct MockRandom {
- MockRandom(std::uint8_t tag, std::uint8_t offset = 0)
- : tag(tag), current(offset) {}
- void operator()(
- std::uint8_t * bytes, std::size_t length
- ) {
- while (length > 32) {
- bytes[0] = tag;
- std::memset(bytes + 1, current, 31);
- length -= 32;
- bytes += 32;
- current += 1;
- }
- if (length) {
- bytes[0] = tag;
- std::memset(bytes + 1, current, length - 1);
- current += 1;
- }
- }
- std::uint8_t tag;
- std::uint8_t current;
-};
-
-int main() {
-
-{ /** Pickle account test */
-
-TestCase test_case("Pickle account test");
-MockRandom mock_random('P');
-
-
-std::uint8_t account_buffer[::axolotl_account_size()];
-::AxolotlAccount *account = ::axolotl_account(account_buffer);
-std::uint8_t random[::axolotl_create_account_random_length(account)];
-mock_random(random, sizeof(random));
-::axolotl_create_account(account, random, sizeof(random));
-std::size_t pickle_length = ::axolotl_pickle_account_length(account);
-std::uint8_t pickle1[pickle_length];
-::axolotl_pickle_account(account, "secret_key", 10, pickle1, pickle_length);
-std::uint8_t pickle2[pickle_length];
-std::memcpy(pickle2, pickle1, pickle_length);
-
-std::uint8_t account_buffer2[::axolotl_account_size()];
-::AxolotlAccount *account2 = ::axolotl_account(account_buffer2);
-::axolotl_unpickle_account(account2, "secret_key", 10, pickle2, pickle_length);
-assert_equals(pickle_length, ::axolotl_pickle_account_length(account2));
-::axolotl_pickle_account(account2, "secret_key", 10, pickle2, pickle_length);
-
-assert_equals(pickle1, pickle2, pickle_length);
-
-}
-
-{ /** Loopback test */
-
-TestCase test_case("Loopback test");
-MockRandom mock_random_a('A', 0x00);
-MockRandom mock_random_b('B', 0x80);
-
-std::uint8_t a_account_buffer[::axolotl_account_size()];
-::AxolotlAccount *a_account = ::axolotl_account(a_account_buffer);
-std::uint8_t a_random[::axolotl_create_account_random_length(a_account)];
-mock_random_a(a_random, sizeof(a_random));
-::axolotl_create_account(a_account, a_random, sizeof(a_random));
-
-std::uint8_t b_account_buffer[::axolotl_account_size()];
-::AxolotlAccount *b_account = ::axolotl_account(b_account_buffer);
-std::uint8_t b_random[::axolotl_create_account_random_length(b_account)];
-mock_random_b(b_random, sizeof(b_random));
-::axolotl_create_account(b_account, b_random, sizeof(b_random));
-
-std::uint8_t b_id_keys[::axolotl_account_identity_keys_length(b_account)];
-std::uint8_t b_ot_keys[::axolotl_account_one_time_keys_length(b_account)];
-::axolotl_account_identity_keys(b_account, b_id_keys, sizeof(b_id_keys));
-::axolotl_account_one_time_keys(b_account, b_ot_keys, sizeof(b_ot_keys));
-
-std::uint8_t a_session_buffer[::axolotl_session_size()];
-::AxolotlSession *a_session = ::axolotl_session(a_session_buffer);
-std::uint8_t a_rand[::axolotl_create_outbound_session_random_length(a_session)];
-mock_random_a(a_rand, sizeof(a_rand));
-assert_not_equals(std::size_t(-1), ::axolotl_create_outbound_session(
- a_session, a_account,
- b_id_keys + 14, 43,
- ::atol((char *)(b_ot_keys + 62)), b_ot_keys + 74, 43,
- a_rand, sizeof(a_rand)
-));
-
-std::uint8_t plaintext[] = "Hello, World";
-std::uint8_t message_1[::axolotl_encrypt_message_length(a_session, 12)];
-std::uint8_t a_message_random[::axolotl_encrypt_random_length(a_session)];
-mock_random_a(a_message_random, sizeof(a_message_random));
-assert_equals(std::size_t(0), ::axolotl_encrypt_message_type(a_session));
-assert_not_equals(std::size_t(-1), ::axolotl_encrypt(
- a_session,
- plaintext, 12,
- a_message_random, sizeof(a_message_random),
- message_1, sizeof(message_1)
-));
-
-
-std::uint8_t tmp_message_1[sizeof(message_1)];
-std::memcpy(tmp_message_1, message_1, sizeof(message_1));
-std::uint8_t b_session_buffer[::axolotl_account_size()];
-::AxolotlSession *b_session = ::axolotl_session(b_session_buffer);
-::axolotl_create_inbound_session(
- b_session, b_account, tmp_message_1, sizeof(message_1)
-);
-
-std::memcpy(tmp_message_1, message_1, sizeof(message_1));
-std::uint8_t plaintext_1[::axolotl_decrypt_max_plaintext_length(
- b_session, 0, tmp_message_1, sizeof(message_1)
-)];
-std::memcpy(tmp_message_1, message_1, sizeof(message_1));
-assert_equals(std::size_t(12), ::axolotl_decrypt(
- b_session, 0,
- tmp_message_1, sizeof(message_1),
- plaintext_1, sizeof(plaintext_1)
-));
-
-assert_equals(plaintext, plaintext_1, 12);
-
-std::uint8_t message_2[::axolotl_encrypt_message_length(b_session, 12)];
-std::uint8_t b_message_random[::axolotl_encrypt_random_length(b_session)];
-mock_random_b(b_message_random, sizeof(b_message_random));
-assert_equals(std::size_t(1), ::axolotl_encrypt_message_type(b_session));
-assert_not_equals(std::size_t(-1), ::axolotl_encrypt(
- b_session,
- plaintext, 12,
- b_message_random, sizeof(b_message_random),
- message_2, sizeof(message_2)
-));
-
-std::uint8_t tmp_message_2[sizeof(message_2)];
-std::memcpy(tmp_message_2, message_2, sizeof(message_2));
-std::uint8_t plaintext_2[::axolotl_decrypt_max_plaintext_length(
- a_session, 1, tmp_message_2, sizeof(message_2)
-)];
-std::memcpy(tmp_message_2, message_2, sizeof(message_2));
-assert_equals(std::size_t(12), ::axolotl_decrypt(
- a_session, 1,
- tmp_message_2, sizeof(message_2),
- plaintext_2, sizeof(plaintext_2)
-));
-
-assert_equals(plaintext, plaintext_2, 12);
-
-std::memcpy(tmp_message_2, message_2, sizeof(message_2));
-assert_equals(std::size_t(-1), ::axolotl_decrypt(
- a_session, 1,
- tmp_message_2, sizeof(message_2),
- plaintext_2, sizeof(plaintext_2)
-));
-
-}
-
-{ /** More messages test */
-
-TestCase test_case("More messages test");
-MockRandom mock_random_a('A', 0x00);
-MockRandom mock_random_b('B', 0x80);
-
-std::uint8_t a_account_buffer[::axolotl_account_size()];
-::AxolotlAccount *a_account = ::axolotl_account(a_account_buffer);
-std::uint8_t a_random[::axolotl_create_account_random_length(a_account)];
-mock_random_a(a_random, sizeof(a_random));
-::axolotl_create_account(a_account, a_random, sizeof(a_random));
-
-std::uint8_t b_account_buffer[::axolotl_account_size()];
-::AxolotlAccount *b_account = ::axolotl_account(b_account_buffer);
-std::uint8_t b_random[::axolotl_create_account_random_length(b_account)];
-mock_random_b(b_random, sizeof(b_random));
-::axolotl_create_account(b_account, b_random, sizeof(b_random));
-
-std::uint8_t b_id_keys[::axolotl_account_identity_keys_length(b_account)];
-std::uint8_t b_ot_keys[::axolotl_account_one_time_keys_length(b_account)];
-::axolotl_account_identity_keys(b_account, b_id_keys, sizeof(b_id_keys));
-::axolotl_account_one_time_keys(b_account, b_ot_keys, sizeof(b_ot_keys));
-
-std::uint8_t a_session_buffer[::axolotl_session_size()];
-::AxolotlSession *a_session = ::axolotl_session(a_session_buffer);
-std::uint8_t a_rand[::axolotl_create_outbound_session_random_length(a_session)];
-mock_random_a(a_rand, sizeof(a_rand));
-assert_not_equals(std::size_t(-1), ::axolotl_create_outbound_session(
- a_session, a_account,
- b_id_keys + 14, 43,
- ::atol((char *)(b_ot_keys + 62)), b_ot_keys + 74, 43,
- a_rand, sizeof(a_rand)
-));
-
-std::uint8_t plaintext[] = "Hello, World";
-std::uint8_t message_1[::axolotl_encrypt_message_length(a_session, 12)];
-std::uint8_t a_message_random[::axolotl_encrypt_random_length(a_session)];
-mock_random_a(a_message_random, sizeof(a_message_random));
-assert_equals(std::size_t(0), ::axolotl_encrypt_message_type(a_session));
-assert_not_equals(std::size_t(-1), ::axolotl_encrypt(
- a_session,
- plaintext, 12,
- a_message_random, sizeof(a_message_random),
- message_1, sizeof(message_1)
-));
-
-std::uint8_t tmp_message_1[sizeof(message_1)];
-std::memcpy(tmp_message_1, message_1, sizeof(message_1));
-std::uint8_t b_session_buffer[::axolotl_account_size()];
-::AxolotlSession *b_session = ::axolotl_session(b_session_buffer);
-::axolotl_create_inbound_session(
- b_session, b_account, tmp_message_1, sizeof(message_1)
-);
-
-std::memcpy(tmp_message_1, message_1, sizeof(message_1));
-std::uint8_t plaintext_1[::axolotl_decrypt_max_plaintext_length(
- b_session, 0, tmp_message_1, sizeof(message_1)
-)];
-std::memcpy(tmp_message_1, message_1, sizeof(message_1));
-assert_equals(std::size_t(12), ::axolotl_decrypt(
- b_session, 0,
- tmp_message_1, sizeof(message_1),
- plaintext_1, sizeof(plaintext_1)
-));
-
-for (unsigned i = 0; i < 8; ++i) {
- {
- std::uint8_t msg_a[::axolotl_encrypt_message_length(a_session, 12)];
- std::uint8_t rnd_a[::axolotl_encrypt_random_length(a_session)];
- mock_random_a(rnd_a, sizeof(rnd_a));
- std::size_t type_a = ::axolotl_encrypt_message_type(a_session);
- assert_not_equals(std::size_t(-1), ::axolotl_encrypt(
- a_session, plaintext, 12, rnd_a, sizeof(rnd_a), msg_a, sizeof(msg_a)
- ));
-
- std::uint8_t tmp_a[sizeof(msg_a)];
- std::memcpy(tmp_a, msg_a, sizeof(msg_a));
- std::uint8_t out_a[::axolotl_decrypt_max_plaintext_length(
- b_session, type_a, tmp_a, sizeof(tmp_a)
- )];
- std::memcpy(tmp_a, msg_a, sizeof(msg_a));
- assert_equals(std::size_t(12), ::axolotl_decrypt(
- b_session, type_a, msg_a, sizeof(msg_a), out_a, sizeof(out_a)
- ));
- }
- {
- std::uint8_t msg_b[::axolotl_encrypt_message_length(b_session, 12)];
- std::uint8_t rnd_b[::axolotl_encrypt_random_length(b_session)];
- mock_random_b(rnd_b, sizeof(rnd_b));
- std::size_t type_b = ::axolotl_encrypt_message_type(b_session);
- assert_not_equals(std::size_t(-1), ::axolotl_encrypt(
- b_session, plaintext, 12, rnd_b, sizeof(rnd_b), msg_b, sizeof(msg_b)
- ));
-
- std::uint8_t tmp_b[sizeof(msg_b)];
- std::memcpy(tmp_b, msg_b, sizeof(msg_b));
- std::uint8_t out_b[::axolotl_decrypt_max_plaintext_length(
- a_session, type_b, tmp_b, sizeof(tmp_b)
- )];
- std::memcpy(tmp_b, msg_b, sizeof(msg_b));
- assert_equals(std::size_t(12), ::axolotl_decrypt(
- a_session, type_b, msg_b, sizeof(msg_b), out_b, sizeof(out_b)
- ));
- }
-}
-}
-
-}
diff --git a/tests/test_base64.cpp b/tests/test_base64.cpp
index fbd9e19..e6b3710 100644
--- a/tests/test_base64.cpp
+++ b/tests/test_base64.cpp
@@ -1,4 +1,4 @@
-#include "axolotl/base64.hh"
+#include "olm/base64.hh"
#include "unittest.hh"
int main() {
@@ -10,11 +10,11 @@ std::uint8_t input[] = "Hello World";
std::uint8_t expected_output[] = "SGVsbG8gV29ybGQ";
std::size_t input_length = sizeof(input) - 1;
-std::size_t output_length = axolotl::encode_base64_length(input_length);
+std::size_t output_length = olm::encode_base64_length(input_length);
assert_equals(std::size_t(15), output_length);
std::uint8_t output[output_length];
-axolotl::encode_base64(input, input_length, output);
+olm::encode_base64(input, input_length, output);
assert_equals(expected_output, output, output_length);
}
@@ -25,11 +25,11 @@ std::uint8_t input[] = "SGVsbG8gV29ybGQ";
std::uint8_t expected_output[] = "Hello World";
std::size_t input_length = sizeof(input) - 1;
-std::size_t output_length = axolotl::decode_base64_length(input_length);
+std::size_t output_length = olm::decode_base64_length(input_length);
assert_equals(std::size_t(11), output_length);
std::uint8_t output[output_length];
-axolotl::decode_base64(input, input_length, output);
+olm::decode_base64(input, input_length, output);
assert_equals(expected_output, output, output_length);
}
diff --git a/tests/test_crypto.cpp b/tests/test_crypto.cpp
index 3ec5360..9b7637b 100644
--- a/tests/test_crypto.cpp
+++ b/tests/test_crypto.cpp
@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "axolotl/crypto.hh"
+#include "olm/crypto.hh"
#include "unittest.hh"
@@ -58,25 +58,25 @@ std::uint8_t expected_agreement[32] = {
0x76, 0xF0, 0x9B, 0x3C, 0x1E, 0x16, 0x17, 0x42
};
-axolotl::Curve25519KeyPair alice_pair;
-axolotl::generate_key(alice_private, alice_pair);
+olm::Curve25519KeyPair alice_pair;
+olm::generate_key(alice_private, alice_pair);
assert_equals(alice_private, alice_pair.private_key, 32);
assert_equals(alice_public, alice_pair.public_key, 32);
-axolotl::Curve25519KeyPair bob_pair;
-axolotl::generate_key(bob_private, bob_pair);
+olm::Curve25519KeyPair bob_pair;
+olm::generate_key(bob_private, bob_pair);
assert_equals(bob_private, bob_pair.private_key, 32);
assert_equals(bob_public, bob_pair.public_key, 32);
-std::uint8_t actual_agreement[axolotl::CURVE25519_SHARED_SECRET_LENGTH] = {};
+std::uint8_t actual_agreement[olm::CURVE25519_SHARED_SECRET_LENGTH] = {};
-axolotl::curve25519_shared_secret(alice_pair, bob_pair, actual_agreement);
+olm::curve25519_shared_secret(alice_pair, bob_pair, actual_agreement);
assert_equals(expected_agreement, actual_agreement, 32);
-axolotl::curve25519_shared_secret(bob_pair, alice_pair, actual_agreement);
+olm::curve25519_shared_secret(bob_pair, alice_pair, actual_agreement);
assert_equals(expected_agreement, actual_agreement, 32);
@@ -90,22 +90,22 @@ std::uint8_t private_key[33] = "This key is a string of 32 bytes";
std::uint8_t message[] = "message";
std::size_t message_length = sizeof(message) - 1;
-axolotl::Curve25519KeyPair key_pair;
-axolotl::generate_key(private_key, key_pair);
+olm::Curve25519KeyPair key_pair;
+olm::generate_key(private_key, key_pair);
std::uint8_t signature[64];
-axolotl::curve25519_sign(
+olm::curve25519_sign(
key_pair, message, message_length, signature
);
-bool result = axolotl::curve25519_verify(
+bool result = olm::curve25519_verify(
key_pair, message, message_length, signature
);
assert_equals(true, result);
message[0] = 'n';
-result = axolotl::curve25519_verify(
+result = olm::curve25519_verify(
key_pair, message, message_length, signature
);
assert_equals(false, result);
@@ -116,8 +116,8 @@ assert_equals(false, result);
TestCase test_case("AES Test Case 1");
-axolotl::Aes256Key key = {};
-axolotl::Aes256Iv iv = {};
+olm::Aes256Key key = {};
+olm::Aes256Iv iv = {};
std::uint8_t input[16] = {};
std::uint8_t expected[32] = {
@@ -127,16 +127,16 @@ std::uint8_t expected[32] = {
0x4B, 0xAE, 0xDF, 0xFC, 0x3D, 0x21, 0x4C, 0x38
};
-std::size_t length = axolotl::aes_encrypt_cbc_length(sizeof(input));
+std::size_t length = olm::aes_encrypt_cbc_length(sizeof(input));
assert_equals(std::size_t(32), length);
std::uint8_t actual[32] = {};
-axolotl::aes_encrypt_cbc(key, iv, input, sizeof(input), actual);
+olm::aes_encrypt_cbc(key, iv, input, sizeof(input), actual);
assert_equals(expected, actual, 32);
-length = axolotl::aes_decrypt_cbc(key, iv, expected, sizeof(expected), actual);
+length = olm::aes_decrypt_cbc(key, iv, expected, sizeof(expected), actual);
assert_equals(std::size_t(16), length);
assert_equals(input, actual, length);
@@ -158,7 +158,7 @@ std::uint8_t expected[32] = {
std::uint8_t actual[32];
-axolotl::sha256(input, sizeof(input), actual);
+olm::sha256(input, sizeof(input), actual);
assert_equals(expected, actual, 32);
@@ -179,7 +179,7 @@ std::uint8_t expected[32] = {
std::uint8_t actual[32];
-axolotl::hmac_sha256(input, sizeof(input), input, sizeof(input), actual);
+olm::hmac_sha256(input, sizeof(input), input, sizeof(input), actual);
assert_equals(expected, actual, 32);
@@ -214,7 +214,7 @@ std::uint8_t hmac_expected_output[32] = {
std::uint8_t hmac_actual_output[32] = {};
-axolotl::hmac_sha256(
+olm::hmac_sha256(
salt, sizeof(salt),
input, sizeof(input),
hmac_actual_output
@@ -233,7 +233,7 @@ std::uint8_t hkdf_expected_output[42] = {
std::uint8_t hkdf_actual_output[42] = {};
-axolotl::hkdf_sha256(
+olm::hkdf_sha256(
input, sizeof(input),
salt, sizeof(salt),
info, sizeof(info),
diff --git a/tests/test_list.cpp b/tests/test_list.cpp
index 2cf23dc..c6d9a9a 100644
--- a/tests/test_list.cpp
+++ b/tests/test_list.cpp
@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "axolotl/list.hh"
+#include "olm/list.hh"
#include "unittest.hh"
int main() {
@@ -21,7 +21,7 @@ int main() {
TestCase test_case("List insert");
-axolotl::List<int, 4> test_list;
+olm::List<int, 4> test_list;
assert_equals(std::size_t(0), test_list.size());
@@ -47,7 +47,7 @@ assert_equals(4, test_list[3]);
{ /** List erase test **/
TestCase test_case("List erase");
-axolotl::List<int, 4> test_list;
+olm::List<int, 4> test_list;
assert_equals(std::size_t(0), test_list.size());
for (int i = 0; i < 4; ++i) {
diff --git a/tests/test_message.cpp b/tests/test_message.cpp
index b46b15a..ff14649 100644
--- a/tests/test_message.cpp
+++ b/tests/test_message.cpp
@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "axolotl/message.hh"
+#include "olm/message.hh"
#include "unittest.hh"
int main() {
@@ -27,8 +27,8 @@ std::uint8_t hmacsha2[9] = "hmacsha2";
TestCase test_case("Message decode test");
-axolotl::MessageReader reader;
-axolotl::decode_message(reader, message1, 35, 8);
+olm::MessageReader reader;
+olm::decode_message(reader, message1, 35, 8);
assert_equals(std::uint8_t(3), reader.version);
assert_equals(true, reader.has_counter);
@@ -46,13 +46,13 @@ assert_equals(ciphertext, reader.ciphertext, 10);
TestCase test_case("Message encode test");
-std::size_t length = axolotl::encode_message_length(1, 10, 10, 8);
+std::size_t length = olm::encode_message_length(1, 10, 10, 8);
assert_equals(std::size_t(35), length);
std::uint8_t output[length];
-axolotl::MessageWriter writer;
-axolotl::encode_message(writer, 3, 1, 10, 10, output);
+olm::MessageWriter writer;
+olm::encode_message(writer, 3, 1, 10, 10, output);
std::memcpy(writer.ratchet_key, ratchetkey, 10);
std::memcpy(writer.ciphertext, ciphertext, 10);
diff --git a/tests/test_olm.cpp b/tests/test_olm.cpp
new file mode 100644
index 0000000..74d19e7
--- /dev/null
+++ b/tests/test_olm.cpp
@@ -0,0 +1,269 @@
+#include "olm/olm.hh"
+#include "unittest.hh"
+
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+
+struct MockRandom {
+ MockRandom(std::uint8_t tag, std::uint8_t offset = 0)
+ : tag(tag), current(offset) {}
+ void operator()(
+ std::uint8_t * bytes, std::size_t length
+ ) {
+ while (length > 32) {
+ bytes[0] = tag;
+ std::memset(bytes + 1, current, 31);
+ length -= 32;
+ bytes += 32;
+ current += 1;
+ }
+ if (length) {
+ bytes[0] = tag;
+ std::memset(bytes + 1, current, length - 1);
+ current += 1;
+ }
+ }
+ std::uint8_t tag;
+ std::uint8_t current;
+};
+
+int main() {
+
+{ /** Pickle account test */
+
+TestCase test_case("Pickle account test");
+MockRandom mock_random('P');
+
+
+std::uint8_t account_buffer[::olm_account_size()];
+::OlmAccount *account = ::olm_account(account_buffer);
+std::uint8_t random[::olm_create_account_random_length(account)];
+mock_random(random, sizeof(random));
+::olm_create_account(account, random, sizeof(random));
+std::size_t pickle_length = ::olm_pickle_account_length(account);
+std::uint8_t pickle1[pickle_length];
+::olm_pickle_account(account, "secret_key", 10, pickle1, pickle_length);
+std::uint8_t pickle2[pickle_length];
+std::memcpy(pickle2, pickle1, pickle_length);
+
+std::uint8_t account_buffer2[::olm_account_size()];
+::OlmAccount *account2 = ::olm_account(account_buffer2);
+::olm_unpickle_account(account2, "secret_key", 10, pickle2, pickle_length);
+assert_equals(pickle_length, ::olm_pickle_account_length(account2));
+::olm_pickle_account(account2, "secret_key", 10, pickle2, pickle_length);
+
+assert_equals(pickle1, pickle2, pickle_length);
+
+}
+
+{ /** Loopback test */
+
+TestCase test_case("Loopback test");
+MockRandom mock_random_a('A', 0x00);
+MockRandom mock_random_b('B', 0x80);
+
+std::uint8_t a_account_buffer[::olm_account_size()];
+::OlmAccount *a_account = ::olm_account(a_account_buffer);
+std::uint8_t a_random[::olm_create_account_random_length(a_account)];
+mock_random_a(a_random, sizeof(a_random));
+::olm_create_account(a_account, a_random, sizeof(a_random));
+
+std::uint8_t b_account_buffer[::olm_account_size()];
+::OlmAccount *b_account = ::olm_account(b_account_buffer);
+std::uint8_t b_random[::olm_create_account_random_length(b_account)];
+mock_random_b(b_random, sizeof(b_random));
+::olm_create_account(b_account, b_random, sizeof(b_random));
+
+std::uint8_t b_id_keys[::olm_account_identity_keys_length(b_account)];
+std::uint8_t b_ot_keys[::olm_account_one_time_keys_length(b_account)];
+::olm_account_identity_keys(b_account, b_id_keys, sizeof(b_id_keys));
+::olm_account_one_time_keys(b_account, b_ot_keys, sizeof(b_ot_keys));
+
+std::uint8_t a_session_buffer[::olm_session_size()];
+::OlmSession *a_session = ::olm_session(a_session_buffer);
+std::uint8_t a_rand[::olm_create_outbound_session_random_length(a_session)];
+mock_random_a(a_rand, sizeof(a_rand));
+assert_not_equals(std::size_t(-1), ::olm_create_outbound_session(
+ a_session, a_account,
+ b_id_keys + 14, 43,
+ ::atol((char *)(b_ot_keys + 62)), b_ot_keys + 74, 43,
+ a_rand, sizeof(a_rand)
+));
+
+std::uint8_t plaintext[] = "Hello, World";
+std::uint8_t message_1[::olm_encrypt_message_length(a_session, 12)];
+std::uint8_t a_message_random[::olm_encrypt_random_length(a_session)];
+mock_random_a(a_message_random, sizeof(a_message_random));
+assert_equals(std::size_t(0), ::olm_encrypt_message_type(a_session));
+assert_not_equals(std::size_t(-1), ::olm_encrypt(
+ a_session,
+ plaintext, 12,
+ a_message_random, sizeof(a_message_random),
+ message_1, sizeof(message_1)
+));
+
+
+std::uint8_t tmp_message_1[sizeof(message_1)];
+std::memcpy(tmp_message_1, message_1, sizeof(message_1));
+std::uint8_t b_session_buffer[::olm_account_size()];
+::OlmSession *b_session = ::olm_session(b_session_buffer);
+::olm_create_inbound_session(
+ b_session, b_account, tmp_message_1, sizeof(message_1)
+);
+
+std::memcpy(tmp_message_1, message_1, sizeof(message_1));
+std::uint8_t plaintext_1[::olm_decrypt_max_plaintext_length(
+ b_session, 0, tmp_message_1, sizeof(message_1)
+)];
+std::memcpy(tmp_message_1, message_1, sizeof(message_1));
+assert_equals(std::size_t(12), ::olm_decrypt(
+ b_session, 0,
+ tmp_message_1, sizeof(message_1),
+ plaintext_1, sizeof(plaintext_1)
+));
+
+assert_equals(plaintext, plaintext_1, 12);
+
+std::uint8_t message_2[::olm_encrypt_message_length(b_session, 12)];
+std::uint8_t b_message_random[::olm_encrypt_random_length(b_session)];
+mock_random_b(b_message_random, sizeof(b_message_random));
+assert_equals(std::size_t(1), ::olm_encrypt_message_type(b_session));
+assert_not_equals(std::size_t(-1), ::olm_encrypt(
+ b_session,
+ plaintext, 12,
+ b_message_random, sizeof(b_message_random),
+ message_2, sizeof(message_2)
+));
+
+std::uint8_t tmp_message_2[sizeof(message_2)];
+std::memcpy(tmp_message_2, message_2, sizeof(message_2));
+std::uint8_t plaintext_2[::olm_decrypt_max_plaintext_length(
+ a_session, 1, tmp_message_2, sizeof(message_2)
+)];
+std::memcpy(tmp_message_2, message_2, sizeof(message_2));
+assert_equals(std::size_t(12), ::olm_decrypt(
+ a_session, 1,
+ tmp_message_2, sizeof(message_2),
+ plaintext_2, sizeof(plaintext_2)
+));
+
+assert_equals(plaintext, plaintext_2, 12);
+
+std::memcpy(tmp_message_2, message_2, sizeof(message_2));
+assert_equals(std::size_t(-1), ::olm_decrypt(
+ a_session, 1,
+ tmp_message_2, sizeof(message_2),
+ plaintext_2, sizeof(plaintext_2)
+));
+
+}
+
+{ /** More messages test */
+
+TestCase test_case("More messages test");
+MockRandom mock_random_a('A', 0x00);
+MockRandom mock_random_b('B', 0x80);
+
+std::uint8_t a_account_buffer[::olm_account_size()];
+::OlmAccount *a_account = ::olm_account(a_account_buffer);
+std::uint8_t a_random[::olm_create_account_random_length(a_account)];
+mock_random_a(a_random, sizeof(a_random));
+::olm_create_account(a_account, a_random, sizeof(a_random));
+
+std::uint8_t b_account_buffer[::olm_account_size()];
+::OlmAccount *b_account = ::olm_account(b_account_buffer);
+std::uint8_t b_random[::olm_create_account_random_length(b_account)];
+mock_random_b(b_random, sizeof(b_random));
+::olm_create_account(b_account, b_random, sizeof(b_random));
+
+std::uint8_t b_id_keys[::olm_account_identity_keys_length(b_account)];
+std::uint8_t b_ot_keys[::olm_account_one_time_keys_length(b_account)];
+::olm_account_identity_keys(b_account, b_id_keys, sizeof(b_id_keys));
+::olm_account_one_time_keys(b_account, b_ot_keys, sizeof(b_ot_keys));
+
+std::uint8_t a_session_buffer[::olm_session_size()];
+::OlmSession *a_session = ::olm_session(a_session_buffer);
+std::uint8_t a_rand[::olm_create_outbound_session_random_length(a_session)];
+mock_random_a(a_rand, sizeof(a_rand));
+assert_not_equals(std::size_t(-1), ::olm_create_outbound_session(
+ a_session, a_account,
+ b_id_keys + 14, 43,
+ ::atol((char *)(b_ot_keys + 62)), b_ot_keys + 74, 43,
+ a_rand, sizeof(a_rand)
+));
+
+std::uint8_t plaintext[] = "Hello, World";
+std::uint8_t message_1[::olm_encrypt_message_length(a_session, 12)];
+std::uint8_t a_message_random[::olm_encrypt_random_length(a_session)];
+mock_random_a(a_message_random, sizeof(a_message_random));
+assert_equals(std::size_t(0), ::olm_encrypt_message_type(a_session));
+assert_not_equals(std::size_t(-1), ::olm_encrypt(
+ a_session,
+ plaintext, 12,
+ a_message_random, sizeof(a_message_random),
+ message_1, sizeof(message_1)
+));
+
+std::uint8_t tmp_message_1[sizeof(message_1)];
+std::memcpy(tmp_message_1, message_1, sizeof(message_1));
+std::uint8_t b_session_buffer[::olm_account_size()];
+::OlmSession *b_session = ::olm_session(b_session_buffer);
+::olm_create_inbound_session(
+ b_session, b_account, tmp_message_1, sizeof(message_1)
+);
+
+std::memcpy(tmp_message_1, message_1, sizeof(message_1));
+std::uint8_t plaintext_1[::olm_decrypt_max_plaintext_length(
+ b_session, 0, tmp_message_1, sizeof(message_1)
+)];
+std::memcpy(tmp_message_1, message_1, sizeof(message_1));
+assert_equals(std::size_t(12), ::olm_decrypt(
+ b_session, 0,
+ tmp_message_1, sizeof(message_1),
+ plaintext_1, sizeof(plaintext_1)
+));
+
+for (unsigned i = 0; i < 8; ++i) {
+ {
+ std::uint8_t msg_a[::olm_encrypt_message_length(a_session, 12)];
+ std::uint8_t rnd_a[::olm_encrypt_random_length(a_session)];
+ mock_random_a(rnd_a, sizeof(rnd_a));
+ std::size_t type_a = ::olm_encrypt_message_type(a_session);
+ assert_not_equals(std::size_t(-1), ::olm_encrypt(
+ a_session, plaintext, 12, rnd_a, sizeof(rnd_a), msg_a, sizeof(msg_a)
+ ));
+
+ std::uint8_t tmp_a[sizeof(msg_a)];
+ std::memcpy(tmp_a, msg_a, sizeof(msg_a));
+ std::uint8_t out_a[::olm_decrypt_max_plaintext_length(
+ b_session, type_a, tmp_a, sizeof(tmp_a)
+ )];
+ std::memcpy(tmp_a, msg_a, sizeof(msg_a));
+ assert_equals(std::size_t(12), ::olm_decrypt(
+ b_session, type_a, msg_a, sizeof(msg_a), out_a, sizeof(out_a)
+ ));
+ }
+ {
+ std::uint8_t msg_b[::olm_encrypt_message_length(b_session, 12)];
+ std::uint8_t rnd_b[::olm_encrypt_random_length(b_session)];
+ mock_random_b(rnd_b, sizeof(rnd_b));
+ std::size_t type_b = ::olm_encrypt_message_type(b_session);
+ assert_not_equals(std::size_t(-1), ::olm_encrypt(
+ b_session, plaintext, 12, rnd_b, sizeof(rnd_b), msg_b, sizeof(msg_b)
+ ));
+
+ std::uint8_t tmp_b[sizeof(msg_b)];
+ std::memcpy(tmp_b, msg_b, sizeof(msg_b));
+ std::uint8_t out_b[::olm_decrypt_max_plaintext_length(
+ a_session, type_b, tmp_b, sizeof(tmp_b)
+ )];
+ std::memcpy(tmp_b, msg_b, sizeof(msg_b));
+ assert_equals(std::size_t(12), ::olm_decrypt(
+ a_session, type_b, msg_b, sizeof(msg_b), out_b, sizeof(out_b)
+ ));
+ }
+}
+}
+
+}
diff --git a/tests/test_ratchet.cpp b/tests/test_ratchet.cpp
index fbc5031..b2db8e7 100644
--- a/tests/test_ratchet.cpp
+++ b/tests/test_ratchet.cpp
@@ -12,37 +12,37 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "axolotl/ratchet.hh"
-#include "axolotl/cipher.hh"
+#include "olm/ratchet.hh"
+#include "olm/cipher.hh"
#include "unittest.hh"
int main() {
-std::uint8_t root_info[] = "Axolotl";
-std::uint8_t ratchet_info[] = "AxolotlRatchet";
-std::uint8_t message_info[] = "AxolotlMessageKeys";
+std::uint8_t root_info[] = "Olm";
+std::uint8_t ratchet_info[] = "OlmRatchet";
+std::uint8_t message_info[] = "OlmMessageKeys";
-axolotl::KdfInfo kdf_info = {
+olm::KdfInfo kdf_info = {
root_info, sizeof(root_info) - 1,
ratchet_info, sizeof(ratchet_info) - 1
};
-axolotl::CipherAesSha256 cipher(
+olm::CipherAesSha256 cipher(
message_info, sizeof(message_info) - 1
);
std::uint8_t random_bytes[] = "0123456789ABDEF0123456789ABCDEF";
-axolotl::Curve25519KeyPair alice_key;
-axolotl::generate_key(random_bytes, alice_key);
+olm::Curve25519KeyPair alice_key;
+olm::generate_key(random_bytes, alice_key);
std::uint8_t shared_secret[] = "A secret";
{ /* Send/Receive test case */
-TestCase test_case("Axolotl Send/Receive");
+TestCase test_case("Olm Send/Receive");
-axolotl::Ratchet alice(kdf_info, cipher);
-axolotl::Ratchet bob(kdf_info, cipher);
+olm::Ratchet alice(kdf_info, cipher);
+olm::Ratchet bob(kdf_info, cipher);
alice.initialise_as_alice(shared_secret, sizeof(shared_secret) - 1, alice_key);
bob.initialise_as_bob(shared_secret, sizeof(shared_secret) - 1, alice_key);
@@ -108,10 +108,10 @@ std::size_t encrypt_length, decrypt_length;
{ /* Out of order test case */
-TestCase test_case("Axolotl Out of Order");
+TestCase test_case("Olm Out of Order");
-axolotl::Ratchet alice(kdf_info, cipher);
-axolotl::Ratchet bob(kdf_info, cipher);
+olm::Ratchet alice(kdf_info, cipher);
+olm::Ratchet bob(kdf_info, cipher);
alice.initialise_as_alice(shared_secret, sizeof(shared_secret) - 1, alice_key);
bob.initialise_as_bob(shared_secret, sizeof(shared_secret) - 1, alice_key);
@@ -180,10 +180,10 @@ std::size_t encrypt_length, decrypt_length;
{ /* More messages */
-TestCase test_case("Axolotl More Messages");
+TestCase test_case("Olm More Messages");
-axolotl::Ratchet alice(kdf_info, cipher);
-axolotl::Ratchet bob(kdf_info, cipher);
+olm::Ratchet alice(kdf_info, cipher);
+olm::Ratchet bob(kdf_info, cipher);
alice.initialise_as_alice(shared_secret, sizeof(shared_secret) - 1, alice_key);
bob.initialise_as_bob(shared_secret, sizeof(shared_secret) - 1, alice_key);