aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-06-12 14:09:41 +0100
committerMark Haines <mark.haines@matrix.org>2015-06-12 14:09:41 +0100
commit6ecea67718803e96e00a18f97ae8abc83ecaa1c2 (patch)
tree41de34500c1dfa104b791606a67b6bcf84a14ed9 /include
parent08a7e44a966047a10d7e959d4a8cdeaaf4139ce0 (diff)
Implement the session key exchange
Diffstat (limited to 'include')
-rw-r--r--include/axolotl/account.hh9
-rw-r--r--include/axolotl/crypto.hh5
-rw-r--r--include/axolotl/error.hh1
-rw-r--r--include/axolotl/list.hh5
-rw-r--r--include/axolotl/message.hh2
-rw-r--r--include/axolotl/session.hh29
6 files changed, 38 insertions, 13 deletions
diff --git a/include/axolotl/account.hh b/include/axolotl/account.hh
index 5edb799..dd9c819 100644
--- a/include/axolotl/account.hh
+++ b/include/axolotl/account.hh
@@ -2,6 +2,8 @@
#define AXOLOTL_ACCOUNT_HH_
#include "axolotl/list.hh"
+#include "axolotl/crypto.hh"
+#include "axolotl/error.hh"
#include <cstdint>
@@ -25,16 +27,21 @@ struct Account {
LocalKey identity_key;
LocalKey last_resort_one_time_key;
List<LocalKey, MAX_ONE_TIME_KEYS> one_time_keys;
+ ErrorCode last_error;
/** Number of random bytes needed to create a new account */
std::size_t new_account_random_length();
/** Create a new account. Returns NOT_ENOUGH_RANDOM if the number of random
* bytes is too small. */
- ErrorCode new_account(
+ std::size_t new_account(
uint8_t const * random, std::size_t random_length
);
+ LocalKey const * lookup_key(
+ std::uint32_t id
+ );
+
/** The number of bytes needed to persist this account. */
std::size_t pickle_length();
diff --git a/include/axolotl/crypto.hh b/include/axolotl/crypto.hh
index 42e4b61..7564e8f 100644
--- a/include/axolotl/crypto.hh
+++ b/include/axolotl/crypto.hh
@@ -12,6 +12,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#ifndef AXOLOTL_CRYPTO_HH_
+#define AXOLOTL_CRYPTO_HH_
+
#include <cstdint>
#include <cstddef>
@@ -141,3 +144,5 @@ void hkdf_sha256(
);
} // namespace axolotl
+
+#endif /* AXOLOTL_CRYPTO_HH_ */
diff --git a/include/axolotl/error.hh b/include/axolotl/error.hh
index 712b9eb..3bf0e63 100644
--- a/include/axolotl/error.hh
+++ b/include/axolotl/error.hh
@@ -10,6 +10,7 @@ enum struct ErrorCode {
BAD_MESSAGE_VERSION = 3, /*!< The message version is unsupported */
BAD_MESSAGE_FORMAT = 4, /*!< The message couldn't be decoded */
BAD_MESSAGE_MAC = 5, /*!< The message couldn't be decrypted */
+ BAD_MESSAGE_KEY_ID = 6, /*!< The message references an unknown key id */
};
} // namespace axolotl
diff --git a/include/axolotl/list.hh b/include/axolotl/list.hh
index ae8900c..604f00f 100644
--- a/include/axolotl/list.hh
+++ b/include/axolotl/list.hh
@@ -12,6 +12,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#ifndef AXOLOTL_LIST_HH_
+#define AXOLOTL_LIST_HH_
+
#include <cstddef>
namespace axolotl {
@@ -112,3 +115,5 @@ private:
};
} // namespace axolotl
+
+#endif /* AXOLOTL_LIST_HH_ */
diff --git a/include/axolotl/message.hh b/include/axolotl/message.hh
index 2b9bc99..5bce277 100644
--- a/include/axolotl/message.hh
+++ b/include/axolotl/message.hh
@@ -88,6 +88,7 @@ struct PreKeyMessageReader {
std::uint8_t const * message; std::size_t message_length;
};
+
/**
* The length of the buffer needed to hold a message.
*/
@@ -99,6 +100,7 @@ std::size_t encode_one_time_key_message_length(
std::size_t message_length
);
+
/**
* Writes the message headers into the output buffer.
* Populates the writer struct with pointers into the output buffer.
diff --git a/include/axolotl/session.hh b/include/axolotl/session.hh
index c69699d..1c3395a 100644
--- a/include/axolotl/session.hh
+++ b/include/axolotl/session.hh
@@ -5,14 +5,13 @@
namespace axolotl {
+class Account;
+
struct RemoteKey {
std::uint32_t id;
Curve25519PublicKey key;
};
-struct RemoteKeys {
-};
-
enum struct MessageType {
PRE_KEY_MESSAGE = 0,
@@ -21,28 +20,34 @@ enum struct MessageType {
struct Session {
+
+ Session();
+
+ Ratchet ratchet;
+ ErrorCode last_error;
+
bool received_message;
+
RemoteKey alice_identity_key;
- RemoteKey alice_base_key;
- RemoteKey bob_identity_key;
- RemoteKey bob_one_time_key;
- Ratchet ratchet;
+ Curve25519PublicKey alice_base_key;
+ std::uint32_t bob_one_time_key_id;
+
- void initialise_outbound_session_random_length();
+ std::size_t new_outbound_session_random_length();
- void initialise_outbound_session(
+ std::size_t new_outbound_session(
Account const & local_account,
- RemoteKey const & identity_key,
+ Curve25519PublicKey const & identity_key,
RemoteKey const & one_time_key,
std::uint8_t const * random, std::size_t random_length
);
- void initialise_inbound_session(
+ std::size_t new_inbound_session(
Account & local_account,
std::uint8_t const * one_time_key_message, std::size_t message_length
);
- void matches_inbound_session(
+ bool matches_inbound_session(
std::uint8_t const * one_time_key_message, std::size_t message_length
);