From 09d8e84c7cbbf21195f3fd2eabbcff44042d5a4e Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Thu, 26 Feb 2015 16:30:19 +0000 Subject: Implement the axlotl ratchet --- include/axolotl/axolotl.hh | 24 +++++++++++++++++++++--- include/axolotl/crypto.hh | 5 +++-- include/axolotl/list.hh | 5 +++++ 3 files changed, 29 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/axolotl/axolotl.hh b/include/axolotl/axolotl.hh index 34280d4..ead52fc 100644 --- a/include/axolotl/axolotl.hh +++ b/include/axolotl/axolotl.hh @@ -1,6 +1,6 @@ -#include "axololt/crypto.hh" -#include "axololt/list.hh" +#include "axolotl/crypto.hh" +#include "axolotl/list.hh" namespace axolotl { @@ -52,7 +52,10 @@ enum struct ErrorCode { static std::size_t const MAX_RECEIVER_CHAINS = 5; static std::size_t const MAX_SKIPPED_MESSAGE_KEYS = 40; + struct KdfInfo { + std::uint8_t const * root_info; + std::size_t root_info_length; std::uint8_t const * ratchet_info; std::size_t ratchet_info_length; std::uint8_t const * message_info; @@ -61,15 +64,30 @@ struct KdfInfo { struct Session { + + Session( + KdfInfo const & kdf_info + ); + /** A pair of string to feed into the KDF identifing the application */ KdfInfo kdf_info; /** The last error that happened encypting or decrypting a message */ ErrorCode last_error; SharedKey root_key; List sender_chain; - List reciever_chains; + List receiver_chains; List skipped_message_keys; + void initialise_as_bob( + std::uint8_t const * shared_secret, std::size_t shared_secret_length, + Curve25519PublicKey const & their_ratchet_key + ); + + void initialise_as_alice( + std::uint8_t const * shared_secret, std::size_t shared_secret_length, + Curve25519KeyPair const & our_ratchet_key + ); + std::size_t encrypt_max_output_length( std::size_t plaintext_length ); diff --git a/include/axolotl/crypto.hh b/include/axolotl/crypto.hh index 42c154b..f1e81ac 100644 --- a/include/axolotl/crypto.hh +++ b/include/axolotl/crypto.hh @@ -15,8 +15,9 @@ struct Curve25519KeyPair : public Curve25519PublicKey { }; -Curve25519KeyPair generate_key( - std::uint8_t const * random_32_bytes +void generate_key( + std::uint8_t const * random_32_bytes, + Curve25519KeyPair & key_pair ); diff --git a/include/axolotl/list.hh b/include/axolotl/list.hh index a3c3d01..4c87630 100644 --- a/include/axolotl/list.hh +++ b/include/axolotl/list.hh @@ -60,6 +60,11 @@ public: return pos; } + /** + * Make space for an item in the list at the start of the list + */ + T * insert() { return insert(begin()); } + /** * Insert an item into the list at a given position. * If inserting the item makes the list longer than max_size then -- cgit v1.2.3