Fix randomness source for key generation.

random(), and mutilations of the output of the same, are not suitable
    for generating cryptographic keys.  Use RAND_bytes() from openssl.

    We can do this without seeding during daemon initialization because:

    	- rtpengine in Linux-specific.
    	- openssl seeds transparently when /dev/urandom is present.

    From RAND_seed(3):

      On systems that provide "/dev/urandom", the randomness device is used
      to seed the PRNG transparently.  However, on all other systems, the
      application is responsible for seeding the PRNG by calling RAND_add(),
      RAND_egd(3) or RAND_load_file(3).
pull/69/head
Carsten Bock 11 years ago committed by Richard Fuchs
parent e24253a709
commit 9a2da87f13

@ -18,8 +18,7 @@
#include <stdlib.h>
#include <math.h>
#include "compat.h"
#include <openssl/rand.h>
#if 0 && defined(__DEBUG)
#define __THREAD_DEBUG 1
@ -292,10 +291,8 @@ INLINE int strmemcmp(const void *mem, int len, const char *str) {
return memcmp(mem, str, len);
}
/* XXX replace with better source of randomness */
INLINE void random_string(unsigned char *buf, int len) {
while (len--)
*buf++ = random() % 0x100;
RAND_bytes(buf, len);
}

Loading…
Cancel
Save