>From bfd73ff216bc18a6661bd12abf0579759a7d5352 Mon Sep 17 00:00:00 2001 From: Ben Sartor Date: Wed, 14 Jan 2015 23:55:43 +0100 Subject: [PATCH 05/12] added getter and setter for supported crypto types --- include/bzrtp/bzrtp.h | 22 ++++++++++++++ src/bzrtp.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) diff --git a/include/bzrtp/bzrtp.h b/include/bzrtp/bzrtp.h index 8262451..417bfe7 100644 --- a/include/bzrtp/bzrtp.h +++ b/include/bzrtp/bzrtp.h @@ -237,6 +237,28 @@ BZRTP_EXPORT void bzrtp_resetSASVerified(bzrtpContext_t *zrtpContext); */ BZRTP_EXPORT int bzrtp_resetRetransmissionTimer(bzrtpContext_t *zrtpContext, uint32_t selfSSRC); +/** + * @brief Get the supported crypto types + * + * @param[int] zrtpContext The ZRTP context we're dealing with + * @param[in] algoType mapped to defines, must be in [ZRTP_HASH_TYPE, ZRTP_CIPHERBLOCK_TYPE, ZRTP_AUTHTAG_TYPE, ZRTP_KEYAGREEMENT_TYPE or ZRTP_SAS_TYPE] + * @param[out] supportedTypes mapped to uint8_t value of the 4 char strings giving the available types as string according to rfc section 5.1.2 to 5.1.6 + * + * @return number of available types, 0 on error + */ +BZRTP_EXPORT uint8_t bzrtp_getSupportedCryptoTypes(bzrtpContext_t *zrtpContext, uint8_t algoType, uint8_t supportedTypes[7]); + +/** + * @brief set the supported crypto types + * + * @param[int/out] zrtpContext The ZRTP context we're dealing with + * @param[in] algoType mapped to defines, must be in [ZRTP_HASH_TYPE, ZRTP_CIPHERBLOCK_TYPE, ZRTP_AUTHTAG_TYPE, ZRTP_KEYAGREEMENT_TYPE or ZRTP_SAS_TYPE] + * @param[in] supportedTypes mapped to uint8_t value of the 4 char strings giving the available types as string according to rfc section 5.1.2 to 5.1.6 + * @param[in] supportedTypesCount number of supported crypto types + */ +BZRTP_EXPORT void bzrtp_setSupportedCryptoTypes(bzrtpContext_t *zrtpContext, uint8_t algoType, uint8_t supportedTypes[7], uint8_t supportedTypesCount); + + #define BZRTP_CUSTOMCACHE_USEKDF 1 #define BZRTP_CUSTOMCACHE_PLAINDATA 0 diff --git a/src/bzrtp.c b/src/bzrtp.c index f1cc2a8..0822a71 100644 --- a/src/bzrtp.c +++ b/src/bzrtp.c @@ -760,3 +760,83 @@ void bzrtp_destroyChannelContext(bzrtpContext_t *zrtpContext, bzrtpChannelContex /* free the channel context */ free(zrtpChannelContext); } + +static uint8_t copyCryptoTypes(uint8_t destination[7], uint8_t source[7], uint8_t size) +{ + int i; + + for (i=0; isupportedHash, zrtpContext->hc); + case ZRTP_CIPHERBLOCK_TYPE: + return copyCryptoTypes(supportedTypes, zrtpContext->supportedCipher, zrtpContext->cc); + case ZRTP_AUTHTAG_TYPE: + return copyCryptoTypes(supportedTypes, zrtpContext->supportedAuthTag, zrtpContext->ac); + case ZRTP_KEYAGREEMENT_TYPE: + return copyCryptoTypes(supportedTypes, zrtpContext->supportedKeyAgreement, zrtpContext->kc); + case ZRTP_SAS_TYPE: + return copyCryptoTypes(supportedTypes, zrtpContext->supportedSas, zrtpContext->sc); + default: + return 0; + } +} + +/** + * @brief set the supported crypto types + * + * @param[int/out] zrtpContext The ZRTP context we're dealing with + * @param[in] algoType mapped to defines, must be in [ZRTP_HASH_TYPE, ZRTP_CIPHERBLOCK_TYPE, ZRTP_AUTHTAG_TYPE, ZRTP_KEYAGREEMENT_TYPE or ZRTP_SAS_TYPE] + * @param[in] supportedTypes mapped to uint8_t value of the 4 char strings giving the available types as string according to rfc section 5.1.2 to 5.1.6 + * @param[in] supportedTypesCount number of supported crypto types + */ +void bzrtp_setSupportedCryptoTypes(bzrtpContext_t *zrtpContext, uint8_t algoType, uint8_t supportedTypes[7], uint8_t supportedTypesCount) +{ + uint8_t implementedTypes[7]; + uint8_t implementedTypesCount; + + if (zrtpContext==NULL) { + return; + } + + supportedTypesCount = supportedTypesCount < 7 ? supportedTypesCount : 7; + implementedTypesCount = bzrtpCrypto_getAvailableCryptoTypes(algoType, implementedTypes); + + switch(algoType) { + case ZRTP_HASH_TYPE: + zrtpContext->hc = selectCommonAlgo(supportedTypes, supportedTypesCount, implementedTypes, implementedTypesCount, zrtpContext->supportedHash); + break; + case ZRTP_CIPHERBLOCK_TYPE: + zrtpContext->cc = selectCommonAlgo(supportedTypes, supportedTypesCount, implementedTypes, implementedTypesCount, zrtpContext->supportedCipher); + break; + case ZRTP_AUTHTAG_TYPE: + zrtpContext->ac = selectCommonAlgo(supportedTypes, supportedTypesCount, implementedTypes, implementedTypesCount, zrtpContext->supportedAuthTag); + break; + case ZRTP_KEYAGREEMENT_TYPE: + zrtpContext->kc = selectCommonAlgo(supportedTypes, supportedTypesCount, implementedTypes, implementedTypesCount, zrtpContext->supportedKeyAgreement); + break; + case ZRTP_SAS_TYPE: + zrtpContext->sc = selectCommonAlgo(supportedTypes, supportedTypesCount, implementedTypes, implementedTypesCount, zrtpContext->supportedSas); + break; + } +} -- 2.1.4