31 template <
typename Curve,
bool = std::is_base_of_v<genericKEM, Curve>>
34 template <
typename Curve>
49 m_SPk.publicKey() = SPkPublic;
50 m_SPk.privateKey() = SPkPrivate;
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]);
76 uint32_t
get_Id(
void)
const {
return m_Id;};
77 void set_Id(uint32_t Id) {m_Id = Id;};
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));
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: ";
111 template <
typename Algo>
137 m_EC_SPk(SPk_EC_Public, SPk_EC_Private), m_KEM_SPk(SPk_KEM_Public, SPk_KEM_Private) {};
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]);
173 uint32_t
get_Id(
void)
const {
return m_Id;};
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));
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): ";
209 os<<std::endl<<indent<<indent<<
"SPK(KEM): ";
211 os<<std::endl<<indent<<indent<<
"SPK Sig: ";
217 template <
typename Curve,
bool = std::is_base_of_v<genericKEM, Curve>>
220 template <
typename Curve>
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]);
254 uint32_t
get_Id(
void)
const {
return m_Id;};
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));
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: ";
281 template <
typename Algo>
303 m_EC_OPk(ECPublic, ECPrivate), m_KEM_OPk(KEMPublic, KEMPrivate), m_Id{Id} {};
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]);
333 uint32_t
get_Id(
void)
const {
return m_Id;};
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));
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): ";
366 os<<std::endl<<indent<<indent<<
"OPK(KEM): ";
372 struct callbackUserData;
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;
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;
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);
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);
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);
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);
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);
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 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
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