mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Improve random number generator
This commit is contained in:
parent
39fcad4566
commit
f72ba4d36f
@ -116,6 +116,58 @@ char *normalize_path(modsec_rec *msr, char *input) {
|
||||
return apr_pstrdup(msr->mp, input);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Create a random number
|
||||
*
|
||||
* \retval seed random seed
|
||||
*/
|
||||
unsigned long prng() {
|
||||
short num_matrix1[10]; num_matrix2[10];
|
||||
unsigned long num, num1, num2;
|
||||
short n, *p;
|
||||
unsigned short seed_num;
|
||||
unsigned long seed;
|
||||
|
||||
seed_num = seed & 16BITS_MASK;
|
||||
num = seed & 31BITS_MASK;
|
||||
|
||||
p = num_matrix1;
|
||||
|
||||
for(n = 18; n-- ; ) {
|
||||
num = 30903*seed_num + (num>>16);
|
||||
*p++ = seed_num = num & 16BITS_MASK;
|
||||
if (n == 9)
|
||||
p = num_matrix2;
|
||||
}
|
||||
|
||||
num_matrix1[0] &= 15BITS_MASK;
|
||||
num_matrix2[0] &= 15BITS_MASK;
|
||||
memcpy((char*)num_matrix1+2,(char*)num_matrix1+1,8*sizeof(short));
|
||||
memcpy((char*)num_matrix2+2,(char*)num_matrix2+1,8*sizeof(short));
|
||||
|
||||
num1 = num_matrix1[0];
|
||||
num2 = num_matrix2[0];
|
||||
|
||||
num1 += 1941 * num_matrix1[2] + 1860 * num_matrix1[3] +
|
||||
1812 * num_matrix1[4] + 1776 * num_matrix1[5] +
|
||||
1492 * num_matrix1[6] + 1215 * num_matrix1[7] +
|
||||
1066 * num_matrix1[8] + 12013 * num_matrix1[9];
|
||||
|
||||
num2 += 1111 * num_matrix2[2] + 2222 * num_matrix2[3] +
|
||||
3333 * num_matrix2[4] + 4444 * num_matrix2[5] +
|
||||
5555 * num_matrix2[6] + 6666 * num_matrix2[7] +
|
||||
7777 * num_matrix2[8] + 9272 * num_matrix2[9];
|
||||
|
||||
num_matrix1[0] = num1/16BITS_MASK;
|
||||
num_matrix2[0] = num2/16BITS_MASK;
|
||||
num_matrix1[1] = 16BITS_MASK&num1;
|
||||
num_matrix2[1] = 16BITS_MASK&num2;
|
||||
|
||||
seed = (((long)num_matrix1[1])<<16)+(long)num_matrix2[1];
|
||||
|
||||
return seed;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Create a random password
|
||||
*
|
||||
@ -139,7 +191,7 @@ unsigned char *getkey(apr_pool_t *mp) {
|
||||
seed += data.add;
|
||||
data.seed = seed % data.mod;
|
||||
output[length] = (rand() % 94 + 33);
|
||||
srand(data.seed + rand() + time(0));
|
||||
srand(data.seed + prng());
|
||||
}
|
||||
|
||||
key = apr_psprintf(mp,"%s",output);
|
||||
|
@ -34,6 +34,11 @@ struct glinear {
|
||||
uint32_t add;
|
||||
};
|
||||
|
||||
#define 16BITS_MASK 65536L
|
||||
#define 16BITS_MASK 0xFFFF
|
||||
#define 15BITS_MASK 0x7FFF
|
||||
#define 31BITS_MASK 0x7FFFFFFF
|
||||
|
||||
char DSOLOCAL *hmac(modsec_rec *msr,const unsigned char *key, int key_len,
|
||||
char *msg, int msglen);
|
||||
unsigned char DSOLOCAL *do_hash_link(modsec_rec *msr, char *link,
|
||||
|
Loading…
x
Reference in New Issue
Block a user