--- clit18/lib/litdrm.c.bak 2004-05-16 17:51:04.000000000 +0300 +++ clit18/lib/litdrm.c 2007-09-09 20:30:41.115715406 +0300 @@ -24,6 +24,7 @@ #include #include #include +#include #include "litlib.h" #include "litinternal.h" #include "d3des.h" @@ -31,7 +32,7 @@ static int calculate_deskey(lit_file *, U8 key[8]); static void hash_bytes(SHA_CTX * pctx, U8 * pdata, int length, int padding); -static void random_data(U8 * pData, int len); +static int random_data(U8 * pData, int len); #define SEALED_SIZE 16 @@ -245,7 +246,9 @@ int lit_change_drm_level(lit_file * litf } if ((litfile->drmlevel == 5) || (litfile->drmlevel == 0)) { /* Need a new bookkey */ - random_data(new_key, 8); + if (random_data(new_key, 8)) { + return E_LIT_URANDOM; + } for (i = 1; i < litfile->num_sections; i++) { status = lit_i_encrypt_section(litfile,litfile->sections[i].name, &new_key[0]); @@ -374,15 +377,21 @@ int calculate_deskey(lit_file * litfile, /*--[random_data]-------------------------------------------------------------- | | Random data for creating book key's. - | FUTUREFIX - This is very non-random. */ -void random_data(U8 * pData, int length) +int random_data(U8 * pData, int length) { - int i, r; + FILE *ura; + int ret; - srand(time(NULL)); - for (i = 0; i < length; i++) { - r = rand() ^ (rand() >> 7); - pData[i] = (r & 0xff); - } + if (length <= 0) return 0; + ura = fopen("/dev/urandom", "r"); + if (ura == NULL) + ura = fopen("/dev/random", "r"); + if (ura == NULL) + return -1; + setbuf(ura, NULL); + ret = fread(pData, 1, length, ura); + fclose(ura); + return length != ret; } + --- clit18/lib/litlib.h.bak 2004-05-15 21:56:12.000000000 +0300 +++ clit18/lib/litlib.h 2007-09-09 20:20:48.938108236 +0300 @@ -210,6 +210,7 @@ typedef struct lit_file #define E_LIT_WRITE_ERROR -2012 #define E_LIT_FILE_NOT_FOUND -2030 +#define E_LIT_URANDOM -2040 #define E_LIT_FORMAT_ERROR -2100 #define E_LIT_NEWER_VERSION -2110