aboutsummaryrefslogtreecommitdiff
path: root/lib/password.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2018-07-04 18:49:03 -0500
committerRob Landley <rob@landley.net>2018-07-04 18:49:03 -0500
commitff2d528a0a6943bd4247f3c122c145a5b19f0387 (patch)
treee79c2baaa076a33deea48e65cf158b62ec6490da /lib/password.c
parent4d673c9ad4c65c329a85ebb19c2812ae93183099 (diff)
downloadtoybox-ff2d528a0a6943bd4247f3c122c145a5b19f0387.tar.gz
Add xgetrandom() with probe for new system call (else open/read /dev/{,u}random)
Diffstat (limited to 'lib/password.c')
-rw-r--r--lib/password.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/lib/password.c b/lib/password.c
index eab2d669..20c2f481 100644
--- a/lib/password.c
+++ b/lib/password.c
@@ -8,7 +8,7 @@
#include "toys.h"
#include <time.h>
-// generate appropriate random salt string for given encryption algorithm.
+// generate ID prefix and random salt for given encryption algorithm.
int get_salt(char *salt, char *algo)
{
struct {
@@ -24,9 +24,7 @@ int get_salt(char *salt, char *algo)
if (al[i].id) s += sprintf(s, "$%c$", '0'+al[i].id);
// Read appropriate number of random bytes for salt
- i = xopenro("/dev/urandom");
- xreadall(i, libbuf, ((len*6)+7)/8);
- close(i);
+ xgetrandom(libbuf, ((len*6)+7)/8, 0);
// Grab 6 bit chunks and convert to characters in ./0-9a-zA-Z
for (i=0; i<len; i++) {