Loading...
Searching...
No Matches
lime_ffi.h
Go to the documentation of this file.
#ifndef lime_ffi_hpp
#define lime_ffi_hpp
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
#include <stdint.h>
typedef struct lime_manager_struct* lime_manager_t;
typedef struct lime_ffi_data_struct* lime_ffi_data_t;
enum LIME_FFI_ERROR {
LIME_FFI_SUCCESS = 0,
LIME_FFI_INVALID_CURVE_ARGUMENT = -1,
LIME_FFI_INTERNAL_ERROR = -2,
LIME_FFI_OUTPUT_BUFFER_TOO_SMALL = -3,
LIME_FFI_USER_NOT_FOUND = -4
};
enum lime_ffi_CurveId {
lime_ffi_CurveId_unset = 0,
lime_ffi_CurveId_c25519 = 1,
lime_ffi_CurveId_c448 = 2
};
enum lime_ffi_EncryptionPolicy {
lime_ffi_EncryptionPolicy_DRMessage,
lime_ffi_EncryptionPolicy_cipherMessage,
lime_ffi_EncryptionPolicy_optimizeUploadSize,
lime_ffi_EncryptionPolicy_optimizeGlobalBandwidth
};
enum lime_ffi_PeerDeviceStatus {
lime_ffi_PeerDeviceStatus_untrusted=0,
lime_ffi_PeerDeviceStatus_trusted=1,
lime_ffi_PeerDeviceStatus_unsafe=2,
lime_ffi_PeerDeviceStatus_fail,
lime_ffi_PeerDeviceStatus_unknown
};
enum lime_ffi_CallbackReturn {
lime_ffi_CallbackReturn_success,
lime_ffi_CallbackReturn_fail
};
typedef struct {
char *deviceId;
enum lime_ffi_PeerDeviceStatus peerStatus;
uint8_t *DRmessage;
size_t DRmessageSize;
} lime_ffi_RecipientData_t;
typedef void (*lime_ffi_Callback)(void *userData, const enum lime_ffi_CallbackReturn status, const char *message);
typedef void (*lime_ffi_X3DHServerPostData)(void *userData, lime_ffi_data_t limeData, const char *url, const char *from,
const uint8_t *message, const size_t message_size);
int lime_ffi_processX3DHServerResponse(lime_ffi_data_t limeData, const int code, const uint8_t *response, const size_t response_size);
int lime_ffi_manager_init(lime_manager_t * const manager, const char *db, const lime_ffi_X3DHServerPostData X3DH_post_data, void *userData);
int lime_ffi_manager_destroy(lime_manager_t manager);
int lime_ffi_create_user(lime_manager_t manager, const char *localDeviceId,
const char *x3dhServerUrl, const enum lime_ffi_CurveId curve, const uint16_t OPkInitialBatchSize,
const lime_ffi_Callback callback, void *callbackUserData);
int lime_ffi_delete_user(lime_manager_t manager, const char *localDeviceId, const lime_ffi_Callback callback, void *callbackUserData);
int lime_ffi_is_user(lime_manager_t manager, const char *localDeviceId);
int lime_ffi_encryptOutBuffersMaximumSize(const size_t plainMessageSize, const enum lime_ffi_CurveId curve, size_t *DRmessageSize, size_t *cipherMessageSize);
int lime_ffi_encrypt(lime_manager_t manager, const char *localDeviceId,
const uint8_t *const recipientUserId, const size_t recipientUserIdSize,
lime_ffi_RecipientData_t *const recipients, const size_t recipientsSize,
const uint8_t *const plainMessage, const size_t plainMessageSize,
uint8_t *const cipherMessage, size_t *cipherMessageSize,
const lime_ffi_Callback callback, void *callbackUserData,
enum lime_ffi_EncryptionPolicy encryptionPolicy);
enum lime_ffi_PeerDeviceStatus lime_ffi_decrypt(lime_manager_t manager, const char *localDeviceId,
const uint8_t *const recipientUserId, const size_t recipientUserIdSize,
const char *senderDeviceId,
const uint8_t *const DRmessage, const size_t DRmessageSize,
const uint8_t *const cipherMessage, const size_t cipherMessageSize,
uint8_t *const plainMessage, size_t *plainMessageSize);
int lime_ffi_get_selfIdentityKey(lime_manager_t manager, const char *localDeviceId, uint8_t *const Ik, size_t *IkSize);
int lime_ffi_set_peerDeviceStatus(lime_manager_t manager, const char *peerDeviceId, const uint8_t *const Ik, const size_t IkSize, enum lime_ffi_PeerDeviceStatus status);
enum lime_ffi_PeerDeviceStatus lime_ffi_get_peerDeviceStatus(lime_manager_t manager, const char *peerDeviceId);
int lime_ffi_delete_peerDevice(lime_manager_t manager, const char *peerDeviceId);
int lime_ffi_stale_sessions(lime_manager_t manager, const char *localDeviceId, const char *peerDeviceId);
int lime_ffi_update(lime_manager_t manager, const char *localDeviceId, const lime_ffi_Callback callback, void *callbackUserData, uint16_t OPkServerLowLimit, uint16_t OPkBatchSize);
int lime_ffi_set_x3dhServerUrl(lime_manager_t manager, const char *localDeviceId, const char *x3dhServerUrl);
int lime_ffi_get_x3dhServerUrl(lime_manager_t manager, const char *localDeviceId, char *x3dhServerUrl, size_t *x3dhServerUrlSize);
#ifdef __cplusplus
}
#endif
#endif /* lime__ffi_hpp */
lime_ffi_decrypt
enum lime_ffi_PeerDeviceStatus lime_ffi_decrypt(lime_manager_t manager, const char *localDeviceId, const uint8_t *const recipientUserId, const size_t recipientUserIdSize, const char *senderDeviceId, const uint8_t *const DRmessage, const size_t DRmessageSize, const uint8_t *const cipherMessage, const size_t cipherMessageSize, uint8_t *const plainMessage, size_t *plainMessageSize)
Decrypt the given message.
Definition lime_ffi.cpp:340
lime_ffi_create_user
int lime_ffi_create_user(lime_manager_t manager, const char *localDeviceId, const char *x3dhServerUrl, const enum lime_ffi_CurveId curve, const uint16_t OPkInitialBatchSize, const lime_ffi_Callback callback, void *callbackUserData)
Insert a lime user in local base and publish him on the X3DH server.
Definition lime_ffi.cpp:183
lime_ffi_CurveId
lime_ffi_CurveId
Definition lime_ffi.h:62
lime_ffi_CurveId_unset
@ lime_ffi_CurveId_unset
Definition lime_ffi.h:63
lime_ffi_CurveId_c448
@ lime_ffi_CurveId_c448
Definition lime_ffi.h:65
lime_ffi_CurveId_c25519
@ lime_ffi_CurveId_c25519
Definition lime_ffi.h:64
lime_ffi_X3DHServerPostData
void(* lime_ffi_X3DHServerPostData)(void *userData, lime_ffi_data_t limeData, const char *url, const char *from, const uint8_t *message, const size_t message_size)
Post a message to the X3DH server.
Definition lime_ffi.h:135
lime_ffi_data_t
struct lime_ffi_data_struct * lime_ffi_data_t
Definition lime_ffi.h:49
lime_ffi_set_peerDeviceStatus
int lime_ffi_set_peerDeviceStatus(lime_manager_t manager, const char *peerDeviceId, const uint8_t *const Ik, const size_t IkSize, enum lime_ffi_PeerDeviceStatus status)
set the peer device status flag in local storage: unsafe, trusted or untrusted.
Definition lime_ffi.cpp:394
lime_ffi_EncryptionPolicy
lime_ffi_EncryptionPolicy
Definition lime_ffi.h:69
lime_ffi_EncryptionPolicy_optimizeUploadSize
@ lime_ffi_EncryptionPolicy_optimizeUploadSize
Definition lime_ffi.h:72
lime_ffi_EncryptionPolicy_optimizeGlobalBandwidth
@ lime_ffi_EncryptionPolicy_optimizeGlobalBandwidth
Definition lime_ffi.h:73
lime_ffi_EncryptionPolicy_DRMessage
@ lime_ffi_EncryptionPolicy_DRMessage
Definition lime_ffi.h:70
lime_ffi_EncryptionPolicy_cipherMessage
@ lime_ffi_EncryptionPolicy_cipherMessage
Definition lime_ffi.h:71
lime_manager_t
struct lime_manager_struct * lime_manager_t
Definition lime_ffi.h:47
lime_ffi_processX3DHServerResponse
int lime_ffi_processX3DHServerResponse(lime_ffi_data_t limeData, const int code, const uint8_t *response, const size_t response_size)
Forward X3DH server response to the lime engine.
Definition lime_ffi.cpp:139
lime_ffi_delete_user
int lime_ffi_delete_user(lime_manager_t manager, const char *localDeviceId, const lime_ffi_Callback callback, void *callbackUserData)
Delete a user from local database and from the X3DH server.
Definition lime_ffi.cpp:203
LIME_FFI_ERROR
LIME_FFI_ERROR
Definition lime_ffi.h:51
LIME_FFI_SUCCESS
@ LIME_FFI_SUCCESS
Definition lime_ffi.h:52
LIME_FFI_USER_NOT_FOUND
@ LIME_FFI_USER_NOT_FOUND
Definition lime_ffi.h:56
LIME_FFI_INVALID_CURVE_ARGUMENT
@ LIME_FFI_INVALID_CURVE_ARGUMENT
Definition lime_ffi.h:53
LIME_FFI_INTERNAL_ERROR
@ LIME_FFI_INTERNAL_ERROR
Definition lime_ffi.h:54
LIME_FFI_OUTPUT_BUFFER_TOO_SMALL
@ LIME_FFI_OUTPUT_BUFFER_TOO_SMALL
Definition lime_ffi.h:55
lime_ffi_PeerDeviceStatus
lime_ffi_PeerDeviceStatus
Definition lime_ffi.h:81
lime_ffi_PeerDeviceStatus_untrusted
@ lime_ffi_PeerDeviceStatus_untrusted
Definition lime_ffi.h:82
lime_ffi_PeerDeviceStatus_fail
@ lime_ffi_PeerDeviceStatus_fail
Definition lime_ffi.h:85
lime_ffi_PeerDeviceStatus_unsafe
@ lime_ffi_PeerDeviceStatus_unsafe
Definition lime_ffi.h:84
lime_ffi_PeerDeviceStatus_unknown
@ lime_ffi_PeerDeviceStatus_unknown
Definition lime_ffi.h:87
lime_ffi_PeerDeviceStatus_trusted
@ lime_ffi_PeerDeviceStatus_trusted
Definition lime_ffi.h:83
lime_ffi_encrypt
int lime_ffi_encrypt(lime_manager_t manager, const char *localDeviceId, const uint8_t *const recipientUserId, const size_t recipientUserIdSize, lime_ffi_RecipientData_t *const recipients, const size_t recipientsSize, const uint8_t *const plainMessage, const size_t plainMessageSize, uint8_t *const cipherMessage, size_t *cipherMessageSize, const lime_ffi_Callback callback, void *callbackUserData, enum lime_ffi_EncryptionPolicy encryptionPolicy)
Encrypt a buffer (text or file) for a given list of recipient devices.
Definition lime_ffi.cpp:267
lime_ffi_get_x3dhServerUrl
int lime_ffi_get_x3dhServerUrl(lime_manager_t manager, const char *localDeviceId, char *x3dhServerUrl, size_t *x3dhServerUrlSize)
Get the X3DH key server URL for this identified user.
Definition lime_ffi.cpp:458
lime_ffi_Callback
void(* lime_ffi_Callback)(void *userData, const enum lime_ffi_CallbackReturn status, const char *message)
Callback use to give a status on asynchronous operation.
Definition lime_ffi.h:121
lime_ffi_stale_sessions
int lime_ffi_stale_sessions(lime_manager_t manager, const char *localDeviceId, const char *peerDeviceId)
Stale all sessions between localDeviceId and peerDevice. If peerDevice keep using this session to enc...
Definition lime_ffi.cpp:420
lime_ffi_get_peerDeviceStatus
enum lime_ffi_PeerDeviceStatus lime_ffi_get_peerDeviceStatus(lime_manager_t manager, const char *peerDeviceId)
get the status of a peer device: unknown, untrusted, trusted, unsafe
Definition lime_ffi.cpp:411
lime_ffi_manager_init
int lime_ffi_manager_init(lime_manager_t *const manager, const char *db, const lime_ffi_X3DHServerPostData X3DH_post_data, void *userData)
Initialise a Lime Manager, only one per end-point is required.
Definition lime_ffi.cpp:154
lime_ffi_CallbackReturn
lime_ffi_CallbackReturn
Definition lime_ffi.h:92
lime_ffi_CallbackReturn_success
@ lime_ffi_CallbackReturn_success
Definition lime_ffi.h:93
lime_ffi_CallbackReturn_fail
@ lime_ffi_CallbackReturn_fail
Definition lime_ffi.h:94
lime_ffi_set_x3dhServerUrl
int lime_ffi_set_x3dhServerUrl(lime_manager_t manager, const char *localDeviceId, const char *x3dhServerUrl)
Set the X3DH key server URL for this identified user.
Definition lime_ffi.cpp:444
lime_ffi_update
int lime_ffi_update(lime_manager_t manager, const char *localDeviceId, const lime_ffi_Callback callback, void *callbackUserData, uint16_t OPkServerLowLimit, uint16_t OPkBatchSize)
Update: shall be called once a day at least, performs checks, updates and cleaning operations.
Definition lime_ffi.cpp:425
lime_ffi_get_selfIdentityKey
int lime_ffi_get_selfIdentityKey(lime_manager_t manager, const char *localDeviceId, uint8_t *const Ik, size_t *IkSize)
retrieve self Identity Key, an EdDSA formatted public key
Definition lime_ffi.cpp:372
lime_ffi_encryptOutBuffersMaximumSize
int lime_ffi_encryptOutBuffersMaximumSize(const size_t plainMessageSize, const enum lime_ffi_CurveId curve, size_t *DRmessageSize, size_t *cipherMessageSize)
Compute the maximum buffer sizes for the encryption outputs: DRmessage and cipherMessage.
Definition lime_ffi.cpp:235
lime_ffi_delete_peerDevice
int lime_ffi_delete_peerDevice(lime_manager_t manager, const char *peerDeviceId)
delete a peerDevice from local storage
Definition lime_ffi.cpp:415
lime_ffi_manager_destroy
int lime_ffi_manager_destroy(lime_manager_t manager)
Destroy the internal structure used to interact with lime.
Definition lime_ffi.cpp:366
lime_ffi_is_user
int lime_ffi_is_user(lime_manager_t manager, const char *localDeviceId)
Check if a user is present and active in local storage.
Definition lime_ffi.cpp:222
lime_ffi_RecipientData_t
The encrypt function input/output data structure.
Definition lime_ffi.h:101
lime_ffi_RecipientData_t::peerStatus
enum lime_ffi_PeerDeviceStatus peerStatus
Definition lime_ffi.h:103
lime_ffi_RecipientData_t::DRmessageSize
size_t DRmessageSize
Definition lime_ffi.h:109
lime_ffi_RecipientData_t::deviceId
char * deviceId
Definition lime_ffi.h:102
lime_ffi_RecipientData_t::DRmessage
uint8_t * DRmessage
Definition lime_ffi.h:108
lime_ffi_data_struct
an opaque structure holding the lime cpp closure to be used to forward the X3DH server's response to ...
Definition lime_ffi.cpp:47
lime_manager_struct
encapsulate a unique pointer to limeManager in an opaque structure
Definition lime_ffi.cpp:40