lime
Lime is a C++ library implementing Open Whisper System Signal protocol
Loading...
Searching...
No Matches
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
29namespace lime {
30 /* The key type for Signed PreKey */
31 template <typename Curve, bool = std::is_base_of_v<genericKEM, Curve>>
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 };
59
60 SignedPreKey(const std::vector<uint8_t>::const_iterator s) {
61 m_SPk.publicKey() = X<Curve, lime::Xtype::publicKey>(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;
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
82 std::copy_n(m_SPk.cpublicKey().cbegin(), X<Curve, lime::Xtype::publicKey>::ssize(), s.begin());
83 std::copy_n(m_SPk.cprivateKey().cbegin(), X<Curve, lime::Xtype::privateKey>::ssize(), s.begin()+X<Curve, lime::Xtype::publicKey>::ssize());
84 return s;
85 }
86
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: ";
105 hexStr(os, m_SPk.cpublicKey().data(), X<Curve, lime::Xtype::publicKey>::ssize());
106 os<<std::endl<<indent<<indent<<"SPK Sig: ";
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:
126
130
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) {
141 m_EC_SPk.publicKey() = X<typename Algo::EC, lime::Xtype::publicKey>(SPk.data());
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 };
150
151 SignedPreKey(const std::vector<uint8_t>::const_iterator s) {
152 m_EC_SPk.publicKey() = X<typename Algo::EC, lime::Xtype::publicKey>(s);
154 m_KEM_SPk.publicKey() = K<typename Algo::KEM, lime::Ktype::publicKey>(s + index);
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
165 const X<typename Algo::EC, lime::Xtype::privateKey> &cECprivateKey(void) const {return m_EC_SPk.cprivateKey();};
166 const X<typename Algo::EC, lime::Xtype::publicKey> &cECpublicKey(void) const {return m_EC_SPk.cpublicKey();};
167 const K<typename Algo::KEM, lime::Ktype::privateKey> &cKEMprivateKey(void) const {return m_KEM_SPk.cprivateKey();};
168 const K<typename Algo::KEM, lime::Ktype::publicKey> &cKEMpublicKey(void) const {return m_KEM_SPk.cpublicKey();};
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
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 }
188
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: ";
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 };
241
242 OneTimePreKey(const std::vector<uint8_t>::const_iterator s) {
243 m_OPk.publicKey() = X<Curve, lime::Xtype::publicKey>(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
260 std::copy_n(m_OPk.cpublicKey().cbegin(), X<Curve, lime::Xtype::publicKey>::ssize(), s.begin());
261 std::copy_n(m_OPk.cprivateKey().cbegin(), X<Curve, lime::Xtype::privateKey>::ssize(), s.begin()+X<Curve, lime::Xtype::publicKey>::ssize());
262 return s;
263 }
264
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: ";
277 hexStr(os, m_OPk.cpublicKey().data(), X<Curve, lime::Xtype::publicKey>::ssize());
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:
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) {
307 m_EC_OPk.publicKey() = X<typename Algo::EC, lime::Xtype::publicKey>(OPk.data());
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 };
316
317 OneTimePreKey(const std::vector<uint8_t>::const_iterator s) {
318 m_EC_OPk.publicKey() = X<typename Algo::EC, lime::Xtype::publicKey>(s);
320 m_KEM_OPk.publicKey() = K<typename Algo::KEM, lime::Ktype::publicKey>(s + index);
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
329 const X<typename Algo::EC, lime::Xtype::privateKey> &cECprivateKey(void) const {return m_EC_OPk.cprivateKey();};
330 const X<typename Algo::EC, lime::Xtype::publicKey> &cECpublicKey(void) const {return m_EC_OPk.cpublicKey();};
331 const K<typename Algo::KEM, lime::Ktype::privateKey> &cKEMprivateKey(void) const {return m_KEM_OPk.cprivateKey();};
332 const K<typename Algo::KEM, lime::Ktype::publicKey> &cKEMpublicKey(void) const {return m_KEM_OPk.cpublicKey();};
333 uint32_t get_Id(void) const {return m_Id;};
334 void set_Id(uint32_t Id) {m_Id = Id;};
335
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 }
348
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 */
Base buffer definition for DSA data structure.
Definition lime_crypto_primitives.hpp:148
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
Base buffer definition for KEM data structure.
Definition lime_crypto_primitives.hpp:102
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
Key pair structure for key exchange algorithm.
Definition lime_crypto_primitives.hpp:120
Definition lime_x3dh.hpp:376
virtual void set_x3dhServerUrl(const std::string &x3dhServerUrl)=0
virtual ~X3DH()=default
virtual bool is_currentSPk_valid(void)=0
virtual void get_Ik(std::vector< uint8_t > &Ik)=0
virtual void publish_user(std::shared_ptr< callbackUserData > userData, const uint16_t OPkInitialBatchSize)=0
virtual std::string get_x3dhServerUrl(void)=0
virtual void update_SPk(std::shared_ptr< callbackUserData > userData)=0
virtual std::shared_ptr< DR > init_receiver_session(const std::vector< uint8_t > initMessage, const std::string &senderDeviceId)=0
virtual long int get_dbUid(void) const noexcept=0
virtual void update_OPk(std::shared_ptr< callbackUserData > userData)=0
virtual void delete_user(std::shared_ptr< callbackUserData > userData)=0
virtual void fetch_peerBundles(std::shared_ptr< callbackUserData > userData, std::vector< std::string > &peerDeviceIds)=0
Base buffer definition for Key Exchange data structure.
Definition lime_crypto_primitives.hpp:56
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
Key pair structure for key exchange algorithm.
Definition lime_crypto_primitives.hpp:74
Definition lime.cpp:33
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
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
@ OPk
Definition lime_x3dh_protocol.hpp:37
void hexStr(std::ostringstream &os, const uint8_t *data, size_t len, size_t digest)
Definition lime_log.cpp:30
const K< typename Algo::KEM, lime::Ktype::privateKey > & cKEMprivateKey(void) const
Definition lime_x3dh.hpp:331
const K< typename Algo::KEM, lime::Ktype::publicKey > & cKEMpublicKey(void) const
Definition lime_x3dh.hpp:332
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
static constexpr size_t serializedPublicSize(void)
Definition lime_x3dh.hpp:291
static constexpr size_t serializedSize(void)
Definition lime_x3dh.hpp:293
OneTimePreKey(const serializedBuffer &OPk, uint32_t Id)
Unserializing constructor: from data read in DB.
Definition lime_x3dh.hpp:306
uint32_t get_Id(void) const
Definition lime_x3dh.hpp:333
std::vector< uint8_t > serializePublic(void) const
Definition lime_x3dh.hpp:352
void set_Id(uint32_t Id)
Definition lime_x3dh.hpp:334
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
void dump(std::ostringstream &os, std::string indent=" ") const
Dump the public key and Id.
Definition lime_x3dh.hpp:363
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
OneTimePreKey()
Definition lime_x3dh.hpp:304
sBuffer< X< Algo, lime::Xtype::publicKey >::ssize()+X< Algo, lime::Xtype::privateKey >::ssize()+K< Algo, lime::Ktype::publicKey >::ssize()+K< Algo, lime::Ktype::privateKey >::ssize()> serializedBuffer
Definition lime_x3dh.hpp:296
const X< typename Algo::EC, lime::Xtype::publicKey > & cECpublicKey(void) const
Definition lime_x3dh.hpp:330
const X< typename Algo::EC, lime::Xtype::privateKey > & cECprivateKey(void) const
accessors
Definition lime_x3dh.hpp:329
const X< Curve, lime::Xtype::privateKey > & cprivateKey(void) const
accessors
Definition lime_x3dh.hpp:252
OneTimePreKey()
Definition lime_x3dh.hpp:234
OneTimePreKey(const std::vector< uint8_t >::const_iterator s)
Unserializing constructor: from data read in received bundle.
Definition lime_x3dh.hpp:242
OneTimePreKey(const X< Curve, lime::Xtype::publicKey > &OPkPublic, const X< Curve, lime::Xtype::privateKey > &OPkPrivate, uint32_t Id)
Definition lime_x3dh.hpp:233
uint32_t get_Id(void) const
Definition lime_x3dh.hpp:254
sBuffer< X< Curve, lime::Xtype::publicKey >::ssize()+X< Curve, lime::Xtype::privateKey >::ssize()> serializedBuffer
Definition lime_x3dh.hpp:231
std::vector< uint8_t > serializePublic(void) const
Serialize the public key and Id to publish on the server.
Definition lime_x3dh.hpp:265
void dump(std::ostringstream &os, std::string indent=" ") const
Dump the public key and Id.
Definition lime_x3dh.hpp:275
OneTimePreKey(const serializedBuffer &OPk, uint32_t Id)
Unserializing constructor: from data read in DB.
Definition lime_x3dh.hpp:236
static constexpr size_t serializedPublicSize(void)
Definition lime_x3dh.hpp:229
void set_Id(uint32_t Id)
Definition lime_x3dh.hpp:255
const X< Curve, lime::Xtype::publicKey > & cpublicKey(void) const
Definition lime_x3dh.hpp:253
static constexpr size_t serializedSize(void)
Definition lime_x3dh.hpp:230
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
Definition lime_x3dh.hpp:218
const DSA< typename Algo::EC, lime::DSAtype::signature > & csignature(void) const
Definition lime_x3dh.hpp:169
static constexpr size_t serializedSize(void)
Definition lime_x3dh.hpp:127
static constexpr size_t serializedPublicSize(void)
Definition lime_x3dh.hpp:122
SignedPreKey(const serializedBuffer &SPk, uint32_t Id)
Unserializing constructor: from data read in DB.
Definition lime_x3dh.hpp:140
DSA< typename Algo::EC, lime::DSAtype::signature > & signature(void)
Definition lime_x3dh.hpp:170
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
const X< typename Algo::EC, lime::Xtype::publicKey > & cECpublicKey(void) const
Definition lime_x3dh.hpp:166
std::vector< uint8_t > serializePublic(bool signedMessage=false) const
Definition lime_x3dh.hpp:193
const Xpair< typename Algo::EC > & cECKeypair(void) const
Definition lime_x3dh.hpp:171
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
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
const K< typename Algo::KEM, lime::Ktype::publicKey > & cKEMpublicKey(void) const
Definition lime_x3dh.hpp:168
uint32_t get_Id(void) const
Definition lime_x3dh.hpp:173
const K< typename Algo::KEM, lime::Ktype::privateKey > & cKEMprivateKey(void) const
Definition lime_x3dh.hpp:167
const Kpair< typename Algo::KEM > & cKEMKeypair(void) const
Definition lime_x3dh.hpp:172
void dump(std::ostringstream &os, std::string indent=" ") const
Dump the public key, signature and Id.
Definition lime_x3dh.hpp:206
void set_Id(uint32_t Id)
Definition lime_x3dh.hpp:174
SignedPreKey()
Definition lime_x3dh.hpp:138
sBuffer< X< Algo, lime::Xtype::publicKey >::ssize()+X< Algo, lime::Xtype::privateKey >::ssize()+K< Algo, lime::Ktype::publicKey >::ssize()+K< Algo, lime::Ktype::privateKey >::ssize()> serializedBuffer
Definition lime_x3dh.hpp:131
const X< typename Algo::EC, lime::Xtype::privateKey > & cECprivateKey(void) const
accessors
Definition lime_x3dh.hpp:165
uint32_t get_Id(void) const
Definition lime_x3dh.hpp:76
void set_Id(uint32_t Id)
Definition lime_x3dh.hpp:77
SignedPreKey(const std::vector< uint8_t >::const_iterator s)
Unserializing constructor: from data read in received bundle.
Definition lime_x3dh.hpp:60
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:91
SignedPreKey()
Definition lime_x3dh.hpp:52
SignedPreKey(const serializedBuffer &SPk, uint32_t Id)
Unserializing constructor: from data read in DB.
Definition lime_x3dh.hpp:54
const X< Curve, lime::Xtype::privateKey > & cprivateKey(void) const
accessors
Definition lime_x3dh.hpp:72
void dump(std::ostringstream &os, std::string indent=" ") const
Dump the public key, signature and Id.
Definition lime_x3dh.hpp:103
SignedPreKey(const X< Curve, lime::Xtype::publicKey > &SPkPublic, const X< Curve, lime::Xtype::privateKey > &SPkPrivate)
Definition lime_x3dh.hpp:48
DSA< Curve, lime::DSAtype::signature > & signature(void)
Definition lime_x3dh.hpp:75
sBuffer< X< Curve, lime::Xtype::publicKey >::ssize()+X< Curve, lime::Xtype::privateKey >::ssize()> serializedBuffer
Definition lime_x3dh.hpp:46
static constexpr size_t serializedPublicSize(void)
Definition lime_x3dh.hpp:44
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
const DSA< Curve, lime::DSAtype::signature > & csignature(void) const
Definition lime_x3dh.hpp:74
static constexpr size_t serializedSize(void)
Definition lime_x3dh.hpp:45
Definition lime_x3dh.hpp:32
auto clean fixed size buffer(std::array based)
Definition lime_crypto_primitives.hpp:42