31 template <
typename Curve,
bool = std::is_base_of_v<genericKEM, Curve>>
34 template <
typename Curve>
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;};
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>
131 using serializedBuffer =
sBuffer<
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;};
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;};
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>
296 using serializedBuffer =
sBuffer<
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;};
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;
384 virtual long int get_dbUid(
void)
const noexcept = 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;
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);
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
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
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