From 09d4125ff164f5ca686d12ccb0790c35ce721a6b Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Sat, 27 Jun 2015 01:15:23 +0200 Subject: [PATCH] Rename axolotlpp as olm to avoid confusion with Axolotl-the-spec and Axolotl-the-OWS-libraries at moxie's request --- README.rst | 23 +- build_shared_library.py | 2 +- docs/Axolotl.svg | 6 +- include/axolotl/axolotl.hh | 295 -------------------- include/{axolotl => olm}/account.hh | 16 +- include/{axolotl => olm}/base64.hh | 4 +- include/{axolotl => olm}/cipher.hh | 8 +- include/{axolotl => olm}/crypto.hh | 10 +- include/{axolotl => olm}/error.hh | 4 +- include/{axolotl => olm}/list.hh | 10 +- include/{axolotl => olm}/memory.hh | 4 +- include/{axolotl => olm}/message.hh | 4 +- include/olm/olm.hh | 295 ++++++++++++++++++++ include/{axolotl => olm}/pickle.hh | 20 +- include/{axolotl => olm}/ratchet.hh | 10 +- include/{axolotl => olm}/session.hh | 12 +- javascript/axolotl_pre.js | 1 - javascript/build.py | 6 +- javascript/demo.html | 10 +- javascript/{axolotl_post.js => olm_post.js} | 66 ++--- javascript/olm_pre.js | 1 + axolotl.py => olm.py | 136 ++++----- src/account.cpp | 88 +++--- src/base64.cpp | 10 +- src/cipher.cpp | 46 +-- src/crypto.cpp | 70 ++--- src/memory.cpp | 6 +- src/message.cpp | 20 +- src/{axolotl.cpp => olm.cpp} | 234 ++++++++-------- src/pickle.cpp | 38 +-- src/ratchet.cpp | 258 ++++++++--------- src/session.cpp | 170 +++++------ tests/test_axolotl.cpp | 269 ------------------ tests/test_base64.cpp | 10 +- tests/test_crypto.cpp | 44 +-- tests/test_list.cpp | 6 +- tests/test_message.cpp | 12 +- tests/test_olm.cpp | 269 ++++++++++++++++++ tests/test_ratchet.cpp | 36 +-- 39 files changed, 1268 insertions(+), 1261 deletions(-) delete mode 100644 include/axolotl/axolotl.hh rename include/{axolotl => olm}/account.hh (88%) rename include/{axolotl => olm}/base64.hh (96%) rename include/{axolotl => olm}/cipher.hh (97%) rename include/{axolotl => olm}/crypto.hh (96%) rename include/{axolotl => olm}/error.hh (96%) rename include/{axolotl => olm}/list.hh (95%) rename include/{axolotl => olm}/memory.hh (96%) rename include/{axolotl => olm}/message.hh (98%) create mode 100644 include/olm/olm.hh rename include/{axolotl => olm}/pickle.hh (91%) rename include/{axolotl => olm}/ratchet.hh (97%) rename include/{axolotl => olm}/session.hh (94%) delete mode 100644 javascript/axolotl_pre.js rename javascript/{axolotl_post.js => olm_post.js} (77%) create mode 100644 javascript/olm_pre.js rename axolotl.py => olm.py (76%) rename src/{axolotl.cpp => olm.cpp} (67%) delete mode 100644 tests/test_axolotl.cpp create mode 100644 tests/test_olm.cpp 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">"AXOLOTL_ROOT" + sodipodi:role="line">"OLM_ROOT" "AXOLOTL_KEYS" + y="-64">"OLM_KEYS" "AXOLOTL_RATCHET" + y="-64">"OLM_RATCHET" - -#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 similarity index 88% rename from include/axolotl/account.hh rename to 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 -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 similarity index 96% rename from include/axolotl/base64.hh rename to include/olm/base64.hh index 361a558..0a7435b 100644 --- a/include/axolotl/base64.hh +++ b/include/olm/base64.hh @@ -18,7 +18,7 @@ #include #include -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 similarity index 97% rename from include/axolotl/cipher.hh rename to 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 #include -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 similarity index 96% rename from include/axolotl/crypto.hh rename to 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 #include -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 similarity index 96% rename from include/axolotl/error.hh rename to 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 similarity index 95% rename from include/axolotl/list.hh rename to 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 -namespace axolotl { +namespace olm { template 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 similarity index 96% rename from include/axolotl/memory.hh rename to include/olm/memory.hh index 68b577d..b19c74b 100644 --- a/include/axolotl/memory.hh +++ b/include/olm/memory.hh @@ -15,7 +15,7 @@ #include #include -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 similarity index 98% rename from include/axolotl/message.hh rename to include/olm/message.hh index 4d7a1c7..fefdd20 100644 --- a/include/axolotl/message.hh +++ b/include/olm/message.hh @@ -16,7 +16,7 @@ #include -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 + +#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 similarity index 91% rename from include/axolotl/pickle.hh rename to 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 #include -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 std::size_t pickle_length( - axolotl::List const & list + olm::List 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 std::uint8_t * pickle( std::uint8_t * pos, - axolotl::List const & list + olm::List const & list ) { pos = pickle(pos, std::uint32_t(list.size())); for (auto const & value : list) { @@ -105,7 +105,7 @@ std::uint8_t * pickle( template std::uint8_t const * unpickle( std::uint8_t const * pos, std::uint8_t const * end, - axolotl::List & list + olm::List & 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 similarity index 97% rename from include/axolotl/ratchet.hh rename to 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 similarity index 94% rename from include/axolotl/session.hh rename to 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 @@ - +