Skip to content
Snippets Groups Projects
Commit 308683a7 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#1722] Generate random keys using OpenSSL's RAND_bytes function

parent 629ca084
No related branches found
No related tags found
No related merge requests found
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/bio.h> #include <openssl/bio.h>
#include <openssl/buffer.h> #include <openssl/buffer.h>
#include <openssl/rand.h>
#include <cstdio> #include <cstdio>
...@@ -101,16 +102,16 @@ void AudioSrtpSession::setRemoteCryptoInfo(sfl::SdesNegotiator& nego) { ...@@ -101,16 +102,16 @@ void AudioSrtpSession::setRemoteCryptoInfo(sfl::SdesNegotiator& nego) {
void AudioSrtpSession::initializeLocalMasterKey(void) void AudioSrtpSession::initializeLocalMasterKey(void)
{ {
// @TODO key shold be generated randomly // @TODO key may have different length depending on cipher suite
_localMasterKeyLength = 16; _localMasterKeyLength = 16;
printf("Local Master: "); unsigned char *random_key = new unsigned char[_localMasterKeyLength];
for(int i = 0; i < 16; i++) {
_localMasterKey[i] = mk[i]; int err;
printf("%d", _localMasterKey[i]); if((err = RAND_bytes(random_key, _localMasterKeyLength)) != 1)
} _debug("Error occured while generating cryptographically strong pseudo-random key");
printf("\n");
memcpy(_localMasterKey, random_key, _localMasterKeyLength);
return; return;
} }
...@@ -119,15 +120,16 @@ void AudioSrtpSession::initializeLocalMasterKey(void) ...@@ -119,15 +120,16 @@ void AudioSrtpSession::initializeLocalMasterKey(void)
void AudioSrtpSession::initializeLocalMasterSalt(void) void AudioSrtpSession::initializeLocalMasterSalt(void)
{ {
// @TODO key shold be generated randomly // @TODO key may have different length depending on cipher suite
_localMasterSaltLength = 14; _localMasterSaltLength = 14;
printf("Local Salt: "); unsigned char *random_key = new unsigned char[_localMasterSaltLength];
for(int i = 0; i < 14; i++) {
_localMasterSalt[i] = ms[i]; int err;
printf("%d", _localMasterSalt[i]); if((err = RAND_bytes(random_key, _localMasterSaltLength)) != 1)
} _debug("Error occured while generating cryptographically strong pseudo-random key");
printf("\n");
memcpy(_localMasterSalt, random_key, _localMasterSaltLength);
return; return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment