fix random() implementation for Android, so not always the same number is returned. Add comment that random() is predictive and non-secure
authorRoker <roker@pep-project.org>
Sat, 30 Jan 2016 11:20:54 +0100
changeset 438106b9765559d
parent 437 53df30d25546
child 440 d4b7814f63ca
fix random() implementation for Android, so not always the same number is returned. Add comment that random() is predictive and non-secure
src/etpan_mime.c
src/platform_unix.c
src/platform_unix.h
     1.1 --- a/src/etpan_mime.c	Sat Jan 30 10:34:26 2016 +0100
     1.2 +++ b/src/etpan_mime.c	Sat Jan 30 11:20:54 2016 +0100
     1.3 @@ -10,22 +10,17 @@
     1.4  #include <assert.h>
     1.5  #include <errno.h>
     1.6  
     1.7 -#define MAX_MESSAGE_ID 512
     1.8 +#define MAX_MESSAGE_ID 128
     1.9  
    1.10  static char * generate_boundary(void)
    1.11  {
    1.12      char id[MAX_MESSAGE_ID];
    1.13 -    long value1;
    1.14 -    long value2;
    1.15 -    long value3;
    1.16 -    long value4;
    1.17 - 
    1.18 -    // no random needed here
    1.19  
    1.20 -    value1 = random();
    1.21 -    value2 = random();
    1.22 -    value3 = random();
    1.23 -    value4 = random();
    1.24 +    // no cryptographically strong random needed here
    1.25 +    const long value1 = random();
    1.26 +    const long value2 = random();
    1.27 +    const long value3 = random();
    1.28 +    const long value4 = random();
    1.29  
    1.30      snprintf(id, MAX_MESSAGE_ID, "%.4lx%.4lx%.4lx%.4lx", value1, value2,
    1.31              value3, value4);
     2.1 --- a/src/platform_unix.c	Sat Jan 30 10:34:26 2016 +0100
     2.2 +++ b/src/platform_unix.c	Sat Jan 30 11:20:54 2016 +0100
     2.3 @@ -50,8 +50,9 @@
     2.4      return dst;
     2.5  }
     2.6  
     2.7 -long int random(void){
     2.8 -    unsigned short xsubi[3] = {'p', 'E', 'p'};
     2.9 +long int random(void)
    2.10 +{
    2.11 +    static unsigned short xsubi[3] = {'p', 'E', 'p'};
    2.12      return nrand48(xsubi);
    2.13  }
    2.14  
     3.1 --- a/src/platform_unix.h	Sat Jan 30 10:34:26 2016 +0100
     3.2 +++ b/src/platform_unix.h	Sat Jan 30 11:20:54 2016 +0100
     3.3 @@ -17,7 +17,11 @@
     3.4  
     3.5  char *stpncpy(char *, const char *, size_t);
     3.6  char *stpcpy(char *, const char *);
     3.7 +
     3.8 +// Beware: predictable pseudo random with static seed!
     3.9 +// Only the lowest 31 bits are filled randomly.
    3.10  long int random(void);
    3.11 +
    3.12  const char *android_system_db(void);
    3.13  #define SYSTEM_DB android_system_db()
    3.14  #define LIBGPGME "libgpgme.so"