23 #include "bctoolbox/crypto.h" 24 #include "bctoolbox/port.h" 31 #define BZRTP_EXPORT __declspec(dllexport) 33 #define BZRTP_EXPORT __declspec(dllimport) 37 #ifndef BZRTP_DEPRECATED 38 #define BZRTP_DEPRECATED __declspec(deprecated) 41 #define BZRTP_EXPORT __attribute__ ((visibility ("default"))) 43 #ifndef BZRTP_DEPRECATED 44 #define BZRTP_DEPRECATED __attribute__ ((deprecated)) 50 #define ZRTP_HASH_TYPE 0x01 51 #define ZRTP_CIPHERBLOCK_TYPE 0x02 52 #define ZRTP_AUTHTAG_TYPE 0x04 53 #define ZRTP_KEYAGREEMENT_TYPE 0x08 54 #define ZRTP_SAS_TYPE 0x10 59 #define ZRTP_UNSET_ALGO 0x00 61 #define ZRTP_HASH_S256 0x11 62 #define ZRTP_HASH_S384 0x12 63 #define ZRTP_HASH_N256 0x13 64 #define ZRTP_HASH_N384 0x14 66 #define ZRTP_CIPHER_AES1 0x21 67 #define ZRTP_CIPHER_AES2 0x22 68 #define ZRTP_CIPHER_AES3 0x23 69 #define ZRTP_CIPHER_2FS1 0x24 70 #define ZRTP_CIPHER_2FS2 0x25 71 #define ZRTP_CIPHER_2FS3 0x26 73 #define ZRTP_AUTHTAG_HS32 0x31 74 #define ZRTP_AUTHTAG_HS80 0x32 75 #define ZRTP_AUTHTAG_SK32 0x33 76 #define ZRTP_AUTHTAG_SK64 0x34 82 #define ZRTP_KEYAGREEMENT_DH2k 0x41 83 #define ZRTP_KEYAGREEMENT_X255 0x42 84 #define ZRTP_KEYAGREEMENT_EC25 0x43 85 #define ZRTP_KEYAGREEMENT_X448 0x44 86 #define ZRTP_KEYAGREEMENT_DH3k 0x45 87 #define ZRTP_KEYAGREEMENT_EC38 0x46 88 #define ZRTP_KEYAGREEMENT_EC52 0x47 90 #define ZRTP_KEYAGREEMENT_Prsh 0x4e 91 #define ZRTP_KEYAGREEMENT_Mult 0x4f 93 #define ZRTP_SAS_B32 0x51 94 #define ZRTP_SAS_B256 0x52 100 #define ZRTP_SRTP_SECRETS_FOR_SENDER 0x01 101 #define ZRTP_SRTP_SECRETS_FOR_RECEIVER 0x02 128 #define BZRTP_AUXSECRET_MATCH 0x00 129 #define BZRTP_AUXSECRET_MISMATCH 0x01 130 #define BZRTP_AUXSECRET_UNSET 0x02 133 #define BZRTP_MESSAGE_ERROR 0x00 134 #define BZRTP_MESSAGE_WARNING 0x01 135 #define BZRTP_MESSAGE_LOG 0x02 136 #define BZRTP_MESSAGE_DEBUG 0x03 139 #define BZRTP_MESSAGE_CACHEMISMATCH 0x01 140 #define BZRTP_MESSAGE_PEERVERSIONOBSOLETE 0x02 141 #define BZRTP_MESSAGE_PEERNOTBZRTP 0x03 152 int (* bzrtp_statusMessage)(
void *clientData,
const uint8_t messageLevel,
const uint8_t messageId,
const char *messageString);
156 int (* bzrtp_sendData)(
void *clientData,
const uint8_t *packetString,
uint16_t packetLength);
163 int (* bzrtp_contextReadyForExportedKeys)(
void *clientData,
int zuid,
uint8_t role);
166 #define ZRTP_MAGIC_COOKIE 0x5a525450 167 #define ZRTP_VERSION "1.10" 170 #define BZRTP_ERROR_INVALIDCALLBACKID 0x0001 171 #define BZRTP_ERROR_CONTEXTNOTREADY 0x0002 172 #define BZRTP_ERROR_INVALIDCONTEXT 0x0004 173 #define BZRTP_ERROR_MULTICHANNELNOTSUPPORTEDBYPEER 0x0008 174 #define BZRTP_ERROR_UNABLETOADDCHANNEL 0x0010 175 #define BZRTP_ERROR_UNABLETOSTARTCHANNEL 0x0020 176 #define BZRTP_ERROR_OUTPUTBUFFER_LENGTH 0x0040 177 #define BZRTP_ERROR_HELLOHASH_MISMATCH 0x0080 178 #define BZRTP_ERROR_CHANNELALREADYSTARTED 0x0100 179 #define BZRTP_ERROR_CACHEDISABLED 0x0200 180 #define BZRTP_ERROR_CACHEMIGRATIONFAILED 0x0400 181 #define BZRTP_ERROR_CACHE_PEERNOTFOUND 0x0800 184 #define BZRTP_CHANNEL_NOTFOUND 0x1000 185 #define BZRTP_CHANNEL_INITIALISED 0x1001 186 #define BZRTP_CHANNEL_ONGOING 0x1002 187 #define BZRTP_CHANNEL_SECURE 0x1004 188 #define BZRTP_CHANNEL_ERROR 0x1008 191 #define BZRTP_ROLE_INITIATOR 0 192 #define BZRTP_ROLE_RESPONDER 1 195 #define BZRTP_CACHE_SETUP 0x2000 196 #define BZRTP_CACHE_UPDATE 0x2001 197 #define BZRTP_CACHE_DATA_NOTFOUND 0x2002 198 #define BZRTP_CACHE_PEER_STATUS_UNKNOWN 0x2010 199 #define BZRTP_CACHE_PEER_STATUS_VALID 0x2011 200 #define BZRTP_CACHE_PEER_STATUS_INVALID 0x2012 203 #define BZRTP_ZIDCACHE_INVALID_CONTEXT 0x2101 204 #define BZRTP_ZIDCACHE_INVALID_CACHE 0x2102 205 #define BZRTP_ZIDCACHE_UNABLETOUPDATE 0x2103 206 #define BZRTP_ZIDCACHE_UNABLETOREAD 0x2104 207 #define BZRTP_ZIDCACHE_BADINPUTDATA 0x2105 208 #define BZRTP_ZIDCACHE_RUNTIME_CACHELESS 0x2110 uint8_t peerSrtpKeyLength
Definition: bzrtp.h:112
BZRTP_EXPORT int bzrtp_getChannelStatus(bzrtpContext_t *zrtpContext, uint32_t selfSSRC)
Get the channel status.
Definition: bzrtp.c:1031
#define BZRTP_EXPORT
Definition: bzrtp.h:41
bctbx_rng_context_t * RNGContext
Definition: typedef.h:204
uint8_t * peerSrtpKey
Definition: bzrtp.h:111
BZRTP_EXPORT int bzrtp_addChannel(bzrtpContext_t *zrtpContext, uint32_t selfSSRC)
Add a channel to an existing context.
Definition: bzrtp.c:339
uint8_t cipherAlgo
Definition: bzrtp.h:115
uint8_t selfZID[12]
Definition: typedef.h:242
char * sas
Definition: bzrtp.h:118
bctbx_mutex_t * zidCacheMutex
Definition: typedef.h:239
BZRTP_EXPORT int bzrtp_setAuxiliarySharedSecret(bzrtpContext_t *zrtpContext, const uint8_t *auxSecret, size_t auxSecretLength)
Set Auxiliary Secret for this channel(shall be used only on primary audio channel) The given auxSecre...
Definition: bzrtp.c:987
BZRTP_EXPORT int bzrtp_exportKey(bzrtpContext_t *zrtpContext, char *label, size_t labelLength, uint8_t *derivedKey, size_t *derivedKeyLength)
Definition: bzrtp.c:622
uint8_t hashAlgo
Definition: bzrtp.h:120
All the callback functions provided by the client needed by the ZRTP engine.
Definition: bzrtp.h:150
BZRTP_EXPORT int bzrtp_setPeerHelloHash(bzrtpContext_t *zrtpContext, uint32_t selfSSRC, uint8_t *peerHelloHashHexString, size_t peerHelloHashHexStringLength)
Set the peer hello hash given by signaling to a ZRTP channel.
Definition: bzrtp.c:790
BZRTP_EXPORT int bzrtp_cache_getPeerStatus_lock(void *dbPointer, const char *peerURI, bctbx_mutex_t *zidCacheMutex)
Retrieve from bzrtp cache the trust status(based on the previously verified flag) of a peer URI...
Definition: zidCache.c:1303
BZRTP_EXPORT uint8_t bzrtp_getSupportedCryptoTypes(bzrtpContext_t *zrtpContext, uint8_t algoType, uint8_t supportedTypes[7])
Get the supported crypto types.
Definition: bzrtp.c:713
BZRTP_EXPORT int bzrtp_resetRetransmissionTimer(bzrtpContext_t *zrtpContext, uint32_t selfSSRC)
Reset the retransmission timer of a given channel. Packets will be sent again if appropriate: ...
Definition: bzrtp.c:681
unsigned short uint16_t
Definition: stdint.h:79
uint8_t * peerSrtpSalt
Definition: bzrtp.h:113
BZRTP_EXPORT int bzrtp_iterate(bzrtpContext_t *zrtpContext, uint32_t selfSSRC, uint64_t timeReference)
Send the current time to a specified channel, it will check if it has to trig some timer...
Definition: bzrtp.c:442
BZRTP_EXPORT int bzrtp_setZIDCache_lock(bzrtpContext_t *context, void *zidCache, const char *selfURI, const char *peerURI, bctbx_mutex_t *zidCacheMutex)
Set the pointer allowing cache access, this version of the function get a mutex to lock the cache whe...
Definition: bzrtp.c:161
unsigned char uint8_t
Definition: stdint.h:78
BZRTP_EXPORT int bzrtp_initCache_lock(void *db, bctbx_mutex_t *zidCacheMutex)
Check the given sqlite3 DB and create requested tables if needed Also manage DB schema upgrade...
int bzrtp_messageLevel
Definition: bzrtp.h:153
char * selfURI
Definition: typedef.h:241
uint8_t peerSrtpSaltLength
Definition: bzrtp.h:114
uint8_t sasAlgo
Definition: bzrtp.h:122
BZRTP_EXPORT int bzrtp_processMessage(bzrtpContext_t *zrtpContext, uint32_t selfSSRC, uint8_t *zrtpPacketString, uint16_t zrtpPacketStringLength)
Process a received message.
Definition: bzrtp.c:510
struct bzrtpSrtpSecrets_struct bzrtpSrtpSecrets_t
uint8_t sasLength
Definition: bzrtp.h:119
uint8_t * selfSrtpKey
Definition: bzrtp.h:107
void * zidCache
Definition: typedef.h:237
uint8_t auxSecretMismatch
Definition: bzrtp.h:124
structure of the ZRTP engine context Store current state, timers, HMAC and encryption keys ...
Definition: typedef.h:202
unsigned int uint32_t
Definition: stdint.h:80
uint8_t selfSrtpSaltLength
Definition: bzrtp.h:110
unsigned __int64 uint64_t
Definition: stdint.h:90
struct bzrtpCallbacks_struct bzrtpCallbacks_t
All the callback functions provided by the client needed by the ZRTP engine.
BZRTP_EXPORT void bzrtp_SASVerified(bzrtpContext_t *zrtpContext)
Called by user when the SAS has been verified.
Definition: bzrtp.c:577
uint8_t * selfSrtpSalt
Definition: bzrtp.h:109
BZRTP_EXPORT int bzrtp_cache_read_lock(void *dbPointer, int zuid, const char *tableName, const char **columns, uint8_t **values, size_t *lengths, uint8_t columnsCount, bctbx_mutex_t *zidCacheMutex)
Read data from specified table/columns from cache adressing it by zuid (ZID/URI binding id used in ca...
Definition: zidCache.c:1295
uint8_t selfSrtpKeyLength
Definition: bzrtp.h:108
BZRTP_EXPORT int bzrtp_getSelfHelloHash(bzrtpContext_t *zrtpContext, uint32_t selfSSRC, uint8_t *output, size_t outputLength)
Get the self hello hash from ZRTP channel.
Definition: bzrtp.c:935
BZRTP_EXPORT BZRTP_DEPRECATED int bzrtp_cache_read(void *dbPointer, int zuid, const char *tableName, const char **columns, uint8_t **values, size_t *lengths, uint8_t columnsCount)
Read data from specified table/columns from cache adressing it by zuid (ZID/URI binding id used in ca...
Definition: zidCache.c:1291
char * peerURI
Definition: typedef.h:243
BZRTP_EXPORT uint8_t bzrtp_getAuxiliarySharedSecretMismatch(bzrtpContext_t *zrtpContext)
Get the ZRTP auxiliary shared secret mismatch status.
Definition: bzrtp.c:1015
BZRTP_EXPORT void bzrtp_resetSASVerified(bzrtpContext_t *zrtpContext)
Called by user when the SAS has been set to unverified.
Definition: bzrtp.c:599
BZRTP_EXPORT int bzrtp_cache_migration(void *cacheXmlPtr, void *cacheSqlite, const char *selfURI)
Perform migration from xml version to sqlite3 version of cache Warning: new version of cache associat...
Definition: zidCache.c:1299
BZRTP_EXPORT int bzrtp_destroyBzrtpContext(bzrtpContext_t *context, uint32_t selfSSRC)
Definition: bzrtp.c:224
BZRTP_EXPORT void bzrtp_setSupportedCryptoTypes(bzrtpContext_t *zrtpContext, uint8_t algoType, uint8_t supportedTypes[7], uint8_t supportedTypesCount)
set the supported crypto types
Definition: bzrtp.c:743
BZRTP_EXPORT BZRTP_DEPRECATED int bzrtp_getSelfZID(void *db, const char *selfURI, uint8_t selfZID[12], bctbx_rng_context_t *RNGContext)
: retrieve ZID from cache ZID is randomly generated if cache is empty or inexistant ZID is randomly g...
Definition: zidCache.c:1249
BZRTP_EXPORT void bzrtp_resetBzrtpContext(bzrtpContext_t *context)
Definition: bzrtp.c:177
uint8_t cacheMismatch
Definition: bzrtp.h:123
BZRTP_EXPORT BZRTP_DEPRECATED int bzrtp_cache_write(void *dbPointer, int zuid, const char *tableName, const char **columns, uint8_t **values, size_t *lengths, uint8_t columnsCount)
Write(insert or update) data in cache, adressing it by zuid (ZID/URI binding id used in cache) Get ar...
Definition: zidCache.c:1283
int zuid
Definition: typedef.h:240
BZRTP_EXPORT int bzrtp_setCallbacks(bzrtpContext_t *context, const bzrtpCallbacks_t *cbs)
Allocate a function pointer to the callback function identified by his id.
Definition: bzrtp.c:321
void(* zrtpFreeBuffer_callback)(void *)
Definition: bzrtp.h:146
uint8_t cipherKeyLength
Definition: bzrtp.h:116
BZRTP_EXPORT int bzrtp_cache_write_lock(void *dbPointer, int zuid, const char *tableName, const char **columns, uint8_t **values, size_t *lengths, uint8_t columnsCount, bctbx_mutex_t *zidCacheMutex)
Write(insert or update) data in cache, adressing it by zuid (ZID/URI binding id used in cache) Get ar...
Definition: zidCache.c:1287
BZRTP_EXPORT int bzrtp_setZIDCache(bzrtpContext_t *context, void *zidCache, const char *selfURI, const char *peerURI)
Set the pointer allowing cache access.
Definition: bzrtp.c:123
#define BZRTP_DEPRECATED
Definition: bzrtp.h:44
BZRTP_EXPORT int bzrtp_startChannelEngine(bzrtpContext_t *zrtpContext, uint32_t selfSSRC)
Start the state machine of the specified channel To be able to start an addional channel, we must be in secure state.
Definition: bzrtp.c:389
uint64_t timeReference
Definition: typedef.h:213
BZRTP_EXPORT BZRTP_DEPRECATED int bzrtp_initCache(void *db)
Check the given sqlite3 DB and create requested tables if needed Also manage DB schema upgrade...
signed int int32_t
Definition: stdint.h:77
BZRTP_EXPORT bzrtpContext_t * bzrtp_createBzrtpContext(void)
Definition: bzrtp.c:45
uint8_t authTagAlgo
Definition: bzrtp.h:117
BZRTP_EXPORT int bzrtp_setClientData(bzrtpContext_t *zrtpContext, uint32_t selfSSRC, void *clientData)
Set the client data pointer in a channel context This pointer is returned to the client by the callba...
Definition: bzrtp.c:487
BZRTP_EXPORT int bzrtp_initBzrtpContext(bzrtpContext_t *context, uint32_t selfSSRC)
Perform initialisation which can't be done without ZIDcache acces.
Definition: bzrtp.c:199
uint8_t keyAgreementAlgo
Definition: bzrtp.h:121
BZRTP_EXPORT int bzrtp_getSelfZID_lock(void *db, const char *selfURI, uint8_t selfZID[12], bctbx_rng_context_t *RNGContext, bctbx_mutex_t *zidCacheMutex)
: retrieve ZID from cache ZID is randomly generated if cache is empty or inexistant ZID is randomly g...
Definition: zidCache.c:1252