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_S512 0x13 64 #define ZRTP_HASH_N256 0x14 65 #define ZRTP_HASH_N384 0x15 67 #define ZRTP_CIPHER_AES1 0x21 68 #define ZRTP_CIPHER_AES2 0x22 69 #define ZRTP_CIPHER_AES3 0x23 70 #define ZRTP_CIPHER_2FS1 0x24 71 #define ZRTP_CIPHER_2FS2 0x25 72 #define ZRTP_CIPHER_2FS3 0x26 74 #define ZRTP_AUTHTAG_HS32 0x31 75 #define ZRTP_AUTHTAG_HS80 0x32 76 #define ZRTP_AUTHTAG_SK32 0x33 77 #define ZRTP_AUTHTAG_SK64 0x34 83 #define ZRTP_KEYAGREEMENT_DH2k 0x41 84 #define ZRTP_KEYAGREEMENT_X255 0x42 85 #define ZRTP_KEYAGREEMENT_K255 0x43 86 #define ZRTP_KEYAGREEMENT_EC25 0x44 87 #define ZRTP_KEYAGREEMENT_X448 0x45 88 #define ZRTP_KEYAGREEMENT_K448 0x46 89 #define ZRTP_KEYAGREEMENT_DH3k 0x47 90 #define ZRTP_KEYAGREEMENT_EC38 0x48 91 #define ZRTP_KEYAGREEMENT_EC52 0x49 92 #define ZRTP_KEYAGREEMENT_KYB1 0x4a 93 #define ZRTP_KEYAGREEMENT_KYB2 0x4b 94 #define ZRTP_KEYAGREEMENT_KYB3 0x4c 95 #define ZRTP_KEYAGREEMENT_HQC1 0x4d 96 #define ZRTP_KEYAGREEMENT_HQC2 0x4e 97 #define ZRTP_KEYAGREEMENT_HQC3 0x4f 98 #define ZRTP_KEYAGREEMENT_K255_KYB512 0x51 99 #define ZRTP_KEYAGREEMENT_K255_HQC128 0x52 100 #define ZRTP_KEYAGREEMENT_K448_KYB1024 0x53 101 #define ZRTP_KEYAGREEMENT_K448_HQC256 0x54 102 #define ZRTP_KEYAGREEMENT_K255_KYB512_HQC128 0x55 103 #define ZRTP_KEYAGREEMENT_K448_KYB1024_HQC256 0x56 105 #define ZRTP_KEYAGREEMENT_Prsh 0x9e 106 #define ZRTP_KEYAGREEMENT_Mult 0x9f 108 #define ZRTP_SAS_B32 0xa1 109 #define ZRTP_SAS_B256 0xa2 115 #define ZRTP_SRTP_SECRETS_FOR_SENDER 0x01 116 #define ZRTP_SRTP_SECRETS_FOR_RECEIVER 0x02 144 #define BZRTP_IS_INITIALISED 0x00 145 #define BZRTP_IS_SECURE 0x01 146 #define BZRTP_PEER_SUPPORT_MULTICHANNEL 0x02 147 #define BZRTP_SELF_ACCEPT_GOCLEAR 0x03 148 #define BZRTP_PEER_ACCEPT_GOCLEAR 0x04 151 #define BZRTP_AUXSECRET_MATCH 0x00 152 #define BZRTP_AUXSECRET_MISMATCH 0x01 153 #define BZRTP_AUXSECRET_UNSET 0x02 156 #define BZRTP_MESSAGE_ERROR 0x00 157 #define BZRTP_MESSAGE_WARNING 0x01 158 #define BZRTP_MESSAGE_LOG 0x02 159 #define BZRTP_MESSAGE_DEBUG 0x03 162 #define BZRTP_MESSAGE_CACHEMISMATCH 0x01 163 #define BZRTP_MESSAGE_PEERVERSIONOBSOLETE 0x02 164 #define BZRTP_MESSAGE_PEERNOTBZRTP 0x03 165 #define BZRTP_MESSAGE_PEERREQUESTGOCLEAR 0x04 166 #define BZRTP_MESSAGE_PEERACKGOCLEAR 0x05 177 int (* bzrtp_statusMessage)(
void *clientData,
const uint8_t messageLevel,
const uint8_t messageId,
const char *messageString);
181 int (* bzrtp_sendData)(
void *clientData,
const uint8_t *packetString,
uint16_t packetLength);
188 int (* bzrtp_contextReadyForExportedKeys)(
void *clientData,
int zuid,
uint8_t role);
191 #define ZRTP_MAGIC_COOKIE 0x5a525450 192 #define ZRTP_VERSION "1.10" 195 #define BZRTP_ERROR_INVALIDCALLBACKID 0x0001 196 #define BZRTP_ERROR_CONTEXTNOTREADY 0x0002 197 #define BZRTP_ERROR_INVALIDCONTEXT 0x0004 198 #define BZRTP_ERROR_MULTICHANNELNOTSUPPORTEDBYPEER 0x0008 199 #define BZRTP_ERROR_UNABLETOADDCHANNEL 0x0010 200 #define BZRTP_ERROR_UNABLETOSTARTCHANNEL 0x0020 201 #define BZRTP_ERROR_OUTPUTBUFFER_LENGTH 0x0040 202 #define BZRTP_ERROR_HELLOHASH_MISMATCH 0x0080 203 #define BZRTP_ERROR_CHANNELALREADYSTARTED 0x0100 204 #define BZRTP_ERROR_CACHEDISABLED 0x0200 205 #define BZRTP_ERROR_CACHEMIGRATIONFAILED 0x0400 206 #define BZRTP_ERROR_CACHE_PEERNOTFOUND 0x0800 207 #define BZRTP_ERROR_INVALIDCLEARMAC 0x1000 208 #define BZRTP_ERROR_PEERDOESNTACCEPTGOCLEAR 0x2000 209 #define BZRTP_ERROR_GOCLEARDISABLED 0x4000 210 #define BZRTP_ERROR_INVALIDARGUMENT 0x8000 213 #define BZRTP_CHANNEL_NOTFOUND 0x1000 214 #define BZRTP_CHANNEL_INITIALISED 0x1001 215 #define BZRTP_CHANNEL_ONGOING 0x1002 216 #define BZRTP_CHANNEL_SECURE 0x1004 217 #define BZRTP_CHANNEL_CLEAR 0x1010 218 #define BZRTP_CHANNEL_ERROR 0x1008 221 #define BZRTP_ROLE_INITIATOR 0 222 #define BZRTP_ROLE_RESPONDER 1 225 #define BZRTP_RECEPTION_UNKNOWN 0 226 #define BZRTP_RECEPTION_YES 1 227 #define BZRTP_RECEPTION_NO 2 230 #define BZRTP_CACHE_SETUP 0x2000 231 #define BZRTP_CACHE_UPDATE 0x2001 232 #define BZRTP_CACHE_DATA_NOTFOUND 0x2002 233 #define BZRTP_CACHE_PEER_STATUS_UNKNOWN 0x2010 234 #define BZRTP_CACHE_PEER_STATUS_VALID 0x2011 235 #define BZRTP_CACHE_PEER_STATUS_INVALID 0x2012 238 #define BZRTP_ZIDCACHE_INVALID_CONTEXT 0x2101 239 #define BZRTP_ZIDCACHE_INVALID_CACHE 0x2102 240 #define BZRTP_ZIDCACHE_UNABLETOUPDATE 0x2103 241 #define BZRTP_ZIDCACHE_UNABLETOREAD 0x2104 242 #define BZRTP_ZIDCACHE_BADINPUTDATA 0x2105 243 #define BZRTP_ZIDCACHE_RUNTIME_CACHELESS 0x2110 uint8_t peerSrtpKeyLength
Definition: bzrtp.h:127
BZRTP_EXPORT int bzrtp_getChannelStatus(bzrtpContext_t *zrtpContext, uint32_t selfSSRC)
Get the channel status.
Definition: bzrtp.c:1090
BZRTP_EXPORT int bzrtp_setFlags(bzrtpContext_t *zrtpContext, uint8_t flagId, uint8_t value)
Set the selfAcceptGoClear flag.
Definition: bzrtp.c:815
size_t mtu
Definition: typedef.h:301
#define BZRTP_EXPORT
Definition: bzrtp.h:41
bctbx_rng_context_t * RNGContext
Definition: typedef.h:237
uint8_t * peerSrtpKey
Definition: bzrtp.h:126
BZRTP_EXPORT int bzrtp_addChannel(bzrtpContext_t *zrtpContext, uint32_t selfSSRC)
Add a channel to an existing context.
Definition: bzrtp.c:367
BZRTP_EXPORT int bzrtp_setSupportedCryptoTypes(bzrtpContext_t *zrtpContext, uint8_t algoType, uint8_t supportedTypes[7], uint8_t supportedTypesCount)
set the supported crypto types. This function must be called before the context is initialised...
Definition: bzrtp.c:773
BZRTP_EXPORT int bzrtp_confirmGoClear(bzrtpContext_t *zrtpContext, uint32_t selfSSRC)
Create a acceptGoClear event and send it to the state machine The user received a valid GoClear packe...
Definition: bzrtp.c:1417
uint8_t cipherAlgo
Definition: bzrtp.h:130
uint8_t selfZID[12]
Definition: typedef.h:278
char * sas
Definition: bzrtp.h:133
bctbx_mutex_t * zidCacheMutex
Definition: typedef.h:275
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:1046
BZRTP_EXPORT int bzrtp_exportKey(bzrtpContext_t *zrtpContext, char *label, size_t labelLength, uint8_t *derivedKey, size_t *derivedKeyLength)
Definition: bzrtp.c:652
uint8_t hashAlgo
Definition: bzrtp.h:135
All the callback functions provided by the client needed by the ZRTP engine.
Definition: bzrtp.h:175
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:849
BZRTP_EXPORT int bzrtp_backToSecureMode(bzrtpContext_t *zrtpContext, uint32_t selfSSRC)
Create a BackToSecure event and send it to the state machine The user has a clear channel...
Definition: bzrtp.c:1449
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:1304
BZRTP_EXPORT uint8_t bzrtp_getSupportedCryptoTypes(bzrtpContext_t *zrtpContext, uint8_t algoType, uint8_t supportedTypes[7])
Get the supported crypto types.
Definition: bzrtp.c:743
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:711
BZRTP_EXPORT bool_t bzrtp_is_PQ_available(void)
check is Post Quantum algorithms are available
Definition: cryptoUtils.cc:167
unsigned short uint16_t
Definition: stdint.h:79
uint8_t * peerSrtpSalt
Definition: bzrtp.h:128
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:465
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:168
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:178
char * selfURI
Definition: typedef.h:277
uint8_t peerSrtpSaltLength
Definition: bzrtp.h:129
uint8_t sasAlgo
Definition: bzrtp.h:137
BZRTP_EXPORT int bzrtp_processMessage(bzrtpContext_t *zrtpContext, uint32_t selfSSRC, uint8_t *zrtpPacketString, uint16_t zrtpPacketStringLength)
Process a received message.
Definition: bzrtp.c:533
struct bzrtpSrtpSecrets_struct bzrtpSrtpSecrets_t
uint8_t sasLength
Definition: bzrtp.h:134
uint8_t * selfSrtpKey
Definition: bzrtp.h:122
void * zidCache
Definition: typedef.h:273
BZRTP_EXPORT int bzrtp_sendGoClear(bzrtpContext_t *context, uint32_t selfSSRC)
Create a GoClear event and send it to the state machine The user is in secure state. He decided to change his encryption mode by clicking on a button for example. The end point continues to send SRTP packets. On ClearACK reception the end point deletes all key materials.
Definition: bzrtp.c:1387
BZRTP_EXPORT size_t bzrtp_get_MTU(bzrtpContext_t *zrtpContext)
get the maximum size of a ZRTP packet generated locally
Definition: bzrtp.c:1380
uint8_t auxSecretMismatch
Definition: bzrtp.h:139
structure of the ZRTP engine context Store current state, timers, HMAC and encryption keys ...
Definition: typedef.h:235
unsigned int uint32_t
Definition: stdint.h:80
uint8_t selfSrtpSaltLength
Definition: bzrtp.h:125
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:607
uint8_t * selfSrtpSalt
Definition: bzrtp.h:124
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:1296
uint8_t selfSrtpKeyLength
Definition: bzrtp.h:123
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:994
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:1292
char * peerURI
Definition: typedef.h:279
BZRTP_EXPORT uint8_t bzrtp_getAuxiliarySharedSecretMismatch(bzrtpContext_t *zrtpContext)
Get the ZRTP auxiliary shared secret mismatch status.
Definition: bzrtp.c:1074
BZRTP_EXPORT void bzrtp_resetSASVerified(bzrtpContext_t *zrtpContext)
Called by user when the SAS has been set to unverified.
Definition: bzrtp.c:629
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:1300
BZRTP_EXPORT int bzrtp_destroyBzrtpContext(bzrtpContext_t *context, uint32_t selfSSRC)
Definition: bzrtp.c:249
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:1250
uint8_t cacheMismatch
Definition: bzrtp.h:138
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:1284
int zuid
Definition: typedef.h:276
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:349
void(* zrtpFreeBuffer_callback)(void *)
Definition: bzrtp.h:171
uint8_t cipherKeyLength
Definition: bzrtp.h:131
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:1288
BZRTP_EXPORT uint8_t bzrtp_available_key_agreement(uint8_t availableTypes[256])
Retrieve the list of available key agreements algorithms.
Definition: cryptoUtils.cc:163
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:130
#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:417
uint64_t timeReference
Definition: typedef.h:249
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:132
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:510
BZRTP_EXPORT const char * bzrtp_algoToString(uint8_t algo)
Retrieve the name of the algo in string.
Definition: bzrtp.c:1315
BZRTP_EXPORT int bzrtp_initBzrtpContext(bzrtpContext_t *context, uint32_t selfSSRC)
Perform initialisation which can't be done without ZIDcache acces.
Definition: bzrtp.c:195
uint8_t keyAgreementAlgo
Definition: bzrtp.h:136
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:1253
BZRTP_EXPORT int bzrtp_set_MTU(bzrtpContext_t *zrtpContext, size_t mtu)
set the maximum size of a ZRTP packet generated locally MTU must be at least 600 bytes to avoid usele...
Definition: bzrtp.c:1368
uint8_t peerAcceptGoClear
Definition: bzrtp.h:140