Commit 532eab69 authored by johan's avatar johan

Prepare for multichannel support

Non functional
parent 0b4f6afe
......@@ -23,7 +23,7 @@
*/
#ifndef BZRTP_H
#define BZRTP_H
typedef struct bzrtpContext_struct bzrtpContext;
typedef struct bzrtpContext_struct bzrtpContext_t;
#include <stdint.h>
/**
......@@ -45,7 +45,11 @@ typedef struct bzrtpSrtpSecrets_struct {
#define ZRTP_CLIENT_IDENTIFIER "LINPHONE-ZRTPCPP"
/* error code definition */
#define BZRTP_ERROR_INVALIDCALLBACKID 0x0001
#define BZRTP_ERROR_INVALIDCALLBACKID 0x0001
#define BZRTP_ERROR_CONTEXTNOTREADY 0x0002
#define BZRTP_ERROR_INVALIDCONTEXT 0x0004
#define BZRTP_ERROR_MULTICHANNELNOTSUPPORTEDBYPEER 0x0008
#define BZRTP_ERROR_UNABLETOADDCHANNEL 0x0010
/**
* @brief bzrtpContext_t The ZRTP engine context
* Store current state, timers, HMAC and encryption keys
......@@ -53,11 +57,15 @@ typedef struct bzrtpSrtpSecrets_struct {
typedef struct bzrtpContext_struct bzrtpContext_t;
/**
* Create context structure and initialise it
* Create context structure and initialise it
* A channel context is created when creating the zrtp context.
*
* @param[in] selfSSRC The SSRC given to the channel context created within the zrtpContext
*
* @return The ZRTP engine context data
*
*/
__attribute__ ((visibility ("default"))) bzrtpContext_t *bzrtp_createBzrtpContext();
__attribute__ ((visibility ("default"))) bzrtpContext_t *bzrtp_createBzrtpContext(uint32_t selfSSRC);
/**
* @brief Perform some initialisation which can't be done without some callback functions:
......@@ -88,4 +96,13 @@ __attribute__ ((visibility ("default"))) void bzrtp_destroyBzrtpContext(bzrtpCon
*/
__attribute__ ((visibility ("default"))) int bzrtp_setCallback(bzrtpContext_t *context, int (*functionPointer)(), uint16_t functionID);
/**
* @brief Add a channel to an existing context, this can be done only if the first channel has concluded a DH key agreement
*
* @param[in] selfSSRC The SSRC given to the channel context
*
* @return 0 on succes, error code otherwise
*/
__attribute__ ((visibility ("default"))) int bzrtp_addChannel(bzrtpContext_t *zrtpContext, uint32_t selfSSRC);
#endif /* ifndef BZRTP_H */
......@@ -28,8 +28,8 @@
#ifndef CRYPTOUTILS_H
#define CRYPTOUTILS_H
#include "packetParser.h"
#include "typedef.h"
#include "packetParser.h"
/**
*
......@@ -104,22 +104,23 @@ uint32_t bzrtp_CRC32(uint8_t *input, uint16_t length);
* rfc section 5.1.5
* The other algorithm choice will finally be set by the endpoint acting as initiator in the commit packet
*
* @param[in/out] zrtpContext The context contains the list of available algo and is set with the selected ones
* @param[in] zrtpContext The context contains the list of available algo
* @param[out] zrtpChannelContext The bzrtp channel context to be updated
* @param[in] peerHelloMessage The peer hello message containing his set of available algos
*
* return 0 on succes, error code otherwise
*
*/
int crypoAlgoAgreement(bzrtpContext_t *zrtpContext, bzrtpHelloMessage_t *peerHelloMessage);
int crypoAlgoAgreement(bzrtpContext_t *zrtpContext, bzrtpChannelContext_t *zrtpChannelContext, bzrtpHelloMessage_t *peerHelloMessage);
/**
* @brief Update context crypto function pointer according to related values of choosen algorithms fields (hashAlgo, cipherAlgo, etc..)
*
* @param[in/out] context The bzrtp context to be updated
* @param[in/out] zrtpChannelContext The bzrtp channel context to be updated
*
* @return 0 on succes
*/
int updateCryptoFunctionPointers(bzrtpContext_t *context);
int updateCryptoFunctionPointers(bzrtpChannelContext_t *zrtpChannelContext);
/**
* @brief Map the string description of algo type to an int defined in cryptoWrapper.h
......@@ -141,7 +142,8 @@ void cryptoAlgoTypeIntToString(uint8_t algoTypeInt, uint8_t algoTypeString[4]);
/**
* @brief Destroy a key by setting it to a random number
* Key is not freed, caller must deal with memory management
* Key is not freed, caller must deal with memory management.
* Does nothing if the key pointer is NULL
*
* @param[in/out] key The key to be destroyed
* @param[in] keyLength The keyLength in bytes
......
......@@ -37,6 +37,10 @@
#define BZRTP_PARSER_ERROR_INVALIDMESSAGE 0xa008
#define BZRTP_PARSER_ERROR_INVALIDCONTEXT 0xa010
#define BZRTP_PARSER_ERROR_UNMATCHINGCONFIRMMAC 0xa020
#define BZRTP_PARSER_ERROR_UNMATCHINGSSRC 0xa040
#define BZRTP_PARSER_ERROR_UNMATCHINGHASHCHAIN 0xa080
#define BZRTP_PARSER_ERROR_UNMATCHINGMAC 0xa100
#define BZRTP_PARSER_ERROR_UNEXPECTEDMESSAGE 0xa200
#define BZRTP_BUILDER_ERROR_INVALIDPACKET 0x5001
#define BZRTP_BUILDER_ERROR_INVALIDMESSAGE 0x5002
......@@ -276,41 +280,43 @@ bzrtpPacket_t *bzrtp_packetCheck(const uint8_t * input, uint16_t inputLength, ui
/**
* @brief Parse the packet to extract the message and allocate the matching message structure if needed
*
* @param[in] zrtpContext The current ZRTP context, some parameters(key agreement algorithm) may be needed to parse packet.
* @param[in] input The string buffer storing the complete ZRTP packet
* @param[in] inputLength Input length in bytes
* @param[in] zrtpPacket The zrtpPacket structure allocated by previous call to bzrtpPacketCheck
*
* @param[in] zrtpContext The current ZRTP context, some parameters(key agreement algorithm) may be needed to parse packet.
* @param[in] zrtpChannelContext The channel context this packet is intended to(channel context and packet must match peer SSRC).
* @param[in] input The string buffer storing the complete ZRTP packet
* @param[in] inputLength Input length in bytes
* @param[in] zrtpPacket The zrtpPacket structure allocated by previous call to bzrtpPacketCheck
*
* @return 0 on sucess, error code otherwise
*/
int bzrtp_packetParser(bzrtpContext_t *zrtpContext, const uint8_t * input, uint16_t inputLength, bzrtpPacket_t *zrtpPacket);
int bzrtp_packetParser(bzrtpContext_t *zrtpContext, bzrtpChannelContext_t *zrtpChannelContext, const uint8_t * input, uint16_t inputLength, bzrtpPacket_t *zrtpPacket);
/**
* @brief Create an empty packet and allocate the messageData according to requested packetType
*
* @param[in] zrtpContext The current ZRTP context, some data (H chain or others, may be needed to create messages)
* @param[in] zrtpChannelContext The channel context this packet is intended to
* @param[in] messageType The 32bit integer mapped to the message type to be created
* @param[in] sourceIdentifier The SSRC of the message creator
* @param[out] exitCode 0 on success, error code otherwise
*
* @return An empty packet initialised to get data for the requested paquet tyep. NULL on error
*/
bzrtpPacket_t *bzrtp_createZrtpPacket(bzrtpContext_t *zrtpContext, uint32_t messageType, uint32_t sourceIdentifier, int *exitCode);
bzrtpPacket_t *bzrtp_createZrtpPacket(bzrtpContext_t *zrtpContext, bzrtpChannelContext_t *zrtpChannelContext, uint32_t messageType, int *exitCode);
/**
* @brief Create a ZRTP packet string from the ZRTP packet values present in the structure
* messageType, messageData and sourceIdentifier in zrtpPacket must have been correctly set before calling this function
*
* @param[in] zrtpContext A zrtp context where to find H0-H3 to compute MAC requested by some paquets or encryption's key for commit/SASRelay packet
* @param[in] zrtpContext A zrtp context where to find H0-H3 to compute MAC requested by some paquets or encryption's key for commit/SASRelay packet
* @param[in] zrtpChannelContext The channel context this packet is intended to
* @param[in/out] zrtpPacket The zrtpPacket structure containing the message Data structure, output is stored in ->packetString
* @param[in] sequenceNumber Sequence number of this packet
*
* @return 0 on success, error code otherwise
*
*/
int bzrtp_packetBuild(bzrtpContext_t *zrtpContext, bzrtpPacket_t *zrtpPacket, uint16_t sequenceNumber);
int bzrtp_packetBuild(bzrtpContext_t *zrtpContext, bzrtpChannelContext_t *zrtpChannelContext, bzrtpPacket_t *zrtpPacket, uint16_t sequenceNumber);
/**
......
This diff is collapsed.
This diff is collapsed.
......@@ -66,7 +66,8 @@ uint8_t bzrtpCrypto_getAvailableCryptoTypes(uint8_t algoType, uint8_t availableT
case ZRTP_KEYAGREEMENT_TYPE:
availableTypes[0] = ZRTP_KEYAGREEMENT_DH3k;
availableTypes[1] = ZRTP_KEYAGREEMENT_DH2k;
return 2;
availableTypes[2] = ZRTP_KEYAGREEMENT_Mult; /* This one shall always be at the end of the list, it is just to inform the peer ZRTP endpoint that we support the Multichannel ZRTP */
return 3;
break;
case ZRTP_SAS_TYPE: /* the SAS function is implemented in cryptoUtils.c and then is not directly linked to the polarSSL crypto wrapper */
availableTypes[0] = ZRTP_SAS_B32;
......
......@@ -29,8 +29,8 @@
#include <stdlib.h>
#include <string.h>
#include "cryptoWrapper.h"
#include "cryptoUtils.h"
#include "cryptoWrapper.h"
/* local function prototype */
uint8_t selectCommonAlgo(uint8_t masterArray[7], uint8_t masterArrayLength, uint8_t slaveArray[7], uint8_t slaveArrayLength, uint8_t commonArray[7]);
......@@ -204,7 +204,7 @@ uint32_t bzrtp_CRC32(uint8_t *input, uint16_t length) {
* return 0 on succes, error code otherwise
*
*/
int crypoAlgoAgreement(bzrtpContext_t *zrtpContext, bzrtpHelloMessage_t *peerHelloMessage) {
int crypoAlgoAgreement(bzrtpContext_t *zrtpContext, bzrtpChannelContext_t *zrtpChannelContext, bzrtpHelloMessage_t *peerHelloMessage) {
/* check context and Message */
if (zrtpContext == NULL) {
return ZRTP_CRYPTOAGREEMENT_INVALIDCONTEXT;
......@@ -240,12 +240,12 @@ int crypoAlgoAgreement(bzrtpContext_t *zrtpContext, bzrtpHelloMessage_t *peerHel
/* if the first choices are the same for both, select it */
if (selfCommonKeyAgreementType[0] == peerCommonKeyAgreementType[0]) {
zrtpContext->keyAgreementAlgo = selfCommonKeyAgreementType[0];
zrtpChannelContext->keyAgreementAlgo = selfCommonKeyAgreementType[0];
} else { /* select the fastest of the two algoritm. Order is "DH2k", "EC25", "DH3k", "EC38", "EC52" */
if (peerCommonKeyAgreementType[0]<selfCommonKeyAgreementType[0]) { /* mapping to uint8_t is defined to have them in the fast to slow order */
zrtpContext->keyAgreementAlgo = peerCommonKeyAgreementType[0];
zrtpChannelContext->keyAgreementAlgo = peerCommonKeyAgreementType[0];
} else {
zrtpContext->keyAgreementAlgo = selfCommonKeyAgreementType[0];
zrtpChannelContext->keyAgreementAlgo = selfCommonKeyAgreementType[0];
}
}
......@@ -262,31 +262,31 @@ int crypoAlgoAgreement(bzrtpContext_t *zrtpContext, bzrtpHelloMessage_t *peerHel
return ZRTP_CRYPTOAGREEMENT_INVALIDCIPHER;
}
/* rfc section 5.1.5 specifies that if EC38 is choosen we SHOULD use AES256 or AES192 */
if (zrtpContext->keyAgreementAlgo == ZRTP_KEYAGREEMENT_EC38) {
zrtpContext->cipherAlgo = ZRTP_UNSET_ALGO;
if (zrtpChannelContext->keyAgreementAlgo == ZRTP_KEYAGREEMENT_EC38) {
zrtpChannelContext->cipherAlgo = ZRTP_UNSET_ALGO;
/* is AES3 available */
int i=0;
while (i<commonCipherTypeNumber && zrtpContext->cipherAlgo == ZRTP_UNSET_ALGO) {
while (i<commonCipherTypeNumber && zrtpChannelContext->cipherAlgo == ZRTP_UNSET_ALGO) {
if (commonCipherType[i] == ZRTP_CIPHER_AES3) {
zrtpContext->cipherAlgo = ZRTP_CIPHER_AES3;
zrtpChannelContext->cipherAlgo = ZRTP_CIPHER_AES3;
}
i++;
}
/* is AES2 available */
if (zrtpContext->cipherAlgo == ZRTP_UNSET_ALGO) {
if (zrtpChannelContext->cipherAlgo == ZRTP_UNSET_ALGO) {
i=0;
while (i<commonCipherTypeNumber && zrtpContext->cipherAlgo == ZRTP_UNSET_ALGO) {
while (i<commonCipherTypeNumber && zrtpChannelContext->cipherAlgo == ZRTP_UNSET_ALGO) {
if (commonCipherType[i] == ZRTP_CIPHER_AES2) {
zrtpContext->cipherAlgo = ZRTP_CIPHER_AES2;
zrtpChannelContext->cipherAlgo = ZRTP_CIPHER_AES2;
}
i++;
}
}
if (zrtpContext->cipherAlgo == ZRTP_UNSET_ALGO) {
if (zrtpChannelContext->cipherAlgo == ZRTP_UNSET_ALGO) {
return ZRTP_CRYPTOAGREEMENT_INVALIDCIPHER;
}
} else { /* no restrictions, pick the first one */
zrtpContext->cipherAlgo = commonCipherType[0];
zrtpChannelContext->cipherAlgo = commonCipherType[0];
}
/*** Hash algorithm ***/
......@@ -298,21 +298,21 @@ int crypoAlgoAgreement(bzrtpContext_t *zrtpContext, bzrtpHelloMessage_t *peerHel
}
/* rfc section 5.1.5 specifies that if EC38 is choosen we SHOULD use SHA384 */
if (zrtpContext->keyAgreementAlgo == ZRTP_KEYAGREEMENT_EC38) {
zrtpContext->hashAlgo = ZRTP_UNSET_ALGO;
if (zrtpChannelContext->keyAgreementAlgo == ZRTP_KEYAGREEMENT_EC38) {
zrtpChannelContext->hashAlgo = ZRTP_UNSET_ALGO;
/* is S384 available */
int i=0;
while (i<commonHashTypeNumber && zrtpContext->hashAlgo == ZRTP_UNSET_ALGO) {
while (i<commonHashTypeNumber && zrtpChannelContext->hashAlgo == ZRTP_UNSET_ALGO) {
if (commonHashType[i] == ZRTP_HASH_S384) {
zrtpContext->hashAlgo = ZRTP_HASH_S384;
zrtpChannelContext->hashAlgo = ZRTP_HASH_S384;
}
i++;
}
if (zrtpContext->hashAlgo == ZRTP_UNSET_ALGO) {
if (zrtpChannelContext->hashAlgo == ZRTP_UNSET_ALGO) {
return ZRTP_CRYPTOAGREEMENT_INVALIDHASH;
}
} else { /* no restrictions, pick the first one */
zrtpContext->hashAlgo = commonHashType[0];
zrtpChannelContext->hashAlgo = commonHashType[0];
}
/*** Authentication Tag algorithm ***/
......@@ -322,7 +322,7 @@ int crypoAlgoAgreement(bzrtpContext_t *zrtpContext, bzrtpHelloMessage_t *peerHel
if (commonAuthTagTypeNumber == 0) {/* This shall never happend but... */
return ZRTP_CRYPTOAGREEMENT_INVALIDAUTHTAG;
}
zrtpContext->authTagAlgo = commonAuthTagType[0];
zrtpChannelContext->authTagAlgo = commonAuthTagType[0];
/*** Sas algorithm ***/
/* get the self Sas rendering types availables */
......@@ -331,10 +331,10 @@ int crypoAlgoAgreement(bzrtpContext_t *zrtpContext, bzrtpHelloMessage_t *peerHel
if (commonSasTypeNumber == 0) {/* This shall never happend but... */
return ZRTP_CRYPTOAGREEMENT_INVALIDSAS;
}
zrtpContext->sasAlgo = commonSasType[0];
zrtpChannelContext->sasAlgo = commonSasType[0];
/* update the function pointers */
return updateCryptoFunctionPointers(zrtpContext);
return updateCryptoFunctionPointers(zrtpChannelContext);
}
/*
......@@ -345,22 +345,22 @@ int crypoAlgoAgreement(bzrtpContext_t *zrtpContext, bzrtpHelloMessage_t *peerHel
*
* @return 0 on succes
*/
int updateCryptoFunctionPointers(bzrtpContext_t *context) {
if (context==NULL) {
int updateCryptoFunctionPointers(bzrtpChannelContext_t *zrtpChannelContext) {
if (zrtpChannelContext==NULL) {
return ZRTP_CRYPTOAGREEMENT_INVALIDCONTEXT;
}
/* Hash algo */
switch (context->hashAlgo) {
switch (zrtpChannelContext->hashAlgo) {
case ZRTP_HASH_S256 :
context->hashFunction = bzrtpCrypto_sha256;
context->hmacFunction = bzrtpCrypto_hmacSha256;
context->hashLength = 32;
zrtpChannelContext->hashFunction = bzrtpCrypto_sha256;
zrtpChannelContext->hmacFunction = bzrtpCrypto_hmacSha256;
zrtpChannelContext->hashLength = 32;
break;
case ZRTP_UNSET_ALGO :
context->hashFunction = NULL;
context->hmacFunction = NULL;
context->hashLength = 0;
zrtpChannelContext->hashFunction = NULL;
zrtpChannelContext->hmacFunction = NULL;
zrtpChannelContext->hashLength = 0;
break;
default:
return ZRTP_CRYPTOAGREEMENT_INVALIDHASH;
......@@ -368,16 +368,16 @@ int updateCryptoFunctionPointers(bzrtpContext_t *context) {
}
/* CipherBlock algo */
switch (context->cipherAlgo) {
switch (zrtpChannelContext->cipherAlgo) {
case ZRTP_CIPHER_AES1 :
context->cipherEncryptionFunction = bzrtpCrypto_aes128CfbEncrypt;
context->cipherDecryptionFunction = bzrtpCrypto_aes128CfbDecrypt;
context->cipherKeyLength = 16;
zrtpChannelContext->cipherEncryptionFunction = bzrtpCrypto_aes128CfbEncrypt;
zrtpChannelContext->cipherDecryptionFunction = bzrtpCrypto_aes128CfbDecrypt;
zrtpChannelContext->cipherKeyLength = 16;
break;
case ZRTP_UNSET_ALGO :
context->cipherEncryptionFunction = NULL;
context->cipherDecryptionFunction = NULL;
context->cipherKeyLength = 0;
zrtpChannelContext->cipherEncryptionFunction = NULL;
zrtpChannelContext->cipherDecryptionFunction = NULL;
zrtpChannelContext->cipherKeyLength = 0;
break;
default:
return ZRTP_CRYPTOAGREEMENT_INVALIDCIPHER;
......@@ -385,12 +385,12 @@ int updateCryptoFunctionPointers(bzrtpContext_t *context) {
}
/* Key agreement algo : there is an unique function for this one in the wrapper, just set the keyAgreementLength */
switch (context->keyAgreementAlgo) {
switch (zrtpChannelContext->keyAgreementAlgo) {
case ZRTP_KEYAGREEMENT_DH2k :
context->keyAgreementLength = 256;
zrtpChannelContext->keyAgreementLength = 256;
break;
case ZRTP_KEYAGREEMENT_DH3k :
context->keyAgreementLength = 384;
zrtpChannelContext->keyAgreementLength = 384;
break;
default:
return ZRTP_CRYPTOAGREEMENT_INVALIDCIPHER;
......@@ -398,12 +398,12 @@ int updateCryptoFunctionPointers(bzrtpContext_t *context) {
}
/* SAS rendering algo */
switch(context->sasAlgo) {
switch(zrtpChannelContext->sasAlgo) {
case ZRTP_SAS_B32:
context->sasFunction = bzrtp_base32;
zrtpChannelContext->sasFunction = bzrtp_base32;
break;
case ZRTP_UNSET_ALGO :
context->sasFunction = NULL;
zrtpChannelContext->sasFunction = NULL;
break;
default:
return ZRTP_CRYPTOAGREEMENT_INVALIDSAS;
......
This diff is collapsed.
......@@ -31,9 +31,9 @@
/* local functions prototypes */
int bzrtp_createTagFromBytes(uint8_t *tagName, uint8_t tagNameLength, uint8_t *data, uint8_t dataLength, uint8_t *tag);
int bzrtp_findNextTag(bzrtpContext *context, uint8_t *tagName);
int bzrtp_findClosingTag(bzrtpContext *context, uint8_t *tagName, uint8_t tagNameLength, uint8_t *data);
int bzrtp_readTag(bzrtpContext *context, uint8_t *tagName, uint8_t tagNameLength, int *dataLength, uint8_t *data);
int bzrtp_findNextTag(bzrtpContext_t *context, uint8_t *tagName);
int bzrtp_findClosingTag(bzrtpContext_t *context, uint8_t *tagName, uint8_t tagNameLength, uint8_t *data);
int bzrtp_readTag(bzrtpContext_t *context, uint8_t *tagName, uint8_t tagNameLength, int *dataLength, uint8_t *data);
void bzrtp_strToUint8(uint8_t *outputBytes, uint8_t *inputString, uint16_t inputLength);
void bzrtp_int8ToStr(uint8_t *outputString, uint8_t *inputBytes, uint16_t inputBytesLength);
uint8_t bzrtp_byteToChar(uint8_t inputByte);
......@@ -198,7 +198,7 @@ int getPeerAssociatedSecretsHash(bzrtpContext_t *context, uint8_t peerZID[12]) {
*
* @return 0 on succes, -1 if the tag is not found
*/
int bzrtp_readTag(bzrtpContext *context, uint8_t *tagName, uint8_t tagNameLength, int *dataLength, uint8_t *data) {
int bzrtp_readTag(bzrtpContext_t *context, uint8_t *tagName, uint8_t tagNameLength, int *dataLength, uint8_t *data) {
uint8_t bufferTag[MAX_TAG_LENGTH+3]; /* max tag length + </> */
uint8_t bufferData[MAX_DATA_LENGTH];
......@@ -275,7 +275,7 @@ int bzrtp_createTagFromBytes(uint8_t *tagName, uint8_t tagNameLength, uint8_t *d
*
* @result tagLength on success, -1 if no tag opening were found
*/
int bzrtp_findNextTag(bzrtpContext *context, uint8_t *tagName) {
int bzrtp_findNextTag(bzrtpContext_t *context, uint8_t *tagName) {
uint8_t buffer;
/* go to the first taf opening (seach for < not followed by /) */
while (context->zrtpCallbacks.bzrtp_readCache(&buffer, 1) == 1) {
......@@ -311,7 +311,7 @@ int bzrtp_findNextTag(bzrtpContext *context, uint8_t *tagName) {
*
* @result dataLength on success, -1 if no tag closing were found
*/
int bzrtp_findClosingTag(bzrtpContext *context, uint8_t *tagName, uint8_t tagNameLength, uint8_t *data) {
int bzrtp_findClosingTag(bzrtpContext_t *context, uint8_t *tagName, uint8_t tagNameLength, uint8_t *data) {
uint8_t buffer;
int dataLength = 0;
/* go to the next closing tag (seach for </) */
......
......@@ -455,23 +455,23 @@ void test_CRC32(void) {
void test_algoAgreement(void) {
int retval;
/* first we have to create a context */
bzrtpContext_t *zrtpContext = bzrtp_createBzrtpContext();
bzrtpContext_t *zrtpContext = bzrtp_createBzrtpContext(0x12345678); /* we don't use the SSRC for this test, set it to 12345678 */
/* and an hello packet to simulate the one received from peer */
bzrtpPacket_t *helloPacket = bzrtp_createZrtpPacket(zrtpContext, MSGTYPE_HELLO, 0x12345678, &retval); /* 0x12345678 is the SSRC of sender */
bzrtpPacket_t *helloPacket = bzrtp_createZrtpPacket(zrtpContext, zrtpContext->channelContext[0], MSGTYPE_HELLO, &retval); /* 0x12345678 is the SSRC of sender */
dumpContext("initial", zrtpContext);
/* Test 1: Context and packet have been initialised with default values algo : DH3k, DH2k for key agreement type and shall then return DH3k as choosen key agreement algo */
retval = crypoAlgoAgreement(zrtpContext, helloPacket->messageData);
retval = crypoAlgoAgreement(zrtpContext, zrtpContext->channelContext[0], helloPacket->messageData);
printf("cryptagre retval is %x\n", retval);
if ((retval==0)
&& (zrtpContext->keyAgreementAlgo == ZRTP_KEYAGREEMENT_DH3k)
&& (zrtpContext->hashAlgo == ZRTP_HASH_S256)
&& (zrtpContext->cipherAlgo == ZRTP_CIPHER_AES1)
&& (zrtpContext->authTagAlgo == ZRTP_AUTHTAG_HS32)
&& (zrtpContext->sasAlgo == ZRTP_SAS_B32)) {
&& (zrtpContext->channelContext[0]->keyAgreementAlgo == ZRTP_KEYAGREEMENT_DH3k)
&& (zrtpContext->channelContext[0]->hashAlgo == ZRTP_HASH_S256)
&& (zrtpContext->channelContext[0]->cipherAlgo == ZRTP_CIPHER_AES1)
&& (zrtpContext->channelContext[0]->authTagAlgo == ZRTP_AUTHTAG_HS32)
&& (zrtpContext->channelContext[0]->sasAlgo == ZRTP_SAS_B32)) {
CU_PASS("Algo agreement test 1");
} else {
CU_FAIL("Algo agreement test 1");
......@@ -484,14 +484,14 @@ void test_algoAgreement(void) {
helloMessage->supportedKeyAgreement[0] = ZRTP_KEYAGREEMENT_DH2k;
helloMessage->supportedKeyAgreement[1] = ZRTP_KEYAGREEMENT_DH3k;
retval = crypoAlgoAgreement(zrtpContext, helloPacket->messageData);
retval = crypoAlgoAgreement(zrtpContext, zrtpContext->channelContext[0], helloPacket->messageData);
printf("cryptagre retval is %x\n", retval);
if ((retval==0)
&& (zrtpContext->keyAgreementAlgo == ZRTP_KEYAGREEMENT_DH2k)
&& (zrtpContext->hashAlgo == ZRTP_HASH_S256)
&& (zrtpContext->cipherAlgo == ZRTP_CIPHER_AES1)
&& (zrtpContext->authTagAlgo == ZRTP_AUTHTAG_HS32)
&& (zrtpContext->sasAlgo == ZRTP_SAS_B32)) {
&& (zrtpContext->channelContext[0]->keyAgreementAlgo == ZRTP_KEYAGREEMENT_DH2k)
&& (zrtpContext->channelContext[0]->hashAlgo == ZRTP_HASH_S256)
&& (zrtpContext->channelContext[0]->cipherAlgo == ZRTP_CIPHER_AES1)
&& (zrtpContext->channelContext[0]->authTagAlgo == ZRTP_AUTHTAG_HS32)
&& (zrtpContext->channelContext[0]->sasAlgo == ZRTP_SAS_B32)) {
CU_PASS("Algo agreement test 2");
} else {
CU_FAIL("Algo agreement test 2");
......
This diff is collapsed.
......@@ -159,27 +159,35 @@ void packetDump(bzrtpPacket_t *zrtpPacket, uint8_t addRawMessage) {
void dumpContext(char *title, bzrtpContext_t *zrtpContext) {
uint8_t buffer[4];
int i;
int i,j;
printf("%s context is :\n", title);
printHex("selfZID", zrtpContext->selfZID, 12);
printHex("peerZID", zrtpContext->peerZID, 12);
cryptoAlgoTypeIntToString(zrtpContext->hashAlgo, buffer);
printf("Selected algos\n - Hash: %.4s\n", buffer);
cryptoAlgoTypeIntToString(zrtpContext->cipherAlgo, buffer);
printf(" - cipher: %.4s\n", buffer);
cryptoAlgoTypeIntToString(zrtpContext->authTagAlgo, buffer);
printf(" - auth tag: %.4s\n", buffer);
cryptoAlgoTypeIntToString(zrtpContext->keyAgreementAlgo, buffer);
printf(" - key agreement: %.4s\n", buffer);
cryptoAlgoTypeIntToString(zrtpContext->sasAlgo, buffer);
printf(" - sas: %.4s\n", buffer);
printf ("selfH: ");
for (i=0; i<4; i++) {
printHex("", zrtpContext->selfH[i], 32);
}
printf ("peerH: ");
for (i=0; i<4; i++) {
printHex("", zrtpContext->peerH[i], 32);
for (i=0; i<ZRTP_MAX_CHANNEL_NUMBER; i++) {
if (zrtpContext->channelContext[i] != NULL) {
bzrtpChannelContext_t *channelContext = zrtpContext->channelContext[i];
printf("Channel %i\n self: %08x peer %08x\n", i, channelContext->selfSSRC, channelContext->peerSSRC);
printf (" selfH: ");
for (j=0; j<4; j++) {
printHex(" ", channelContext->selfH[j], 32);
}
printf (" peerH: ");
for (j=0; j<4; j++) {
printHex(" ", channelContext->peerH[j], 32);
}
cryptoAlgoTypeIntToString(channelContext->hashAlgo, buffer);
printf(" Selected algos\n - Hash: %.4s\n", buffer);
cryptoAlgoTypeIntToString(channelContext->cipherAlgo, buffer);
printf(" - cipher: %.4s\n", buffer);
cryptoAlgoTypeIntToString(channelContext->authTagAlgo, buffer);
printf(" - auth tag: %.4s\n", buffer);
cryptoAlgoTypeIntToString(channelContext->keyAgreementAlgo, buffer);
printf(" - key agreement: %.4s\n", buffer);
cryptoAlgoTypeIntToString(channelContext->sasAlgo, buffer);
printf(" - sas: %.4s\n", buffer);
}
}
printf("Initiator Shared Secrets :\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment