Improve random number generator

This commit is contained in:
brenosilva 2012-06-15 12:43:29 +00:00
parent 0ed1a1b8b4
commit 517abc595b
2 changed files with 15 additions and 2 deletions

View File

@ -125,15 +125,21 @@ char *normalize_path(modsec_rec *msr, char *input) {
*/ */
unsigned char *getkey(apr_pool_t *mp) { unsigned char *getkey(apr_pool_t *mp) {
unsigned short int length = 12; unsigned short int length = 12;
struct glinear data;
uint64_t seed;
char output[13]; char output[13];
char *key = NULL; char *key = NULL;
output[length] = '\0'; output[length] = '\0';
srand((unsigned int) time(0)); seed = data.seed;
srand(data.seed);
while(length--) { while(length--) {
seed *= data.mul;
seed += data.add;
data.seed = seed % data.mod;
output[length] = (rand() % 94 + 33); output[length] = (rand() % 94 + 33);
srand(rand()); srand(data.seed + rand() + time(0));
} }
key = apr_psprintf(mp,"%s",output); key = apr_psprintf(mp,"%s",output);

View File

@ -27,6 +27,13 @@
#define INT32_MAX (2147483647) #define INT32_MAX (2147483647)
#endif #endif
struct glinear {
uint32_t seed;
uint32_t mod;
uint32_t mul;
uint32_t add;
};
char DSOLOCAL *hmac(modsec_rec *msr,const unsigned char *key, int key_len, char DSOLOCAL *hmac(modsec_rec *msr,const unsigned char *key, int key_len,
char *msg, int msglen); char *msg, int msglen);
unsigned char DSOLOCAL *do_hash_link(modsec_rec *msr, char *link, unsigned char DSOLOCAL *do_hash_link(modsec_rec *msr, char *link,