lime
Lime is a C++ library implementing Open Whisper System Signal protocol
lime_x3dh.hpp
Go to the documentation of this file.
1 /*
2  lime_impl.hpp
3  @author Johan Pascal
4  @copyright Copyright (C) 2017 Belledonne Communications SARL
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #ifndef lime_x3dh_hpp
20 #define lime_x3dh_hpp
21 
22 #include <memory>
23 #include <vector>
24 
25 #include "lime/lime.hpp"
27 #include "lime_log.hpp"
28 
29 namespace lime {
30  /* The key type for Signed PreKey */
31  template <typename Curve, bool = std::is_base_of_v<genericKEM, Curve>>
32  struct SignedPreKey;
33 
34  template <typename Curve>
35  struct SignedPreKey <Curve, false> {
36  private:
37  Xpair<Curve> m_SPk;
39  uint32_t m_Id;
40  public:
47 
49  m_SPk.publicKey() = SPkPublic;
50  m_SPk.privateKey() = SPkPrivate;
51  };
54  SignedPreKey(const serializedBuffer &SPk, uint32_t Id) {
55  m_SPk.publicKey() = X<Curve, lime::Xtype::publicKey>(SPk.data());
57  m_Id = Id;
58  };
60  SignedPreKey(const std::vector<uint8_t>::const_iterator s) {
63  m_Id = static_cast<uint32_t>(s[index])<<24 |
64  static_cast<uint32_t>(s[index + 1])<<16 |
65  static_cast<uint32_t>(s[index + 2])<<8 |
66  static_cast<uint32_t>(s[index + 3]);
67  index +=4;
68  m_Sig = DSA<Curve, lime::DSAtype::signature>(s+index);
69  };
70 
72  const X<Curve, lime::Xtype::privateKey> &cprivateKey(void) const {return m_SPk.cprivateKey();};
73  const X<Curve, lime::Xtype::publicKey> &cpublicKey(void) const {return m_SPk.cpublicKey();};
74  const DSA<Curve, lime::DSAtype::signature> &csignature(void) const {return m_Sig;};
76  uint32_t get_Id(void) const {return m_Id;};
77  void set_Id(uint32_t Id) {m_Id = Id;};
78 
81  serializedBuffer s{};
82  std::copy_n(m_SPk.cpublicKey().cbegin(), X<Curve, lime::Xtype::publicKey>::ssize(), s.begin());
84  return s;
85  }
91  std::vector<uint8_t> serializePublic(bool signedMessage=false) const {
92  std::vector<uint8_t> v(m_SPk.cpublicKey().cbegin(), m_SPk.cpublicKey().cend());
93  if (signedMessage) return v;
94  v.insert(v.end(), m_Sig.cbegin(), m_Sig.cend());
95  v.push_back(static_cast<uint8_t>((m_Id>>24)&0xFF));
96  v.push_back(static_cast<uint8_t>((m_Id>>16)&0xFF));
97  v.push_back(static_cast<uint8_t>((m_Id>>8)&0xFF));
98  v.push_back(static_cast<uint8_t>((m_Id)&0xFF));
99  return v;
100  }
101 
103  void dump(std::ostringstream &os, std::string indent=" ") const {
104  os<<std::endl<<indent<<"SPK Id: 0x"<<std::hex<<std::setw(8) << std::setfill('0') << m_Id <<std::endl<<indent<<indent<<"SPK: ";
106  os<<std::endl<<indent<<indent<<"SPK Sig: ";
107  hexStr(os, m_Sig.data(), DSA<Curve, lime::DSAtype::signature>::ssize(), 2);
108  }
109  };
110 
111  template <typename Algo>
112  struct SignedPreKey <Algo, true> {
113  private:
114  Xpair<typename Algo::EC> m_EC_SPk;
115  Kpair<typename Algo::KEM> m_KEM_SPk;
117  uint32_t m_Id;
118  public:
122  static constexpr size_t serializedPublicSize(void) { return
126 
127  static constexpr size_t serializedSize(void) {return
130 
131  using serializedBuffer = sBuffer<
134 
137  m_EC_SPk(SPk_EC_Public, SPk_EC_Private), m_KEM_SPk(SPk_KEM_Public, SPk_KEM_Private) {};
140  SignedPreKey(const serializedBuffer &SPk, uint32_t Id) {
143  m_EC_SPk.privateKey() = X<typename Algo::EC, lime::Xtype::privateKey>(SPk.data() + index);
145  m_KEM_SPk.publicKey() = K<typename Algo::KEM, lime::Ktype::publicKey>(SPk.data() + index);
147  m_KEM_SPk.privateKey() = K<typename Algo::KEM, lime::Ktype::privateKey>(SPk.data() + index);
148  m_Id = Id;
149  };
151  SignedPreKey(const std::vector<uint8_t>::const_iterator s) {
156  m_Id = static_cast<uint32_t>(s[index])<<24 |
157  static_cast<uint32_t>(s[index + 1])<<16 |
158  static_cast<uint32_t>(s[index + 2])<<8 |
159  static_cast<uint32_t>(s[index + 3]);
160  index +=4;
162  };
163 
171  const Xpair<typename Algo::EC> &cECKeypair(void) const {return m_EC_SPk;};
172  const Kpair<typename Algo::KEM> &cKEMKeypair(void) const {return m_KEM_SPk;};
173  uint32_t get_Id(void) const {return m_Id;};
174  void set_Id(uint32_t Id) {m_Id = Id;};
175 
178  serializedBuffer s{};
179  std::copy_n(m_EC_SPk.cpublicKey().cbegin(), X<Algo, lime::Xtype::publicKey>::ssize(), s.begin());
181  std::copy_n(m_EC_SPk.cprivateKey().cbegin(), X<Algo, lime::Xtype::privateKey>::ssize(), s.begin() + index);
183  std::copy_n(m_KEM_SPk.cpublicKey().cbegin(), K<Algo, lime::Ktype::publicKey>::ssize(), s.begin() + index);
185  std::copy_n(m_KEM_SPk.cprivateKey().cbegin(), K<Algo, lime::Ktype::privateKey>::ssize(), s.begin() + index);
186  return s;
187  }
193  std::vector<uint8_t> serializePublic(bool signedMessage=false) const {
194  std::vector<uint8_t> v(m_EC_SPk.cpublicKey().cbegin(), m_EC_SPk.cpublicKey().cend());
195  v.insert(v.end(), m_KEM_SPk.cpublicKey().cbegin(), m_KEM_SPk.cpublicKey().cend());
196  if (signedMessage) return v;
197  v.insert(v.end(), m_Sig.cbegin(), m_Sig.cend());
198  v.push_back(static_cast<uint8_t>((m_Id>>24)&0xFF));
199  v.push_back(static_cast<uint8_t>((m_Id>>16)&0xFF));
200  v.push_back(static_cast<uint8_t>((m_Id>>8)&0xFF));
201  v.push_back(static_cast<uint8_t>((m_Id)&0xFF));
202  return v;
203  }
204 
206  void dump(std::ostringstream &os, std::string indent=" ") const {
207  os<<std::endl<<indent<<"SPK Id: 0x"<<std::hex<<std::setw(8) << std::setfill('0') << m_Id <<std::endl<<indent<<indent<<"SPK(EC): ";
208  hexStr(os, m_EC_SPk.cpublicKey().data(), X<Algo, lime::Xtype::publicKey>::ssize());
209  os<<std::endl<<indent<<indent<<"SPK(KEM): ";
210  hexStr(os, m_KEM_SPk.cpublicKey().data(), K<Algo, lime::Ktype::publicKey>::ssize(), 2);
211  os<<std::endl<<indent<<indent<<"SPK Sig: ";
212  hexStr(os, m_Sig.data(), DSA<Algo, lime::DSAtype::signature>::ssize(), 2);
213  }
214  };
215 
216  /* The key type for One time PreKey */
217  template <typename Curve, bool = std::is_base_of_v<genericKEM, Curve>>
219 
220  template <typename Curve>
221  struct OneTimePreKey <Curve, false> {
222  private:
223  Xpair<Curve> m_OPk;
224  uint32_t m_Id;
225  public:
229  static constexpr size_t serializedPublicSize(void) {return X<Curve, lime::Xtype::publicKey>::ssize() + 4;};
232 
233  OneTimePreKey(const X<Curve, lime::Xtype::publicKey> &OPkPublic, const X<Curve, lime::Xtype::privateKey> &OPkPrivate, uint32_t Id) : m_OPk(OPkPublic, OPkPrivate), m_Id{Id} {};
236  OneTimePreKey(const serializedBuffer &OPk, uint32_t Id) {
237  m_OPk.publicKey() = X<Curve, lime::Xtype::publicKey>(OPk.data());
239  m_Id = Id;
240  };
242  OneTimePreKey(const std::vector<uint8_t>::const_iterator s) {
245  m_Id = static_cast<uint32_t>(s[index])<<24 |
246  static_cast<uint32_t>(s[index + 1])<<16 |
247  static_cast<uint32_t>(s[index + 2])<<8 |
248  static_cast<uint32_t>(s[index + 3]);
249  };
250 
252  const X<Curve, lime::Xtype::privateKey> &cprivateKey(void) const {return m_OPk.cprivateKey();};
253  const X<Curve, lime::Xtype::publicKey> &cpublicKey(void) const {return m_OPk.cpublicKey();};
254  uint32_t get_Id(void) const {return m_Id;};
255  void set_Id(uint32_t Id) {m_Id = Id;};
256 
259  serializedBuffer s{};
260  std::copy_n(m_OPk.cpublicKey().cbegin(), X<Curve, lime::Xtype::publicKey>::ssize(), s.begin());
262  return s;
263  }
265  std::vector<uint8_t> serializePublic(void) const {
266  std::vector<uint8_t> v(m_OPk.cpublicKey().cbegin(), m_OPk.cpublicKey().cend());
267  v.push_back(static_cast<uint8_t>((m_Id>>24)&0xFF));
268  v.push_back(static_cast<uint8_t>((m_Id>>16)&0xFF));
269  v.push_back(static_cast<uint8_t>((m_Id>>8)&0xFF));
270  v.push_back(static_cast<uint8_t>((m_Id)&0xFF));
271  return v;
272  }
273 
275  void dump(std::ostringstream &os, std::string indent=" ") const {
276  os<<std::endl<<indent<<"OPK Id: 0x"<<std::hex<<std::setw(8) << std::setfill('0') << m_Id <<std::endl<<indent<<indent<<"OPK: ";
278  }
279  };
280 
281  template <typename Algo>
282  struct OneTimePreKey <Algo, true> {
283  private:
284  Xpair<typename Algo::EC> m_EC_OPk;
285  Kpair<typename Algo::KEM> m_KEM_OPk;
286  uint32_t m_Id;
287  public:
291  static constexpr size_t serializedPublicSize(void) {return
293  static constexpr size_t serializedSize(void) {return
296  using serializedBuffer = sBuffer<
299 
302  uint32_t Id) :
303  m_EC_OPk(ECPublic, ECPrivate), m_KEM_OPk(KEMPublic, KEMPrivate), m_Id{Id} {};
306  OneTimePreKey(const serializedBuffer &OPk, uint32_t Id) {
309  m_EC_OPk.privateKey() = X<typename Algo::EC, lime::Xtype::privateKey>(OPk.data() + index);
311  m_KEM_OPk.publicKey() = K<typename Algo::KEM, lime::Ktype::publicKey>(OPk.data() + index);
313  m_KEM_OPk.privateKey() = K<typename Algo::KEM, lime::Ktype::privateKey>(OPk.data() + index);
314  m_Id = Id;
315  };
317  OneTimePreKey(const std::vector<uint8_t>::const_iterator s) {
322  m_Id = static_cast<uint32_t>(s[index])<<24 |
323  static_cast<uint32_t>(s[index + 1])<<16 |
324  static_cast<uint32_t>(s[index + 2])<<8 |
325  static_cast<uint32_t>(s[index + 3]);
326  };
327 
333  uint32_t get_Id(void) const {return m_Id;};
334  void set_Id(uint32_t Id) {m_Id = Id;};
335 
338  serializedBuffer s{};
339  std::copy_n(m_EC_OPk.cpublicKey().cbegin(), X<Algo, lime::Xtype::publicKey>::ssize(), s.begin());
341  std::copy_n(m_EC_OPk.cprivateKey().cbegin(), X<Algo, lime::Xtype::privateKey>::ssize(), s.begin() + index);
343  std::copy_n(m_KEM_OPk.cpublicKey().cbegin(), K<Algo, lime::Ktype::publicKey>::ssize(), s.begin() + index);
345  std::copy_n(m_KEM_OPk.cprivateKey().cbegin(), K<Algo, lime::Ktype::privateKey>::ssize(), s.begin() + index);
346  return s;
347  }
352  std::vector<uint8_t> serializePublic(void) const {
353  std::vector<uint8_t> v(m_EC_OPk.cpublicKey().cbegin(), m_EC_OPk.cpublicKey().cend());
354  v.insert(v.end(), m_KEM_OPk.cpublicKey().cbegin(), m_KEM_OPk.cpublicKey().cend());
355  v.push_back(static_cast<uint8_t>((m_Id>>24)&0xFF));
356  v.push_back(static_cast<uint8_t>((m_Id>>16)&0xFF));
357  v.push_back(static_cast<uint8_t>((m_Id>>8)&0xFF));
358  v.push_back(static_cast<uint8_t>((m_Id)&0xFF));
359  return v;
360  }
361 
363  void dump(std::ostringstream &os, std::string indent=" ") const {
364  os<<std::endl<<indent<<"OPK Id: 0x"<<std::hex<<std::setw(8) << std::setfill('0') << m_Id <<std::endl<<indent<<indent<<"OPK(EC): ";
365  hexStr(os, m_EC_OPk.cpublicKey().data(), X<Algo, lime::Xtype::publicKey>::ssize());
366  os<<std::endl<<indent<<indent<<"OPK(KEM): ";
367  hexStr(os, m_KEM_OPk.cpublicKey().data(), K<Algo, lime::Ktype::publicKey>::ssize(), 2);
368  }
369  };
370 
371  // forward declarations
372  struct callbackUserData;
373  class DR;
374 
375  class X3DH
376  {
377  public:
378  virtual void set_x3dhServerUrl(const std::string &x3dhServerUrl) = 0;
379  virtual std::string get_x3dhServerUrl(void) = 0;
380  virtual std::shared_ptr<DR> init_receiver_session(const std::vector<uint8_t> initMessage, const std::string &senderDeviceId) = 0;
381  virtual void fetch_peerBundles(std::shared_ptr<callbackUserData> userData, std::vector<std::string> &peerDeviceIds) = 0;
382  virtual void publish_user(std::shared_ptr<callbackUserData> userData, const uint16_t OPkInitialBatchSize) = 0;
383  virtual void delete_user(std::shared_ptr<callbackUserData> userData) = 0;
384  virtual long int get_dbUid(void) const noexcept = 0;
385  virtual bool is_currentSPk_valid(void) = 0;
386  virtual void update_SPk(std::shared_ptr<callbackUserData> userData) = 0;
387  virtual void update_OPk(std::shared_ptr<callbackUserData> userData) = 0;
388  virtual void get_Ik(std::vector<uint8_t> &Ik) = 0;
389  virtual ~X3DH() = default;
390  };
391 
403  template <typename Algo> std::shared_ptr<X3DH> make_X3DH(std::shared_ptr<lime::Db> localStorage, const std::string &selfDeviceId, const std::string &X3DHServerURL, const limeX3DHServerPostData &X3DH_post_data, std::shared_ptr<RNG> RNG_context, const long Uid = 0);
404 
405 
406 #ifdef EC25519_ENABLED
407  extern template std::shared_ptr<X3DH> make_X3DH<C255>(std::shared_ptr<lime::Db> localStorage, const std::string &selfDeviceId, const std::string &X3DHServerURL, const limeX3DHServerPostData &X3DH_post_data, std::shared_ptr<RNG> RNG_context, const long Uid);
408 #endif
409 #ifdef EC448_ENABLED
410  extern template std::shared_ptr<X3DH> make_X3DH<C448>(std::shared_ptr<lime::Db> localStorage, const std::string &selfDeviceId, const std::string &X3DHServerURL, const limeX3DHServerPostData &X3DH_post_data, std::shared_ptr<RNG> RNG_context, const long Uid);
411 #endif
412 #ifdef HAVE_BCTBXPQ
413 #ifdef EC25519_ENABLED
414  extern template std::shared_ptr<X3DH> make_X3DH<C255K512>(std::shared_ptr<lime::Db> localStorage, const std::string &selfDeviceId, const std::string &X3DHServerURL, const limeX3DHServerPostData &X3DH_post_data, std::shared_ptr<RNG> RNG_context, const long Uid);
415  extern template std::shared_ptr<X3DH> make_X3DH<C255MLK512>(std::shared_ptr<lime::Db> localStorage, const std::string &selfDeviceId, const std::string &X3DHServerURL, const limeX3DHServerPostData &X3DH_post_data, std::shared_ptr<RNG> RNG_context, const long Uid);
416 #endif
417 #ifdef EC448_ENABLED
418  extern template std::shared_ptr<X3DH> make_X3DH<C448MLK1024>(std::shared_ptr<lime::Db> localStorage, const std::string &selfDeviceId, const std::string &X3DHServerURL, const limeX3DHServerPostData &X3DH_post_data, std::shared_ptr<RNG> RNG_context, const long Uid);
419 #endif
420 #endif
421 } //namespace lime
422 #endif /* lime_x3dh_hpp */
static constexpr size_t ssize(void)
provide a static size function to be able to call the function not on an object
Definition: lime_crypto_primitives.hpp:105
const Xpair< typename Algo::EC > & cECKeypair(void) const
Definition: lime_x3dh.hpp:171
const X< typename Algo::EC, lime::Xtype::publicKey > & cECpublicKey(void) const
Definition: lime_x3dh.hpp:166
static constexpr size_t ssize(void)
provide a static size function to be able to call the function not on an object
Definition: lime_crypto_primitives.hpp:59
SignedPreKey(const serializedBuffer &SPk, uint32_t Id)
Unserializing constructor: from data read in DB.
Definition: lime_x3dh.hpp:54
void dump(std::ostringstream &os, std::string indent=" ") const
Dump the public key, signature and Id.
Definition: lime_x3dh.hpp:206
virtual void publish_user(std::shared_ptr< callbackUserData > userData, const uint16_t OPkInitialBatchSize)=0
X< Curve, lime::Xtype::privateKey > & privateKey(void)
access the private key
Definition: lime_crypto_primitives.hpp:80
void set_Id(uint32_t Id)
Definition: lime_x3dh.hpp:77
OneTimePreKey()
Definition: lime_x3dh.hpp:234
virtual void update_OPk(std::shared_ptr< callbackUserData > userData)=0
OneTimePreKey(const std::vector< uint8_t >::const_iterator s)
Unserializing constructor: from data read in received bundle.
Definition: lime_x3dh.hpp:242
Base buffer definition for KEM data structure.
Definition: lime_crypto_primitives.hpp:102
const K< typename Algo::KEM, lime::Ktype::publicKey > & cKEMpublicKey(void) const
Definition: lime_x3dh.hpp:332
const Kpair< typename Algo::KEM > & cKEMKeypair(void) const
Definition: lime_x3dh.hpp:172
const X< Curve, lime::Xtype::publicKey > & cpublicKey(void) const
Definition: lime_x3dh.hpp:73
std::vector< uint8_t > serializePublic(bool signedMessage=false) const
Definition: lime_x3dh.hpp:193
const DSA< typename Algo::EC, lime::DSAtype::signature > & csignature(void) const
Definition: lime_x3dh.hpp:169
Key pair structure for key exchange algorithm.
Definition: lime_crypto_primitives.hpp:74
static constexpr size_t serializedSize(void)
Definition: lime_x3dh.hpp:45
uint32_t get_Id(void) const
Definition: lime_x3dh.hpp:333
const X< Curve, lime::Xtype::publicKey > & cpublicKey(void) const
Definition: lime_crypto_primitives.hpp:84
static constexpr size_t serializedSize(void)
Definition: lime_x3dh.hpp:293
SignedPreKey()
Definition: lime_x3dh.hpp:52
virtual ~X3DH()=default
DSA< typename Algo::EC, lime::DSAtype::signature > & signature(void)
Definition: lime_x3dh.hpp:170
void set_Id(uint32_t Id)
Definition: lime_x3dh.hpp:174
uint32_t get_Id(void) const
Definition: lime_x3dh.hpp:173
serializedBuffer serialize(void) const
Serialize the key pair (to store in DB): EC public || EC private || KEM public || KEM private...
Definition: lime_x3dh.hpp:337
SignedPreKey(const std::vector< uint8_t >::const_iterator s)
Unserializing constructor: from data read in received bundle.
Definition: lime_x3dh.hpp:60
OneTimePreKey(const X< typename Algo::EC, lime::Xtype::publicKey > &ECPublic, const X< typename Algo::EC, lime::Xtype::privateKey > &ECPrivate, const K< typename Algo::KEM, lime::Ktype::publicKey > &KEMPublic, const K< typename Algo::KEM, lime::Ktype::privateKey > &KEMPrivate, uint32_t Id)
Definition: lime_x3dh.hpp:300
virtual void delete_user(std::shared_ptr< callbackUserData > userData)=0
const K< Algo, lime::Ktype::privateKey > & cprivateKey(void) const
Definition: lime_crypto_primitives.hpp:127
OneTimePreKey(const std::vector< uint8_t >::const_iterator s)
Unserializing constructor: from data read in received bundle EC public key || KEM public key || Id...
Definition: lime_x3dh.hpp:317
DSA< Curve, lime::DSAtype::signature > & signature(void)
Definition: lime_x3dh.hpp:75
K< Algo, lime::Ktype::privateKey > & privateKey(void)
access the private key
Definition: lime_crypto_primitives.hpp:126
SignedPreKey(const serializedBuffer &SPk, uint32_t Id)
Unserializing constructor: from data read in DB.
Definition: lime_x3dh.hpp:140
std::function< void(const std::string &url, const std::string &from, std::vector< uint8_t > &&message, const limeX3DHServerResponseProcess &reponseProcess)> limeX3DHServerPostData
Post a message to the X3DH server.
Definition: lime.hpp:123
K< Algo, lime::Ktype::publicKey > & publicKey(void)
access the public key
Definition: lime_crypto_primitives.hpp:129
std::vector< uint8_t > serializePublic(bool signedMessage=false) const
Definition: lime_x3dh.hpp:91
SignedPreKey()
Definition: lime_x3dh.hpp:138
serializedBuffer serialize(void) const
Serialize the key pair (to store in DB): First the public value, then the private one...
Definition: lime_x3dh.hpp:80
std::shared_ptr< X3DH > make_X3DH(std::shared_ptr< lime::Db > localStorage, const std::string &selfDeviceId, const std::string &X3DHServerURL, const limeX3DHServerPostData &X3DH_post_data, std::shared_ptr< RNG > RNG_context, const long Uid)
Definition: lime_x3dh.cpp:1394
std::vector< uint8_t > serializePublic(void) const
Definition: lime_x3dh.hpp:352
const K< Algo, lime::Ktype::publicKey > & cpublicKey(void) const
Definition: lime_crypto_primitives.hpp:130
static constexpr size_t serializedPublicSize(void)
Definition: lime_x3dh.hpp:291
const X< typename Algo::EC, lime::Xtype::privateKey > & cECprivateKey(void) const
accessors
Definition: lime_x3dh.hpp:165
const K< typename Algo::KEM, lime::Ktype::privateKey > & cKEMprivateKey(void) const
Definition: lime_x3dh.hpp:331
virtual bool is_currentSPk_valid(void)=0
uint32_t get_Id(void) const
Definition: lime_x3dh.hpp:254
static constexpr size_t serializedPublicSize(void)
Definition: lime_x3dh.hpp:229
virtual void get_Ik(std::vector< uint8_t > &Ik)=0
serializedBuffer serialize(void) const
Serialize the key pair (to store in DB): EC public || EC private || KEM public || KEM private...
Definition: lime_x3dh.hpp:177
Definition: lime_x3dh.hpp:218
virtual long int get_dbUid(void) const noexcept=0
const X< Curve, lime::Xtype::publicKey > & cpublicKey(void) const
Definition: lime_x3dh.hpp:253
virtual std::string get_x3dhServerUrl(void)=0
virtual std::shared_ptr< DR > init_receiver_session(const std::vector< uint8_t > initMessage, const std::string &senderDeviceId)=0
SignedPreKey(const std::vector< uint8_t >::const_iterator s)
Unserializing constructor: from data read in received bundle: EC public key || KEM public key || Id |...
Definition: lime_x3dh.hpp:151
void dump(std::ostringstream &os, std::string indent=" ") const
Dump the public key, signature and Id.
Definition: lime_x3dh.hpp:103
const X< Curve, lime::Xtype::privateKey > & cprivateKey(void) const
accessors
Definition: lime_x3dh.hpp:72
std::vector< uint8_t > serializePublic(void) const
Serialize the public key and Id to publish on the server.
Definition: lime_x3dh.hpp:265
OneTimePreKey(const X< Curve, lime::Xtype::publicKey > &OPkPublic, const X< Curve, lime::Xtype::privateKey > &OPkPrivate, uint32_t Id)
Definition: lime_x3dh.hpp:233
SignedPreKey(const X< Curve, lime::Xtype::publicKey > &SPkPublic, const X< Curve, lime::Xtype::privateKey > &SPkPrivate)
Definition: lime_x3dh.hpp:48
Key pair structure for key exchange algorithm.
Definition: lime_crypto_primitives.hpp:120
static constexpr size_t ssize(void)
provide a static size function to be able to call the function not on an object
Definition: lime_crypto_primitives.hpp:151
const X< typename Algo::EC, lime::Xtype::privateKey > & cECprivateKey(void) const
accessors
Definition: lime_x3dh.hpp:329
SignedPreKey(const X< typename Algo::EC, lime::Xtype::publicKey > &SPk_EC_Public, const X< typename Algo::EC, lime::Xtype::privateKey > &SPk_EC_Private, const K< typename Algo::KEM, lime::Ktype::publicKey > &SPk_KEM_Public, const K< typename Algo::KEM, lime::Ktype::privateKey > &SPk_KEM_Private)
Definition: lime_x3dh.hpp:135
Definition: lime.cpp:33
uint32_t get_Id(void) const
Definition: lime_x3dh.hpp:76
const K< typename Algo::KEM, lime::Ktype::publicKey > & cKEMpublicKey(void) const
Definition: lime_x3dh.hpp:168
OneTimePreKey(const serializedBuffer &OPk, uint32_t Id)
Unserializing constructor: from data read in DB.
Definition: lime_x3dh.hpp:306
static constexpr size_t serializedPublicSize(void)
Definition: lime_x3dh.hpp:44
void set_Id(uint32_t Id)
Definition: lime_x3dh.hpp:255
X< Curve, lime::Xtype::publicKey > & publicKey(void)
access the public key
Definition: lime_crypto_primitives.hpp:83
Definition: lime_x3dh.hpp:375
const K< typename Algo::KEM, lime::Ktype::privateKey > & cKEMprivateKey(void) const
Definition: lime_x3dh.hpp:167
static constexpr size_t serializedSize(void)
Definition: lime_x3dh.hpp:127
const X< Curve, lime::Xtype::privateKey > & cprivateKey(void) const
accessors
Definition: lime_x3dh.hpp:252
serializedBuffer serialize(void) const
Serialize the key pair (to store in DB): First the public value, then the private one...
Definition: lime_x3dh.hpp:258
virtual void update_SPk(std::shared_ptr< callbackUserData > userData)=0
Definition: lime_x3dh.hpp:32
virtual void set_x3dhServerUrl(const std::string &x3dhServerUrl)=0
auto clean fixed size buffer(std::array based)
Definition: lime_crypto_primitives.hpp:42
void dump(std::ostringstream &os, std::string indent=" ") const
Dump the public key and Id.
Definition: lime_x3dh.hpp:363
virtual void fetch_peerBundles(std::shared_ptr< callbackUserData > userData, std::vector< std::string > &peerDeviceIds)=0
void dump(std::ostringstream &os, std::string indent=" ") const
Dump the public key and Id.
Definition: lime_x3dh.hpp:275
OneTimePreKey()
Definition: lime_x3dh.hpp:304
const X< Curve, lime::Xtype::privateKey > & cprivateKey(void) const
Definition: lime_crypto_primitives.hpp:81
const DSA< Curve, lime::DSAtype::signature > & csignature(void) const
Definition: lime_x3dh.hpp:74
static constexpr size_t serializedPublicSize(void)
Definition: lime_x3dh.hpp:122
OneTimePreKey(const serializedBuffer &OPk, uint32_t Id)
Unserializing constructor: from data read in DB.
Definition: lime_x3dh.hpp:236
void hexStr(std::ostringstream &os, const uint8_t *data, size_t len, size_t digest)
Definition: lime_log.cpp:30
void set_Id(uint32_t Id)
Definition: lime_x3dh.hpp:334
static constexpr size_t serializedSize(void)
Definition: lime_x3dh.hpp:230
const X< typename Algo::EC, lime::Xtype::publicKey > & cECpublicKey(void) const
Definition: lime_x3dh.hpp:330