19 #ifndef lime_double_ratchet_hpp 20 #define lime_double_ratchet_hpp 24 #include <unordered_map> 56 using SharedADBuffer = std::array<uint8_t, lime::settings::DRSessionSharedADSize>;
62 template <
typename Curve>
81 template <
typename Curve>
91 std::uint16_t m_Ns,m_Nr;
94 std::vector<lime::ReceiverKeyChain<Curve>> m_mkskipped;
97 std::shared_ptr<RNG> m_RNG;
98 long int m_dbSessionId;
101 uint32_t m_usedOPkId;
102 std::shared_ptr<lime::Db> m_localStorage;
105 std::string m_peerDeviceId;
108 bool m_active_status;
109 std::vector<uint8_t> m_X3DH_initMessage;
112 void skipMessageKeys(
const uint16_t until,
const int limit);
121 DR(std::shared_ptr<lime::Db> localStorage,
const DRChainKey &SK,
const SharedADBuffer &AD,
const X<Curve, lime::Xtype::publicKey> &peerPublicKey,
const long int peerDid,
const std::string &peerDeviceId,
const DSA<Curve, lime::DSAtype::publicKey> &peerIk,
long int selfDeviceId,
const std::vector<uint8_t> &X3DH_initMessage, std::shared_ptr<RNG> RNG_context);
122 DR(std::shared_ptr<lime::Db> localStorage,
const DRChainKey &SK,
const SharedADBuffer &AD,
const Xpair<Curve> &selfKeyPair,
long int peerDid,
const std::string &peerDeviceId,
const uint32_t OPk_id,
const DSA<Curve, lime::DSAtype::publicKey> &peerIk,
long int selfDeviceId, std::shared_ptr<RNG> RNG_context);
123 DR(std::shared_ptr<lime::Db> localStorage,
long sessionId, std::shared_ptr<RNG> RNG_context);
128 template<
typename inputContainer>
129 void ratchetEncrypt(
const inputContainer &plaintext, std::vector<uint8_t> &&AD, std::vector<uint8_t> &ciphertext,
const bool payloadDirectEncryption);
130 template<
typename outputContainer>
131 bool ratchetDecrypt(
const std::vector<uint8_t> &cipherText,
const std::vector<uint8_t> &AD, outputContainer &plaintext,
const bool payloadDirectEncryption);
135 bool isActive(
void)
const {
return m_active_status;}
142 template <
typename Curve>
163 template <
typename Curve>
166 template <
typename Curve>
167 std::shared_ptr<DR<Curve>>
decryptMessage(
const std::string& sourceDeviceId,
const std::string& recipientDeviceId,
const std::string& recipientUserId, std::vector<std::shared_ptr<
DR<Curve>>>& DRSessions,
const std::vector<uint8_t>& DRmessage,
const std::vector<uint8_t>& cipherMessage, std::vector<uint8_t>& plaintext);
170 #ifdef EC25519_ENABLED 172 extern template void encryptMessage<C255>(std::vector<RecipientInfos<C255>>& recipients,
const std::vector<uint8_t>& plaintext,
const std::string& recipientUserId,
const std::string& sourceDeviceId, std::vector<uint8_t>&
cipherMessage,
const lime::EncryptionPolicy encryptionPolicy);
173 extern template std::shared_ptr<DR<C255>> decryptMessage<C255>(
const std::string& sourceDeviceId,
const std::string& recipientDeviceId,
const std::string& recipientUserId, std::vector<std::shared_ptr<DR<C255>>>& DRSessions,
const std::vector<uint8_t>& DRmessage,
const std::vector<uint8_t>&
cipherMessage, std::vector<uint8_t>& plaintext);
177 extern template void encryptMessage<C448>(std::vector<RecipientInfos<C448>>& recipients,
const std::vector<uint8_t>& plaintext,
const std::string& recipientUserId,
const std::string& sourceDeviceId, std::vector<uint8_t>&
cipherMessage,
const lime::EncryptionPolicy encryptionPolicy);
178 extern template std::shared_ptr<DR<C448>> decryptMessage<C448>(
const std::string& sourceDeviceId,
const std::string& recipientDeviceId,
const std::string& recipientUserId, std::vector<std::shared_ptr<DR<C448>>>& DRSessions,
const std::vector<uint8_t>& DRmessage,
const std::vector<uint8_t>&
cipherMessage, std::vector<uint8_t>& plaintext);
RecipientInfos(const std::string &deviceId)
Definition: lime_double_ratchet.hpp:159
store a Double Rachet session.
Definition: lime_double_ratchet.hpp:82
DRSessionDbStatus
the possible status of session regarding the Local Storage
Definition: lime_double_ratchet.hpp:41
std::unordered_map< std::uint16_t, DRMKey > messageKeys
Definition: lime_double_ratchet.hpp:65
Chain storing the DH and MKs associated with Nr(uint16_t map index)
Definition: lime_double_ratchet.hpp:63
std::shared_ptr< DR< Curve > > decryptMessage(const std::string &sourceDeviceId, const std::string &recipientDeviceId, const std::string &recipientUserId, std::vector< std::shared_ptr< DR< Curve >>> &DRSessions, const std::vector< uint8_t > &DRmessage, const std::vector< uint8_t > &cipherMessage, std::vector< uint8_t > &plaintext)
Decrypt a message.
Definition: lime_double_ratchet.cpp:589
void encryptMessage(std::vector< RecipientInfos< Curve >> &recipients, const std::vector< uint8_t > &plaintext, const std::string &recipientUserId, const std::string &sourceDeviceId, std::vector< uint8_t > &cipherMessage, const lime::EncryptionPolicy encryptionPolicy)
Encrypt a message to all recipients, identified by their device id.
Definition: lime_double_ratchet.cpp:469
Key pair structure for key exchange algorithm.
Definition: lime_crypto_primitives.hpp:71
X< Curve, lime::Xtype::publicKey > DHr
Definition: lime_double_ratchet.hpp:64
bool isActive(void) const
return the current status of session
Definition: lime_double_ratchet.hpp:135
std::array< uint8_t, lime::settings::DRSessionSharedADSize > SharedADBuffer
Definition: lime_double_ratchet.hpp:56
std::shared_ptr< DR< Curve > > DRSession
Definition: lime_double_ratchet.hpp:144
RecipientInfos(const std::string &deviceId, std::shared_ptr< DR< Curve >> session)
Definition: lime_double_ratchet.hpp:153
ReceiverKeyChain(X< Curve, lime::Xtype::publicKey > key)
Definition: lime_double_ratchet.hpp:70
long int dbSessionId(void) const
return the session's local storage id
Definition: lime_double_ratchet.hpp:133
extend the RecipientData to add a Double Ratchet session shared with the recipient ...
Definition: lime_double_ratchet.hpp:143
The encrypt function input/output data structure.
Definition: lime.hpp:67
EncryptionPolicy
Definition: lime.hpp:41