Browse Source

[core] adjust li_rand_pseudo* interfaces

personal/stbuehler/mod-csrf
Glenn Strauss 4 years ago
parent
commit
6e171bd4b9
  1. 2
      src/mod_auth.c
  2. 2
      src/mod_usertrack.c
  3. 11
      src/rand.c
  4. 3
      src/rand.h

2
src/mod_auth.c

@ -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);

2
src/mod_usertrack.c

@ -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);

11
src/rand.c

@ -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;
}

3
src/rand.h

@ -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