summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2017-09-20 22:48:35 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2017-09-20 22:48:35 -0400
commit6e171bd4b98128e215ad8f13702bd1183cb30edb (patch)
tree79ef6bd6c957dad86484e989a59dcaae008240db
parent2bed2c14afbf6c2d3222b96ef2f8f13421ef8ce5 (diff)
downloadlighttpd1.4-6e171bd4b98128e215ad8f13702bd1183cb30edb.tar.gz
lighttpd1.4-6e171bd4b98128e215ad8f13702bd1183cb30edb.zip
[core] adjust li_rand_pseudo* interfaces
-rw-r--r--src/mod_auth.c2
-rw-r--r--src/mod_usertrack.c2
-rw-r--r--src/rand.c11
-rw-r--r--src/rand.h3
4 files changed, 12 insertions, 6 deletions
diff --git a/src/mod_auth.c b/src/mod_auth.c
index 1cb6a22f..e1b8ed51 100644
--- a/src/mod_auth.c
+++ b/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);
diff --git a/src/mod_usertrack.c b/src/mod_usertrack.c
index 3cd76289..a5098561 100644
--- a/src/mod_usertrack.c
+++ b/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);
diff --git a/src/rand.c b/src/rand.c
index be63c922..10cd0252 100644
--- a/src/rand.c
+++ b/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;
}
diff --git a/src/rand.h b/src/rand.h
index c7bcba23..d80f6a12 100644
--- a/src/rand.h
+++ b/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);