[core] adjust li_rand_pseudo* interfaces

personal/stbuehler/mod-csrf
Glenn Strauss 6 years ago
parent 2bed2c14af
commit 6e171bd4b9

@ -845,7 +845,7 @@ static handler_t mod_auth_send_401_unauthorized_digest(server *srv, connection *
li_itostrn(hh, sizeof(hh), srv->cur_ts);
li_MD5_Update(&Md5Ctx, (unsigned char *)hh, strlen(hh));
li_itostrn(hh, sizeof(hh), li_rand_pseudo_bytes());
li_itostrn(hh, sizeof(hh), li_rand_pseudo());
li_MD5_Update(&Md5Ctx, (unsigned char *)hh, strlen(hh));
li_MD5_Final(h, &Md5Ctx);

@ -236,7 +236,7 @@ URIHANDLER_FUNC(mod_usertrack_uri_handler) {
li_itostrn(hh, sizeof(hh), srv->cur_ts);
li_MD5_Update(&Md5Ctx, (unsigned char *)hh, strlen(hh));
li_itostrn(hh, sizeof(hh), li_rand_pseudo_bytes());
li_itostrn(hh, sizeof(hh), li_rand_pseudo());
li_MD5_Update(&Md5Ctx, (unsigned char *)hh, strlen(hh));
li_MD5_Final(h, &Md5Ctx);

@ -172,7 +172,7 @@ void li_rand_reseed (void)
if (li_rand_inited) li_rand_init();
}
int li_rand_pseudo_bytes (void)
int li_rand_pseudo (void)
{
/* randomness *is not* cryptographically strong */
/* (attempt to use better mechanisms to replace the more portable rand()) */
@ -198,6 +198,12 @@ int li_rand_pseudo_bytes (void)
#endif
}
void li_rand_pseudo_bytes (unsigned char *buf, int num)
{
for (int i = 0; i < num; ++i)
buf[i] = li_rand_pseudo() & 0xFF;
}
int li_rand_bytes (unsigned char *buf, int num)
{
#ifdef USE_OPENSSL_CRYPTO
@ -211,8 +217,7 @@ int li_rand_bytes (unsigned char *buf, int num)
}
else {
/* NOTE: not cryptographically random !!! */
for (int i = 0; i < num; ++i)
buf[i] = li_rand_pseudo_bytes() & 0xFF;
li_rand_pseudo_bytes(buf, num);
/*(openssl RAND_pseudo_bytes rc for non-cryptographically random data)*/
return 0;
}

@ -2,7 +2,8 @@
#define LI_RAND_H_
#include "first.h"
int li_rand_pseudo_bytes (void);
int li_rand_pseudo (void);
void li_rand_pseudo_bytes (unsigned char *buf, int num);
void li_rand_reseed (void);
int li_rand_bytes (unsigned char *buf, int num);
void li_rand_cleanup (void);

Loading…
Cancel
Save