Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions srtp/CryptoContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,11 @@ class CryptoContext {
typedef union _hmacCtx {
SkeinCtx_t hmacSkeinCtx;
#ifdef ZRTP_OPENSSL
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#if OPENSSL_VERSION_NUMBER < 0x10100000L
HMAC_CTX hmacSha1Ctx;
#else
HMAC_CTX * hmacSha1Ctx;
#endif
#else
HMAC_CTX * hmacSha1Ctx;
#endif
#else
hmacSha1Context hmacSha1Ctx;
#endif
Expand Down
1 change: 1 addition & 0 deletions srtp/crypto/hmac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ void* createSha1HmacContext(uint8_t* key, int32_t keyLength)

void* initializeSha1HmacContext(void* ctx, uint8_t* key, int32_t keyLength)
{
puts("!!! Not using OpenSSL for initializeSha1HmacContext");
hmacSha1Context *pctx = (hmacSha1Context*)ctx;

hmacSha1Init(pctx, key, keyLength);
Expand Down
23 changes: 23 additions & 0 deletions srtp/crypto/hmac.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,30 @@ void* createSha1HmacContext(uint8_t* key, int32_t key_length);
* Lenght of the MAC key in bytes
* @return Returns a pointer to the initialized context.
*/
// void* initializeSha1HmacContext(void* ctx, uint8_t* key, int32_t key_length);

/**
* Initialize a SHA1 HMAC context.
*
* An application uses this context to create several HMAC with the same key.
*
* @param ctx
* Pointer to initialized SHA1 HMAC context
* @param key
* The MAC key.
* @param key_length
* Lenght of the MAC key in bytes
* @return Returns a pointer to the initialized context.
*/
// void* initializeSha1HmacContext(void** ctx, uint8_t* key, int32_t key_length);

#if OPENSSL_VERSION_NUMBER < 0x10100000L
void* initializeSha1HmacContext(void* ctx, uint8_t* key, int32_t key_length);
#else
// We still need to provide both the double- and single-pointer functions for CryptoContext.cpp and CryptoContextCtrl.cpp
void* initializeSha1HmacContext(void** ctx, uint8_t* key, int32_t key_length);
void* initializeSha1HmacContext(void* ctx, uint8_t* key, int32_t key_length);
#endif

/**
* Compute SHA1 HMAC.
Expand Down
94 changes: 55 additions & 39 deletions srtp/crypto/openssl/hmac.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/*
Copyright (C) 2010 Werner Dittmann

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Copyright (C) 2010 Werner Dittmann
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
Expand Down Expand Up @@ -47,23 +47,23 @@ void hmac_sha1(uint8_t * key, int32_t key_length,
}

void hmac_sha1( uint8_t* key, int32_t key_length,
const uint8_t* data_chunks[],
uint32_t data_chunck_length[],
uint8_t* mac, int32_t* mac_length ) {
const uint8_t* data_chunks[],
uint32_t data_chunck_length[],
uint8_t* mac, int32_t* mac_length ) {
#if OPENSSL_VERSION_NUMBER < 0x10100000L
HMAC_CTX ctx;
HMAC_CTX_init(&ctx);
HMAC_Init_ex(&ctx, key, key_length, EVP_sha1(), NULL);
#else
HMAC_CTX* ctx;
ctx = HMAC_CTX_new();
HMAC_Init_ex(ctx, key, key_length, EVP_sha1(), NULL);
HMAC_CTX* ctx;
ctx = HMAC_CTX_new();
HMAC_Init_ex(ctx, key, key_length, EVP_sha1(), NULL);
#endif
while (*data_chunks) {
#if OPENSSL_VERSION_NUMBER < 0x10100000L
HMAC_Update(&ctx, *data_chunks, *data_chunck_length);
#else
HMAC_Update(ctx, *data_chunks, *data_chunck_length);
HMAC_Update(ctx, *data_chunks, *data_chunck_length);
#endif
data_chunks ++;
data_chunck_length ++;
Expand All @@ -72,52 +72,68 @@ void hmac_sha1( uint8_t* key, int32_t key_length,
HMAC_Final(&ctx, mac, reinterpret_cast<uint32_t*>(mac_length));
HMAC_CTX_cleanup(&ctx);
#else
HMAC_Final(ctx, mac, reinterpret_cast<uint32_t*>(mac_length));
HMAC_CTX_free( ctx );
HMAC_Final(ctx, mac, reinterpret_cast<uint32_t*>(mac_length));
HMAC_CTX_reset( ctx );
#endif
}

void* createSha1HmacContext(uint8_t* key, int32_t key_length)
{
#if OPENSSL_VERSION_NUMBER < 0x10100000L
HMAC_CTX* ctx = (HMAC_CTX*)malloc(sizeof(HMAC_CTX));

HMAC_CTX_init(ctx);
#else
HMAC_CTX* ctx = HMAC_CTX_new();
HMAC_CTX* ctx = HMAC_CTX_new();
#endif
HMAC_Init_ex(ctx, key, key_length, EVP_sha1(), NULL);
return ctx;
}

void* initializeSha1HmacContext(void* ctx, uint8_t* key, int32_t keyLength)
#if OPENSSL_VERSION_NUMBER < 0x10100000L
void* initializeSha1HmacContext(void* ctx, uint8_t* key, int32_t key_length)
{
HMAC_CTX *pctx = (HMAC_CTX*)ctx;

#if OPENSSL_VERSION_NUMBER < 0x10100000L
HMAC_CTX_init(pctx);
HMAC_Init_ex(pctx, key, key_length, EVP_sha1(), NULL);
return pctx;
}

#else
HMAC_CTX_reset(pctx);
#endif
HMAC_Init_ex(pctx, key, keyLength, EVP_sha1(), NULL);
// We still need to provide both the double- and single-pointer functions.
void* initializeSha1HmacContext(void** ctx, uint8_t* key, int32_t key_length)
{
HMAC_CTX **pctx = (HMAC_CTX**)ctx;
*pctx = HMAC_CTX_new(); // correct (!)
HMAC_Init_ex(*pctx, key, key_length, EVP_sha1(), NULL);
return *pctx;
}

void* initializeSha1HmacContext(void* ctx, uint8_t* key, int32_t key_length)
{
HMAC_CTX *pctx = (HMAC_CTX*)ctx;
pctx = HMAC_CTX_new();
HMAC_Init_ex(pctx, key, key_length, EVP_sha1(), NULL);
return pctx;
}
#endif


void hmacSha1Ctx(void* ctx, const uint8_t* data, uint32_t data_length,
uint8_t* mac, int32_t* mac_length)
uint8_t* mac, int32_t* mac_length)
{
HMAC_CTX* pctx = (HMAC_CTX*)ctx;

HMAC_Init_ex( pctx, NULL, 0, NULL, NULL );
HMAC_Update( pctx, data, data_length );
HMAC_Final( pctx, mac, reinterpret_cast<uint32_t*>(mac_length) );
}

void hmacSha1Ctx(void* ctx, const uint8_t* data[], uint32_t data_length[],
uint8_t* mac, int32_t* mac_length )
uint8_t* mac, int32_t* mac_length )
{
HMAC_CTX* pctx = (HMAC_CTX*)ctx;

HMAC_Init_ex( pctx, NULL, 0, NULL, NULL );
while (*data) {
HMAC_Update( pctx, *data, *data_length );
Expand All @@ -132,9 +148,9 @@ void freeSha1HmacContext(void* ctx)
if (ctx) {
#if OPENSSL_VERSION_NUMBER < 0x10100000L
HMAC_CTX_cleanup((HMAC_CTX*)ctx);
free(ctx);
free(ctx);
#else
HMAC_CTX_free((HMAC_CTX*)ctx);
HMAC_CTX_free((HMAC_CTX*)ctx);
#endif
}
}
1 change: 1 addition & 0 deletions zrtp/ZIDCacheFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ void ZIDCacheFile::checkDoMigration(char* name) {
}
zidFile = fopen(name, "wb+"); // create new format file in binary r/w mode
if (zidFile == NULL) {
fputs("ZIDCacheFile::checkDoMigration error: zidFile fopen failed", stderr);
fclose(fdOld);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion zrtp/ZrtpCWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void zrtp_initializeZrtpEngine(ZrtpContext* zrtpContext,
}

// Initialize ZID file (cache) and get my own ZID
zrtp_initZidFile(zidFilename);
int32_t res = zrtp_initZidFile(zidFilename);
const unsigned char* myZid = getZidCacheInstance()->getZid();

zrtpContext->zrtpEngine = new ZRtp((uint8_t*)myZid, zrtpContext->zrtpCallback,
Expand Down
18 changes: 9 additions & 9 deletions zrtp/crypto/openssl/hmac256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,28 @@ void hmac_sha256(uint8_t* key, uint32_t key_length,
HMAC_CTX_init( &ctx );
HMAC_Init_ex( &ctx, key, key_length, EVP_sha256(), NULL );
#else
HMAC_CTX * ctx;
ctx = HMAC_CTX_new();
HMAC_Init_ex( ctx, key, key_length, EVP_sha256(), NULL );
HMAC_CTX * ctx;
ctx = HMAC_CTX_new();
HMAC_Init_ex( ctx, key, key_length, EVP_sha256(), NULL );
#endif
while( *data_chunks ){
#if OPENSSL_VERSION_NUMBER < 0x10100000L
HMAC_Update( &ctx, *data_chunks, *data_chunck_length );
HMAC_Update( &ctx, *data_chunks, *data_chunck_length );
#else
HMAC_Update( ctx, *data_chunks, *data_chunck_length );
HMAC_Update( ctx, *data_chunks, *data_chunck_length );
#endif
data_chunks ++;
data_chunck_length ++;
data_chunks ++;
data_chunck_length ++;
}
#if OPENSSL_VERSION_NUMBER < 0x10100000L
HMAC_Final( &ctx, mac, &tmp);
#else
HMAC_Final( ctx, mac, &tmp);
HMAC_Final( ctx, mac, &tmp);
#endif
*mac_length = tmp;
#if OPENSSL_VERSION_NUMBER < 0x10100000L
HMAC_CTX_cleanup( &ctx );
#else
HMAC_CTX_free( ctx );
HMAC_CTX_reset( ctx );
#endif
}
22 changes: 11 additions & 11 deletions zrtp/crypto/openssl/hmac384.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,31 @@ void hmac_sha384(uint8_t* key, uint32_t key_length,
unsigned int tmp;
#if OPENSSL_VERSION_NUMBER < 0x10100000L
HMAC_CTX ctx;
HMAC_CTX_init( &ctx );
HMAC_Init_ex( &ctx, key, key_length, EVP_sha384(), NULL );
HMAC_CTX_init( &ctx );
HMAC_Init_ex( &ctx, key, key_length, EVP_sha384(), NULL );
#else
HMAC_CTX * ctx;
ctx = HMAC_CTX_new();
HMAC_Init_ex( ctx, key, key_length, EVP_sha384(), NULL );
HMAC_CTX * ctx;
ctx = HMAC_CTX_new();
HMAC_Init_ex( ctx, key, key_length, EVP_sha384(), NULL );
#endif
while( *data_chunks ){
#if OPENSSL_VERSION_NUMBER < 0x10100000L
HMAC_Update( &ctx, *data_chunks, *data_chunck_length );
HMAC_Update( &ctx, *data_chunks, *data_chunck_length );
#else
HMAC_Update( ctx, *data_chunks, *data_chunck_length );
HMAC_Update( ctx, *data_chunks, *data_chunck_length );
#endif
data_chunks ++;
data_chunck_length ++;
data_chunks ++;
data_chunck_length ++;
}
#if OPENSSL_VERSION_NUMBER < 0x10100000L
HMAC_Final( &ctx, mac, &tmp);
#else
HMAC_Final( ctx, mac, &tmp);
HMAC_Final( ctx, mac, &tmp);
#endif
*mac_length = tmp;
#if OPENSSL_VERSION_NUMBER < 0x10100000L
HMAC_CTX_cleanup( &ctx );
#else
HMAC_CTX_free( ctx );
HMAC_CTX_reset( ctx );
#endif
}
Loading