lime
Lime is a C++ library implementing Open Whisper System Signal protocol
Public Member Functions | List of all members
lime::DRi< Curve > Class Template Reference

a Double Rachet session, implements the DR interface. More...

Inheritance diagram for lime::DRi< Curve >:
lime::DR

Public Member Functions

template<typename Curve_ = Curve, std::enable_if_t<!std::is_base_of_v< genericKEM, Curve_ >, bool > = true>
 DRi (std::shared_ptr< lime::Db > localStorage, const DRChainKey &SK, const SharedADBuffer &AD, const ARrKey< Curve > &peerPublicKey, long int peerDid, const std::string &peerDeviceId, const DSA< Curve, lime::DSAtype::publicKey > &peerIk, long int selfDid, const std::vector< uint8_t > &X3DH_initMessage, std::shared_ptr< RNG > RNG_context)
 Create a new DR session for sending message. Match pseudo code for RatchetInitAlice in DR spec section 3.3 We have a shared key and peer's public key for EC based only Double Ratchet. More...
 
template<typename Curve_ = Curve, std::enable_if_t< std::is_base_of_v< genericKEM, Curve_ >, bool > = true>
 DRi (std::shared_ptr< lime::Db > localStorage, const DRChainKey &SK, const SharedADBuffer &AD, const ARrKey< Curve > &peerPublicKey, long int peerDid, const std::string &peerDeviceId, const DSA< typename Curve::EC, lime::DSAtype::publicKey > &peerIk, long int selfDid, const std::vector< uint8_t > &X3DH_initMessage, std::shared_ptr< RNG > RNG_context)
 Create a new DR session for sending message. Match pseudo code for RatchetInitAlice in DR spec section 3.3 for KEM and EC based Double Ratchet. More...
 
 DRi (std::shared_ptr< lime::Db > localStorage, const DRChainKey &SK, const SharedADBuffer &AD, const ARsKey< Curve > &selfKeyPair, long int peerDid, const std::string &peerDeviceId, const uint32_t OPk_id, const DSA< typename Curve::EC, lime::DSAtype::publicKey > &peerIk, long int selfDid, std::shared_ptr< RNG > RNG_context)
 Create a new DR session for message reception. Match pseudo code for RatchetInitBob in DR spec section 3.3. More...
 
 DRi (std::shared_ptr< lime::Db > localStorage, long sessionId, std::shared_ptr< RNG > RNG_context)
 Create a new DR session to be loaded from db. More...
 
 DRi ()=delete
 
 DRi (DRi< Curve > &a)=delete
 
DRi< Curve > & operator= (DRi< Curve > &a)=delete
 
 ~DRi ()
 
void ratchetEncrypt (const std::vector< uint8_t > &plaintext, std::vector< uint8_t > &&AD, std::vector< uint8_t > &ciphertext, const bool payloadDirectEncryption) override
 Encrypt using the double-ratchet algorithm. More...
 
bool ratchetDecrypt (const std::vector< uint8_t > &cipherText, const std::vector< uint8_t > &AD, std::vector< uint8_t > &plaintext, const bool payloadDirectEncryption) override
 Decrypt Double Ratchet message. More...
 
long int dbSessionId (void) const override
 return the session's local storage id More...
 
bool isActive (void) const override
 return the current status of session More...
 
- Public Member Functions inherited from lime::DR
virtual ~DR ()=default
 

Detailed Description

template<typename Curve>
class lime::DRi< Curve >

a Double Rachet session, implements the DR interface.

A session is associated to a local user and a peer device. It stores all the state variables described in Double Ratcher spec section 3.2 and provide encrypt/decrypt functions

Template Parameters
CurveThe elliptic curve to use: C255 or C448

Constructor & Destructor Documentation

template<typename Curve >
template<typename Curve_ = Curve, std::enable_if_t<!std::is_base_of_v< genericKEM, Curve_ >, bool > = true>
lime::DRi< Curve >::DRi ( std::shared_ptr< lime::Db localStorage,
const DRChainKey SK,
const SharedADBuffer AD,
const ARrKey< Curve > &  peerPublicKey,
long int  peerDid,
const std::string &  peerDeviceId,
const DSA< Curve, lime::DSAtype::publicKey > &  peerIk,
long int  selfDid,
const std::vector< uint8_t > &  X3DH_initMessage,
std::shared_ptr< RNG RNG_context 
)
inline

Create a new DR session for sending message. Match pseudo code for RatchetInitAlice in DR spec section 3.3 We have a shared key and peer's public key for EC based only Double Ratchet.

Parameters
[in]localStorageLocal storage accessor to save DR session and perform mkskipped lookup
[in]SKa 32 bytes shared secret established prior the session init (likely done using X3DH)
[in]ADThe associated data generated by X3DH protocol and permanently part of the DR session(see X3DH spec section 3.3 and lime doc section 5.4.3)
[in]peerPublicKeythe public key of message recipient (also obtained through X3DH, shall be peer SPk)
[in]peerDidId used in local storage for this peer Device this session shall be attached to
[in]peerDeviceIdThe peer Device Id this session is connected to. Ignored if peerDid is not 0
[in]peerIkThe Identity Key of the peer device this session is connected to. Ignored if peerDid is not 0
[in]selfDidId used in local storage for local user this session shall be attached to
[in]X3DH_initMessageat session creation as sender we shall also store the X3DHInit message to be able to include it in all message until we got a response from peer
[in]RNG_contextA Random Number Generator context used for any rndom generation needed by this session
template<typename Curve >
template<typename Curve_ = Curve, std::enable_if_t< std::is_base_of_v< genericKEM, Curve_ >, bool > = true>
lime::DRi< Curve >::DRi ( std::shared_ptr< lime::Db localStorage,
const DRChainKey SK,
const SharedADBuffer AD,
const ARrKey< Curve > &  peerPublicKey,
long int  peerDid,
const std::string &  peerDeviceId,
const DSA< typename Curve::EC, lime::DSAtype::publicKey > &  peerIk,
long int  selfDid,
const std::vector< uint8_t > &  X3DH_initMessage,
std::shared_ptr< RNG RNG_context 
)
inline

Create a new DR session for sending message. Match pseudo code for RatchetInitAlice in DR spec section 3.3 for KEM and EC based Double Ratchet.

Parameters
[in]localStorageLocal storage accessor to save DR session and perform mkskipped lookup
[in]SKa 32 bytes shared secret established prior the session init (likely done using X3DH)
[in]ADThe associated data generated by X3DH protocol and permanently part of the DR session(see X3DH spec section 3.3 and lime doc section 5.4.3)
[in]peerPublicKeythe public key of message recipient (also obtained through X3DH, shall be peer SPk): holds DH and KEM peer public key provided by PQX3DH
[in]peerDidId used in local storage for this peer Device this session shall be attached to
[in]peerDeviceIdThe peer Device Id this session is connected to. Ignored if peerDid is not 0
[in]peerIkThe Identity Key of the peer device this session is connected to. Ignored if peerDid is not 0
[in]selfDidId used in local storage for local user this session shall be attached to
[in]X3DH_initMessageat session creation as sender we shall also store the X3DHInit message to be able to include it in all message until we got a response from peer
[in]RNG_contextA Random Number Generator context used for any rndom generation needed by this session
template<typename Curve >
lime::DRi< Curve >::DRi ( std::shared_ptr< lime::Db localStorage,
const DRChainKey SK,
const SharedADBuffer AD,
const ARsKey< Curve > &  selfKeyPair,
long int  peerDid,
const std::string &  peerDeviceId,
const uint32_t  OPk_id,
const DSA< typename Curve::EC, lime::DSAtype::publicKey > &  peerIk,
long int  selfDid,
std::shared_ptr< RNG RNG_context 
)
inline

Create a new DR session for message reception. Match pseudo code for RatchetInitBob in DR spec section 3.3.

Parameters
[in]localStorageLocal storage accessor to save DR session and perform mkskipped lookup
[in]SKa 32 bytes shared secret established prior the session init (likely done using X3DH)
[in]ADThe associated data generated by X3DH protocol and permanently part of the DR session(see X3DH spec section 3.3 and lime doc section 5.4.3)
[in]selfKeyPairthe key pair used by sender to establish this DR session (DR spec section 5.1: it shall be our SPk)
[in]peerDidId used in local storage for this peer Device this session shall be attached to
[in]peerDeviceIdThe peer Device Id this session is connected to. Ignored if peerDid is not 0
[in]OPk_idId of the self OPk used to create this session: we must remove it from local storage when saving the session in it. (ignored if 0)
[in]peerIkThe Identity Key of the peer device this session is connected to. Ignored if peerDid is not 0
[in]selfDidId used in local storage for local user this session shall be attached to
[in]RNG_contextA Random Number Generator context used for any rndom generation needed by this session
template<typename Curve >
lime::DRi< Curve >::DRi ( std::shared_ptr< lime::Db localStorage,
long  sessionId,
std::shared_ptr< RNG RNG_context 
)
inline

Create a new DR session to be loaded from db.

m_dirty is already set to clean and DHR_valid to true as we won't save a session if no successfull sending or reception was performed if loading fails, caller should destroy the session

Parameters
[in]localStorageLocal storage accessor to save DR session and perform mkskipped lookup
[in]sessionIdrow id in the database identifying the session to be loaded
[in]RNG_contextA Random Number Generator context used for any rndom generation needed by this session
template<typename Curve >
lime::DRi< Curve >::DRi ( )
delete
template<typename Curve >
lime::DRi< Curve >::DRi ( DRi< Curve > &  a)
delete
template<typename Curve >
lime::DRi< Curve >::~DRi ( )
inline

Member Function Documentation

template<typename Curve >
long int lime::DRi< Curve >::dbSessionId ( void  ) const
inlineoverridevirtual

return the session's local storage id

Implements lime::DR.

template<typename Curve >
bool lime::DRi< Curve >::isActive ( void  ) const
inlineoverridevirtual

return the current status of session

Implements lime::DR.

template<typename Curve >
DRi<Curve>& lime::DRi< Curve >::operator= ( DRi< Curve > &  a)
delete
template<typename Curve >
bool lime::DRi< Curve >::ratchetDecrypt ( const std::vector< uint8_t > &  ciphertext,
const std::vector< uint8_t > &  AD,
std::vector< uint8_t > &  plaintext,
const bool  payloadDirectEncryption 
)
overridevirtual

Decrypt Double Ratchet message.

Parameters
[in]ciphertextInput to be decrypted, is likely to be a 32 bytes vector holding the crypted version of a random seed
[in]ADAssociated data authenticated along the encryption (initial session AD and DR message header are append to it)
[out]plaintextDecrypted output
[in]payloadDirectEncryptionA flag to enforce checking on message type: when set we expect to get payload in the message(so message header matching flag must be set)
Returns
true on success

Implements lime::DR.

template<typename Curve >
void lime::DRi< Curve >::ratchetEncrypt ( const std::vector< uint8_t > &  plaintext,
std::vector< uint8_t > &&  AD,
std::vector< uint8_t > &  ciphertext,
const bool  payloadDirectEncryption 
)
overridevirtual

Encrypt using the double-ratchet algorithm.

Parameters
[in]plaintextthe input to be encrypted, may actually be a 32 bytes buffer holding the seed used to generate key+IV for a AES-GCM encryption to the actual message
[in]ADAssociated Data, this buffer shall hold: source GRUU<...> || recipient GRUU<...> || [ actual message AEAD auth tag OR recipient User Id]
[out]ciphertextbuffer holding the header, cipher text and auth tag, shall contain the key and IV used to cipher the actual message, auth tag applies on AD || header
[in]payloadDirectEncryptionA flag to set in message header: set when having payload in the DR message

Implements lime::DR.


The documentation for this class was generated from the following file: