>From f065065fce4cc6179880d5255f994e026d431717 Mon Sep 17 00:00:00 2001 From: Ben Sartor Date: Thu, 22 Jan 2015 18:59:55 +0100 Subject: [PATCH 12/12] selectCommonAlgo now prevents adding the same element twice --- src/cryptoUtils.c | 24 ++++++++++++++++-------- test/bzrtpCryptoTest.c | 8 ++++---- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/cryptoUtils.c b/src/cryptoUtils.c index b4f3988..a2dafc2 100644 --- a/src/cryptoUtils.c +++ b/src/cryptoUtils.c @@ -438,17 +438,25 @@ int updateCryptoFunctionPointers(bzrtpChannelContext_t *zrtpChannelContext) { * @return the number of common algorithms found */ uint8_t selectCommonAlgo(uint8_t masterArray[7], uint8_t masterArrayLength, uint8_t slaveArray[7], uint8_t slaveArrayLength, uint8_t commonArray[7]) { - int i,j; + int i; uint8_t commonLength = 0; + const int bitsProInt = 8*sizeof(int); + const int algosBitmapSize = 256/bitsProInt; + int algosBitmap[algosBitmapSize]; + + memset(algosBitmap, 0, sizeof(int)*algosBitmapSize); + for (i=0; i