bcrypt

bcrypt with a threadpool
git clone https://noulin.net/git/bcrypt.git
Log | Files | Refs | README | LICENSE

commit d58f7265ced47c79b87b75564935a0d2ee96b8f6
parent 747c68570fa8c96a6212ebc1427f5994f19a130b
Author: Remy Noulin <loader2x@gmail.com>
Date:   Tue, 11 Sep 2018 09:24:40 +0200

use hw random number generator when /dev/urandom in not available (chroot envionment)

bcrypt.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

Diffstat:
Mbcrypt.c | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/bcrypt.c b/bcrypt.c @@ -110,8 +110,12 @@ int bcryptGensaltSync(int workfactor, char salt[BCRYPT_HASHSIZE]) char *aux; fd = open("/dev/urandom", O_RDONLY); - if (fd == -1) - return 1; + if (fd == -1) { + u64 *in = (u64*) input; + *(in++) = randomWordFromHW(); + *(in++) = randomWordFromHW(); + goto gensalt; + } if (try_read(fd, input, RANDBYTES) != 0) { if (try_close(fd) != 0) @@ -123,6 +127,7 @@ int bcryptGensaltSync(int workfactor, char salt[BCRYPT_HASHSIZE]) return 3; /* Generate salt. */ + gensalt: workf = (workfactor < 4 || workfactor > 31)?12:workfactor; aux = crypt_gensalt_rn("$2b$", workf, input, RANDBYTES, salt, BCRYPT_HASHSIZE);