From 21e1b04474ee5e8bc7acdd53772331f850234811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 8 Jan 2022 18:28:32 +0100 Subject: Channel: use counter to generate nonce --- src/channel.h | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/channel.h') diff --git a/src/channel.h b/src/channel.h index 1c7df30..5f1786e 100644 --- a/src/channel.h +++ b/src/channel.h @@ -4,8 +4,15 @@ #include "identity.h" +#include +#include + namespace erebos { +using std::array; +using std::atomic; +using std::unique_ptr; + struct ChannelRequestData { Ref store(const Storage & st) const; @@ -22,7 +29,7 @@ struct ChannelAcceptData Ref store(const Storage & st) const; static ChannelAcceptData load(const Ref &); - Stored channel() const; + unique_ptr channel() const; const Stored request; const Stored key; @@ -34,25 +41,33 @@ class Channel { public: Channel(const vector>> & peers, - vector && key): + vector && key, bool ourRequest): peers(peers), - key(std::move(key)) + key(std::move(key)), + nonceFixedOur({ uint8_t(ourRequest ? 1 : 2), 0, 0, 0, 0, 0 }), + nonceFixedPeer({ uint8_t(ourRequest ? 2 : 1), 0, 0, 0, 0, 0 }) {} - Ref store(const Storage & st) const; - static Channel load(const Ref &); + Channel(const Channel &) = delete; + Channel(Channel &&) = delete; + Channel & operator=(const Channel &) = delete; + Channel & operator=(Channel &&) = delete; static Stored generateRequest(const Storage &, const Identity & self, const Identity & peer); static optional> acceptRequest(const Identity & self, const Identity & peer, const Stored & request); - vector encrypt(const vector &) const; - optional> decrypt(const vector &) const; + vector encrypt(const vector &); + optional> decrypt(const vector &); private: const vector>> peers; const vector key; + + const array nonceFixedOur; + const array nonceFixedPeer; + atomic nonceCounter = 0; }; } -- cgit v1.2.3