Loading...
Searching...
No Matches
lime_x3dh_protocol.hpp
Go to the documentation of this file.
/*
lime_x3dh_protocol.hpp
@author Johan Pascal
@copyright Copyright (C) 2017 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef lime_x3dh_protocol_hpp
#define lime_x3dh_protocol_hpp
#include "lime_crypto_primitives.hpp"
namespace lime {
enum class X3DHKeyBundleFlag : uint8_t {
noOPk=0,
OPk=1,
noBundle=2};
template <typename Curve>
struct X3DH_peerBundle {
const std::string deviceId;
const DSA<Curve, lime::DSAtype::publicKey> Ik;
const X<Curve, lime::Xtype::publicKey> SPk;
const uint32_t SPk_id;
const DSA<Curve, lime::DSAtype::signature> SPk_sig;
const lime::X3DHKeyBundleFlag bundleFlag;
const X<Curve, lime::Xtype::publicKey> OPk;
const uint32_t OPk_id;
X3DH_peerBundle(std::string &&deviceId, std::vector<uint8_t>::const_iterator Ik, std::vector<uint8_t>::const_iterator SPk, uint32_t SPk_id, std::vector<uint8_t>::const_iterator SPk_sig, std::vector<uint8_t>::const_iterator OPk, uint32_t OPk_id) :
deviceId{deviceId}, Ik{Ik}, SPk{SPk}, SPk_id{SPk_id}, SPk_sig{SPk_sig}, bundleFlag{lime::X3DHKeyBundleFlag::OPk}, OPk{OPk}, OPk_id{OPk_id} {};
X3DH_peerBundle(std::string &&deviceId, std::vector<uint8_t>::const_iterator Ik, std::vector<uint8_t>::const_iterator SPk, uint32_t SPk_id, std::vector<uint8_t>::const_iterator SPk_sig) :
deviceId{deviceId}, Ik{Ik}, SPk{SPk}, SPk_id{SPk_id}, SPk_sig{SPk_sig}, bundleFlag{lime::X3DHKeyBundleFlag::noOPk}, OPk{}, OPk_id{0} {};
X3DH_peerBundle(std::string &&deviceId) :
deviceId{deviceId}, Ik{}, SPk{}, SPk_id{0}, SPk_sig{}, bundleFlag{lime::X3DHKeyBundleFlag::noBundle}, OPk{}, OPk_id{0} {};
};
namespace x3dh_protocol {
template <typename Curve>
void buildMessage_registerUser(std::vector<uint8_t> &message, const DSA<Curve, lime::DSAtype::publicKey> &Ik, const X<Curve, lime::Xtype::publicKey> &SPk, const DSA<Curve, lime::DSAtype::signature> &Sig, const uint32_t SPk_id, const std::vector<X<Curve, lime::Xtype::publicKey>> &OPks, const std::vector<uint32_t> &OPk_ids) noexcept;
template <typename Curve>
void buildMessage_deleteUser(std::vector<uint8_t> &message) noexcept;
template <typename Curve>
void buildMessage_publishSPk(std::vector<uint8_t> &message, const X<Curve, lime::Xtype::publicKey> &SPk, const DSA<Curve, lime::DSAtype::signature> &Sig, const uint32_t SPk_id) noexcept;
template <typename Curve>
void buildMessage_publishOPks(std::vector<uint8_t> &message, const std::vector<X<Curve, lime::Xtype::publicKey>> &OPks, const std::vector<uint32_t> &OPk_ids) noexcept;
template <typename Curve>
void buildMessage_getPeerBundles(std::vector<uint8_t> &message, std::vector<std::string> &peer_device_ids) noexcept;
template <typename Curve>
void buildMessage_getSelfOPks(std::vector<uint8_t> &message) noexcept;
/* this templates are intanciated in lime_x3dh_procotocol.cpp, do not re-instanciate it anywhere else */
#ifdef EC25519_ENABLED
extern template void buildMessage_registerUser<C255>(std::vector<uint8_t> &message, const DSA<C255, lime::DSAtype::publicKey> &Ik, const X<C255, lime::Xtype::publicKey> &SPk, const DSA<C255, lime::DSAtype::signature> &Sig, const uint32_t SPk_id, const std::vector<X<C255, lime::Xtype::publicKey>> &OPks, const std::vector<uint32_t> &OPk_ids) noexcept;
extern template void buildMessage_deleteUser<C255>(std::vector<uint8_t> &message) noexcept;
extern template void buildMessage_publishSPk<C255>(std::vector<uint8_t> &message, const X<C255, lime::Xtype::publicKey> &SPk, const DSA<C255, lime::DSAtype::signature> &Sig, const uint32_t SPk_id) noexcept;
extern template void buildMessage_publishOPks<C255>(std::vector<uint8_t> &message, const std::vector<X<C255, lime::Xtype::publicKey>> &OPks, const std::vector<uint32_t> &OPk_ids) noexcept;
extern template void buildMessage_getPeerBundles<C255>(std::vector<uint8_t> &message, std::vector<std::string> &peer_device_ids) noexcept;
extern template void buildMessage_getSelfOPks<C255>(std::vector<uint8_t> &message) noexcept;
#endif
#ifdef EC448_ENABLED
extern template void buildMessage_registerUser<C448>(std::vector<uint8_t> &message, const DSA<C448, lime::DSAtype::publicKey> &Ik, const X<C448, lime::Xtype::publicKey> &SPk, const DSA<C448, lime::DSAtype::signature> &Sig, const uint32_t SPk_id, const std::vector<X<C448, lime::Xtype::publicKey>> &OPks, const std::vector<uint32_t> &OPk_ids) noexcept;
extern template void buildMessage_deleteUser<C448>(std::vector<uint8_t> &message) noexcept;
extern template void buildMessage_publishSPk<C448>(std::vector<uint8_t> &message, const X<C448, lime::Xtype::publicKey> &SPk, const DSA<C448, lime::DSAtype::signature> &Sig, const uint32_t SPk_id) noexcept;
extern template void buildMessage_publishOPks<C448>(std::vector<uint8_t> &message, const std::vector<X<C448, lime::Xtype::publicKey>> &OPks, const std::vector<uint32_t> &OPk_ids) noexcept;
extern template void buildMessage_getPeerBundles<C448>(std::vector<uint8_t> &message, std::vector<std::string> &peer_device_ids) noexcept;
extern template void buildMessage_getSelfOPks<C448>(std::vector<uint8_t> &message) noexcept;
#endif
} // namespace x3dh_protocol
} // namespace lime
#endif /* lime_x3dh_protocol_hpp */
lime::DSA
Base buffer definition for DSA data structure.
Definition lime_crypto_primitives.hpp:97
lime::X
Base buffer definition for Key Exchange data structure.
Definition lime_crypto_primitives.hpp:56
lime_crypto_primitives.hpp
lime::x3dh_protocol::buildMessage_registerUser
void buildMessage_registerUser(std::vector< uint8_t > &message, const DSA< Curve, lime::DSAtype::publicKey > &Ik, const X< Curve, lime::Xtype::publicKey > &SPk, const DSA< Curve, lime::DSAtype::signature > &Sig, const uint32_t SPk_id, const std::vector< X< Curve, lime::Xtype::publicKey > > &OPks, const std::vector< uint32_t > &OPk_ids) noexcept
build a registerUser message : Identity Key<EDDSA Public Key length>
Definition lime_x3dh_protocol.cpp:180
lime::x3dh_protocol::buildMessage_getSelfOPks
void buildMessage_getSelfOPks(std::vector< uint8_t > &message) noexcept
build a getSelfOPks message
Definition lime_x3dh_protocol.cpp:396
lime::x3dh_protocol::buildMessage_publishOPks
void buildMessage_publishOPks(std::vector< uint8_t > &message, const std::vector< X< Curve, lime::Xtype::publicKey > > &OPks, const std::vector< uint32_t > &OPk_ids) noexcept
build a postOPks message
Definition lime_x3dh_protocol.cpp:304
lime::x3dh_protocol::buildMessage_getPeerBundles
void buildMessage_getPeerBundles(std::vector< uint8_t > &message, std::vector< std::string > &peer_device_ids) noexcept
build a getPeerBundle message
Definition lime_x3dh_protocol.cpp:353
lime::x3dh_protocol::buildMessage_deleteUser
void buildMessage_deleteUser(std::vector< uint8_t > &message) noexcept
build a deleteUser message
Definition lime_x3dh_protocol.cpp:248
lime::x3dh_protocol::buildMessage_publishSPk
void buildMessage_publishSPk(std::vector< uint8_t > &message, const X< Curve, lime::Xtype::publicKey > &SPk, const DSA< Curve, lime::DSAtype::signature > &Sig, const uint32_t SPk_id) noexcept
build a postSPk message
Definition lime_x3dh_protocol.cpp:267
lime
Definition lime.cpp:30
lime::X3DHKeyBundleFlag
X3DHKeyBundleFlag
Set possible values for a flag in the keyBundle X3DH packet.
Definition lime_x3dh_protocol.hpp:31
lime::X3DHKeyBundleFlag::OPk
@ OPk
Definition lime_x3dh_protocol.hpp:33
lime::X3DHKeyBundleFlag::noOPk
@ noOPk
Definition lime_x3dh_protocol.hpp:32
lime::X3DHKeyBundleFlag::noBundle
@ noBundle
Definition lime_x3dh_protocol.hpp:34
lime::X3DH_peerBundle::X3DH_peerBundle
X3DH_peerBundle(std::string &&deviceId)
Definition lime_x3dh_protocol.hpp:74
lime::X3DH_peerBundle::Ik
const DSA< Curve, lime::DSAtype::publicKey > Ik
Definition lime_x3dh_protocol.hpp:43
lime::X3DH_peerBundle::bundleFlag
const lime::X3DHKeyBundleFlag bundleFlag
Definition lime_x3dh_protocol.hpp:47
lime::X3DH_peerBundle::X3DH_peerBundle
X3DH_peerBundle(std::string &&deviceId, std::vector< uint8_t >::const_iterator Ik, std::vector< uint8_t >::const_iterator SPk, uint32_t SPk_id, std::vector< uint8_t >::const_iterator SPk_sig)
Definition lime_x3dh_protocol.hpp:68
lime::X3DH_peerBundle::OPk
const X< Curve, lime::Xtype::publicKey > OPk
Definition lime_x3dh_protocol.hpp:48
lime::X3DH_peerBundle::SPk_sig
const DSA< Curve, lime::DSAtype::signature > SPk_sig
Definition lime_x3dh_protocol.hpp:46
lime::X3DH_peerBundle::OPk_id
const uint32_t OPk_id
Definition lime_x3dh_protocol.hpp:49
lime::X3DH_peerBundle::X3DH_peerBundle
X3DH_peerBundle(std::string &&deviceId, std::vector< uint8_t >::const_iterator Ik, std::vector< uint8_t >::const_iterator SPk, uint32_t SPk_id, std::vector< uint8_t >::const_iterator SPk_sig, std::vector< uint8_t >::const_iterator OPk, uint32_t OPk_id)
Definition lime_x3dh_protocol.hpp:62
lime::X3DH_peerBundle::SPk_id
const uint32_t SPk_id
Definition lime_x3dh_protocol.hpp:45
lime::X3DH_peerBundle::SPk
const X< Curve, lime::Xtype::publicKey > SPk
Definition lime_x3dh_protocol.hpp:44
lime::X3DH_peerBundle::deviceId
const std::string deviceId
Definition lime_x3dh_protocol.hpp:42